revisions: allow --glob and friends in parse_options-enabled commands
As v1.6.0-rc2~42 (2008-07-31) explains, even pseudo-options like --not and --glob that need to be parsed in order with revisions should be marked handled by handle_revision_opt to avoid an error when parse_revision_opt callers like "git shortlog" encounter them. Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Nieder committed
Apr 21, 2011 at 05:48 UTC
0fc63ec4e7291361b59e12433e5c07117951cf19
2 files changed
+63
-1
revision.c
+13
-1
@@ -1178,7 +1178,9 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1178
!strcmp(arg, "--tags") || !strcmp(arg, "--remotes") ||
1179
!strcmp(arg, "--reflog") || !strcmp(arg, "--not") ||
1180
!strcmp(arg, "--no-walk") || !strcmp(arg, "--do-walk") ||
1181
- !strcmp(arg, "--bisect"))
1181
+ !strcmp(arg, "--bisect") || !prefixcmp(arg, "--glob=") ||
1182
+ !prefixcmp(arg, "--branches=") || !prefixcmp(arg, "--tags=") ||
1183
+ !prefixcmp(arg, "--remotes="))
1184
{
1185
unkv[(*unkc)++] = arg;
1186
return 1;
@@ -1534,6 +1536,16 @@ static int handle_revision_pseudo_opt(const char *submodule,
1536
const char *optarg;
1537
int argcount;
1538
1539
+ /*
1540
+ * NOTE!
1541
+ *
1542
+ * Commands like "git shortlog" will not accept the options below
1543
+ * unless parse_revision_opt queues them (as opposed to erroring
1544
+ * out).
1545
+ *
1546
+ * When implementing your new pseudo-option, remember to
1547
+ * register it in the list at the top of handle_revision_opt.
1548
+ */
1549
if (!strcmp(arg, "--all")) {
1550
handle_refs(submodule, revs, *flags, for_each_ref_submodule);
1551
handle_refs(submodule, revs, *flags, head_ref_submodule);
t/t6018-rev-list-glob.sh
+50
@@ -69,6 +69,18 @@ test_expect_success 'rev-parse --glob=heads/subspace' '
69
70
'
71
72
+test_expect_failure 'rev-parse accepts --glob as detached option' '
73
+
74
+ compare rev-parse "subspace/one subspace/two" "--glob heads/subspace"
75
+
76
+'
77
+
78
+test_expect_failure 'rev-parse is not confused by option-like glob' '
79
+
80
+ compare rev-parse "master" "--glob --symbolic master"
81
+
82
+'
83
+
84
test_expect_success 'rev-parse --branches=subspace/*' '
85
86
compare rev-parse "subspace/one subspace/two" "--branches=subspace/*"
@@ -129,6 +141,12 @@ test_expect_success 'rev-list --glob refs/heads/subspace/*' '
141
142
'
143
144
+test_expect_success 'rev-list not confused by option-like --glob arg' '
145
+
146
+ compare rev-list "master" "--glob -0 master"
147
+
148
+'
149
+
150
test_expect_success 'rev-list --glob=heads/subspace/*' '
151
152
compare rev-list "subspace/one subspace/two" "--glob=heads/subspace/*"
@@ -213,4 +231,36 @@ test_expect_success 'rev-list --remotes=foo' '
231
232
'
233
234
+test_expect_success 'shortlog accepts --glob/--tags/--remotes' '
235
+
236
+ compare shortlog "subspace/one subspace/two" --branches=subspace &&
237
+ compare shortlog \
238
+ "master subspace-x someref other/three subspace/one subspace/two" \
239
+ --branches &&
240
+ compare shortlog master "--glob=heads/someref/* master" &&
241
+ compare shortlog "subspace/one subspace/two other/three" \
242
+ "--glob=heads/subspace/* --glob=heads/other/*" &&
243
+ compare shortlog \
244
+ "master other/three someref subspace-x subspace/one subspace/two" \
245
+ "--glob=heads/*" &&
246
+ compare shortlog foo/bar --tags=foo &&
247
+ compare shortlog foo/bar --tags &&
248
+ compare shortlog foo/baz --remotes=foo
249
+
250
+'
251
+
252
+test_expect_failure 'shortlog accepts --glob as detached option' '
253
+
254
+ compare shortlog \
255
+ "master other/three someref subspace-x subspace/one subspace/two" \
256
+ "--glob heads/*"
257
+
258
+'
259
+
260
+test_expect_failure 'shortlog --glob is not confused by option-like argument' '
261
+
262
+ compare shortlog master "--glob -e master"
263
+
264
+'
265
+
266
test_done