sha1-lookup: handle duplicates in sha1_pos()
If the first 18 bytes of the SHA1's of all entries are the same then sha1_pos() dies and reports that the lower and upper limits of the binary search were the same that this wasn't supposed to happen. This is wrong because the remaining two bytes could still differ. Furthermore: It wouldn't be a problem if they actually were the same, i.e. if all entries have the same SHA1. The code already handles duplicates just fine. Simply remove the erroneous check. Signed-off-by: Rene Scharfe <l.s.r@web.de> Acked-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Oct 1, 2014 at 17:02 UTC
0eb0fb889e2e7e063e7dd8cbee38af106aa195f6
2 files changed
+20
-2
sha1-lookup.c
-2
@@ -84,8 +84,6 @@ int sha1_pos(const unsigned char *sha1, void *table, size_t nr,
84
die("BUG: assertion failed in binary search");
85
}
86
}
87
- if (18 <= ofs)
88
- die("cannot happen -- lo and hi are identical");
87
}
88
89
do {
t/t0064-sha1-array.sh
+20
@@ -71,4 +71,24 @@ test_expect_success 'lookup non-existing entry with duplicates' '
71
test "$n" -lt 0
72
'
73
74
+test_expect_success 'lookup with almost duplicate values' '
75
+ {
76
+ echo "append 5555555555555555555555555555555555555555" &&
77
+ echo "append 555555555555555555555555555555555555555f" &&
78
+ echo20 lookup 55
79
+ } | test-sha1-array >actual &&
80
+ n=$(cat actual) &&
81
+ test "$n" -eq 0
82
+'
83
+
84
+test_expect_success 'lookup with single duplicate value' '
85
+ {
86
+ echo20 append 55 55 &&
87
+ echo20 lookup 55
88
+ } | test-sha1-array >actual &&
89
+ n=$(cat actual) &&
90
+ test "$n" -ge 0 &&
91
+ test "$n" -le 1
92
+'
93
+
94
test_done