diff --git a/diffcore-delta.c b/diffcore-delta.c index c30b56e983bda3..7136c3dd203592 100644 --- a/diffcore-delta.c +++ b/diffcore-delta.c @@ -159,6 +159,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 3dc90470446dbb..5c61f2cce420ca 100755 --- a/t/t4001-diff-rename.sh +++ b/t/t4001-diff-rename.sh @@ -286,4 +286,23 @@ 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 >nonewline && + printf "git ignores final up to 63 characters if not newline terminated" >>nonewline && + git add nonewline && + 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 >nonewline && + printf "git ignores final up to 63 characters if not newline terminated" >>nonewline && + git add nonewline && + git mv nonewline still-no-newline && + git commit -a -m "rename nonewline -> still-no-newline" && + git diff-tree -r -M01 --name-status HEAD^ HEAD >actual && + cat >expected <<-\EOF && + R097 nonewline still-no-newline + EOF + test_cmp expected actual +' + test_done