|
10 | 10 | #include "log-tree.h" |
11 | 11 | #include "bisect.h" |
12 | 12 | #include "sha1-array.h" |
| 13 | +#include "argv-array.h" |
13 | 14 |
|
14 | 15 | static struct sha1_array good_revs; |
15 | 16 | static struct sha1_array skipped_revs; |
16 | 17 |
|
17 | 18 | static const unsigned char *current_bad_sha1; |
18 | 19 |
|
19 | | -struct argv_array { |
20 | | - const char **argv; |
21 | | - int argv_nr; |
22 | | - int argv_alloc; |
23 | | -}; |
24 | | - |
25 | 20 | static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL}; |
26 | 21 | static const char *argv_show_branch[] = {"show-branch", NULL, NULL}; |
27 | 22 | static const char *argv_update_ref[] = {"update-ref", "--no-deref", "BISECT_HEAD", NULL, NULL}; |
@@ -405,21 +400,6 @@ struct commit_list *find_bisection(struct commit_list *list, |
405 | 400 | return best; |
406 | 401 | } |
407 | 402 |
|
408 | | -static void argv_array_push(struct argv_array *array, const char *string) |
409 | | -{ |
410 | | - ALLOC_GROW(array->argv, array->argv_nr + 1, array->argv_alloc); |
411 | | - array->argv[array->argv_nr++] = string; |
412 | | -} |
413 | | - |
414 | | -static void argv_array_push_sha1(struct argv_array *array, |
415 | | - const unsigned char *sha1, |
416 | | - const char *format) |
417 | | -{ |
418 | | - struct strbuf buf = STRBUF_INIT; |
419 | | - strbuf_addf(&buf, format, sha1_to_hex(sha1)); |
420 | | - argv_array_push(array, strbuf_detach(&buf, NULL)); |
421 | | -} |
422 | | - |
423 | 403 | static int register_ref(const char *refname, const unsigned char *sha1, |
424 | 404 | int flags, void *cb_data) |
425 | 405 | { |
@@ -449,16 +429,10 @@ static void read_bisect_paths(struct argv_array *array) |
449 | 429 | die_errno("Could not open file '%s'", filename); |
450 | 430 |
|
451 | 431 | while (strbuf_getline(&str, fp, '\n') != EOF) { |
452 | | - char *quoted; |
453 | | - int res; |
454 | | - |
455 | 432 | strbuf_trim(&str); |
456 | | - quoted = strbuf_detach(&str, NULL); |
457 | | - res = sq_dequote_to_argv(quoted, &array->argv, |
458 | | - &array->argv_nr, &array->argv_alloc); |
459 | | - if (res) |
| 433 | + if (sq_dequote_to_argv_array(str.buf, array)) |
460 | 434 | die("Badly quoted content in file '%s': %s", |
461 | | - filename, quoted); |
| 435 | + filename, str.buf); |
462 | 436 | } |
463 | 437 |
|
464 | 438 | strbuf_release(&str); |
@@ -623,25 +597,25 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix, |
623 | 597 | const char *bad_format, const char *good_format, |
624 | 598 | int read_paths) |
625 | 599 | { |
626 | | - struct argv_array rev_argv = { NULL, 0, 0 }; |
| 600 | + struct argv_array rev_argv = ARGV_ARRAY_INIT; |
627 | 601 | int i; |
628 | 602 |
|
629 | 603 | init_revisions(revs, prefix); |
630 | 604 | revs->abbrev = 0; |
631 | 605 | revs->commit_format = CMIT_FMT_UNSPECIFIED; |
632 | 606 |
|
633 | 607 | /* rev_argv.argv[0] will be ignored by setup_revisions */ |
634 | | - argv_array_push(&rev_argv, xstrdup("bisect_rev_setup")); |
635 | | - argv_array_push_sha1(&rev_argv, current_bad_sha1, bad_format); |
| 608 | + argv_array_push(&rev_argv, "bisect_rev_setup"); |
| 609 | + argv_array_pushf(&rev_argv, bad_format, sha1_to_hex(current_bad_sha1)); |
636 | 610 | for (i = 0; i < good_revs.nr; i++) |
637 | | - argv_array_push_sha1(&rev_argv, good_revs.sha1[i], |
638 | | - good_format); |
639 | | - argv_array_push(&rev_argv, xstrdup("--")); |
| 611 | + argv_array_pushf(&rev_argv, good_format, |
| 612 | + sha1_to_hex(good_revs.sha1[i])); |
| 613 | + argv_array_push(&rev_argv, "--"); |
640 | 614 | if (read_paths) |
641 | 615 | read_bisect_paths(&rev_argv); |
642 | | - argv_array_push(&rev_argv, NULL); |
643 | 616 |
|
644 | | - setup_revisions(rev_argv.argv_nr, rev_argv.argv, revs, NULL); |
| 617 | + setup_revisions(rev_argv.argc, rev_argv.argv, revs, NULL); |
| 618 | + /* XXX leak rev_argv, as "revs" may still be pointing to it */ |
645 | 619 | } |
646 | 620 |
|
647 | 621 | static void bisect_common(struct rev_info *revs) |
|
0 commit comments