summaryrefslogtreecommitdiff
path: root/builtin-describe.c
diff options
context:
space:
mode:
authorShawn O. Pearce <spearce@spearce.org>2007-05-21 03:20:25 -0400
committerJunio C Hamano <junkio@cox.net>2007-05-21 23:56:28 -0700
commit23615708e2abef5c293ddee9335950161a038133 (patch)
treeae1e929a1ebc5342b977ad6a8dedf82376eebecb /builtin-describe.c
parent302b9282c9ddfcc704ca759bdc98c1d5f75eba2f (diff)
downloadgit-23615708e2abef5c293ddee9335950161a038133.tar.gz
Teach git-describe how to run name-rev
Often users want to know not which tagged version a commit came after, but which tagged version a commit is contained within. This latter task is the job of git-name-rev, but most users are looking to git-describe to do the job. Junio suggested we make `git describe --contains` run the correct tool, `git name-rev`, and that's exactly what we do here. The output of name-rev was adjusted slightly through the new --name-only option, allowing describe to execv into name-rev and maintain its current output format. Signed-off-by: Shawn O. Pearce <spearce@spearce.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-describe.c')
-rw-r--r--builtin-describe.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/builtin-describe.c b/builtin-describe.c
index 165917e40d..669110cb06 100644
--- a/builtin-describe.c
+++ b/builtin-describe.c
@@ -3,6 +3,7 @@
#include "tag.h"
#include "refs.h"
#include "builtin.h"
+#include "exec_cmd.h"
#define SEEN (1u<<0)
#define MAX_TAGS (FLAG_BITS - 1)
@@ -242,12 +243,15 @@ static void describe(const char *arg, int last_one)
int cmd_describe(int argc, const char **argv, const char *prefix)
{
int i;
+ int contains = 0;
for (i = 1; i < argc; i++) {
const char *arg = argv[i];
if (*arg != '-')
break;
+ else if (!strcmp(arg, "--contains"))
+ contains = 1;
else if (!strcmp(arg, "--debug"))
debug = 1;
else if (!strcmp(arg, "--all"))
@@ -272,6 +276,16 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
save_commit_buffer = 0;
+ if (contains) {
+ const char **args = xmalloc((4 + argc - i) * sizeof(char*));
+ args[0] = "name-rev";
+ args[1] = "--name-only";
+ args[2] = "--tags";
+ memcpy(args + 3, argv + i, (argc - i) * sizeof(char*));
+ args[3 + argc - i] = NULL;
+ return cmd_name_rev(3 + argc - i, args, prefix);
+ }
+
if (argc <= i)
describe("HEAD", 1);
else