show-branch: use argv_array for default arguments

Use argv_array instead of open-coding it. Signed-off-by: Rene Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Oct 31, 2015 at 20:06 UTC c949b00fb8ade8b5ad806ea801983f980181d5a5
1 file changed +8 -16
builtin/show-branch.c
+8 -16
@@ -3,6 +3,7 @@
3 #include "refs.h"
4 #include "builtin.h"
5 #include "color.h"
6 +#include "argv-array.h"
7 #include "parse-options.h"
8
9 static const char* show_branch_usage[] = {
@@ -16,9 +17,7 @@ static const char* show_branch_usage[] = {
17
18 static int showbranch_use_color = -1;
19
19 -static int default_num;
20 -static int default_alloc;
21 -static const char **default_arg;
20 +static struct argv_array default_args = ARGV_ARRAY_INIT;
21
22 #define UNINTERESTING 01
23
@@ -560,16 +559,9 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
559 * default_arg is now passed to parse_options(), so we need to
560 * mimic the real argv a bit better.
561 */
563 - if (!default_num) {
564 - default_alloc = 20;
565 - default_arg = xcalloc(default_alloc, sizeof(*default_arg));
566 - default_arg[default_num++] = "show-branch";
567 - } else if (default_alloc <= default_num + 1) {
568 - default_alloc = default_alloc * 3 / 2 + 20;
569 - REALLOC_ARRAY(default_arg, default_alloc);
570 - }
571 - default_arg[default_num++] = xstrdup(value);
572 - default_arg[default_num] = NULL;
562 + if (!default_args.argc)
563 + argv_array_push(&default_args, "show-branch");
564 + argv_array_push(&default_args, value);
565 return 0;
566 }
567
@@ -689,9 +681,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
681 git_config(git_show_branch_config, NULL);
682
683 /* If nothing is specified, try the default first */
692 - if (ac == 1 && default_num) {
693 - ac = default_num;
694 - av = default_arg;
684 + if (ac == 1 && default_args.argc) {
685 + ac = default_args.argc;
686 + av = default_args.argv;
687 }
688
689 ac = parse_options(ac, av, prefix, builtin_show_branch_options,