aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-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();