@matheusbsbs / matheus-bagliano / commits / 1c953a1f46
Fork 0

bisect: use new "struct argv_array" to prepare argv for "setup_revisions"

Because we will use other instances of this struct. The "rev_argv_push" function is changed into 2 functions "argv_array_push" and "argv_array_push_sha1" that take a "struct argv_array *" as first argument. And these functions are used to simplify "bisect_rev_setup". Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Christian Couder committed May 9, 2009 at 17:55 UTC 1c953a1f46340a9ca0fc84345e826c9372dee42a
1 file changed +29 -28
bisect.c
+29 -28
@@ -18,12 +18,16 @@ struct sha1_array {
18 static struct sha1_array good_revs;
19 static struct sha1_array skipped_revs;
20
21 -static const char **rev_argv;
22 -static int rev_argv_nr;
23 -static int rev_argv_alloc;
24 -
21 static const unsigned char *current_bad_sha1;
22
23 +struct argv_array {
24 + const char **argv;
25 + int argv_nr;
26 + int argv_alloc;
27 +};
28 +
29 +struct argv_array rev_argv;
30 +
31 static const char *argv_diff_tree[] = {"diff-tree", "--pretty", NULL, NULL};
32 static const char *argv_checkout[] = {"checkout", "-q", NULL, "--", NULL};
33 static const char *argv_show_branch[] = {"show-branch", NULL, NULL};
@@ -410,13 +414,19 @@ struct commit_list *find_bisection(struct commit_list *list,
414 return best;
415 }
416
413 -static void rev_argv_push(const unsigned char *sha1, const char *format)
417 +static void argv_array_push(struct argv_array *array, const char *string)
418 {
415 - struct strbuf buf = STRBUF_INIT;
419 + ALLOC_GROW(array->argv, array->argv_nr + 1, array->argv_alloc);
420 + array->argv[array->argv_nr++] = string;
421 +}
422
423 +static void argv_array_push_sha1(struct argv_array *array,
424 + const unsigned char *sha1,
425 + const char *format)
426 +{
427 + struct strbuf buf = STRBUF_INIT;
428 strbuf_addf(&buf, format, sha1_to_hex(sha1));
418 - ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
419 - rev_argv[rev_argv_nr++] = strbuf_detach(&buf, NULL);
429 + argv_array_push(array, strbuf_detach(&buf, NULL));
430 }
431
432 static void sha1_array_push(struct sha1_array *array,
@@ -445,7 +455,7 @@ static int read_bisect_refs(void)
455 return for_each_ref_in("refs/bisect/", register_ref, NULL);
456 }
457
448 -void read_bisect_paths(void)
458 +void read_bisect_paths(struct argv_array *array)
459 {
460 struct strbuf str = STRBUF_INIT;
461 const char *filename = git_path("BISECT_NAMES");
@@ -460,8 +470,8 @@ void read_bisect_paths(void)
470
471 strbuf_trim(&str);
472 quoted = strbuf_detach(&str, NULL);
463 - res = sq_dequote_to_argv(quoted, &rev_argv,
464 - &rev_argv_nr, &rev_argv_alloc);
473 + res = sq_dequote_to_argv(quoted, &array->argv,
474 + &array->argv_nr, &array->argv_alloc);
475 if (res)
476 die("Badly quoted content in file '%s': %s",
477 filename, quoted);
@@ -538,25 +548,16 @@ static void bisect_rev_setup(struct rev_info *revs, const char *prefix)
548 if (read_bisect_refs())
549 die("reading bisect refs failed");
550
541 - /* argv[0] will be ignored by setup_revisions */
542 - ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
543 - rev_argv[rev_argv_nr++] = xstrdup("bisect_rev_setup");
544 -
545 - rev_argv_push(current_bad_sha1, "%s");
546 -
551 + /* rev_argv.argv[0] will be ignored by setup_revisions */
552 + argv_array_push(&rev_argv, xstrdup("bisect_rev_setup"));
553 + argv_array_push_sha1(&rev_argv, current_bad_sha1, "%s");
554 for (i = 0; i < good_revs.sha1_nr; i++)
548 - rev_argv_push(good_revs.sha1[i], "^%s");
549 -
550 - ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
551 - rev_argv[rev_argv_nr++] = xstrdup("--");
552 -
553 - read_bisect_paths();
554 -
555 - ALLOC_GROW(rev_argv, rev_argv_nr + 1, rev_argv_alloc);
556 - rev_argv[rev_argv_nr++] = NULL;
557 -
558 - setup_revisions(rev_argv_nr, rev_argv, revs, NULL);
555 + argv_array_push_sha1(&rev_argv, good_revs.sha1[i], "^%s");
556 + argv_array_push(&rev_argv, xstrdup("--"));
557 + read_bisect_paths(&rev_argv);
558 + argv_array_push(&rev_argv, NULL);
559
560 + setup_revisions(rev_argv.argv_nr, rev_argv.argv, revs, NULL);
561 revs->limited = 1;
562 }
563