Skip to content

Commit 1da8c4f

Browse files
chriscoolgitster
authored andcommitted
bisect: automatically sort sha1_array if needed when looking it up
This makes sha1_array easier to use, so later patches will be simpler. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aaaff9e commit 1da8c4f

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

bisect.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ struct sha1_array {
1313
unsigned char (*sha1)[20];
1414
int sha1_nr;
1515
int sha1_alloc;
16+
int sorted;
1617
};
1718

1819
static struct sha1_array good_revs;
@@ -487,6 +488,8 @@ static int array_cmp(const void *a, const void *b)
487488
static void sort_sha1_array(struct sha1_array *array)
488489
{
489490
qsort(array->sha1, array->sha1_nr, sizeof(*array->sha1), array_cmp);
491+
492+
array->sorted = 1;
490493
}
491494

492495
static const unsigned char *sha1_access(size_t index, void *table)
@@ -498,6 +501,9 @@ static const unsigned char *sha1_access(size_t index, void *table)
498501
static int lookup_sha1_array(struct sha1_array *array,
499502
const unsigned char *sha1)
500503
{
504+
if (!array->sorted)
505+
sort_sha1_array(array);
506+
501507
return sha1_pos(sha1, array->sha1, array->sha1_nr, sha1_access);
502508
}
503509

@@ -512,8 +518,6 @@ struct commit_list *filter_skipped(struct commit_list *list,
512518
if (!skipped_revs.sha1_nr)
513519
return list;
514520

515-
sort_sha1_array(&skipped_revs);
516-
517521
while (list) {
518522
struct commit_list *next = list->next;
519523
list->next = NULL;

0 commit comments

Comments
 (0)