Merge branch 'maint'
[gitweb.git] / builtin-log.c
index 1df38e17a2a1795f6bd34aee5249fbc91a8b927b..c7a57725948553a955f49ab891aed3fbdd3aa33d 100644 (file)
@@ -429,6 +429,8 @@ static const char *fmt_patch_suffix = ".patch";
 static int numbered = 0;
 static int auto_number = 1;
 
+static char *default_attach = NULL;
+
 static char **extra_hdr;
 static int extra_hdr_nr;
 static int extra_hdr_alloc;
@@ -460,6 +462,10 @@ static void add_header(const char *value)
        extra_hdr[extra_hdr_nr++] = xstrndup(value, len);
 }
 
+#define THREAD_SHALLOW 1
+#define THREAD_DEEP 2
+static int thread = 0;
+
 static int git_format_config(const char *var, const char *value, void *cb)
 {
        if (!strcmp(var, "format.headers")) {
@@ -489,6 +495,25 @@ static int git_format_config(const char *var, const char *value, void *cb)
                auto_number = auto_number && numbered;
                return 0;
        }
+       if (!strcmp(var, "format.attach")) {
+               if (value && *value)
+                       default_attach = xstrdup(value);
+               else
+                       default_attach = xstrdup(git_version_string);
+               return 0;
+       }
+       if (!strcmp(var, "format.thread")) {
+               if (value && !strcasecmp(value, "deep")) {
+                       thread = THREAD_DEEP;
+                       return 0;
+               }
+               if (value && !strcasecmp(value, "shallow")) {
+                       thread = THREAD_SHALLOW;
+                       return 0;
+               }
+               thread = git_config_bool(var, value) && THREAD_SHALLOW;
+               return 0;
+       }
 
        return git_log_config(var, value, cb);
 }
@@ -548,7 +573,7 @@ static FILE *realstdout = NULL;
 static const char *output_directory = NULL;
 static int outdir_offset;
 
-static int reopen_stdout(const char *oneline, int nr, int total)
+static int reopen_stdout(const char *oneline, int nr, struct rev_info *rev)
 {
        char filename[PATH_MAX];
        int len = 0;
@@ -573,7 +598,9 @@ static int reopen_stdout(const char *oneline, int nr, int total)
                strcpy(filename + len, fmt_patch_suffix);
        }
 
-       fprintf(realstdout, "%s\n", filename + outdir_offset);
+       if (!DIFF_OPT_TST(&rev->diffopt, QUIET))
+               fprintf(realstdout, "%s\n", filename + outdir_offset);
+
        if (freopen(filename, "w", stdout) == NULL)
                return error("Cannot open patch file %s",filename);
 
@@ -662,7 +689,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
                die("Cover letter needs email format");
 
        if (!use_stdout && reopen_stdout(numbered_files ?
-                               NULL : "cover-letter", 0, rev->total))
+                               NULL : "cover-letter", 0, rev))
                return;
 
        head_sha1 = sha1_to_hex(head->object.sha1);
@@ -767,7 +794,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        int numbered_files = 0;         /* _just_ numbers */
        int subject_prefix = 0;
        int ignore_if_in_upstream = 0;
-       int thread = 0;
        int cover_letter = 0;
        int boundary_count = 0;
        int no_binary_diff = 0;
@@ -788,6 +814,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 
        rev.subject_prefix = fmt_patch_subject_prefix;
 
+       if (default_attach) {
+               rev.mime_boundary = default_attach;
+               rev.no_inline = 1;
+       }
+
        /*
         * Parse the arguments before setup_revisions(), or something
         * like "git format-patch -o a123 HEAD^.." may fail; a123 is
@@ -850,6 +881,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                        rev.mime_boundary = argv[i] + 9;
                        rev.no_inline = 1;
                }
+               else if (!strcmp(argv[i], "--no-attach")) {
+                       rev.mime_boundary = NULL;
+                       rev.no_inline = 0;
+               }
                else if (!strcmp(argv[i], "--inline")) {
                        rev.mime_boundary = git_version_string;
                        rev.no_inline = 0;
@@ -860,8 +895,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                }
                else if (!strcmp(argv[i], "--ignore-if-in-upstream"))
                        ignore_if_in_upstream = 1;
-               else if (!strcmp(argv[i], "--thread"))
-                       thread = 1;
+               else if (!strcmp(argv[i], "--thread")
+                       || !strcmp(argv[i], "--thread=shallow"))
+                       thread = THREAD_SHALLOW;
+               else if (!strcmp(argv[i], "--thread=deep"))
+                       thread = THREAD_DEEP;
+               else if (!strcmp(argv[i], "--no-thread"))
+                       thread = 0;
                else if (!prefixcmp(argv[i], "--in-reply-to="))
                        in_reply_to = argv[i] + 14;
                else if (!strcmp(argv[i], "--in-reply-to")) {
@@ -918,8 +958,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                die ("-n and -k are mutually exclusive.");
        if (keep_subject && subject_prefix)
                die ("--subject-prefix and -k are mutually exclusive.");
-       if (numbered_files && use_stdout)
-               die ("--numbered-files and --stdout are mutually exclusive.");
 
        argc = setup_revisions(argc, argv, &rev, "HEAD");
        if (argc > 1)
@@ -1036,6 +1074,12 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                        /* Have we already had a message ID? */
                        if (rev.message_id) {
                                /*
+                                * For deep threading: make every mail
+                                * a reply to the previous one, no
+                                * matter what other options are set.
+                                *
+                                * For shallow threading:
+                                *
                                 * Without --cover-letter and
                                 * --in-reply-to, make every mail a
                                 * reply to the one before.
@@ -1050,7 +1094,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                                 * letter is a reply to the
                                 * --in-reply-to, if specified.
                                 */
-                               if (rev.ref_message_ids->nr > 0
+                               if (thread == THREAD_SHALLOW
+                                   && rev.ref_message_ids->nr > 0
                                    && (!cover_letter || rev.nr > 1))
                                        free(rev.message_id);
                                else
@@ -1061,7 +1106,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                }
                if (!use_stdout && reopen_stdout(numbered_files ? NULL :
                                get_oneline_for_filename(commit, keep_subject),
-                               rev.nr, rev.total))
+                               rev.nr, &rev))
                        die("Failed to create output files");
                shown = log_tree_commit(&rev, commit);
                free(commit->buffer);