@@ -32,7 +32,8 @@ static const char * const git_tag_usage[] = {
32
32
static unsigned int colopts ;
33
33
static int force_sign_annotate ;
34
34
35
- static int list_tags (struct ref_filter * filter , struct ref_sorting * sorting , const char * format )
35
+ static int list_tags (struct ref_filter * filter , struct ref_sorting * sorting ,
36
+ struct ref_format * format )
36
37
{
37
38
struct ref_array array ;
38
39
char * to_free = NULL ;
@@ -43,23 +44,24 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, con
43
44
if (filter -> lines == -1 )
44
45
filter -> lines = 0 ;
45
46
46
- if (!format ) {
47
+ if (!format -> format ) {
47
48
if (filter -> lines ) {
48
49
to_free = xstrfmt ("%s %%(contents:lines=%d)" ,
49
50
"%(align:15)%(refname:lstrip=2)%(end)" ,
50
51
filter -> lines );
51
- format = to_free ;
52
+ format -> format = to_free ;
52
53
} else
53
- format = "%(refname:lstrip=2)" ;
54
+ format -> format = "%(refname:lstrip=2)" ;
54
55
}
55
56
56
- verify_ref_format (format );
57
+ if (verify_ref_format (format ))
58
+ die (_ ("unable to parse format string" ));
57
59
filter -> with_commit_tag_algo = 1 ;
58
60
filter_refs (& array , filter , FILTER_REFS_TAGS );
59
61
ref_array_sort (sorting , & array );
60
62
61
63
for (i = 0 ; i < array .nr ; i ++ )
62
- show_ref_array_item (array .items [i ], format , 0 );
64
+ show_ref_array_item (array .items [i ], format );
63
65
ref_array_clear (& array );
64
66
free (to_free );
65
67
@@ -105,17 +107,17 @@ static int verify_tag(const char *name, const char *ref,
105
107
const struct object_id * oid , const void * cb_data )
106
108
{
107
109
int flags ;
108
- const char * fmt_pretty = cb_data ;
110
+ const struct ref_format * format = cb_data ;
109
111
flags = GPG_VERIFY_VERBOSE ;
110
112
111
- if (fmt_pretty )
113
+ if (format -> format )
112
114
flags = GPG_VERIFY_OMIT_STATUS ;
113
115
114
116
if (gpg_verify_tag (oid , name , flags ))
115
117
return -1 ;
116
118
117
- if (fmt_pretty )
118
- pretty_print_ref (name , oid -> hash , fmt_pretty );
119
+ if (format -> format )
120
+ pretty_print_ref (name , oid -> hash , format );
119
121
120
122
return 0 ;
121
123
}
@@ -134,30 +136,6 @@ static const char tag_template_nocleanup[] =
134
136
"Lines starting with '%c' will be kept; you may remove them"
135
137
" yourself if you want to.\n" );
136
138
137
- /* Parse arg given and add it the ref_sorting array */
138
- static int parse_sorting_string (const char * arg , struct ref_sorting * * sorting_tail )
139
- {
140
- struct ref_sorting * s ;
141
- int len ;
142
-
143
- s = xcalloc (1 , sizeof (* s ));
144
- s -> next = * sorting_tail ;
145
- * sorting_tail = s ;
146
-
147
- if (* arg == '-' ) {
148
- s -> reverse = 1 ;
149
- arg ++ ;
150
- }
151
- if (skip_prefix (arg , "version:" , & arg ) ||
152
- skip_prefix (arg , "v:" , & arg ))
153
- s -> version = 1 ;
154
-
155
- len = strlen (arg );
156
- s -> atom = parse_ref_filter_atom (arg , arg + len );
157
-
158
- return 0 ;
159
- }
160
-
161
139
static int git_tag_config (const char * var , const char * value , void * cb )
162
140
{
163
141
int status ;
@@ -166,7 +144,7 @@ static int git_tag_config(const char *var, const char *value, void *cb)
166
144
if (!strcmp (var , "tag.sort" )) {
167
145
if (!value )
168
146
return config_error_nonbool (var );
169
- parse_sorting_string ( value , sorting_tail );
147
+ parse_ref_sorting ( sorting_tail , value );
170
148
return 0 ;
171
149
}
172
150
@@ -392,7 +370,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
392
370
struct strbuf err = STRBUF_INIT ;
393
371
struct ref_filter filter ;
394
372
static struct ref_sorting * sorting = NULL , * * sorting_tail = & sorting ;
395
- const char * format = NULL ;
373
+ struct ref_format format = REF_FORMAT_INIT ;
396
374
int icase = 0 ;
397
375
struct option options [] = {
398
376
OPT_CMDMODE ('l' , "list" , & cmdmode , N_ ("list tag names" ), 'l' ),
@@ -431,7 +409,8 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
431
409
N_ ("print only tags of the object" ), PARSE_OPT_LASTARG_DEFAULT ,
432
410
parse_opt_object_name , (intptr_t ) "HEAD"
433
411
},
434
- OPT_STRING ( 0 , "format" , & format , N_ ("format" ), N_ ("format to use for the output" )),
412
+ OPT_STRING ( 0 , "format" , & format .format , N_ ("format" ),
413
+ N_ ("format to use for the output" )),
435
414
OPT_BOOL ('i' , "ignore-case" , & icase , N_ ("sorting and filtering are case insensitive" )),
436
415
OPT_END ()
437
416
};
@@ -483,7 +462,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
483
462
run_column_filter (colopts , & copts );
484
463
}
485
464
filter .name_patterns = argv ;
486
- ret = list_tags (& filter , sorting , format );
465
+ ret = list_tags (& filter , sorting , & format );
487
466
if (column_active (colopts ))
488
467
stop_column_filter ();
489
468
return ret ;
@@ -501,9 +480,9 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
501
480
if (cmdmode == 'd' )
502
481
return for_each_tag_name (argv , delete_tag , NULL );
503
482
if (cmdmode == 'v' ) {
504
- if (format )
505
- verify_ref_format ( format );
506
- return for_each_tag_name (argv , verify_tag , format );
483
+ if (format . format && verify_ref_format ( & format ) )
484
+ usage_with_options ( git_tag_usage , options );
485
+ return for_each_tag_name (argv , verify_tag , & format );
507
486
}
508
487
509
488
if (msg .given || msgfile ) {
0 commit comments