Skip to content

Commit b96c396

Browse files
committed
Merge branch 'sg/diff-multiple-identical-renames' into maint
"git diff -M" used to work better when two originally identical files A and B got renamed to X/A and X/B by pairing A to X/A and B to X/B, but this was broken in the 2.0 timeframe. * sg/diff-multiple-identical-renames: diffcore: fix iteration order of identical files during rename detection
2 parents 3bb56a9 + ca4e3ca commit b96c396

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

diffcore-rename.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,9 +340,11 @@ static int find_exact_renames(struct diff_options *options)
340340
int i, renames = 0;
341341
struct hashmap file_table;
342342

343-
/* Add all sources to the hash table */
343+
/* Add all sources to the hash table in reverse order, because
344+
* later on they will be retrieved in LIFO order.
345+
*/
344346
hashmap_init(&file_table, NULL, rename_src_nr);
345-
for (i = 0; i < rename_src_nr; i++)
347+
for (i = rename_src_nr-1; i >= 0; i--)
346348
insert_file_table(&file_table, i, rename_src[i].p->one);
347349

348350
/* Walk the destinations and find best source match */

t/t4001-diff-rename.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,17 @@ test_expect_success 'favour same basenames even with minor differences' '
7777
git show HEAD:path1 | sed "s/15/16/" > subdir/path1 &&
7878
git status | test_i18ngrep "renamed: .*path1 -> subdir/path1"'
7979

80+
test_expect_success 'two files with same basename and same content' '
81+
git reset --hard &&
82+
mkdir -p dir/A dir/B &&
83+
cp path1 dir/A/file &&
84+
cp path1 dir/B/file &&
85+
git add dir &&
86+
git commit -m 2 &&
87+
git mv dir other-dir &&
88+
git status | test_i18ngrep "renamed: .*dir/A/file -> other-dir/A/file"
89+
'
90+
8091
test_expect_success 'setup for many rename source candidates' '
8192
git reset --hard &&
8293
for i in 0 1 2 3 4 5 6 7 8 9;

0 commit comments

Comments
 (0)