Skip to content

Commit fad2d31

Browse files
chriscoolgitster
authored andcommitted
bisect: store good revisions in a "sha1_array"
This will make it easier to use good revisions for checking merge bases later. To simplify the code, a new "sha1_array_push" function is also introduced. And while at it we move the earlier part of the code to fill the argv that is passed to "setup_revisions", so that all this code is now completely after "read_bisect_refs". Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3755ccd commit fad2d31

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

bisect.c

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ struct sha1_array {
1515
int sha1_alloc;
1616
};
1717

18+
static struct sha1_array good_revs;
1819
static struct sha1_array skipped_revs;
1920

2021
static const char **rev_argv;
@@ -418,18 +419,22 @@ static void rev_argv_push(const unsigned char *sha1, const char *format)
418419
rev_argv[rev_argv_nr++] = strbuf_detach(&buf, NULL);
419420
}
420421

422+
static void sha1_array_push(struct sha1_array *array,
423+
const unsigned char *sha1)
424+
{
425+
ALLOC_GROW(array->sha1, array->sha1_nr + 1, array->sha1_alloc);
426+
hashcpy(array->sha1[array->sha1_nr++], sha1);
427+
}
428+
421429
static int register_ref(const char *refname, const unsigned char *sha1,
422430
int flags, void *cb_data)
423431
{
424432
if (!strcmp(refname, "bad")) {
425433
current_bad_sha1 = sha1;
426-
rev_argv_push(sha1, "%s");
427434
} else if (!prefixcmp(refname, "good-")) {
428-
rev_argv_push(sha1, "^%s");
435+
sha1_array_push(&good_revs, sha1);
429436
} else if (!prefixcmp(refname, "skip-")) {
430-
ALLOC_GROW(skipped_revs.sha1, skipped_revs.sha1_nr + 1,
431-
skipped_revs.sha1_alloc);
432-
hashcpy(skipped_revs.sha1[skipped_revs.sha1_nr++], sha1);
437+
sha1_array_push(&skipped_revs, sha1);
433438
}
434439

435440
return 0;
@@ -524,16 +529,23 @@ struct commit_list *filter_skipped(struct commit_list *list,
524529

525530
static void bisect_rev_setup(struct rev_info *revs, const char *prefix)
526531
{
532+
int i;
533+
527534
init_revisions(revs, prefix);
528535
revs->abbrev = 0;
529536
revs->commit_format = CMIT_FMT_UNSPECIFIED;
530537

538+
if (read_bisect_refs())
539+
die("reading bisect refs failed");
540+
531541
/* argv[0] will be ignored by setup_revisions */
532542
ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
533543
rev_argv[rev_argv_nr++] = xstrdup("bisect_rev_setup");
534544

535-
if (read_bisect_refs())
536-
die("reading bisect refs failed");
545+
rev_argv_push(current_bad_sha1, "%s");
546+
547+
for (i = 0; i < good_revs.sha1_nr; i++)
548+
rev_argv_push(good_revs.sha1[i], "^%s");
537549

538550
ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
539551
rev_argv[rev_argv_nr++] = xstrdup("--");

0 commit comments

Comments
 (0)