@@ -98,7 +98,7 @@ static struct used_atom {
9898} * used_atom ;
9999static int used_atom_cnt , need_tagged , need_symref ;
100100
101- static void color_atom_parser (struct used_atom * atom , const char * color_value )
101+ static void color_atom_parser (const struct ref_format * format , struct used_atom * atom , const char * color_value )
102102{
103103 if (!color_value )
104104 die (_ ("expected format: %%(color:<color>)" ));
@@ -126,7 +126,7 @@ static void refname_atom_parser_internal(struct refname_atom *atom,
126126 die (_ ("unrecognized %%(%s) argument: %s" ), name , arg );
127127}
128128
129- static void remote_ref_atom_parser (struct used_atom * atom , const char * arg )
129+ static void remote_ref_atom_parser (const struct ref_format * format , struct used_atom * atom , const char * arg )
130130{
131131 struct string_list params = STRING_LIST_INIT_DUP ;
132132 int i ;
@@ -160,28 +160,28 @@ static void remote_ref_atom_parser(struct used_atom *atom, const char *arg)
160160 string_list_clear (& params , 0 );
161161}
162162
163- static void body_atom_parser (struct used_atom * atom , const char * arg )
163+ static void body_atom_parser (const struct ref_format * format , struct used_atom * atom , const char * arg )
164164{
165165 if (arg )
166166 die (_ ("%%(body) does not take arguments" ));
167167 atom -> u .contents .option = C_BODY_DEP ;
168168}
169169
170- static void subject_atom_parser (struct used_atom * atom , const char * arg )
170+ static void subject_atom_parser (const struct ref_format * format , struct used_atom * atom , const char * arg )
171171{
172172 if (arg )
173173 die (_ ("%%(subject) does not take arguments" ));
174174 atom -> u .contents .option = C_SUB ;
175175}
176176
177- static void trailers_atom_parser (struct used_atom * atom , const char * arg )
177+ static void trailers_atom_parser (const struct ref_format * format , struct used_atom * atom , const char * arg )
178178{
179179 if (arg )
180180 die (_ ("%%(trailers) does not take arguments" ));
181181 atom -> u .contents .option = C_TRAILERS ;
182182}
183183
184- static void contents_atom_parser (struct used_atom * atom , const char * arg )
184+ static void contents_atom_parser (const struct ref_format * format , struct used_atom * atom , const char * arg )
185185{
186186 if (!arg )
187187 atom -> u .contents .option = C_BARE ;
@@ -201,7 +201,7 @@ static void contents_atom_parser(struct used_atom *atom, const char *arg)
201201 die (_ ("unrecognized %%(contents) argument: %s" ), arg );
202202}
203203
204- static void objectname_atom_parser (struct used_atom * atom , const char * arg )
204+ static void objectname_atom_parser (const struct ref_format * format , struct used_atom * atom , const char * arg )
205205{
206206 if (!arg )
207207 atom -> u .objectname .option = O_FULL ;
@@ -218,7 +218,7 @@ static void objectname_atom_parser(struct used_atom *atom, const char *arg)
218218 die (_ ("unrecognized %%(objectname) argument: %s" ), arg );
219219}
220220
221- static void refname_atom_parser (struct used_atom * atom , const char * arg )
221+ static void refname_atom_parser (const struct ref_format * format , struct used_atom * atom , const char * arg )
222222{
223223 refname_atom_parser_internal (& atom -> u .refname , arg , atom -> name );
224224}
@@ -234,7 +234,7 @@ static align_type parse_align_position(const char *s)
234234 return -1 ;
235235}
236236
237- static void align_atom_parser (struct used_atom * atom , const char * arg )
237+ static void align_atom_parser (const struct ref_format * format , struct used_atom * atom , const char * arg )
238238{
239239 struct align * align = & atom -> u .align ;
240240 struct string_list params = STRING_LIST_INIT_DUP ;
@@ -273,7 +273,7 @@ static void align_atom_parser(struct used_atom *atom, const char *arg)
273273 string_list_clear (& params , 0 );
274274}
275275
276- static void if_atom_parser (struct used_atom * atom , const char * arg )
276+ static void if_atom_parser (const struct ref_format * format , struct used_atom * atom , const char * arg )
277277{
278278 if (!arg ) {
279279 atom -> u .if_then_else .cmp_status = COMPARE_NONE ;
@@ -287,7 +287,7 @@ static void if_atom_parser(struct used_atom *atom, const char *arg)
287287 }
288288}
289289
290- static void head_atom_parser (struct used_atom * atom , const char * arg )
290+ static void head_atom_parser (const struct ref_format * format , struct used_atom * atom , const char * arg )
291291{
292292 struct object_id unused ;
293293
@@ -297,7 +297,7 @@ static void head_atom_parser(struct used_atom *atom, const char *arg)
297297static struct {
298298 const char * name ;
299299 cmp_type cmp_type ;
300- void (* parser )(struct used_atom * atom , const char * arg );
300+ void (* parser )(const struct ref_format * format , struct used_atom * atom , const char * arg );
301301} valid_atom [] = {
302302 { "refname" , FIELD_STR , refname_atom_parser },
303303 { "objecttype" },
@@ -364,7 +364,8 @@ struct atom_value {
364364/*
365365 * Used to parse format string and sort specifiers
366366 */
367- static int parse_ref_filter_atom (const char * atom , const char * ep )
367+ static int parse_ref_filter_atom (const struct ref_format * format ,
368+ const char * atom , const char * ep )
368369{
369370 const char * sp ;
370371 const char * arg ;
@@ -412,7 +413,7 @@ static int parse_ref_filter_atom(const char *atom, const char *ep)
412413 arg = used_atom [at ].name + (arg - atom ) + 1 ;
413414 memset (& used_atom [at ].u , 0 , sizeof (used_atom [at ].u ));
414415 if (valid_atom [i ].parser )
415- valid_atom [i ].parser (& used_atom [at ], arg );
416+ valid_atom [i ].parser (format , & used_atom [at ], arg );
416417 if (* atom == '*' )
417418 need_tagged = 1 ;
418419 if (!strcmp (valid_atom [i ].name , "symref" ))
@@ -668,7 +669,7 @@ int verify_ref_format(struct ref_format *format)
668669 if (!ep )
669670 return error (_ ("malformed format string %s" ), sp );
670671 /* sp points at "%(" and ep points at the closing ")" */
671- at = parse_ref_filter_atom (sp + 2 , ep );
672+ at = parse_ref_filter_atom (format , sp + 2 , ep );
672673 cp = ep + 1 ;
673674
674675 if (skip_prefix (used_atom [at ].name , "color:" , & color ))
@@ -2075,7 +2076,9 @@ void format_ref_array_item(struct ref_array_item *info,
20752076 ep = strchr (sp , ')' );
20762077 if (cp < sp )
20772078 append_literal (cp , sp , & state );
2078- get_ref_atom_value (info , parse_ref_filter_atom (sp + 2 , ep ), & atomv );
2079+ get_ref_atom_value (info ,
2080+ parse_ref_filter_atom (format , sp + 2 , ep ),
2081+ & atomv );
20792082 atomv -> handler (atomv , & state );
20802083 }
20812084 if (* cp ) {
@@ -2116,8 +2119,13 @@ void pretty_print_ref(const char *name, const unsigned char *sha1,
21162119
21172120static int parse_sorting_atom (const char * atom )
21182121{
2122+ /*
2123+ * This parses an atom using a dummy ref_format, since we don't
2124+ * actually care about the formatting details.
2125+ */
2126+ struct ref_format dummy = REF_FORMAT_INIT ;
21192127 const char * end = atom + strlen (atom );
2120- return parse_ref_filter_atom (atom , end );
2128+ return parse_ref_filter_atom (& dummy , atom , end );
21212129}
21222130
21232131/* If no sorting option is given, use refname to sort as default */
0 commit comments