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
@@ -556,16 +555,9 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
556
555
* default_arg is now passed to parse_options(), so we need to
557
556
* mimic the real argv a bit better.
558
557
*/
559
- if (!default_num ) {
560
- default_alloc = 20 ;
561
- default_arg = xcalloc (default_alloc , sizeof (* default_arg ));
562
- default_arg [default_num ++ ] = "show-branch" ;
563
- } else if (default_alloc <= default_num + 1 ) {
564
- default_alloc = default_alloc * 3 / 2 + 20 ;
565
- REALLOC_ARRAY (default_arg , default_alloc );
566
- }
567
- default_arg [default_num ++ ] = xstrdup (value );
568
- default_arg [default_num ] = NULL ;
558
+ if (!default_args .argc )
559
+ argv_array_push (& default_args , "show-branch" );
560
+ argv_array_push (& default_args , value );
569
561
return 0 ;
570
562
}
571
563
@@ -685,9 +677,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
685
677
git_config (git_show_branch_config , NULL );
686
678
687
679
/* If nothing is specified, try the default first */
688
- if (ac == 1 && default_num ) {
689
- ac = default_num ;
690
- av = default_arg ;
680
+ if (ac == 1 && default_args . argc ) {
681
+ ac = default_args . argc ;
682
+ av = default_args . argv ;
691
683
}
692
684
693
685
ac = parse_options (ac , av , prefix , builtin_show_branch_options ,
0 commit comments