Skip to content

Commit 8997355

Browse files
jonathantanmygitster
authored andcommitted
diffcore-rename: make diff-tree -l0 mean -l<large>
In the documentation of diff-tree, it is stated that the -l option "prevents rename/copy detection from running if the number of rename/copy targets exceeds the specified number". The documentation does not mention any special handling for the number 0, but the implementation before commit 9f7e4bf ("diff: remove silent clamp of renameLimit", 2017-11-13) treated 0 as a special value indicating that the rename limit is to be a very large number instead. The commit 9f7e4bf changed that behavior, treating 0 as 0. Revert this behavior to what it was previously. This allows existing scripts and tools that use "-l0" to continue working. The alternative (to have "-l0" suppress rename detection) is probably much less useful, since users can just refrain from specifying -M and/or -C to have the same effect. Signed-off-by: Jonathan Tan <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Reviewed-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9268cf4 commit 8997355

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

diffcore-rename.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ static int too_many_rename_candidates(int num_create,
392392
*
393393
* num_create * num_src > rename_limit * rename_limit
394394
*/
395+
if (rename_limit <= 0)
396+
rename_limit = 32767;
395397
if ((num_create <= rename_limit || num_src <= rename_limit) &&
396398
((uint64_t)num_create * (uint64_t)num_src
397399
<= (uint64_t)rename_limit * (uint64_t)rename_limit))

t/t4001-diff-rename.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,4 +230,19 @@ test_expect_success 'rename pretty print common prefix and suffix overlap' '
230230
test_i18ngrep " d/f/{ => f}/e " output
231231
'
232232

233+
test_expect_success 'diff-tree -l0 defaults to a big rename limit, not zero' '
234+
test_write_lines line1 line2 line3 >myfile &&
235+
git add myfile &&
236+
git commit -m x &&
237+
238+
test_write_lines line1 line2 line4 >myotherfile &&
239+
git rm myfile &&
240+
git add myotherfile &&
241+
git commit -m x &&
242+
243+
git diff-tree -M -l0 HEAD HEAD^ >actual &&
244+
# Verify that a rename from myotherfile to myfile was detected
245+
grep "myotherfile.*myfile" actual
246+
'
247+
233248
test_done

0 commit comments

Comments
 (0)