rev-parse --branches/--tags/--remotes=pattern
Since local branch, tags and remote tracking branch namespaces are most often used, add shortcut notations for globbing those in manner similar to --glob option. With this, one can express the "what I have but origin doesn't?" as: 'git log --branches --not --remotes=origin' Original-idea-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ilari Liusvaara committed
Jan 20, 2010 at 11:48 UTC
b09fe971dea73ff6f5296ce533a566114b23ca4e
9 files changed
+139
-20
Documentation/git-log.txt
+2
-2
@@ -107,13 +107,13 @@ git log --follow builtin-rev-list.c::
107
those commits that occurred before the file was given its
108
present name.
109
110
-git log --branches --not --glob=remotes/origin/*::
110
+git log --branches --not --remotes=origin::
111
112
Shows all commits that are in any of local branches but not in
113
any of remote tracking branches for 'origin' (what you have that
114
origin doesn't).
115
116
-git log master --not --glob=remotes/*/master::
116
+git log master --not --remotes=*/master::
117
118
Shows all commits that are in local master but not in any remote
119
repository master branches.
Documentation/git-rev-list.txt
+3
-3
@@ -21,9 +21,9 @@ SYNOPSIS
21
[ \--full-history ]
22
[ \--not ]
23
[ \--all ]
24
- [ \--branches ]
25
- [ \--tags ]
26
- [ \--remotes ]
24
+ [ \--branches[=pattern] ]
25
+ [ \--tags=[pattern] ]
26
+ [ \--remotes=[pattern] ]
27
[ \--glob=glob-pattern ]
28
[ \--stdin ]
29
[ \--quiet ]
Documentation/git-rev-parse.txt
+13
-6
@@ -103,14 +103,21 @@ OPTIONS
103
--all::
104
Show all refs found in `$GIT_DIR/refs`.
105
106
---branches::
107
- Show branch refs found in `$GIT_DIR/refs/heads`.
106
+--branches[=pattern]::
107
+ Show branch refs found in `$GIT_DIR/refs/heads`. If `pattern`
108
+ is given, only branches matching given shell glob are shown.
109
+ If pattern lacks '?', '*', or '[', '/*' at the end is impiled.
110
109
---tags::
110
- Show tag refs found in `$GIT_DIR/refs/tags`.
111
+--tags[=pattern]::
112
+ Show tag refs found in `$GIT_DIR/refs/tags`. If `pattern`
113
+ is given, only tags matching given shell glob are shown.
114
+ If pattern lacks '?', '*', or '[', '/*' at the end is impiled.
115
112
---remotes::
113
- Show tag refs found in `$GIT_DIR/refs/remotes`.
116
+--remotes[=pattern]::
117
+ Show tag refs found in `$GIT_DIR/refs/remotes`. If `pattern`
118
+ is given, only remote tracking branches matching given shell glob
119
+ are shown. If pattern lacks '?', '*', or '[', '/*' at the end is
120
+ impiled.
121
122
--glob=glob-pattern::
123
Show refs matching shell glob pattern `glob-pattern`. If pattern
Documentation/rev-list-options.txt
+12
-6
@@ -228,20 +228,26 @@ endif::git-rev-list[]
228
Pretend as if all the refs in `$GIT_DIR/refs/` are listed on the
229
command line as '<commit>'.
230
231
---branches::
231
+--branches[=pattern]::
232
233
Pretend as if all the refs in `$GIT_DIR/refs/heads` are listed
234
- on the command line as '<commit>'.
234
+ on the command line as '<commit>'. If `pattern` is given, limit
235
+ branches to ones matching given shell glob. If pattern lacks '?',
236
+ '*', or '[', '/*' at the end is impiled.
237
236
---tags::
238
+--tags[=pattern]::
239
240
Pretend as if all the refs in `$GIT_DIR/refs/tags` are listed
239
- on the command line as '<commit>'.
241
+ on the command line as '<commit>'. If `pattern` is given, limit
242
+ tags to ones matching given shell glob. If pattern lacks '?', '*',
243
+ or '[', '/*' at the end is impiled.
244
241
---remotes::
245
+--remotes[=pattern]::
246
247
Pretend as if all the refs in `$GIT_DIR/refs/remotes` are listed
244
- on the command line as '<commit>'.
248
+ on the command line as '<commit>'. If `pattern`is given, limit
249
+ remote tracking branches to ones matching given shell glob.
250
+ If pattern lacks '?', '*', or '[', '/*' at the end is impiled.
251
252
--glob=glob-pattern::
253
Pretend as if all the refs matching shell glob `glob-pattern`
builtin-rev-parse.c
+18
@@ -41,6 +41,7 @@ static int is_rev_argument(const char *arg)
41
"--all",
42
"--bisect",
43
"--dense",
44
+ "--branches=",
45
"--branches",
46
"--header",
47
"--max-age=",
@@ -51,9 +52,11 @@ static int is_rev_argument(const char *arg)
52
"--objects-edge",
53
"--parents",
54
"--pretty",
55
+ "--remotes=",
56
"--remotes",
57
"--glob=",
58
"--sparse",
59
+ "--tags=",
60
"--tags",
61
"--topo-order",
62
"--date-order",
@@ -570,10 +573,20 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
573
for_each_ref_in("refs/bisect/good", anti_reference, NULL);
574
continue;
575
}
576
+ if (!prefixcmp(arg, "--branches=")) {
577
+ for_each_glob_ref_in(show_reference, arg + 11,
578
+ "refs/heads/", NULL);
579
+ continue;
580
+ }
581
if (!strcmp(arg, "--branches")) {
582
for_each_branch_ref(show_reference, NULL);
583
continue;
584
}
585
+ if (!prefixcmp(arg, "--tags=")) {
586
+ for_each_glob_ref_in(show_reference, arg + 7,
587
+ "refs/tags/", NULL);
588
+ continue;
589
+ }
590
if (!strcmp(arg, "--tags")) {
591
for_each_tag_ref(show_reference, NULL);
592
continue;
@@ -582,6 +595,11 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
595
for_each_glob_ref(show_reference, arg + 7, NULL);
596
continue;
597
}
598
+ if (!prefixcmp(arg, "--remotes=")) {
599
+ for_each_glob_ref_in(show_reference, arg + 10,
600
+ "refs/remotes/", NULL);
601
+ continue;
602
+ }
603
if (!strcmp(arg, "--remotes")) {
604
for_each_remote_ref(show_reference, NULL);
605
continue;
refs.c
+10
-2
@@ -690,15 +690,18 @@ int for_each_replace_ref(each_ref_fn fn, void *cb_data)
690
return do_for_each_ref("refs/replace/", fn, 13, 0, cb_data);
691
}
692
693
-int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
693
+int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,
694
+ const char *prefix, void *cb_data)
695
{
696
struct strbuf real_pattern = STRBUF_INIT;
697
struct ref_filter filter;
698
const char *has_glob_specials;
699
int ret;
700
700
- if (prefixcmp(pattern, "refs/"))
701
+ if (!prefix && prefixcmp(pattern, "refs/"))
702
strbuf_addstr(&real_pattern, "refs/");
703
+ else if (prefix)
704
+ strbuf_addstr(&real_pattern, prefix);
705
strbuf_addstr(&real_pattern, pattern);
706
707
has_glob_specials = strpbrk(pattern, "?*[");
@@ -719,6 +722,11 @@ int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
722
return ret;
723
}
724
725
+int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)
726
+{
727
+ return for_each_glob_ref_in(fn, pattern, NULL, cb_data);
728
+}
729
+
730
int for_each_rawref(each_ref_fn fn, void *cb_data)
731
{
732
return do_for_each_ref("refs/", fn, 0,
refs.h
+1
@@ -26,6 +26,7 @@ extern int for_each_branch_ref(each_ref_fn, void *);
26
extern int for_each_remote_ref(each_ref_fn, void *);
27
extern int for_each_replace_ref(each_ref_fn, void *);
28
extern int for_each_glob_ref(each_ref_fn, const char *pattern, void *);
29
+extern int for_each_glob_ref_in(each_ref_fn, const char *pattern, const char* prefix, void *);
30
31
/* can be used to learn about broken ref and symref */
32
extern int for_each_rawref(each_ref_fn, void *);
revision.c
+18
@@ -1364,6 +1364,24 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, const ch
1364
for_each_glob_ref(handle_one_ref, arg + 7, &cb);
1365
continue;
1366
}
1367
+ if (!prefixcmp(arg, "--branches=")) {
1368
+ struct all_refs_cb cb;
1369
+ init_all_refs_cb(&cb, revs, flags);
1370
+ for_each_glob_ref_in(handle_one_ref, arg + 11, "refs/heads/", &cb);
1371
+ continue;
1372
+ }
1373
+ if (!prefixcmp(arg, "--tags=")) {
1374
+ struct all_refs_cb cb;
1375
+ init_all_refs_cb(&cb, revs, flags);
1376
+ for_each_glob_ref_in(handle_one_ref, arg + 7, "refs/tags/", &cb);
1377
+ continue;
1378
+ }
1379
+ if (!prefixcmp(arg, "--remotes=")) {
1380
+ struct all_refs_cb cb;
1381
+ init_all_refs_cb(&cb, revs, flags);
1382
+ for_each_glob_ref_in(handle_one_ref, arg + 10, "refs/remotes/", &cb);
1383
+ continue;
1384
+ }
1385
if (!strcmp(arg, "--reflog")) {
1386
handle_reflog(revs, flags);
1387
continue;
t/t6018-rev-list-glob.sh
+62
-1
@@ -32,7 +32,9 @@ test_expect_success 'setup' '
32
git checkout -b someref master &&
33
commit some &&
34
git checkout master &&
35
- commit master2
35
+ commit master2 &&
36
+ git tag foo/bar master &&
37
+ git update-ref refs/remotes/foo/baz master
38
'
39
40
test_expect_success 'rev-parse --glob=refs/heads/subspace/*' '
@@ -65,6 +67,24 @@ test_expect_success 'rev-parse --glob=heads/subspace' '
67
68
'
69
70
+test_expect_success 'rev-parse --branches=subspace/*' '
71
+
72
+ compare rev-parse "subspace/one subspace/two" "--branches=subspace/*"
73
+
74
+'
75
+
76
+test_expect_success 'rev-parse --branches=subspace/' '
77
+
78
+ compare rev-parse "subspace/one subspace/two" "--branches=subspace/"
79
+
80
+'
81
+
82
+test_expect_success 'rev-parse --branches=subspace' '
83
+
84
+ compare rev-parse "subspace/one subspace/two" "--branches=subspace"
85
+
86
+'
87
+
88
test_expect_success 'rev-parse --glob=heads/subspace/* --glob=heads/other/*' '
89
90
compare rev-parse "subspace/one subspace/two other/three" "--glob=heads/subspace/* --glob=heads/other/*"
@@ -83,6 +103,18 @@ test_expect_success 'rev-parse --glob=heads/*' '
103
104
'
105
106
+test_expect_success 'rev-parse --tags=foo' '
107
+
108
+ compare rev-parse "foo/bar" "--tags=foo"
109
+
110
+'
111
+
112
+test_expect_success 'rev-parse --remotes=foo' '
113
+
114
+ compare rev-parse "foo/baz" "--remotes=foo"
115
+
116
+'
117
+
118
test_expect_success 'rev-list --glob=refs/heads/subspace/*' '
119
120
compare rev-list "subspace/one subspace/two" "--glob=refs/heads/subspace/*"
@@ -113,6 +145,23 @@ test_expect_success 'rev-list --glob=heads/subspace' '
145
146
'
147
148
+test_expect_success 'rev-list --branches=subspace/*' '
149
+
150
+ compare rev-list "subspace/one subspace/two" "--branches=subspace/*"
151
+
152
+'
153
+
154
+test_expect_success 'rev-list --branches=subspace/' '
155
+
156
+ compare rev-list "subspace/one subspace/two" "--branches=subspace/"
157
+
158
+'
159
+
160
+test_expect_success 'rev-list --branches=subspace' '
161
+
162
+ compare rev-list "subspace/one subspace/two" "--branches=subspace"
163
+
164
+'
165
test_expect_success 'rev-list --glob=heads/someref/* master' '
166
167
compare rev-list "master" "--glob=heads/someref/* master"
@@ -131,4 +180,16 @@ test_expect_success 'rev-list --glob=heads/*' '
180
181
'
182
183
+test_expect_success 'rev-list --tags=foo' '
184
+
185
+ compare rev-list "foo/bar" "--tags=foo"
186
+
187
+'
188
+
189
+test_expect_success 'rev-list --remotes=foo' '
190
+
191
+ compare rev-list "foo/baz" "--remotes=foo"
192
+
193
+'
194
+
195
test_done