Skip to content

Commit

Permalink
bisect: automatically sort sha1_array if needed when looking it up
Browse files Browse the repository at this point in the history
This makes sha1_array easier to use, so later patches will be simpler.

Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Christian Couder authored and Junio C Hamano committed May 10, 2009
1 parent aaaff9e commit 1da8c4f
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions bisect.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct sha1_array {
unsigned char (*sha1)[20];
int sha1_nr;
int sha1_alloc;
int sorted;
};

static struct sha1_array good_revs;
Expand Down Expand Up @@ -487,6 +488,8 @@ static int array_cmp(const void *a, const void *b)
static void sort_sha1_array(struct sha1_array *array)
{
qsort(array->sha1, array->sha1_nr, sizeof(*array->sha1), array_cmp);

array->sorted = 1;
}

static const unsigned char *sha1_access(size_t index, void *table)
Expand All @@ -498,6 +501,9 @@ static const unsigned char *sha1_access(size_t index, void *table)
static int lookup_sha1_array(struct sha1_array *array,
const unsigned char *sha1)
{
if (!array->sorted)
sort_sha1_array(array);

return sha1_pos(sha1, array->sha1, array->sha1_nr, sha1_access);
}

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

sort_sha1_array(&skipped_revs);

while (list) {
struct commit_list *next = list->next;
list->next = NULL;
Expand Down

0 comments on commit 1da8c4f

Please sign in to comment.