Skip to content

Commit c949b00

Browse files
rscharfegitster
authored andcommitted
show-branch: use argv_array for default arguments
Use argv_array instead of open-coding it. Signed-off-by: Rene Scharfe <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a2558fb commit c949b00

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

builtin/show-branch.c

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "refs.h"
44
#include "builtin.h"
55
#include "color.h"
6+
#include "argv-array.h"
67
#include "parse-options.h"
78

89
static const char* show_branch_usage[] = {
@@ -16,9 +17,7 @@ static const char* show_branch_usage[] = {
1617

1718
static int showbranch_use_color = -1;
1819

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;
2221

2322
#define UNINTERESTING 01
2423

@@ -560,16 +559,9 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
560559
* default_arg is now passed to parse_options(), so we need to
561560
* mimic the real argv a bit better.
562561
*/
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);
573565
return 0;
574566
}
575567

@@ -689,9 +681,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
689681
git_config(git_show_branch_config, NULL);
690682

691683
/* 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;
695687
}
696688

697689
ac = parse_options(ac, av, prefix, builtin_show_branch_options,

0 commit comments

Comments
 (0)