Merge branch 'mk/color'
[gitweb.git] / builtin-tag.c
index 274901a408fa0d1d988da35d637ead7ca565552e..129ff57f11d2cdfdacc6be9685736ada07caef7f 100644 (file)
@@ -16,7 +16,7 @@
 static const char * const git_tag_usage[] = {
        "git-tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]",
        "git-tag -d <tagname>...",
-       "git-tag [-n [<num>]] -l [<pattern>]",
+       "git-tag -l [-n[<num>]] [<pattern>]",
        "git-tag -v <tagname>...",
        NULL
 };
@@ -47,10 +47,26 @@ void launch_editor(const char *path, struct strbuf *buffer, const char *const *e
                editor = "vi";
 
        if (strcmp(editor, ":")) {
-               const char *args[] = { editor, path, NULL };
+               size_t len = strlen(editor);
+               int i = 0;
+               const char *args[6];
+               struct strbuf arg0;
+
+               strbuf_init(&arg0, 0);
+               if (strcspn(editor, "$ \t'") != len) {
+                       /* there are specials */
+                       strbuf_addf(&arg0, "%s \"$@\"", editor);
+                       args[i++] = "sh";
+                       args[i++] = "-c";
+                       args[i++] = arg0.buf;
+               }
+               args[i++] = editor;
+               args[i++] = path;
+               args[i] = NULL;
 
                if (run_command_v_opt_cd_env(args, 0, NULL, env))
                        die("There was a problem with the editor %s.", editor);
+               strbuf_release(&arg0);
        }
 
        if (!buffer)
@@ -214,19 +230,17 @@ static int do_sign(struct strbuf *buffer)
 
        if (write_in_full(gpg.in, buffer->buf, buffer->len) != buffer->len) {
                close(gpg.in);
+               close(gpg.out);
                finish_command(&gpg);
                return error("gpg did not accept the tag data");
        }
        close(gpg.in);
-       gpg.close_in = 0;
        len = strbuf_read(buffer, gpg.out, 1024);
+       close(gpg.out);
 
        if (finish_command(&gpg) || !len || len < 0)
                return error("gpg failed to sign the tag");
 
-       if (len < 0)
-               return error("could not read the entire signature from gpg.");
-
        return 0;
 }
 
@@ -246,7 +260,7 @@ static int git_tag_config(const char *var, const char *value)
 {
        if (!strcmp(var, "user.signingkey")) {
                if (!value)
-                       die("user.signingkey without value");
+                       return config_error_nonbool(value);
                set_signingkey(value);
                return 0;
        }
@@ -370,13 +384,11 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
        struct ref_lock *lock;
 
        int annotate = 0, sign = 0, force = 0, lines = 0,
-                                       delete = 0, verify = 0;
-       char *list = NULL, *msgfile = NULL, *keyid = NULL;
-       const char *no_pattern = "NO_PATTERN";
+               list = 0, delete = 0, verify = 0;
+       char *msgfile = NULL, *keyid = NULL;
        struct msg_arg msg = { 0, STRBUF_INIT };
        struct option options[] = {
-               { OPTION_STRING, 'l', NULL, &list, "pattern", "list tag names",
-                       PARSE_OPT_OPTARG, NULL, (intptr_t) no_pattern },
+               OPT_BOOLEAN('l', NULL, &list, "list tag names"),
                { OPTION_INTEGER, 'n', NULL, &lines, NULL,
                                "print n lines of each tag message",
                                PARSE_OPT_OPTARG, NULL, 1 },
@@ -408,7 +420,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                annotate = 1;
 
        if (list)
-               return list_tags(list == no_pattern ? NULL : list, lines);
+               return list_tags(argv[0], lines);
        if (delete)
                return for_each_tag_name(argv, delete_tag);
        if (verify)