Git fork

diffcore-delta: avoid ignoring final 'line' of file

hash_chars() would hash lines to integers, and store them in a spanhash,
but cut lines at 64 characters. Thus, whenever it reached 64 characters
or a newline, it would create a new spanhash. The problem is, the final
part of the file might not end 64 characters after the previous 'line'
and might not end with a newline. This could, for example, cause an
85-byte file with 12 lines and only the first character in the file
differing to appear merely 23% similar rather than the expected 97%.
Ensure the last line is included, and add a testcase that would have
caught this problem.

Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Elijah Newren and committed by
Junio C Hamano
1c5bc697 ec583449

+28
+4
diffcore-delta.c
··· 159 159 n = 0; 160 160 accum1 = accum2 = 0; 161 161 } 162 + if (n > 0) { 163 + hashval = (accum1 + accum2 * 0x61) % HASHBASE; 164 + hash = add_spanhash(hash, hashval, n); 165 + } 162 166 QSORT(hash->data, (size_t)1ul << hash->alloc_log2, spanhash_cmp); 163 167 return hash; 164 168 }
+24
t/t4001-diff-rename.sh
··· 286 286 test_cmp expected actual 287 287 ' 288 288 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 + 289 313 test_done