@@ -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
@@ -340,14 +341,14 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r
340
341
return strbuf_detach (& fmt , NULL );
341
342
}
342
343
343
- static void print_ref_list (struct ref_filter * filter , struct ref_sorting * sorting )
344
+ static void print_ref_list (struct ref_filter * filter , struct ref_sorting * sorting , const char * format )
344
345
{
345
346
int i ;
346
347
struct ref_array array ;
347
348
int maxwidth = 0 ;
348
349
const char * remote_prefix = "" ;
349
350
struct strbuf out = STRBUF_INIT ;
350
- char * format ;
351
+ char * to_free = NULL ;
351
352
352
353
/*
353
354
* If we are listing more than just remote branches,
@@ -364,7 +365,8 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
364
365
if (filter -> verbose )
365
366
maxwidth = calc_maxwidth (& array , strlen (remote_prefix ));
366
367
367
- format = build_format (filter , maxwidth , remote_prefix );
368
+ if (!format )
369
+ format = to_free = build_format (filter , maxwidth , remote_prefix );
368
370
verify_ref_format (format );
369
371
370
372
/*
@@ -392,7 +394,7 @@ static void print_ref_list(struct ref_filter *filter, struct ref_sorting *sortin
392
394
}
393
395
394
396
ref_array_clear (& array );
395
- free (format );
397
+ free (to_free );
396
398
}
397
399
398
400
static void rename_branch (const char * oldname , const char * newname , int force )
@@ -491,6 +493,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
491
493
enum branch_track track ;
492
494
struct ref_filter filter ;
493
495
static struct ref_sorting * sorting = NULL , * * sorting_tail = & sorting ;
496
+ const char * format = NULL ;
494
497
495
498
struct option options [] = {
496
499
OPT_GROUP (N_ ("Generic options" )),
@@ -531,6 +534,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
531
534
OPTION_CALLBACK , 0 , "points-at" , & filter .points_at , N_ ("object" ),
532
535
N_ ("print only branches of the object" ), 0 , parse_opt_object_name
533
536
},
537
+ OPT_STRING ( 0 , "format" , & format , N_ ("format" ), N_ ("format to use for the output" )),
534
538
OPT_END (),
535
539
};
536
540
@@ -591,7 +595,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)
591
595
if ((filter .kind & FILTER_REFS_BRANCHES ) && filter .detached )
592
596
filter .kind |= FILTER_REFS_DETACHED_HEAD ;
593
597
filter .name_patterns = argv ;
594
- print_ref_list (& filter , sorting );
598
+ print_ref_list (& filter , sorting , format );
595
599
print_columns (& output , colopts , NULL );
596
600
string_list_clear (& output , 0 );
597
601
return 0 ;
0 commit comments