Skip to content

Commit 295e393

Browse files
committed
Merge branch 'jc/describe' into maint
The "--match=<pattern>" option of "git describe", when used with "--all" to allow refs that are not annotated tags to be used as a base of description, did not restrict the output from the command to those that match the given pattern. * jc/describe: describe: --match=<pattern> must limit the refs even when used with --all
2 parents eeecf39 + 46e1d6e commit 295e393

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

builtin/describe.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -137,40 +137,39 @@ static void add_to_known_names(const char *path,
137137

138138
static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)
139139
{
140-
int might_be_tag = !prefixcmp(path, "refs/tags/");
140+
int is_tag = !prefixcmp(path, "refs/tags/");
141141
unsigned char peeled[20];
142-
int is_tag, prio;
142+
int is_annotated, prio;
143143

144-
if (!all && !might_be_tag)
144+
/* Reject anything outside refs/tags/ unless --all */
145+
if (!all && !is_tag)
145146
return 0;
146147

148+
/* Accept only tags that match the pattern, if given */
149+
if (pattern && (!is_tag || fnmatch(pattern, path + 10, 0)))
150+
return 0;
151+
152+
/* Is it annotated? */
147153
if (!peel_ref(path, peeled)) {
148-
is_tag = !!hashcmp(sha1, peeled);
154+
is_annotated = !!hashcmp(sha1, peeled);
149155
} else {
150156
hashcpy(peeled, sha1);
151-
is_tag = 0;
157+
is_annotated = 0;
152158
}
153159

154-
/* If --all, then any refs are used.
155-
* If --tags, then any tags are used.
156-
* Otherwise only annotated tags are used.
160+
/*
161+
* By default, we only use annotated tags, but with --tags
162+
* we fall back to lightweight ones (even without --tags,
163+
* we still remember lightweight ones, only to give hints
164+
* in an error message). --all allows any refs to be used.
157165
*/
158-
if (might_be_tag) {
159-
if (is_tag)
160-
prio = 2;
161-
else
162-
prio = 1;
163-
164-
if (pattern && fnmatch(pattern, path + 10, 0))
165-
prio = 0;
166-
}
166+
if (is_annotated)
167+
prio = 2;
168+
else if (is_tag)
169+
prio = 1;
167170
else
168171
prio = 0;
169172

170-
if (!all) {
171-
if (!prio)
172-
return 0;
173-
}
174173
add_to_known_names(all ? path + 5 : path + 10, peeled, prio, sha1);
175174
return 0;
176175
}

0 commit comments

Comments
 (0)