@@ -18,10 +18,17 @@ static const char * const show_ref_usage[] = {
18
18
NULL
19
19
};
20
20
21
- static int deref_tags , show_head , tags_only , heads_only , verify ,
22
- quiet , hash_only , abbrev ;
21
+ static int show_head , tags_only , heads_only , verify ;
23
22
24
- static void show_one (const char * refname , const struct object_id * oid )
23
+ struct show_one_options {
24
+ int quiet ;
25
+ int hash_only ;
26
+ int abbrev ;
27
+ int deref_tags ;
28
+ };
29
+
30
+ static void show_one (const struct show_one_options * opts ,
31
+ const char * refname , const struct object_id * oid )
25
32
{
26
33
const char * hex ;
27
34
struct object_id peeled ;
@@ -30,25 +37,26 @@ static void show_one(const char *refname, const struct object_id *oid)
30
37
die ("git show-ref: bad ref %s (%s)" , refname ,
31
38
oid_to_hex (oid ));
32
39
33
- if (quiet )
40
+ if (opts -> quiet )
34
41
return ;
35
42
36
- hex = repo_find_unique_abbrev (the_repository , oid , abbrev );
37
- if (hash_only )
43
+ hex = repo_find_unique_abbrev (the_repository , oid , opts -> abbrev );
44
+ if (opts -> hash_only )
38
45
printf ("%s\n" , hex );
39
46
else
40
47
printf ("%s %s\n" , hex , refname );
41
48
42
- if (!deref_tags )
49
+ if (!opts -> deref_tags )
43
50
return ;
44
51
45
52
if (!peel_iterated_oid (oid , & peeled )) {
46
- hex = repo_find_unique_abbrev (the_repository , & peeled , abbrev );
53
+ hex = repo_find_unique_abbrev (the_repository , & peeled , opts -> abbrev );
47
54
printf ("%s %s^{}\n" , hex , refname );
48
55
}
49
56
}
50
57
51
58
struct show_ref_data {
59
+ const struct show_one_options * show_one_opts ;
52
60
const char * * patterns ;
53
61
int found_match ;
54
62
};
@@ -81,7 +89,7 @@ static int show_ref(const char *refname, const struct object_id *oid,
81
89
match :
82
90
data -> found_match ++ ;
83
91
84
- show_one (refname , oid );
92
+ show_one (data -> show_one_opts , refname , oid );
85
93
86
94
return 0 ;
87
95
}
@@ -153,7 +161,8 @@ static int cmd_show_ref__exclude_existing(const struct exclude_existing_options
153
161
return 0 ;
154
162
}
155
163
156
- static int cmd_show_ref__verify (const char * * refs )
164
+ static int cmd_show_ref__verify (const struct show_one_options * show_one_opts ,
165
+ const char * * refs )
157
166
{
158
167
if (!refs || !* refs )
159
168
die ("--verify requires a reference" );
@@ -163,9 +172,9 @@ static int cmd_show_ref__verify(const char **refs)
163
172
164
173
if ((starts_with (* refs , "refs/" ) || !strcmp (* refs , "HEAD" )) &&
165
174
!read_ref (* refs , & oid )) {
166
- show_one (* refs , & oid );
175
+ show_one (show_one_opts , * refs , & oid );
167
176
}
168
- else if (!quiet )
177
+ else if (!show_one_opts -> quiet )
169
178
die ("'%s' - not a valid ref" , * refs );
170
179
else
171
180
return 1 ;
@@ -175,9 +184,12 @@ static int cmd_show_ref__verify(const char **refs)
175
184
return 0 ;
176
185
}
177
186
178
- static int cmd_show_ref__patterns (const char * * patterns )
187
+ static int cmd_show_ref__patterns (const struct show_one_options * show_one_opts ,
188
+ const char * * patterns )
179
189
{
180
- struct show_ref_data show_ref_data = {0 };
190
+ struct show_ref_data show_ref_data = {
191
+ .show_one_opts = show_one_opts ,
192
+ };
181
193
182
194
if (patterns && * patterns )
183
195
show_ref_data .patterns = patterns ;
@@ -200,11 +212,16 @@ static int cmd_show_ref__patterns(const char **patterns)
200
212
201
213
static int hash_callback (const struct option * opt , const char * arg , int unset )
202
214
{
203
- hash_only = 1 ;
215
+ struct show_one_options * opts = opt -> value ;
216
+ struct option abbrev_opt = * opt ;
217
+
218
+ opts -> hash_only = 1 ;
204
219
/* Use full length SHA1 if no argument */
205
220
if (!arg )
206
221
return 0 ;
207
- return parse_opt_abbrev_cb (opt , arg , unset );
222
+
223
+ abbrev_opt .value = & opts -> abbrev ;
224
+ return parse_opt_abbrev_cb (& abbrev_opt , arg , unset );
208
225
}
209
226
210
227
static int exclude_existing_callback (const struct option * opt , const char * arg ,
@@ -220,6 +237,7 @@ static int exclude_existing_callback(const struct option *opt, const char *arg,
220
237
int cmd_show_ref (int argc , const char * * argv , const char * prefix )
221
238
{
222
239
struct exclude_existing_options exclude_existing_opts = {0 };
240
+ struct show_one_options show_one_opts = {0 };
223
241
const struct option show_ref_options [] = {
224
242
OPT_BOOL (0 , "tags" , & tags_only , N_ ("only show tags (can be combined with heads)" )),
225
243
OPT_BOOL (0 , "heads" , & heads_only , N_ ("only show heads (can be combined with tags)" )),
@@ -229,13 +247,13 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
229
247
N_ ("show the HEAD reference, even if it would be filtered out" )),
230
248
OPT_BOOL (0 , "head" , & show_head ,
231
249
N_ ("show the HEAD reference, even if it would be filtered out" )),
232
- OPT_BOOL ('d' , "dereference" , & deref_tags ,
250
+ OPT_BOOL ('d' , "dereference" , & show_one_opts . deref_tags ,
233
251
N_ ("dereference tags into object IDs" )),
234
- OPT_CALLBACK_F ('s' , "hash" , & abbrev , N_ ("n" ),
252
+ OPT_CALLBACK_F ('s' , "hash" , & show_one_opts , N_ ("n" ),
235
253
N_ ("only show SHA1 hash using <n> digits" ),
236
254
PARSE_OPT_OPTARG , & hash_callback ),
237
- OPT__ABBREV (& abbrev ),
238
- OPT__QUIET (& quiet ,
255
+ OPT__ABBREV (& show_one_opts . abbrev ),
256
+ OPT__QUIET (& show_one_opts . quiet ,
239
257
N_ ("do not print results to stdout (useful with --verify)" )),
240
258
OPT_CALLBACK_F (0 , "exclude-existing" , & exclude_existing_opts ,
241
259
N_ ("pattern" ), N_ ("show refs from stdin that aren't in local repository" ),
@@ -251,7 +269,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)
251
269
if (exclude_existing_opts .enabled )
252
270
return cmd_show_ref__exclude_existing (& exclude_existing_opts );
253
271
else if (verify )
254
- return cmd_show_ref__verify (argv );
272
+ return cmd_show_ref__verify (& show_one_opts , argv );
255
273
else
256
- return cmd_show_ref__patterns (argv );
274
+ return cmd_show_ref__patterns (& show_one_opts , argv );
257
275
}
0 commit comments