]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin-log.c
Introduce 'git-format-patch --suffix=.patch'
[thirdparty/git.git] / builtin-log.c
index 8df3c1394a0b70548708137bfe20126fbea01709..7397a5af07c1bd1889d5c0bc2959060401f48829 100644 (file)
@@ -20,6 +20,8 @@ void add_head(struct rev_info *revs);
 static void cmd_log_init(int argc, const char **argv, const char *prefix,
                      struct rev_info *rev)
 {
+       int i;
+
        rev->abbrev = DEFAULT_ABBREV;
        rev->commit_format = CMIT_FMT_DEFAULT;
        rev->verbose_header = 1;
@@ -27,8 +29,18 @@ static void cmd_log_init(int argc, const char **argv, const char *prefix,
        argc = setup_revisions(argc, argv, rev, "HEAD");
        if (rev->diffopt.pickaxe || rev->diffopt.filter)
                rev->always_show_header = 0;
-       if (argc > 1)
-               die("unrecognized argument: %s", argv[1]);
+       for (i = 1; i < argc; i++) {
+               const char *arg = argv[i];
+               if (!strncmp(arg, "--encoding=", 11)) {
+                       arg += 11;
+                       if (strcmp(arg, "none"))
+                               git_log_output_encoding = strdup(arg);
+                       else
+                               git_log_output_encoding = "";
+               }
+               else
+                       die("unrecognized argument: %s", arg);
+       }
 }
 
 static int cmd_log_walk(struct rev_info *rev)
@@ -185,6 +197,7 @@ static int istitlechar(char c)
 
 static char *extra_headers = NULL;
 static int extra_headers_size = 0;
+static const char *fmt_patch_suffix = ".txt";
 
 static int git_format_config(const char *var, const char *value)
 {
@@ -196,6 +209,12 @@ static int git_format_config(const char *var, const char *value)
                strcat(extra_headers, value);
                return 0;
        }
+       if (!strcmp(var, "format.suffix")) {
+               if (!value)
+                       die("format.suffix without value");
+               fmt_patch_suffix = xstrdup(value);
+               return 0;
+       }
        if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
                return 0;
        }
@@ -211,9 +230,10 @@ static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
        char filename[1024];
        char *sol;
        int len = 0;
+       int suffix_len = strlen(fmt_patch_suffix) + 10; /* ., NUL and slop */
 
        if (output_directory) {
-               strlcpy(filename, output_directory, 1010);
+               strlcpy(filename, output_directory, 1000);
                len = strlen(filename);
                if (filename[len - 1] != '/')
                        filename[len++] = '/';
@@ -237,7 +257,10 @@ static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
                        }
                }
 
-               for (j = 0; len < 1024 - 6 && sol[j] && sol[j] != '\n'; j++) {
+               for (j = 0;
+                    len < sizeof(filename) - suffix_len &&
+                            sol[j] && sol[j] != '\n';
+                    j++) {
                        if (istitlechar(sol[j])) {
                                if (space) {
                                        filename[len++] = '-';
@@ -253,7 +276,7 @@ static void reopen_stdout(struct commit *commit, int nr, int keep_subject)
                while (filename[len - 1] == '.' || filename[len - 1] == '-')
                        len--;
        }
-       strcpy(filename + len, ".txt");
+       strcpy(filename + len, fmt_patch_suffix);
        fprintf(realstdout, "%s\n", filename);
        freopen(filename, "w", stdout);
 }
@@ -424,6 +447,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                                die("Need a Message-Id for --in-reply-to");
                        in_reply_to = argv[i];
                }
+               else if (!strncmp(argv[i], "--suffix=", 9))
+                       fmt_patch_suffix = argv[i] + 9;
                else
                        argv[j++] = argv[i];
        }