Code

archive: clarify description of path parameter
[git.git] / builtin-mailinfo.c
index 1c14d381d23074d1c6b2a2180c25629974e3b5c4..3c4f0753fe157960e206f50fbedb7f63d1a7f47d 100644 (file)
@@ -26,6 +26,7 @@ static struct strbuf charset = STRBUF_INIT;
 static int patch_lines;
 static struct strbuf **p_hdr_data, **s_hdr_data;
 static int use_scissors;
+static int use_inbody_headers = 1;
 
 #define MAX_HDR_PARSED 10
 #define MAX_BOUNDARIES 5
@@ -774,10 +775,17 @@ static int handle_commit_msg(struct strbuf *line)
                strbuf_ltrim(line);
                if (!line->len)
                        return 0;
+       }
+
+       if (use_inbody_headers && still_looking) {
                still_looking = check_header(line, s_hdr_data, 0);
                if (still_looking)
                        return 0;
-       }
+       } else
+               /* Only trim the first (blank) line of the commit message
+                * when ignoring in-body headers.
+                */
+               still_looking = 0;
 
        /* normalize the log message to UTF-8. */
        if (metainfo_charset)
@@ -785,8 +793,10 @@ static int handle_commit_msg(struct strbuf *line)
 
        if (use_scissors && is_scissors_line(line)) {
                int i;
-               rewind(cmitmsg);
-               ftruncate(fileno(cmitmsg), 0);
+               if (fseek(cmitmsg, 0L, SEEK_SET))
+                       die_errno("Could not rewind output message file");
+               if (ftruncate(fileno(cmitmsg), 0))
+                       die_errno("Could not truncate output message file at scissors");
                still_looking = 1;
 
                /*
@@ -991,8 +1001,20 @@ static int mailinfo(FILE *in, FILE *out, const char *msg, const char *patch)
        return 0;
 }
 
+static int git_mailinfo_config(const char *var, const char *value, void *unused)
+{
+       if (prefixcmp(var, "mailinfo."))
+               return git_default_config(var, value, unused);
+       if (!strcmp(var, "mailinfo.scissors")) {
+               use_scissors = git_config_bool(var, value);
+               return 0;
+       }
+       /* perhaps others here */
+       return 0;
+}
+
 static const char mailinfo_usage[] =
-       "git mailinfo [-k] [-u | --encoding=<encoding> | -n] msg patch <mail >info";
+       "git mailinfo [-k] [-u | --encoding=<encoding> | -n] [--scissors | --no-scissors] msg patch < mail >info";
 
 int cmd_mailinfo(int argc, const char **argv, const char *prefix)
 {
@@ -1001,7 +1023,7 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
        /* NEEDSWORK: might want to do the optional .git/ directory
         * discovery
         */
-       git_config(git_default_config, NULL);
+       git_config(git_mailinfo_config, NULL);
 
        def_charset = (git_commit_encoding ? git_commit_encoding : "UTF-8");
        metainfo_charset = def_charset;
@@ -1019,6 +1041,8 @@ int cmd_mailinfo(int argc, const char **argv, const char *prefix)
                        use_scissors = 1;
                else if (!strcmp(argv[1], "--no-scissors"))
                        use_scissors = 0;
+               else if (!strcmp(argv[1], "--no-inbody-headers"))
+                       use_inbody_headers = 0;
                else
                        usage(mailinfo_usage);
                argc--; argv++;