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>
diff --git a/builtin-describe.c b/builtin-describe.c
index 165917e..669110c 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 @@
 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 @@
 
 	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