Skip to content

Commit 902f5a2

Browse files
rscharfegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0aaf05b commit 902f5a2

File tree

1 file changed

+2
-19
lines changed

1 file changed

+2
-19
lines changed

sha1_name.c

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -150,31 +150,14 @@ static int match_sha(unsigned len, const unsigned char *a, const unsigned char *
150150
static void unique_in_pack(struct packed_git *p,
151151
struct disambiguate_state *ds)
152152
{
153-
uint32_t num, last, i, first = 0;
153+
uint32_t num, i, first = 0;
154154
const struct object_id *current = NULL;
155155

156156
if (open_pack_index(p) || !p->num_objects)
157157
return;
158158

159159
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);
178161

179162
/*
180163
* At this point, "first" is the location of the lowest object

0 commit comments

Comments
 (0)