Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2024-01-22 20:26:18 +0300
committerJunio C Hamano <gitster@pobox.com>2024-01-22 20:26:18 +0300
commit7141d202cbb3eddb9d48e4cb1daf1e153a69c065 (patch)
treecb325e9025a82e6251a8361cf9c24311a9b329eb
parentf70f463847d9f9f0fd78ea445d473905f2aad8fe (diff)
parent1c5bc6971e28c581b17b812cbbd1f09e39f0bb63 (diff)
Merge branch 'en/diffcore-delta-final-line-fix' into next
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
-rw-r--r--diffcore-delta.c4
-rwxr-xr-xt/t4001-diff-rename.sh24
2 files changed, 28 insertions, 0 deletions
diff --git a/diffcore-delta.c b/diffcore-delta.c
index 4927ab8fb0..ba6cbee76b 100644
--- a/diffcore-delta.c
+++ b/diffcore-delta.c
@@ -158,6 +158,10 @@ static struct spanhash_top *hash_chars(struct repository *r,
n = 0;
accum1 = accum2 = 0;
}
+ if (n > 0) {
+ hashval = (accum1 + accum2 * 0x61) % HASHBASE;
+ hash = add_spanhash(hash, hashval, n);
+ }
QSORT(hash->data, (size_t)1ul << hash->alloc_log2, spanhash_cmp);
return hash;
}
diff --git a/t/t4001-diff-rename.sh b/t/t4001-diff-rename.sh
index 85be1367de..49c042a38a 100755
--- a/t/t4001-diff-rename.sh
+++ b/t/t4001-diff-rename.sh
@@ -286,4 +286,28 @@ test_expect_success 'basename similarity vs best similarity' '
test_cmp expected actual
'
+test_expect_success 'last line matters too' '
+ {
+ test_write_lines a 0 1 2 3 4 5 6 7 8 9 &&
+ printf "git ignores final up to 63 characters if not newline terminated"
+ } >no-final-lf &&
+ git add no-final-lf &&
+ git commit -m "original version of file with no final newline" &&
+
+ # Change ONLY the first character of the whole file
+ {
+ test_write_lines b 0 1 2 3 4 5 6 7 8 9 &&
+ printf "git ignores final up to 63 characters if not newline terminated"
+ } >no-final-lf &&
+ git add no-final-lf &&
+ git mv no-final-lf still-absent-final-lf &&
+ git commit -a -m "rename no-final-lf -> still-absent-final-lf" &&
+ git diff-tree -r -M --name-status HEAD^ HEAD >actual &&
+ sed -e "s/^R[0-9]* /R /" actual >actual.munged &&
+ cat >expected <<-\EOF &&
+ R no-final-lf still-absent-final-lf
+ EOF
+ test_cmp expected actual.munged
+'
+
test_done