@@ -28,6 +28,7 @@ static const char * const builtin_branch_usage[] = {
28
28
N_ ("git branch [<options>] [-r] (-d | -D) <branch-name>..." ),
29
29
N_ ("git branch [<options>] (-m | -M) [<old-branch>] <new-branch>" ),
30
30
N_ ("git branch [<options>] [-r | -a] [--points-at]" ),
31
+ N_ ("git branch [<options>] [-r | -a] [--format]" ),
31
32
NULL
32
33
};
33
34
@@ -364,14 +365,14 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
364
365
return strbuf_detach (& fmt , NULL );
365
366
}
366
367
367
- static void print_ref_list (struct ref_filter * filter , struct ref_sorting * sorting )
368
+ static void print_ref_list (struct ref_filter * filter , struct ref_sorting * sorting , const char * format )
368
369
{
369
370
int i ;
370
371
struct ref_array array ;
371
372
int maxwidth = 0 ;
372
373
const char * remote_prefix = "" ;
373
374
struct strbuf out = STRBUF_INIT ;
374
- char * format ;
375
+ char * to_free = NULL ;
375
376
376
377
/*
377
378
* If we are listing more than just remote branches,
@@ -388,7 +389,8 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
388
389
if (filter -> verbose )
389
390
maxwidth = calc_maxwidth (& array , strlen (remote_prefix ));
390
391
391
- format = build_format (filter , maxwidth , remote_prefix );
392
+ if (!format )
393
+ format = to_free = build_format (filter , maxwidth , remote_prefix );
392
394
verify_ref_format (format );
393
395
394
396
ref_array_sort (sorting , & array );
@@ -407,7 +409,7 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
407
409
}
408
410
409
411
ref_array_clear (& array );
410
- free (format );
412
+ free (to_free );
411
413
}
412
414
413
415
static void reject_rebase_or_bisect_branch (const char * target )
@@ -528,6 +530,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
528
530
struct ref_filter filter ;
529
531
int icase = 0 ;
530
532
static struct ref_sorting * sorting = NULL , * * sorting_tail = & sorting ;
533
+ const char * format = NULL ;
531
534
532
535
struct option options [] = {
533
536
OPT_GROUP (N_ ("Generic options" )),
@@ -569,6 +572,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
569
572
N_ ("print only branches of the object" ), 0 , parse_opt_object_name
570
573
},
571
574
OPT_BOOL ('i' , "ignore-case" , & icase , N_ ("sorting and filtering are case insensitive" )),
575
+ OPT_STRING ( 0 , "format" , & format , N_ ("format" ), N_ ("format to use for the output" )),
572
576
OPT_END (),
573
577
};
574
578
@@ -641,7 +645,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
641
645
if (!sorting )
642
646
sorting = ref_default_sorting ();
643
647
sorting -> ignore_case = icase ;
644
- print_ref_list (& filter , sorting );
648
+ print_ref_list (& filter , sorting , format );
645
649
print_columns (& output , colopts , NULL );
646
650
string_list_clear (& output , 0 );
647
651
return 0 ;
0 commit comments