@@ -48,8 +48,10 @@ static struct used_atom {
4848 union {
4949 char color [COLOR_MAXLEN ];
5050 struct align align ;
51- enum { RR_NORMAL , RR_SHORTEN , RR_TRACK , RR_TRACKSHORT }
52- remote_ref ;
51+ struct {
52+ enum { RR_NORMAL , RR_SHORTEN , RR_TRACK , RR_TRACKSHORT } option ;
53+ unsigned int nobracket : 1 ;
54+ } remote_ref ;
5355 struct {
5456 enum { C_BARE , C_BODY , C_BODY_DEP , C_LINES , C_SIG , C_SUB , C_TRAILERS } option ;
5557 unsigned int nlines ;
@@ -77,16 +79,33 @@ static void color_atom_parser(struct used_atom *atom, const char *color_value)
7779
7880static void remote_ref_atom_parser (struct used_atom * atom , const char * arg )
7981{
80- if (!arg )
81- atom -> u .remote_ref = RR_NORMAL ;
82- else if (!strcmp (arg , "short" ))
83- atom -> u .remote_ref = RR_SHORTEN ;
84- else if (!strcmp (arg , "track" ))
85- atom -> u .remote_ref = RR_TRACK ;
86- else if (!strcmp (arg , "trackshort" ))
87- atom -> u .remote_ref = RR_TRACKSHORT ;
88- else
89- die (_ ("unrecognized format: %%(%s)" ), atom -> name );
82+ struct string_list params = STRING_LIST_INIT_DUP ;
83+ int i ;
84+
85+ if (!arg ) {
86+ atom -> u .remote_ref .option = RR_NORMAL ;
87+ return ;
88+ }
89+
90+ atom -> u .remote_ref .nobracket = 0 ;
91+ string_list_split (& params , arg , ',' , -1 );
92+
93+ for (i = 0 ; i < params .nr ; i ++ ) {
94+ const char * s = params .items [i ].string ;
95+
96+ if (!strcmp (s , "short" ))
97+ atom -> u .remote_ref .option = RR_SHORTEN ;
98+ else if (!strcmp (s , "track" ))
99+ atom -> u .remote_ref .option = RR_TRACK ;
100+ else if (!strcmp (s , "trackshort" ))
101+ atom -> u .remote_ref .option = RR_TRACKSHORT ;
102+ else if (!strcmp (s , "nobracket" ))
103+ atom -> u .remote_ref .nobracket = 1 ;
104+ else
105+ die (_ ("unrecognized format: %%(%s)" ), atom -> name );
106+ }
107+
108+ string_list_clear (& params , 0 );
90109}
91110
92111static void body_atom_parser (struct used_atom * atom , const char * arg )
@@ -1069,25 +1088,27 @@ static void fill_remote_ref_details(struct used_atom *atom, const char *refname,
10691088 struct branch * branch , const char * * s )
10701089{
10711090 int num_ours , num_theirs ;
1072- if (atom -> u .remote_ref == RR_SHORTEN )
1091+ if (atom -> u .remote_ref . option == RR_SHORTEN )
10731092 * s = shorten_unambiguous_ref (refname , warn_ambiguous_refs );
1074- else if (atom -> u .remote_ref == RR_TRACK ) {
1093+ else if (atom -> u .remote_ref . option == RR_TRACK ) {
10751094 if (stat_tracking_info (branch , & num_ours ,
10761095 & num_theirs , NULL )) {
1077- * s = "[gone]" ;
1078- return ;
1079- }
1080-
1081- if (!num_ours && !num_theirs )
1096+ * s = xstrdup ("gone" );
1097+ } else if (!num_ours && !num_theirs )
10821098 * s = "" ;
10831099 else if (!num_ours )
1084- * s = xstrfmt ("[ behind %d] " , num_theirs );
1100+ * s = xstrfmt ("behind %d" , num_theirs );
10851101 else if (!num_theirs )
1086- * s = xstrfmt ("[ ahead %d] " , num_ours );
1102+ * s = xstrfmt ("ahead %d" , num_ours );
10871103 else
1088- * s = xstrfmt ("[ ahead %d, behind %d] " ,
1104+ * s = xstrfmt ("ahead %d, behind %d" ,
10891105 num_ours , num_theirs );
1090- } else if (atom -> u .remote_ref == RR_TRACKSHORT ) {
1106+ if (!atom -> u .remote_ref .nobracket && * s [0 ]) {
1107+ const char * to_free = * s ;
1108+ * s = xstrfmt ("[%s]" , * s );
1109+ free ((void * )to_free );
1110+ }
1111+ } else if (atom -> u .remote_ref .option == RR_TRACKSHORT ) {
10911112 if (stat_tracking_info (branch , & num_ours ,
10921113 & num_theirs , NULL ))
10931114 return ;
0 commit comments