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>

Kirill Smelkov committed Feb 24, 2014 at 20:21 UTC 7e9003c1497d01f2e75a5f3df7303643fb2432c3
1 file changed +3 -32
tree-diff.c
+3 -32
@@ -55,25 +55,7 @@ static int compare_tree_entry(struct tree_desc *t1, struct tree_desc *t2,
55 return 0;
56 }
57
58 -/* A whole sub-tree went away or appeared */
59 -static void show_tree(struct diff_options *opt, const char *prefix,
60 - struct tree_desc *desc, struct strbuf *base)
61 -{
62 - enum interesting match = entry_not_interesting;
63 - for (; desc->size; update_tree_entry(desc)) {
64 - if (match != all_entries_interesting) {
65 - match = tree_entry_interesting(&desc->entry, base, 0,
66 - &opt->pathspec);
67 - if (match == all_entries_not_interesting)
68 - break;
69 - if (match == entry_not_interesting)
70 - continue;
71 - }
72 - show_entry(opt, prefix, desc, base);
73 - }
74 -}
75 -
76 -/* A file entry went away or appeared */
58 +/* An entry went away or appeared */
59 static void show_entry(struct diff_options *opt, const char *prefix,
60 struct tree_desc *desc, struct strbuf *base)
61 {
@@ -85,23 +67,12 @@ static void show_entry(struct diff_options *opt, const char *prefix,
67
68 strbuf_add(base, path, pathlen);
69 if (DIFF_OPT_TST(opt, RECURSIVE) && S_ISDIR(mode)) {
88 - enum object_type type;
89 - struct tree_desc inner;
90 - void *tree;
91 - unsigned long size;
92 -
93 - tree = read_sha1_file(sha1, &type, &size);
94 - if (!tree || type != OBJ_TREE)
95 - die("corrupt tree sha %s", sha1_to_hex(sha1));
96 -
70 if (DIFF_OPT_TST(opt, TREE_IN_RECURSIVE))
71 opt->add_remove(opt, *prefix, mode, sha1, 1, base->buf, 0);
72
73 strbuf_addch(base, '/');
101 -
102 - init_tree_desc(&inner, tree, size);
103 - show_tree(opt, prefix, &inner, base);
104 - free(tree);
74 + diff_tree_sha1(*prefix == '-' ? sha1 : NULL,
75 + *prefix == '+' ? sha1 : NULL, base->buf, opt);
76 } else
77 opt->add_remove(opt, prefix[0], mode, sha1, 1, base->buf, 0);
78