summaryrefslogtreecommitdiff
path: root/tree-diff.c
diff options
context:
space:
mode:
authorKirill Smelkov <kirr@mns.spb.ru>2014-02-24 20:21:37 +0400
committerJunio C Hamano <gitster@pobox.com>2014-03-04 13:33:47 -0800
commit7e9003c1497d01f2e75a5f3df7303643fb2432c3 (patch)
treefde09d5b9bfbeb6f6fc2cee5db1da33d0a3fbc3a /tree-diff.c
parente906612121bc9d436a3a64cd03be0537654e800c (diff)
downloadgit-7e9003c1497d01f2e75a5f3df7303643fb2432c3.tar.gz
tree-diff: show_tree() is not needed
We don't need special code for showing added/removed subtree, because we can do the same via diff_tree_sha1, just passing NULL for absent tree. And compared to show_tree(), which was calling show_entry() for every tree entry, that would lead to the same show_entry() callings: show_tree(t): for e in t.entries: show_entry(e) diff_tree_sha1(NULL, new): /* the same applies to (old, NULL) */ diff_tree(t1=NULL, t2) ... if (!t1->size) show_entry(t2) ... and possible overhead is negligible, since after the patch, timing for `git log --raw --no-abbrev --no-renames` for navy.git and `linux.git v3.10..v3.11` is practically the same. So let's say goodbye to show_tree() - it removes some code, but also, and what is important, consolidates more code for showing/recursing into trees into one place. Signed-off-by: Kirill Smelkov <kirr@mns.spb.ru> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'tree-diff.c')
-rw-r--r--tree-diff.c35
1 files changed, 3 insertions, 32 deletions
diff --git a/tree-diff.c b/tree-diff.c
index a8c2aecd1d..2ad778884a 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -55,25 +55,7 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2,
return 0;
}
-/* A whole sub-tree went away or appeared */
-static void show_tree(struct diff_options *opt, const char *prefix,
- struct tree_desc *desc, struct strbuf *base)
-{
- enum interesting match = entry_not_interesting;
- for (; desc->size; update_tree_entry(desc)) {
- if (match != all_entries_interesting) {
- match = tree_entry_interesting(&desc->entry, base, 0,
- &opt->pathspec);
- if (match == all_entries_not_interesting)
- break;
- if (match == entry_not_interesting)
- continue;
- }
- show_entry(opt, prefix, desc, base);
- }
-}
-
-/* A file entry went away or appeared */
+/* An entry went away or appeared */
static void show_entry(struct diff_options *opt, const char *prefix,
struct tree_desc *desc, struct strbuf *base)
{
@@ -85,23 +67,12 @@ static void show_entry(struct diff_options *opt, const char *prefix,
strbuf_add(base, path, pathlen);
if (DIFF_OPT_TST(opt, RECURSIVE) && S_ISDIR(mode)) {
- enum object_type type;
- struct tree_desc inner;
- void *tree;
- unsigned long size;
-
- tree = read_sha1_file(sha1, &type, &size);
- if (!tree || type != OBJ_TREE)
- die("corrupt tree sha %s", sha1_to_hex(sha1));
-
if (DIFF_OPT_TST(opt, TREE_IN_RECURSIVE))
opt->add_remove(opt, *prefix, mode, sha1, 1, base->buf, 0);
strbuf_addch(base, '/');
-
- init_tree_desc(&inner, tree, size);
- show_tree(opt, prefix, &inner, base);
- free(tree);
+ diff_tree_sha1(*prefix == '-' ? sha1 : NULL,
+ *prefix == '+' ? sha1 : NULL, base->buf, opt);
} else
opt->add_remove(opt, prefix[0], mode, sha1, 1, base->buf, 0);