1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
cgit: list directories and submodules first, then everything else
The tree view lists entries in the tree's order. This reads the tree
twice instead, first for directories and submodules, then for the rest,
both at the root and in a subdirectory.
diff --git a/ui-tree.c b/ui-tree.c
index 5ac8c9a..6491c47 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -281,6 +281,34 @@ cleanup:
return 0;
}
+/* Directories and submodules first, then everything else. */
+static int is_dir_like(unsigned mode)
+{
+ return S_ISDIR(mode) || S_ISGITLINK(mode);
+}
+
+static int ls_dir_item(const struct object_id *oid, struct strbuf *base,
+ const char *pathname, unsigned mode, void *cbdata)
+{
+ return is_dir_like(mode) ? ls_item(oid, base, pathname, mode, cbdata) : 0;
+}
+
+static int ls_other_item(const struct object_id *oid, struct strbuf *base,
+ const char *pathname, unsigned mode, void *cbdata)
+{
+ return is_dir_like(mode) ? 0 : ls_item(oid, base, pathname, mode, cbdata);
+}
+
+static void ls_entries(struct tree *tree, struct walk_tree_context *walk_tree_ctx)
+{
+ struct pathspec paths = {
+ .nr = 0
+ };
+
+ read_tree(the_repository, tree, &paths, ls_dir_item, walk_tree_ctx);
+ read_tree(the_repository, tree, &paths, ls_other_item, walk_tree_ctx);
+}
+
static void ls_head(void)
{
cgit_print_layout_start();
@@ -302,9 +330,6 @@ static void ls_tail(void)
static void ls_tree(const struct object_id *oid, const char *path, struct walk_tree_context *walk_tree_ctx)
{
struct tree *tree;
- struct pathspec paths = {
- .nr = 0
- };
tree = parse_tree_indirect(oid);
if (!tree) {
@@ -314,7 +339,7 @@ static void ls_tree(const struct object_id *oid, const char *path, struct walk_t
}
ls_head();
- read_tree(the_repository, tree, &paths, ls_item, walk_tree_ctx);
+ ls_entries(tree, walk_tree_ctx);
ls_tail();
}
@@ -333,11 +358,15 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base,
return READ_TREE_RECURSIVE;
if (S_ISDIR(mode)) {
+ struct tree *tree = parse_tree_indirect(oid);
+
walk_tree_ctx->state = 1;
cgit_set_title_from_path(buffer.buf);
strbuf_release(&buffer);
ls_head();
- return READ_TREE_RECURSIVE;
+ if (tree)
+ ls_entries(tree, walk_tree_ctx);
+ return 0;
} else {
walk_tree_ctx->state = 2;
print_object(oid, buffer.buf, pathname, walk_tree_ctx->curr_rev);
@@ -345,7 +374,6 @@ static int walk_tree(const struct object_id *oid, struct strbuf *base,
return 0;
}
}
- ls_item(oid, base, pathname, mode, walk_tree_ctx);
return 0;
}
|