@@ -18,8 +18,6 @@ static const char * const show_ref_usage[] = {
18
18
NULL
19
19
};
20
20
21
- static int show_head , tags_only , heads_only , verify ;
22
-
23
21
struct show_one_options {
24
22
int quiet ;
25
23
int hash_only ;
@@ -59,14 +57,15 @@ struct show_ref_data {
59
57
const struct show_one_options * show_one_opts ;
60
58
const char * * patterns ;
61
59
int found_match ;
60
+ int show_head ;
62
61
};
63
62
64
63
static int show_ref (const char * refname , const struct object_id * oid ,
65
64
int flag UNUSED , void * cbdata )
66
65
{
67
66
struct show_ref_data * data = cbdata ;
68
67
69
- if (show_head && !strcmp (refname , "HEAD" ))
68
+ if (data -> show_head && !strcmp (refname , "HEAD" ))
70
69
goto match ;
71
70
72
71
if (data -> patterns ) {
@@ -184,22 +183,30 @@ static int cmd_show_ref__verify(const struct show_one_options *show_one_opts,
184
183
return 0 ;
185
184
}
186
185
187
- static int cmd_show_ref__patterns (const struct show_one_options * show_one_opts ,
186
+ struct patterns_options {
187
+ int show_head ;
188
+ int heads_only ;
189
+ int tags_only ;
190
+ };
191
+
192
+ static int cmd_show_ref__patterns (const struct patterns_options * opts ,
193
+ const struct show_one_options * show_one_opts ,
188
194
const char * * patterns )
189
195
{
190
196
struct show_ref_data show_ref_data = {
191
197
.show_one_opts = show_one_opts ,
198
+ .show_head = opts -> show_head ,
192
199
};
193
200
194
201
if (patterns && * patterns )
195
202
show_ref_data .patterns = patterns ;
196
203
197
- if (show_head )
204
+ if (opts -> show_head )
198
205
head_ref (show_ref , & show_ref_data );
199
- if (heads_only || tags_only ) {
200
- if (heads_only )
206
+ if (opts -> heads_only || opts -> tags_only ) {
207
+ if (opts -> heads_only )
201
208
for_each_fullref_in ("refs/heads/" , show_ref , & show_ref_data );
202
- if (tags_only )
209
+ if (opts -> tags_only )
203
210
for_each_fullref_in ("refs/tags/" , show_ref , & show_ref_data );
204
211
} else {
205
212
for_each_ref (show_ref , & show_ref_data );
@@ -237,15 +244,17 @@ static int exclude_existing_callback(const struct option *opt, const char *arg,
237
244
int cmd_show_ref (int argc , const char * * argv , const char * prefix )
238
245
{
239
246
struct exclude_existing_options exclude_existing_opts = {0 };
247
+ struct patterns_options patterns_opts = {0 };
240
248
struct show_one_options show_one_opts = {0 };
249
+ int verify = 0 ;
241
250
const struct option show_ref_options [] = {
242
- OPT_BOOL (0 , "tags" , & tags_only , N_ ("only show tags (can be combined with heads)" )),
243
- OPT_BOOL (0 , "heads" , & heads_only , N_ ("only show heads (can be combined with tags)" )),
251
+ OPT_BOOL (0 , "tags" , & patterns_opts . tags_only , N_ ("only show tags (can be combined with heads)" )),
252
+ OPT_BOOL (0 , "heads" , & patterns_opts . heads_only , N_ ("only show heads (can be combined with tags)" )),
244
253
OPT_BOOL (0 , "verify" , & verify , N_ ("stricter reference checking, "
245
254
"requires exact ref path" )),
246
- OPT_HIDDEN_BOOL ('h' , NULL , & show_head ,
255
+ OPT_HIDDEN_BOOL ('h' , NULL , & patterns_opts . show_head ,
247
256
N_ ("show the HEAD reference, even if it would be filtered out" )),
248
- OPT_BOOL (0 , "head" , & show_head ,
257
+ OPT_BOOL (0 , "head" , & patterns_opts . show_head ,
249
258
N_ ("show the HEAD reference, even if it would be filtered out" )),
250
259
OPT_BOOL ('d' , "dereference" , & show_one_opts .deref_tags ,
251
260
N_ ("dereference tags into object IDs" )),
@@ -271,5 +280,5 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
271
280
else if (verify )
272
281
return cmd_show_ref__verify (& show_one_opts , argv );
273
282
else
274
- return cmd_show_ref__patterns (& show_one_opts , argv );
283
+ return cmd_show_ref__patterns (& patterns_opts , & show_one_opts , argv );
275
284
}
0 commit comments