Skip to content

Commit 201ea45

Browse files
Mroikgitster
authored andcommitted
format-patch: add preset for --commit-list-format
"git format-patch --commit-list-format" enables the user to make their own format for the commit list in the cover letter. It would be nice to have a ready to use format to replace shortlog. Teach make_cover_letter() the "modern" format preset. This new format is the same as: "log:[%(count)/%(total)] %s". Signed-off-by: Mirko Faina <mroik@delayed.space> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 68f99b5 commit 201ea45

4 files changed

Lines changed: 21 additions & 8 deletions

File tree

Documentation/config/format.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ format.coverLetter::
104104
format.commitListFormat::
105105
When the `--cover-letter-format` option is not given, `format-patch`
106106
uses the value of this variable to decide how to format the title of
107-
each commit. Default to `shortlog`.
107+
each commit. Defaults to `shortlog`.
108108

109109
format.outputDirectory::
110110
Set a custom directory to store the resulting files instead of the

Documentation/git-format-patch.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ feeding the result to `git send-email`.
325325
326326
--commit-list-format=<format-spec>::
327327
Specify the format in which to generate the commit list of the patch
328-
series. The accepted values for format-spec are "shortlog" or a format
329-
string prefixed with `log:`.
328+
series. The accepted values for format-spec are `shortlog`, `modern` or a
329+
format string prefixed with `log:`.
330330
e.g. `log: %s (%an)`
331331
If not given, defaults to the `format.commitListFormat` configuration
332332
variable.

builtin/log.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,6 +1445,9 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
14451445
generate_commit_list_cover(rev->diffopt.file, format, list, nr);
14461446
else if (!strcmp(format, "shortlog"))
14471447
generate_shortlog_cover_letter(&log, rev, list, nr);
1448+
else if (!strcmp(format, "modern"))
1449+
generate_commit_list_cover(rev->diffopt.file, "[%(count)/%(total)] %s",
1450+
list, nr);
14481451
else
14491452
die(_("'%s' is not a valid format string"), format);
14501453

t/t4014-format-patch.sh

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -392,18 +392,17 @@ test_expect_success 'cover letter with subject, author and count' '
392392
test_grep "^\[1/1\] This is a subject (A U Thor)$" patches/0000-cover-letter.patch
393393
'
394394

395-
test_expect_success 'cover letter with author and count' '
395+
test_expect_success 'cover letter modern format' '
396396
test_when_finished "git reset --hard HEAD~1" &&
397397
test_when_finished "rm -rf patches test_file" &&
398398
touch test_file &&
399399
git add test_file &&
400400
git commit -m "This is a subject" &&
401-
git format-patch --commit-list-format="log:[%(count)/%(total)] %an" \
402-
-o patches HEAD~1 &&
403-
test_grep "^\[1/1\] A U Thor$" patches/0000-cover-letter.patch
401+
git format-patch --commit-list-format="modern" -o patches HEAD~1 &&
402+
test_grep "^\[1/1\] This is a subject$" patches/0000-cover-letter.patch
404403
'
405404

406-
test_expect_success 'cover letter shortlog' '
405+
test_expect_success 'cover letter shortlog format' '
407406
test_when_finished "git reset --hard HEAD~1" &&
408407
test_when_finished "rm -rf expect patches result test_file" &&
409408
cat >expect <<-"EOF" &&
@@ -451,6 +450,17 @@ test_expect_success 'cover letter config with count and author' '
451450
test_line_count = 2 result
452451
'
453452

453+
test_expect_success 'cover letter config commitlistformat set to modern' '
454+
test_when_finished "rm -rf patches result" &&
455+
test_when_finished "git config unset format.coverletter" &&
456+
test_when_finished "git config unset format.commitlistformat" &&
457+
git config set format.coverletter true &&
458+
git config set format.commitlistformat modern &&
459+
git format-patch -o patches HEAD~2 &&
460+
grep -E "^[[[:digit:]]+/[[:digit:]]+] .*$" patches/0000-cover-letter.patch >result &&
461+
test_line_count = 2 result
462+
'
463+
454464
test_expect_success 'cover letter config commitlistformat set to shortlog' '
455465
test_when_finished "rm -rf patches result" &&
456466
test_when_finished "git config unset format.coverletter" &&

0 commit comments

Comments
 (0)