Skip to content

Commit 904ca69

Browse files
committed
Merge branch 'en/diffcore-delta-final-line-fix' into maint-2.43
Rename detection logic ignored the final line of a file if it is an incomplete line. * en/diffcore-delta-final-line-fix: diffcore-delta: avoid ignoring final 'line' of file
2 parents 908fde1 + 1c5bc69 commit 904ca69

File tree

2 files changed

+28
-0
lines changed

2 files changed

+28
-0
lines changed

diffcore-delta.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,10 @@ static struct spanhash_top *hash_chars(struct repository *r,
158158
n = 0;
159159
accum1 = accum2 = 0;
160160
}
161+
if (n > 0) {
162+
hashval = (accum1 + accum2 * 0x61) % HASHBASE;
163+
hash = add_spanhash(hash, hashval, n);
164+
}
161165
QSORT(hash->data, (size_t)1ul << hash->alloc_log2, spanhash_cmp);
162166
return hash;
163167
}

t/t4001-diff-rename.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,28 @@ test_expect_success 'basename similarity vs best similarity' '
286286
test_cmp expected actual
287287
'
288288

289+
test_expect_success 'last line matters too' '
290+
{
291+
test_write_lines a 0 1 2 3 4 5 6 7 8 9 &&
292+
printf "git ignores final up to 63 characters if not newline terminated"
293+
} >no-final-lf &&
294+
git add no-final-lf &&
295+
git commit -m "original version of file with no final newline" &&
296+
297+
# Change ONLY the first character of the whole file
298+
{
299+
test_write_lines b 0 1 2 3 4 5 6 7 8 9 &&
300+
printf "git ignores final up to 63 characters if not newline terminated"
301+
} >no-final-lf &&
302+
git add no-final-lf &&
303+
git mv no-final-lf still-absent-final-lf &&
304+
git commit -a -m "rename no-final-lf -> still-absent-final-lf" &&
305+
git diff-tree -r -M --name-status HEAD^ HEAD >actual &&
306+
sed -e "s/^R[0-9]* /R /" actual >actual.munged &&
307+
cat >expected <<-\EOF &&
308+
R no-final-lf still-absent-final-lf
309+
EOF
310+
test_cmp expected actual.munged
311+
'
312+
289313
test_done

0 commit comments

Comments
 (0)