Skip to content

Commit 2afc29a

Browse files
dschoJunio C Hamano
authored andcommitted
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* 33db5f4 33db5f4 tags/v1.0rc1^0~1593 Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>
1 parent 53756f2 commit 2afc29a

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

Documentation/git-name-rev.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ git-name-rev - Find symbolic names for given revs
88

99
SYNOPSIS
1010
--------
11-
'git-name-rev' [--tags] ( --all | --stdin | <committish>... )
11+
'git-name-rev' [--tags] [--refs=<pattern>]
12+
( --all | --stdin | <committish>... )
1213

1314
DESCRIPTION
1415
-----------
@@ -22,6 +23,9 @@ OPTIONS
2223
--tags::
2324
Do not use branch names, but only tags to name the commits
2425

26+
--refs=<pattern>::
27+
Only use refs whose names match a given shell pattern.
28+
2529
--all::
2630
List all commits reachable from all refs
2731

builtin-name-rev.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
#include "refs.h"
66

77
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";
99

1010
typedef struct rev_name {
1111
const char *tip_name;
@@ -74,13 +74,21 @@ static void name_rev(struct commit *commit,
7474
}
7575
}
7676

77+
struct name_ref_data {
78+
int tags_only;
79+
const char *ref_filter;
80+
};
81+
7782
static int name_ref(const char *path, const unsigned char *sha1, int flags, void *cb_data)
7883
{
7984
struct object *o = parse_object(sha1);
80-
int tags_only = *(int*)cb_data;
85+
struct name_ref_data *data = cb_data;
8186
int deref = 0;
8287

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))
8492
return 0;
8593

8694
while (o && o->type == OBJ_TAG) {
@@ -129,7 +137,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
129137
{
130138
struct object_array revs = { 0, 0, NULL };
131139
int as_is = 0, all = 0, transform_stdin = 0;
132-
int tags_only = 0;
140+
struct name_ref_data data = { 0, NULL };
133141

134142
git_config(git_default_config);
135143

@@ -146,7 +154,10 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
146154
as_is = 1;
147155
continue;
148156
} 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;
150161
continue;
151162
} else if (!strcmp(*argv, "--all")) {
152163
if (argc > 1)
@@ -185,7 +196,7 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
185196
add_object_array((struct object *)commit, *argv, &revs);
186197
}
187198

188-
for_each_ref(name_ref, &tags_only);
199+
for_each_ref(name_ref, &data);
189200

190201
if (transform_stdin) {
191202
char buffer[2048];

0 commit comments

Comments
 (0)