checkout: use argv_array API

We were using a similar ad-hoc rev_list_args structure, but this saves some 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 7bf0b01750e975f8a4df925ac75efa7f984bf393
1 file changed +8 -19
builtin/checkout.c
+8 -19
@@ -19,6 +19,7 @@
19 #include "ll-merge.h"
20 #include "resolve-undo.h"
21 #include "submodule.h"
22 +#include "argv-array.h"
23
24 static const char * const checkout_usage[] = {
25 "git checkout [options] <branch>",
@@ -588,24 +589,12 @@ static void update_refs_for_switch(struct checkout_opts *opts,
589 report_tracking(new);
590 }
591
591 -struct rev_list_args {
592 - int argc;
593 - int alloc;
594 - const char **argv;
595 -};
596 -
597 -static void add_one_rev_list_arg(struct rev_list_args *args, const char *s)
598 -{
599 - ALLOC_GROW(args->argv, args->argc + 1, args->alloc);
600 - args->argv[args->argc++] = s;
601 -}
602 -
592 static int add_one_ref_to_rev_list_arg(const char *refname,
593 const unsigned char *sha1,
594 int flags,
595 void *cb_data)
596 {
608 - add_one_rev_list_arg(cb_data, refname);
597 + argv_array_push(cb_data, refname);
598 return 0;
599 }
600
@@ -684,15 +673,14 @@ static void suggest_reattach(struct commit *commit, struct rev_info *revs)
673 */
674 static void orphaned_commit_warning(struct commit *commit)
675 {
687 - struct rev_list_args args = { 0, 0, NULL };
676 + struct argv_array args = ARGV_ARRAY_INIT;
677 struct rev_info revs;
678
690 - add_one_rev_list_arg(&args, "(internal)");
691 - add_one_rev_list_arg(&args, sha1_to_hex(commit->object.sha1));
692 - add_one_rev_list_arg(&args, "--not");
679 + argv_array_push(&args, "(internal)");
680 + argv_array_push(&args, sha1_to_hex(commit->object.sha1));
681 + argv_array_push(&args, "--not");
682 for_each_ref(add_one_ref_to_rev_list_arg, &args);
694 - add_one_rev_list_arg(&args, "--");
695 - add_one_rev_list_arg(&args, NULL);
683 + argv_array_push(&args, "--");
684
685 init_revisions(&revs, NULL);
686 if (setup_revisions(args.argc - 1, args.argv, &revs, NULL) != 1)
@@ -704,6 +692,7 @@ static void orphaned_commit_warning(struct commit *commit)
692 else
693 describe_detached_head(_("Previous HEAD position was"), commit);
694
695 + argv_array_clear(&args);
696 clear_commit_marks(commit, -1);
697 for_each_ref(clear_commit_marks_from_one_ref, NULL);
698 }