bisect: use argv_array API

Now that the argv_array API exists, we can save some lines of code. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 13, 2011 at 17:58 UTC 8a534b612410b9746ef33af9e4631fc18bd77621
1 file changed +11 -37
bisect.c
+11 -37
@@ -10,18 +10,13 @@
10 #include "log-tree.h"
11 #include "bisect.h"
12 #include "sha1-array.h"
13 +#include "argv-array.h"
14
15 static struct sha1_array good_revs;
16 static struct sha1_array skipped_revs;
17
18 static const unsigned char *current_bad_sha1;
19
19 -struct argv_array {
20 - const char **argv;
21 - int argv_nr;
22 - int argv_alloc;
23 -};
24 -
20 static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
21 static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
22
@@ -404,21 +399,6 @@ struct commit_list *find_bisection(struct commit_list *list,
399 return best;
400 }
401
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 -
402 static int register_ref(const char *refname, const unsigned char *sha1,
403 int flags, void *cb_data)
404 {
@@ -448,16 +428,10 @@ static void read_bisect_paths(struct argv_array *array)
428 die_errno("Could not open file '%s'", filename);
429
430 while (strbuf_getline(&str, fp, '\n') != EOF) {
451 - char *quoted;
452 - int res;
453 -
431 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))
433 die("Badly quoted content in file '%s': %s",
460 - filename, quoted);
434 + filename, str.buf);
435 }
436
437 strbuf_release(&str);
@@ -622,7 +596,7 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
596 const char *bad_format, const char *good_format,
597 int read_paths)
598 {
625 - struct argv_array rev_argv = { NULL, 0, 0 };
599 + struct argv_array rev_argv = ARGV_ARRAY_INIT;
600 int i;
601
602 init_revisions(revs, prefix);
@@ -630,17 +604,17 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
604 revs->commit_format = CMIT_FMT_UNSPECIFIED;
605
606 /* 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));
609 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, "--");
613 if (read_paths)
614 read_bisect_paths(&rev_argv);
641 - argv_array_push(&rev_argv, NULL);
615
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 */
618 }
619
620 static void bisect_common(struct rev_info *revs)