sha1_name: use bsearch_pack() in unique_in_pack()

Replace the custom binary search in unique_in_pack() with a call to bsearch_pack(). This reduces code duplication and makes use of the fan-out table of packs. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Mar 24, 2018 at 17:41 UTC 902f5a2119089472c905407cb0a9b3886d032ebd
1 file changed +2 -19
sha1_name.c
+2 -19
@@ -150,31 +150,14 @@ static int match_sha(unsigned len, const unsigned char *a, const unsigned char *
150 static void unique_in_pack(struct packed_git *p,
151 struct disambiguate_state *ds)
152 {
153 - uint32_t num, last, i, first = 0;
153 + uint32_t num, i, first = 0;
154 const struct object_id *current = NULL;
155
156 if (open_pack_index(p) || !p->num_objects)
157 return;
158
159 num = p->num_objects;
160 - last = num;
161 - while (first < last) {
162 - uint32_t mid = first + (last - first) / 2;
163 - const unsigned char *current;
164 - int cmp;
165 -
166 - current = nth_packed_object_sha1(p, mid);
167 - cmp = hashcmp(ds->bin_pfx.hash, current);
168 - if (!cmp) {
169 - first = mid;
170 - break;
171 - }
172 - if (cmp > 0) {
173 - first = mid+1;
174 - continue;
175 - }
176 - last = mid;
177 - }
160 + bsearch_pack(&ds->bin_pfx, p, &first);
161
162 /*
163 * At this point, "first" is the location of the lowest object