@matheusbsbs / matheus-bagliano / commits / 2afc29aa84
Fork 0

name-rev: introduce the --refs=<pattern> option

Instead of (or, in addition to) --tags, to use only tags for naming, you can now use --refs=<pattern> to specify a shell glob pattern which the refs must match to be used for naming. Example: $ git name-rev --refs=*v1* 33db5f4d 33db5f4d tags/v1.0rc1^0~1593 Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Feb 17, 2007 at 19:22 UTC 2afc29aa84f518906c50a1f005e3d715babb5c20
2 files changed +22 -7
Documentation/git-name-rev.txt
+5 -1
@@ -8,7 +8,8 @@ git-name-rev - Find symbolic names for given revs
8
9 SYNOPSIS
10 --------
11 -'git-name-rev' [--tags] ( --all | --stdin | <committish>... )
11 +'git-name-rev' [--tags] [--refs=<pattern>]
12 + ( --all | --stdin | <committish>... )
13
14 DESCRIPTION
15 -----------
@@ -22,6 +23,9 @@ OPTIONS
23 --tags::
24 Do not use branch names, but only tags to name the commits
25
26 +--refs=<pattern>::
27 + Only use refs whose names match a given shell pattern.
28 +
29 --all::
30 List all commits reachable from all refs
31
builtin-name-rev.c
+17 -6
@@ -5,7 +5,7 @@
5 #include "refs.h"
6
7 static const char name_rev_usage[] =
8 - "git-name-rev [--tags] ( --all | --stdin | committish [committish...] )\n";
8 + "git-name-rev [--tags | --refs=<pattern>] ( --all | --stdin | committish [committish...] )\n";
9
10 typedef struct rev_name {
11 const char *tip_name;
@@ -74,13 +74,21 @@ copy_data:
74 }
75 }
76
77 +struct name_ref_data {
78 + int tags_only;
79 + const char *ref_filter;
80 +};
81 +
82 static int name_ref(const char *path, const unsigned char *sha1, int flags, void *cb_data)
83 {
84 struct object *o = parse_object(sha1);
80 - int tags_only = *(int*)cb_data;
85 + struct name_ref_data *data = cb_data;
86 int deref = 0;
87
83 - if (tags_only && strncmp(path, "refs/tags/", 10))
88 + if (data->tags_only && strncmp(path, "refs/tags/", 10))
89 + return 0;
90 +
91 + if (data->ref_filter && fnmatch(data->ref_filter, path, 0))
92 return 0;
93
94 while (o && o->type == OBJ_TAG) {
@@ -129,7 +137,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
137 {
138 struct object_array revs = { 0, 0, NULL };
139 int as_is = 0, all = 0, transform_stdin = 0;
132 - int tags_only = 0;
140 + struct name_ref_data data = { 0, NULL };
141
142 git_config(git_default_config);
143
@@ -146,7 +154,10 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
154 as_is = 1;
155 continue;
156 } else if (!strcmp(*argv, "--tags")) {
149 - tags_only = 1;
157 + data.tags_only = 1;
158 + continue;
159 + } else if (!strncmp(*argv, "--refs=", 7)) {
160 + data.ref_filter = *argv + 7;
161 continue;
162 } else if (!strcmp(*argv, "--all")) {
163 if (argc > 1)
@@ -185,7 +196,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
196 add_object_array((struct object *)commit, *argv, &revs);
197 }
198
188 - for_each_ref(name_ref, &tags_only);
199 + for_each_ref(name_ref, &data);
200
201 if (transform_stdin) {
202 char buffer[2048];