Skip to content

Commit 8a534b6

Browse files
peffgitster
authored andcommitted
bisect: use argv_array API
Now that the argv_array API exists, we can save some lines of code. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 37e8161 commit 8a534b6

File tree

1 file changed

+11
-37
lines changed

1 file changed

+11
-37
lines changed

bisect.c

Lines changed: 11 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,13 @@
1010
#include "log-tree.h"
1111
#include "bisect.h"
1212
#include "sha1-array.h"
13+
#include "argv-array.h"
1314

1415
static struct sha1_array good_revs;
1516
static struct sha1_array skipped_revs;
1617

1718
static const unsigned char *current_bad_sha1;
1819

19-
struct argv_array {
20-
const char **argv;
21-
int argv_nr;
22-
int argv_alloc;
23-
};
24-
2520
static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
2621
static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
2722

@@ -404,21 +399,6 @@ struct commit_list *find_bisection(struct commit_list *list,
404399
return best;
405400
}
406401

407-
static void argv_array_push(struct argv_array *array, const char *string)
408-
{
409-
ALLOC_GROW(array->argv, array->argv_nr + 1, array->argv_alloc);
410-
array->argv[array->argv_nr++] = string;
411-
}
412-
413-
static void argv_array_push_sha1(struct argv_array *array,
414-
const unsigned char *sha1,
415-
const char *format)
416-
{
417-
struct strbuf buf = STRBUF_INIT;
418-
strbuf_addf(&buf, format, sha1_to_hex(sha1));
419-
argv_array_push(array, strbuf_detach(&buf, NULL));
420-
}
421-
422402
static int register_ref(const char *refname, const unsigned char *sha1,
423403
int flags, void *cb_data)
424404
{
@@ -448,16 +428,10 @@ static void read_bisect_paths(struct argv_array *array)
448428
die_errno("Could not open file '%s'", filename);
449429

450430
while (strbuf_getline(&str, fp, '\n') != EOF) {
451-
char *quoted;
452-
int res;
453-
454431
strbuf_trim(&str);
455-
quoted = strbuf_detach(&str, NULL);
456-
res = sq_dequote_to_argv(quoted, &array->argv,
457-
&array->argv_nr, &array->argv_alloc);
458-
if (res)
432+
if (sq_dequote_to_argv_array(str.buf, array))
459433
die("Badly quoted content in file '%s': %s",
460-
filename, quoted);
434+
filename, str.buf);
461435
}
462436

463437
strbuf_release(&str);
@@ -622,25 +596,25 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
622596
const char *bad_format, const char *good_format,
623597
int read_paths)
624598
{
625-
struct argv_array rev_argv = { NULL, 0, 0 };
599+
struct argv_array rev_argv = ARGV_ARRAY_INIT;
626600
int i;
627601

628602
init_revisions(revs, prefix);
629603
revs->abbrev = 0;
630604
revs->commit_format = CMIT_FMT_UNSPECIFIED;
631605

632606
/* rev_argv.argv[0] will be ignored by setup_revisions */
633-
argv_array_push(&rev_argv, xstrdup("bisect_rev_setup"));
634-
argv_array_push_sha1(&rev_argv, current_bad_sha1, bad_format);
607+
argv_array_push(&rev_argv, "bisect_rev_setup");
608+
argv_array_pushf(&rev_argv, bad_format, sha1_to_hex(current_bad_sha1));
635609
for (i = 0; i < good_revs.nr; i++)
636-
argv_array_push_sha1(&rev_argv, good_revs.sha1[i],
637-
good_format);
638-
argv_array_push(&rev_argv, xstrdup("--"));
610+
argv_array_pushf(&rev_argv, good_format,
611+
sha1_to_hex(good_revs.sha1[i]));
612+
argv_array_push(&rev_argv, "--");
639613
if (read_paths)
640614
read_bisect_paths(&rev_argv);
641-
argv_array_push(&rev_argv, NULL);
642615

643-
setup_revisions(rev_argv.argv_nr, rev_argv.argv, revs, NULL);
616+
setup_revisions(rev_argv.argc, rev_argv.argv, revs, NULL);
617+
/* XXX leak rev_argv, as "revs" may still be pointing to it */
644618
}
645619

646620
static void bisect_common(struct rev_info *revs)

0 commit comments

Comments
 (0)