@@ -72,10 +72,10 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting,
72
72
}
73
73
74
74
typedef int (* each_tag_name_fn )(const char * name , const char * ref ,
75
- const struct object_id * oid , const void * cb_data );
75
+ const struct object_id * oid , void * cb_data );
76
76
77
77
static int for_each_tag_name (const char * * argv , each_tag_name_fn fn ,
78
- const void * cb_data )
78
+ void * cb_data )
79
79
{
80
80
const char * * p ;
81
81
struct strbuf ref = STRBUF_INIT ;
@@ -97,18 +97,42 @@ static int for_each_tag_name(const char **argv, each_tag_name_fn fn,
97
97
return had_error ;
98
98
}
99
99
100
- static int delete_tag (const char * name , const char * ref ,
101
- const struct object_id * oid , const void * cb_data )
100
+ static int collect_tags (const char * name , const char * ref ,
101
+ const struct object_id * oid , void * cb_data )
102
102
{
103
- if ( delete_ref ( NULL , ref , oid , 0 ))
104
- return 1 ;
105
- printf ( _ ( "Deleted tag '%s' (was %s)\n" ), name ,
106
- find_unique_abbrev (oid , DEFAULT_ABBREV ) );
103
+ struct string_list * ref_list = cb_data ;
104
+
105
+ string_list_append ( ref_list , ref );
106
+ ref_list -> items [ ref_list -> nr - 1 ]. util = oiddup (oid );
107
107
return 0 ;
108
108
}
109
109
110
+ static int delete_tags (const char * * argv )
111
+ {
112
+ int result ;
113
+ struct string_list refs_to_delete = STRING_LIST_INIT_DUP ;
114
+ struct string_list_item * item ;
115
+
116
+ result = for_each_tag_name (argv , collect_tags , (void * )& refs_to_delete );
117
+ if (delete_refs (NULL , & refs_to_delete , REF_NO_DEREF ))
118
+ result = 1 ;
119
+
120
+ for_each_string_list_item (item , & refs_to_delete ) {
121
+ const char * name = item -> string ;
122
+ struct object_id * oid = item -> util ;
123
+ if (!ref_exists (name ))
124
+ printf (_ ("Deleted tag '%s' (was %s)\n" ),
125
+ item -> string + 10 ,
126
+ find_unique_abbrev (oid , DEFAULT_ABBREV ));
127
+
128
+ free (oid );
129
+ }
130
+ string_list_clear (& refs_to_delete , 0 );
131
+ return result ;
132
+ }
133
+
110
134
static int verify_tag (const char * name , const char * ref ,
111
- const struct object_id * oid , const void * cb_data )
135
+ const struct object_id * oid , void * cb_data )
112
136
{
113
137
int flags ;
114
138
const struct ref_format * format = cb_data ;
@@ -512,7 +536,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
512
536
if (filter .reachable_from || filter .unreachable_from )
513
537
die (_ ("--merged and --no-merged options are only allowed in list mode" ));
514
538
if (cmdmode == 'd' )
515
- return for_each_tag_name (argv , delete_tag , NULL );
539
+ return delete_tags (argv );
516
540
if (cmdmode == 'v' ) {
517
541
if (format .format && verify_ref_format (& format ))
518
542
usage_with_options (git_tag_usage , options );
0 commit comments