Skip to content

Commit 3755ccd

Browse files
chriscoolgitster
authored andcommitted
bisect: implement "rev_argv_push" to fill an argv with revs
This patch is a minor clean up right now, but the new function will evolve and be used more later. Signed-off-by: Christian Couder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6212b1a commit 3755ccd

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

bisect.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -409,20 +409,23 @@ struct commit_list *find_bisection(struct commit_list *list,
409409
return best;
410410
}
411411

412+
static void rev_argv_push(const unsigned char *sha1, const char *format)
413+
{
414+
struct strbuf buf = STRBUF_INIT;
415+
416+
strbuf_addf(&buf, format, sha1_to_hex(sha1));
417+
ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
418+
rev_argv[rev_argv_nr++] = strbuf_detach(&buf, NULL);
419+
}
420+
412421
static int register_ref(const char *refname, const unsigned char *sha1,
413422
int flags, void *cb_data)
414423
{
415424
if (!strcmp(refname, "bad")) {
416-
ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
417425
current_bad_sha1 = sha1;
418-
rev_argv[rev_argv_nr++] = xstrdup(sha1_to_hex(sha1));
426+
rev_argv_push(sha1, "%s");
419427
} else if (!prefixcmp(refname, "good-")) {
420-
const char *hex = sha1_to_hex(sha1);
421-
char *good = xmalloc(strlen(hex) + 2);
422-
*good = '^';
423-
memcpy(good + 1, hex, strlen(hex) + 1);
424-
ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
425-
rev_argv[rev_argv_nr++] = good;
428+
rev_argv_push(sha1, "^%s");
426429
} else if (!prefixcmp(refname, "skip-")) {
427430
ALLOC_GROW(skipped_revs.sha1, skipped_revs.sha1_nr + 1,
428431
skipped_revs.sha1_alloc);

0 commit comments

Comments
 (0)