]> git.ipfire.org Git - thirdparty/git.git/blobdiff - builtin/log.c
Merge branch 'pb/log-first-parent-p-m'
[thirdparty/git.git] / builtin / log.c
similarity index 95%
rename from builtin-log.c
rename to builtin/log.c
index 4dd6d2c449cc42b164ff2e6fe0d5526cca3ccc7c..fade77200f14514950c727bae7af402d7174f11a 100644 (file)
@@ -483,35 +483,28 @@ static int auto_number = 1;
 
 static char *default_attach = NULL;
 
-static char **extra_hdr;
-static int extra_hdr_nr;
-static int extra_hdr_alloc;
-
-static char **extra_to;
-static int extra_to_nr;
-static int extra_to_alloc;
-
-static char **extra_cc;
-static int extra_cc_nr;
-static int extra_cc_alloc;
+static struct string_list extra_hdr;
+static struct string_list extra_to;
+static struct string_list extra_cc;
 
 static void add_header(const char *value)
 {
+       struct string_list_item *item;
        int len = strlen(value);
        while (len && value[len - 1] == '\n')
                len--;
+
        if (!strncasecmp(value, "to: ", 4)) {
-               ALLOC_GROW(extra_to, extra_to_nr + 1, extra_to_alloc);
-               extra_to[extra_to_nr++] = xstrndup(value + 4, len - 4);
-               return;
-       }
-       if (!strncasecmp(value, "cc: ", 4)) {
-               ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);
-               extra_cc[extra_cc_nr++] = xstrndup(value + 4, len - 4);
-               return;
+               item = string_list_append(value + 4, &extra_to);
+               len -= 4;
+       } else if (!strncasecmp(value, "cc: ", 4)) {
+               item = string_list_append(value + 4, &extra_cc);
+               len -= 4;
+       } else {
+               item = string_list_append(value, &extra_hdr);
        }
-       ALLOC_GROW(extra_hdr, extra_hdr_nr + 1, extra_hdr_alloc);
-       extra_hdr[extra_hdr_nr++] = xstrndup(value, len);
+
+       item->string[len] = '\0';
 }
 
 #define THREAD_SHALLOW 1
@@ -529,11 +522,16 @@ static int git_format_config(const char *var, const char *value, void *cb)
        }
        if (!strcmp(var, "format.suffix"))
                return git_config_string(&fmt_patch_suffix, var, value);
+       if (!strcmp(var, "format.to")) {
+               if (!value)
+                       return config_error_nonbool(var);
+               string_list_append(value, &extra_to);
+               return 0;
+       }
        if (!strcmp(var, "format.cc")) {
                if (!value)
                        return config_error_nonbool(var);
-               ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);
-               extra_cc[extra_cc_nr++] = xstrdup(value);
+               string_list_append(value, &extra_cc);
                return 0;
        }
        if (!strcmp(var, "diff.color") || !strcmp(var, "color.diff")) {
@@ -896,14 +894,31 @@ static int inline_callback(const struct option *opt, const char *arg, int unset)
 
 static int header_callback(const struct option *opt, const char *arg, int unset)
 {
-       add_header(arg);
+       if (unset) {
+               string_list_clear(&extra_hdr, 0);
+               string_list_clear(&extra_to, 0);
+               string_list_clear(&extra_cc, 0);
+       } else {
+           add_header(arg);
+       }
+       return 0;
+}
+
+static int to_callback(const struct option *opt, const char *arg, int unset)
+{
+       if (unset)
+               string_list_clear(&extra_to, 0);
+       else
+               string_list_append(arg, &extra_to);
        return 0;
 }
 
 static int cc_callback(const struct option *opt, const char *arg, int unset)
 {
-       ALLOC_GROW(extra_cc, extra_cc_nr + 1, extra_cc_alloc);
-       extra_cc[extra_cc_nr++] = xstrdup(arg);
+       if (unset)
+               string_list_clear(&extra_cc, 0);
+       else
+               string_list_append(arg, &extra_cc);
        return 0;
 }
 
@@ -963,10 +978,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                  PARSE_OPT_NONEG | PARSE_OPT_NOARG },
                OPT_GROUP("Messaging"),
                { OPTION_CALLBACK, 0, "add-header", NULL, "header",
-                           "add email header", PARSE_OPT_NONEG,
-                           header_callback },
+                           "add email header", 0, header_callback },
+               { OPTION_CALLBACK, 0, "to", NULL, "email", "add To: header",
+                           0, to_callback },
                { OPTION_CALLBACK, 0, "cc", NULL, "email", "add Cc: header",
-                           PARSE_OPT_NONEG, cc_callback },
+                           0, cc_callback },
                OPT_STRING(0, "in-reply-to", &in_reply_to, "message-id",
                            "make first mail a reply to <message-id>"),
                { OPTION_CALLBACK, 0, "attach", &rev, "boundary",
@@ -982,6 +998,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                OPT_END()
        };
 
+       extra_hdr.strdup_strings = 1;
+       extra_to.strdup_strings = 1;
+       extra_cc.strdup_strings = 1;
        git_config(git_format_config, NULL);
        init_revisions(&rev, prefix);
        rev.commit_format = CMIT_FMT_EMAIL;
@@ -1019,29 +1038,29 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                add_signoff = xmemdupz(committer, endpos - committer + 1);
        }
 
-       for (i = 0; i < extra_hdr_nr; i++) {
-               strbuf_addstr(&buf, extra_hdr[i]);
+       for (i = 0; i < extra_hdr.nr; i++) {
+               strbuf_addstr(&buf, extra_hdr.items[i].string);
                strbuf_addch(&buf, '\n');
        }
 
-       if (extra_to_nr)
+       if (extra_to.nr)
                strbuf_addstr(&buf, "To: ");
-       for (i = 0; i < extra_to_nr; i++) {
+       for (i = 0; i < extra_to.nr; i++) {
                if (i)
                        strbuf_addstr(&buf, "    ");
-               strbuf_addstr(&buf, extra_to[i]);
-               if (i + 1 < extra_to_nr)
+               strbuf_addstr(&buf, extra_to.items[i].string);
+               if (i + 1 < extra_to.nr)
                        strbuf_addch(&buf, ',');
                strbuf_addch(&buf, '\n');
        }
 
-       if (extra_cc_nr)
+       if (extra_cc.nr)
                strbuf_addstr(&buf, "Cc: ");
-       for (i = 0; i < extra_cc_nr; i++) {
+       for (i = 0; i < extra_cc.nr; i++) {
                if (i)
                        strbuf_addstr(&buf, "    ");
-               strbuf_addstr(&buf, extra_cc[i]);
-               if (i + 1 < extra_cc_nr)
+               strbuf_addstr(&buf, extra_cc.items[i].string);
+               if (i + 1 < extra_cc.nr)
                        strbuf_addch(&buf, ',');
                strbuf_addch(&buf, '\n');
        }
@@ -1116,7 +1135,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 
        /*
         * We cannot move this anywhere earlier because we do want to
-        * know if --root was given explicitly from the comand line.
+        * know if --root was given explicitly from the command line.
         */
        rev.show_root_diff = 1;
 
@@ -1250,6 +1269,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                        fclose(stdout);
        }
        free(list);
+       string_list_clear(&extra_to, 0);
+       string_list_clear(&extra_cc, 0);
+       string_list_clear(&extra_hdr, 0);
        if (ignore_if_in_upstream)
                free_patch_ids(&ids);
        return 0;