3
3
#include "refs.h"
4
4
#include "builtin.h"
5
5
#include "color.h"
6
+ #include "argv-array.h"
6
7
#include "parse-options.h"
7
8
8
9
static const char * show_branch_usage [] = {
@@ -16,9 +17,7 @@ static const char* show_branch_usage[] = {
16
17
17
18
static int showbranch_use_color = -1 ;
18
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 ;
22
21
23
22
#define UNINTERESTING 01
24
23
@@ -560,16 +559,9 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
560
559
* default_arg is now passed to parse_options(), so we need to
561
560
* mimic the real argv a bit better.
562
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 );
573
565
return 0 ;
574
566
}
575
567
@@ -689,9 +681,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
689
681
git_config (git_show_branch_config , NULL );
690
682
691
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 ;
695
687
}
696
688
697
689
ac = parse_options (ac , av , prefix , builtin_show_branch_options ,
0 commit comments