format-patch: add format.coverLetter configuration variable

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>

Felipe Contreras committed Apr 7, 2013 at 12:46 UTC 2a4c26076c3c99300a51439702791c17e7d21e6c
4 files changed +62 -8
Documentation/config.txt
+5
@@ -1096,6 +1096,11 @@ format.signoff::
1096 the rights to submit this work under the same open source license.
1097 Please see the 'SubmittingPatches' document for further discussion.
1098
1099 +format.coverLetter::
1100 + A boolean that controls whether to generate a cover-letter when
1101 + format-patch is invoked, but in addition can be set to "auto", to
1102 + generate a cover-letter only when there's more than one patch.
1103 +
1104 filter.<driver>.clean::
1105 The command which is used to convert the content of a worktree
1106 file to a blob upon checkin. See linkgit:gitattributes[5] for
Documentation/git-format-patch.txt
+3 -2
@@ -20,7 +20,7 @@ SYNOPSIS
20 [--ignore-if-in-upstream]
21 [--subject-prefix=Subject-Prefix] [(--reroll-count|-v) <n>]
22 [--to=<email>] [--cc=<email>]
23 - [--cover-letter] [--quiet] [--notes[=<ref>]]
23 + [--[no-]cover-letter] [--quiet] [--notes[=<ref>]]
24 [<common diff options>]
25 [ <since> | <revision range> ]
26
@@ -195,7 +195,7 @@ will want to ensure that threading is disabled for `git send-email`.
195 `Cc:`, and custom) headers added so far from config or command
196 line.
197
198 ---cover-letter::
198 +--[no-]cover-letter::
199 In addition to the patches, generate a cover letter file
200 containing the shortlog and the overall diffstat. You can
201 fill in a description in the file before sending it out.
@@ -260,6 +260,7 @@ attachments, and sign off patches with configuration variables.
260 cc = <email>
261 attach [ = mime-boundary-string ]
262 signoff = true
263 + coverletter = auto
264 ------------
265
266
builtin/log.c
+26 -6
@@ -622,6 +622,14 @@ static void add_header(const char *value)
622 static int thread;
623 static int do_signoff;
624 static const char *signature = git_version_string;
625 +static int config_cover_letter;
626 +
627 +enum {
628 + COVER_UNSET,
629 + COVER_OFF,
630 + COVER_ON,
631 + COVER_AUTO
632 +};
633
634 static int git_format_config(const char *var, const char *value, void *cb)
635 {
@@ -683,6 +691,14 @@ static int git_format_config(const char *var, const char *value, void *cb)
691 }
692 if (!strcmp(var, "format.signature"))
693 return git_config_string(&signature, var, value);
694 + if (!strcmp(var, "format.coverletter")) {
695 + if (value && !strcasecmp(value, "auto")) {
696 + config_cover_letter = COVER_AUTO;
697 + return 0;
698 + }
699 + config_cover_letter = git_config_bool(var, value) ? COVER_ON : COVER_OFF;
700 + return 0;
701 + }
702
703 return git_log_config(var, value, cb);
704 }
@@ -1074,7 +1090,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1090 int start_number = -1;
1091 int just_numbers = 0;
1092 int ignore_if_in_upstream = 0;
1077 - int cover_letter = 0;
1093 + int cover_letter = -1;
1094 int boundary_count = 0;
1095 int no_binary_diff = 0;
1096 struct commit *origin = NULL, *head = NULL;
@@ -1309,11 +1325,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1325 */
1326 rev.show_root_diff = 1;
1327
1312 - if (cover_letter) {
1313 - if (!branch_name)
1314 - branch_name = find_branch_name(&rev);
1315 - }
1316 -
1328 if (ignore_if_in_upstream) {
1329 /* Don't say anything if head and upstream are the same. */
1330 if (rev.pending.nr == 2) {
@@ -1354,6 +1365,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1365 numbered = 1;
1366 if (numbered)
1367 rev.total = total + start_number - 1;
1368 + if (cover_letter == -1) {
1369 + if (config_cover_letter == COVER_AUTO)
1370 + cover_letter = (total > 1);
1371 + else
1372 + cover_letter = (config_cover_letter == COVER_ON);
1373 + }
1374 +
1375 if (in_reply_to || thread || cover_letter)
1376 rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
1377 if (in_reply_to) {
@@ -1365,6 +1383,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1383 if (cover_letter) {
1384 if (thread)
1385 gen_message_id(&rev, "cover");
1386 + if (!branch_name)
1387 + branch_name = find_branch_name(&rev);
1388 make_cover_letter(&rev, use_stdout,
1389 origin, nr, list, head, branch_name, quiet);
1390 total++;
t/t4014-format-patch.sh
+28
@@ -1289,4 +1289,32 @@ test_expect_success 'cover letter with nothing' '
1289 test_line_count = 0 actual
1290 '
1291
1292 +test_expect_success 'cover letter auto' '
1293 + mkdir -p tmp &&
1294 + test_when_finished "rm -rf tmp;
1295 + git config --unset format.coverletter" &&
1296 +
1297 + git config format.coverletter auto &&
1298 + git format-patch -o tmp -1 >list &&
1299 + test_line_count = 1 list &&
1300 + git format-patch -o tmp -2 >list &&
1301 + test_line_count = 3 list
1302 +'
1303 +
1304 +test_expect_success 'cover letter auto user override' '
1305 + mkdir -p tmp &&
1306 + test_when_finished "rm -rf tmp;
1307 + git config --unset format.coverletter" &&
1308 +
1309 + git config format.coverletter auto &&
1310 + git format-patch -o tmp --cover-letter -1 >list &&
1311 + test_line_count = 2 list &&
1312 + git format-patch -o tmp --cover-letter -2 >list &&
1313 + test_line_count = 3 list &&
1314 + git format-patch -o tmp --no-cover-letter -1 >list &&
1315 + test_line_count = 1 list &&
1316 + git format-patch -o tmp --no-cover-letter -2 >list &&
1317 + test_line_count = 2 list
1318 +'
1319 +
1320 test_done