Merge branch 'sp/clip-read-write-to-8mb'
[gitweb.git] / builtin / name-rev.c
index 4c7cc62a9ca9320a5582e824b0c811bece1c7610..20fcf8c696700993617649da77e5bbf6b416498a 100644 (file)
@@ -307,25 +307,31 @@ static void name_rev_line(char *p, struct name_ref_data *data)
 int cmd_name_rev(int argc, const char **argv, const char *prefix)
 {
        struct object_array revs = OBJECT_ARRAY_INIT;
-       int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0;
+       int all = 0, transform_stdin = 0, allow_undefined = 1, always = 0, peel_tag = 0;
        struct name_ref_data data = { 0, 0, NULL };
        struct option opts[] = {
-               OPT_BOOLEAN(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")),
-               OPT_BOOLEAN(0, "tags", &data.tags_only, N_("only use tags to name the commits")),
+               OPT_BOOL(0, "name-only", &data.name_only, N_("print only names (no SHA-1)")),
+               OPT_BOOL(0, "tags", &data.tags_only, N_("only use tags to name the commits")),
                OPT_STRING(0, "refs", &data.ref_filter, N_("pattern"),
                                   N_("only use refs matching <pattern>")),
                OPT_GROUP(""),
-               OPT_BOOLEAN(0, "all", &all, N_("list all commits reachable from all refs")),
-               OPT_BOOLEAN(0, "stdin", &transform_stdin, N_("read from stdin")),
-               OPT_BOOLEAN(0, "undefined", &allow_undefined, N_("allow to print `undefined` names")),
-               OPT_BOOLEAN(0, "always",     &always,
+               OPT_BOOL(0, "all", &all, N_("list all commits reachable from all refs")),
+               OPT_BOOL(0, "stdin", &transform_stdin, N_("read from stdin")),
+               OPT_BOOL(0, "undefined", &allow_undefined, N_("allow to print `undefined` names (default)")),
+               OPT_BOOL(0, "always",     &always,
                           N_("show abbreviated commit object as fallback")),
+               {
+                       /* A Hidden OPT_BOOL */
+                       OPTION_SET_INT, 0, "peel-tag", &peel_tag, NULL,
+                       N_("dereference tags in the input (internal use)"),
+                       PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1,
+               },
                OPT_END(),
        };
 
        git_config(git_default_config, NULL);
        argc = parse_options(argc, argv, prefix, opts, name_rev_usage, 0);
-       if (!!all + !!transform_stdin + !!argc > 1) {
+       if (all + transform_stdin + !!argc > 1) {
                error("Specify either a list, or --all, not both!");
                usage_with_options(name_rev_usage, opts);
        }
@@ -361,6 +367,15 @@ int cmd_name_rev(int argc, const char **argv, const char *prefix)
                        if (cutoff > commit->date)
                                cutoff = commit->date;
                }
+
+               if (peel_tag) {
+                       if (!commit) {
+                               fprintf(stderr, "Could not get commit for %s. Skipping.\n",
+                                       *argv);
+                               continue;
+                       }
+                       object = (struct object *)commit;
+               }
                add_object_array(object, *argv, &revs);
        }