diff options
author | Elijah Newren <newren@gmail.com> | 2024-01-13 05:26:13 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-01-19 04:10:11 +0100 |
commit | 1c5bc6971e28c581b17b812cbbd1f09e39f0bb63 (patch) | |
tree | 35205f57d7ae32ab60600d29dcc88857fea51853 /diffcore-delta.c | |
parent | Git 2.38.5 (diff) | |
download | git-1c5bc6971e28c581b17b812cbbd1f09e39f0bb63.tar.xz git-1c5bc6971e28c581b17b812cbbd1f09e39f0bb63.zip |
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>
Diffstat (limited to 'diffcore-delta.c')
-rw-r--r-- | diffcore-delta.c | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/diffcore-delta.c b/diffcore-delta.c index 18d8f766d7..0b45f64400 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; } |