format-patch: add format.coverLetter configuration variable
authorFelipe Contreras <felipe.contreras@gmail.com>
Sun, 7 Apr 2013 17:46:23 +0000 (12:46 -0500)
committerJunio C Hamano <gitster@pobox.com>
Sun, 7 Apr 2013 20:37:47 +0000 (13:37 -0700)
Also, add a new option: 'auto', so if there's more than one patch, the
cover letter is generated, otherwise it's not.

Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config.txt
Documentation/git-format-patch.txt
builtin/log.c
t/t4014-format-patch.sh
index 50840aab5e9b8c525271d171f719ff6bda3580b0..83b924494c30bf5d8180ab7592536fb5b9d44b69 100644 (file)
@@ -1096,6 +1096,11 @@ format.signoff::
     the rights to submit this work under the same open source license.
     Please see the 'SubmittingPatches' document for further discussion.
 
     the rights to submit this work under the same open source license.
     Please see the 'SubmittingPatches' document for further discussion.
 
+format.coverLetter::
+       A boolean that controls whether to generate a cover-letter when
+       format-patch is invoked, but in addition can be set to "auto", to
+       generate a cover-letter only when there's more than one patch.
+
 filter.<driver>.clean::
        The command which is used to convert the content of a worktree
        file to a blob upon checkin.  See linkgit:gitattributes[5] for
 filter.<driver>.clean::
        The command which is used to convert the content of a worktree
        file to a blob upon checkin.  See linkgit:gitattributes[5] for
index 3a62f50edae9cdc772cb1009cf839b18e0079a9c..39118774afbbd730e4464f44e24a05af91432c30 100644 (file)
@@ -20,7 +20,7 @@ SYNOPSIS
                   [--ignore-if-in-upstream]
                   [--subject-prefix=Subject-Prefix] [(--reroll-count|-v) <n>]
                   [--to=<email>] [--cc=<email>]
                   [--ignore-if-in-upstream]
                   [--subject-prefix=Subject-Prefix] [(--reroll-count|-v) <n>]
                   [--to=<email>] [--cc=<email>]
-                  [--cover-letter] [--quiet] [--notes[=<ref>]]
+                  [--[no-]cover-letter] [--quiet] [--notes[=<ref>]]
                   [<common diff options>]
                   [ <since> | <revision range> ]
 
                   [<common diff options>]
                   [ <since> | <revision range> ]
 
@@ -195,7 +195,7 @@ will want to ensure that threading is disabled for `git send-email`.
        `Cc:`, and custom) headers added so far from config or command
        line.
 
        `Cc:`, and custom) headers added so far from config or command
        line.
 
---cover-letter::
+--[no-]cover-letter::
        In addition to the patches, generate a cover letter file
        containing the shortlog and the overall diffstat.  You can
        fill in a description in the file before sending it out.
        In addition to the patches, generate a cover letter file
        containing the shortlog and the overall diffstat.  You can
        fill in a description in the file before sending it out.
@@ -260,6 +260,7 @@ attachments, and sign off patches with configuration variables.
        cc = <email>
        attach [ = mime-boundary-string ]
        signoff = true
        cc = <email>
        attach [ = mime-boundary-string ]
        signoff = true
+       coverletter = auto
 ------------
 
 
 ------------
 
 
index 40347adde434c4714ea7af8c697bfbf2ad12696c..9d2b23aa805dc4374420429efc8f795a75d289e8 100644 (file)
@@ -622,6 +622,14 @@ static void add_header(const char *value)
 static int thread;
 static int do_signoff;
 static const char *signature = git_version_string;
 static int thread;
 static int do_signoff;
 static const char *signature = git_version_string;
+static int config_cover_letter;
+
+enum {
+       COVER_UNSET,
+       COVER_OFF,
+       COVER_ON,
+       COVER_AUTO
+};
 
 static int git_format_config(const char *var, const char *value, void *cb)
 {
 
 static int git_format_config(const char *var, const char *value, void *cb)
 {
@@ -683,6 +691,14 @@ static int git_format_config(const char *var, const char *value, void *cb)
        }
        if (!strcmp(var, "format.signature"))
                return git_config_string(&signature, var, value);
        }
        if (!strcmp(var, "format.signature"))
                return git_config_string(&signature, var, value);
+       if (!strcmp(var, "format.coverletter")) {
+               if (value && !strcasecmp(value, "auto")) {
+                       config_cover_letter = COVER_AUTO;
+                       return 0;
+               }
+               config_cover_letter = git_config_bool(var, value) ? COVER_ON : COVER_OFF;
+               return 0;
+       }
 
        return git_log_config(var, value, cb);
 }
 
        return git_log_config(var, value, cb);
 }
@@ -1074,7 +1090,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        int start_number = -1;
        int just_numbers = 0;
        int ignore_if_in_upstream = 0;
        int start_number = -1;
        int just_numbers = 0;
        int ignore_if_in_upstream = 0;
-       int cover_letter = 0;
+       int cover_letter = -1;
        int boundary_count = 0;
        int no_binary_diff = 0;
        struct commit *origin = NULL, *head = NULL;
        int boundary_count = 0;
        int no_binary_diff = 0;
        struct commit *origin = NULL, *head = NULL;
@@ -1309,11 +1325,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
         */
        rev.show_root_diff = 1;
 
         */
        rev.show_root_diff = 1;
 
-       if (cover_letter) {
-               if (!branch_name)
-                       branch_name = find_branch_name(&rev);
-       }
-
        if (ignore_if_in_upstream) {
                /* Don't say anything if head and upstream are the same. */
                if (rev.pending.nr == 2) {
        if (ignore_if_in_upstream) {
                /* Don't say anything if head and upstream are the same. */
                if (rev.pending.nr == 2) {
@@ -1354,6 +1365,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
                numbered = 1;
        if (numbered)
                rev.total = total + start_number - 1;
                numbered = 1;
        if (numbered)
                rev.total = total + start_number - 1;
+       if (cover_letter == -1) {
+               if (config_cover_letter == COVER_AUTO)
+                       cover_letter = (total > 1);
+               else
+                       cover_letter = (config_cover_letter == COVER_ON);
+       }
+
        if (in_reply_to || thread || cover_letter)
                rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
        if (in_reply_to) {
        if (in_reply_to || thread || cover_letter)
                rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
        if (in_reply_to) {
@@ -1365,6 +1383,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        if (cover_letter) {
                if (thread)
                        gen_message_id(&rev, "cover");
        if (cover_letter) {
                if (thread)
                        gen_message_id(&rev, "cover");
+               if (!branch_name)
+                       branch_name = find_branch_name(&rev);
                make_cover_letter(&rev, use_stdout,
                                  origin, nr, list, head, branch_name, quiet);
                total++;
                make_cover_letter(&rev, use_stdout,
                                  origin, nr, list, head, branch_name, quiet);
                total++;
index 0ada8c78e7af875f371121fff388fd911a3e3974..8368181d6ce7a94a620a46fd300c57521e72a825 100755 (executable)
@@ -1289,4 +1289,32 @@ test_expect_success 'cover letter with nothing' '
        test_line_count = 0 actual
 '
 
        test_line_count = 0 actual
 '
 
+test_expect_success 'cover letter auto' '
+       mkdir -p tmp &&
+       test_when_finished "rm -rf tmp;
+               git config --unset format.coverletter" &&
+
+       git config format.coverletter auto &&
+       git format-patch -o tmp -1 >list &&
+       test_line_count = 1 list &&
+       git format-patch -o tmp -2 >list &&
+       test_line_count = 3 list
+'
+
+test_expect_success 'cover letter auto user override' '
+       mkdir -p tmp &&
+       test_when_finished "rm -rf tmp;
+               git config --unset format.coverletter" &&
+
+       git config format.coverletter auto &&
+       git format-patch -o tmp --cover-letter -1 >list &&
+       test_line_count = 2 list &&
+       git format-patch -o tmp --cover-letter -2 >list &&
+       test_line_count = 3 list &&
+       git format-patch -o tmp --no-cover-letter -1 >list &&
+       test_line_count = 1 list &&
+       git format-patch -o tmp --no-cover-letter -2 >list &&
+       test_line_count = 2 list
+'
+
 test_done
 test_done