@matheusbsbs / matheus-bagliano / commits / 30ffa60377
Fork 0

git-describe: Add a --match option to limit considered tags.

Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Pierre Habouzit committed Dec 21, 2007 at 22:49 UTC 30ffa60377acb443033045a42ffecefdb0921ebb
2 files changed +20 -5
Documentation/git-describe.txt
+4
@@ -51,6 +51,10 @@ OPTIONS
51 being employed to standard error. The tag name will still
52 be printed to standard out.
53
54 +--match <pattern>::
55 + Only consider tags matching the given pattern (can be used to avoid
56 + leaking private tags made from the repository).
57 +
58 EXAMPLES
59 --------
60
builtin-describe.c
+16 -5
@@ -19,6 +19,7 @@ static int all; /* Default to annotated tags only */
19 static int tags; /* But allow any tags if --tags is specified */
20 static int abbrev = DEFAULT_ABBREV;
21 static int max_candidates = 10;
22 +const char *pattern = NULL;
23
24 struct commit_name {
25 int prio; /* annotated tag = 2, tag = 1, head = 0 */
@@ -57,9 +58,11 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
58 * Otherwise only annotated tags are used.
59 */
60 if (!prefixcmp(path, "refs/tags/")) {
60 - if (object->type == OBJ_TAG)
61 + if (object->type == OBJ_TAG) {
62 prio = 2;
62 - else
63 + if (pattern && fnmatch(pattern, path + 10, 0))
64 + prio = 0;
65 + } else
66 prio = 1;
67 }
68 else
@@ -253,7 +256,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
256 OPT_BOOLEAN(0, "tags", &tags, "use any tag in .git/refs/tags"),
257 OPT__ABBREV(&abbrev),
258 OPT_INTEGER(0, "candidates", &max_candidates,
256 - "consider <n> most recent tags (default: 10)"),
259 + "consider <n> most recent tags (default: 10)"),
260 + OPT_STRING(0, "match", &pattern, "pattern",
261 + "only consider tags matching <pattern>"),
262 OPT_END(),
263 };
264
@@ -266,12 +271,18 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
271 save_commit_buffer = 0;
272
273 if (contains) {
269 - const char **args = xmalloc((4 + argc) * sizeof(char*));
274 + const char **args = xmalloc((5 + argc) * sizeof(char*));
275 int i = 0;
276 args[i++] = "name-rev";
277 args[i++] = "--name-only";
273 - if (!all)
278 + if (!all) {
279 args[i++] = "--tags";
280 + if (pattern) {
281 + char *s = xmalloc(strlen("--refs=refs/tags/") + strlen(pattern) + 1);
282 + sprintf(s, "--refs=refs/tags/%s", pattern);
283 + args[i++] = s;
284 + }
285 + }
286 memcpy(args + i, argv, argc * sizeof(char*));
287 args[i + argc] = NULL;
288 return cmd_name_rev(i + argc, args, prefix);