aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlookshe <github@lookshe.org>2016-02-02 15:12:42 +0100
committerlookshe <github@lookshe.org>2016-02-02 15:12:42 +0100
commit1ca23059758b5d1af843aa62a4aeb5de5b6bd5c8 (patch)
treed3aec011f2a23c271909a0cce3cea5ef7757dbd7
parent25eb0a096f0887c1d2516dd4b7c5e51fe340e008 (diff)
call read_tree_recursive two times with different context to list directories first
-rw-r--r--ui-tree.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/ui-tree.c b/ui-tree.c
index a8172ac..1f99d97 100644
--- a/ui-tree.c
+++ b/ui-tree.c
@@ -15,6 +15,7 @@ struct walk_tree_context {
char *curr_rev;
char *match_path;
int state;
+ bool dir_mode;
};
struct flatten_walk_tree_context {
@@ -173,6 +174,10 @@ static int ls_item(const unsigned char *sha1, struct strbuf *base,
enum object_type type;
unsigned long size = 0;
+ if ((!S_ISDIR(mode) && walk_tree_ctx->dir_mode) || (S_ISDIR(mode) && !walk_tree_ctx->dir_mode)) {
+ return 0;
+ }
+
name = xstrdup(pathname);
strbuf_addf(&fullpath, "%s%s%s", ctx.qry.path ? ctx.qry.path : "",
ctx.qry.path ? "/" : "", name);
@@ -286,6 +291,9 @@ static void ls_tree(const unsigned char *sha1, char *path, struct walk_tree_cont
}
ls_head();
+ walk_tree_ctx->dir_mode = true;
+ read_tree_recursive(tree, "", 0, 1, &paths, ls_item, walk_tree_ctx);
+ walk_tree_ctx->dir_mode = false;
read_tree_recursive(tree, "", 0, 1, &paths, ls_item, walk_tree_ctx);
ls_tail();
}
@@ -305,11 +313,15 @@ static int walk_tree(const unsigned char *sha1, struct strbuf *base,
if (S_ISDIR(mode)) {
walk_tree_ctx->state = 1;
- ls_head();
+ if (walk_tree_ctx->dir_mode) {
+ ls_head();
+ }
return READ_TREE_RECURSIVE;
} else {
walk_tree_ctx->state = 2;
- print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev);
+ if (walk_tree_ctx->dir_mode) {
+ print_object(sha1, buffer, pathname, walk_tree_ctx->curr_rev);
+ }
return 0;
}
}
@@ -361,6 +373,10 @@ void cgit_print_tree(const char *rev, char *path)
goto cleanup;
}
+ walk_tree_ctx.dir_mode = true;
+ read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
+ walk_tree_ctx.state = 0;
+ walk_tree_ctx.dir_mode = false;
read_tree_recursive(commit->tree, "", 0, 0, &paths, walk_tree, &walk_tree_ctx);
if (walk_tree_ctx.state == 1)
ls_tail();