Code

git-mergetool: Make default selection of merge-tool more intelligent
[git.git] / builtin-describe.c
index bcc645622a962166d19ea811af185ae4d68bd011..669110cb0645629ca5b152d8328aa91d63be1550 100644 (file)
@@ -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)
@@ -52,7 +53,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void
         * If --tags, then any tags are used.
         * Otherwise only annotated tags are used.
         */
-       if (!strncmp(path, "refs/tags/", 10)) {
+       if (!prefixcmp(path, "refs/tags/")) {
                if (object->type == OBJ_TAG)
                        prio = 2;
                else
@@ -242,24 +243,27 @@ 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"))
                        all = 1;
                else if (!strcmp(arg, "--tags"))
                        tags = 1;
-               else if (!strncmp(arg, "--abbrev=", 9)) {
+               else if (!prefixcmp(arg, "--abbrev=")) {
                        abbrev = strtoul(arg + 9, NULL, 10);
                        if (abbrev != 0 && (abbrev < MINIMUM_ABBREV || 40 < abbrev))
                                abbrev = DEFAULT_ABBREV;
                }
-               else if (!strncmp(arg, "--candidates=", 13)) {
+               else if (!prefixcmp(arg, "--candidates=")) {
                        max_candidates = strtoul(arg + 13, NULL, 10);
                        if (max_candidates < 1)
                                max_candidates = 1;
@@ -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