Skip to content

Commit 0aaf05b

Browse files
derrickstoleegitster
authored andcommitted
sha1_name: use bsearch_pack() for abbreviations
When computing abbreviation lengths for an object ID against a single packfile, the method find_abbrev_len_for_pack() currently implements binary search. This is one of several implementations. One issue with this implementation is that it ignores the fanout table in the pack- index. Translate this binary search to use the existing bsearch_pack() method that correctly uses a fanout table. Due to the use of the fanout table, the abbreviation computation is slightly faster than before. For a fully-repacked copy of the Linux repo, the following 'git log' commands improved: * git log --oneline --parents --raw Before: 59.2s After: 56.9s Rel %: -3.8% * git log --oneline --parents Before: 6.48s After: 5.91s Rel %: -8.9% Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3d475f4 commit 0aaf05b

File tree

1 file changed

+4
-20
lines changed

1 file changed

+4
-20
lines changed

sha1_name.c

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -512,32 +512,16 @@ static void find_abbrev_len_for_pack(struct packed_git *p,
512512
struct min_abbrev_data *mad)
513513
{
514514
int match = 0;
515-
uint32_t num, last, first = 0;
515+
uint32_t num, first = 0;
516516
struct object_id oid;
517+
const struct object_id *mad_oid;
517518

518519
if (open_pack_index(p) || !p->num_objects)
519520
return;
520521

521522
num = p->num_objects;
522-
last = num;
523-
while (first < last) {
524-
uint32_t mid = first + (last - first) / 2;
525-
const unsigned char *current;
526-
int cmp;
527-
528-
current = nth_packed_object_sha1(p, mid);
529-
cmp = hashcmp(mad->oid->hash, current);
530-
if (!cmp) {
531-
match = 1;
532-
first = mid;
533-
break;
534-
}
535-
if (cmp > 0) {
536-
first = mid + 1;
537-
continue;
538-
}
539-
last = mid;
540-
}
523+
mad_oid = mad->oid;
524+
match = bsearch_pack(mad_oid, p, &first);
541525

542526
/*
543527
* first is now the position in the packfile where we would insert

0 commit comments

Comments
 (0)