Skip to content

Commit 39f75d2

Browse files
committed
diff --follow: do not waste cycles while recursing
The "--follow" logic is called from diff_tree_sha1() function, but the input trees to diff_tree_sha1() are not necessarily the top-level trees (compare_tree_entry() calls it while it recursively descends into subtrees). When a newly created path lives in somewhere deep in the source hierarchy, e.g. "platform/", but the rename source is in a totally different place in the destination hierarchy, e.g. "lang-api/src/com/...", running "try_to_find_renames()" while base is set to "platform/" is a wasted call. We only need to run the rename following at the very top level. Signed-off-by: Junio C Hamano <[email protected]> Acked-by: Linus Torvalds <[email protected]>
1 parent 452c6d5 commit 39f75d2

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

tree-diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ int diff_tree_sha1(const unsigned char *old, const unsigned char *new, const cha
412412
init_tree_desc(&t1, tree1, size1);
413413
init_tree_desc(&t2, tree2, size2);
414414
retval = diff_tree(&t1, &t2, base, opt);
415-
if (DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename()) {
415+
if (!*base && DIFF_OPT_TST(opt, FOLLOW_RENAMES) && diff_might_be_rename()) {
416416
init_tree_desc(&t1, tree1, size1);
417417
init_tree_desc(&t2, tree2, size2);
418418
try_to_follow_renames(&t1, &t2, base, opt);

0 commit comments

Comments
 (0)