|
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 |
|
@@ -404,21 +399,6 @@ struct commit_list *find_bisection(struct commit_list *list,
|
404 | 399 | return best;
|
405 | 400 | }
|
406 | 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 |
| - |
422 | 402 | static int register_ref(const char *refname, const unsigned char *sha1,
|
423 | 403 | int flags, void *cb_data)
|
424 | 404 | {
|
@@ -448,16 +428,10 @@ static void read_bisect_paths(struct argv_array *array)
|
448 | 428 | die_errno("Could not open file '%s'", filename);
|
449 | 429 |
|
450 | 430 | while (strbuf_getline(&str, fp, '\n') != EOF) {
|
451 |
| - char *quoted; |
452 |
| - int res; |
453 |
| - |
454 | 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)) |
459 | 433 | die("Badly quoted content in file '%s': %s",
|
460 |
| - filename, quoted); |
| 434 | + filename, str.buf); |
461 | 435 | }
|
462 | 436 |
|
463 | 437 | strbuf_release(&str);
|
@@ -622,25 +596,25 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix,
|
622 | 596 | const char *bad_format, const char *good_format,
|
623 | 597 | int read_paths)
|
624 | 598 | {
|
625 |
| - struct argv_array rev_argv = { NULL, 0, 0 }; |
| 599 | + struct argv_array rev_argv = ARGV_ARRAY_INIT; |
626 | 600 | int i;
|
627 | 601 |
|
628 | 602 | init_revisions(revs, prefix);
|
629 | 603 | revs->abbrev = 0;
|
630 | 604 | revs->commit_format = CMIT_FMT_UNSPECIFIED;
|
631 | 605 |
|
632 | 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)); |
635 | 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, "--"); |
639 | 613 | if (read_paths)
|
640 | 614 | read_bisect_paths(&rev_argv);
|
641 |
| - argv_array_push(&rev_argv, NULL); |
642 | 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 */ |
644 | 618 | }
|
645 | 619 |
|
646 | 620 | static void bisect_common(struct rev_info *revs)
|
|
0 commit comments