git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 16:10 UTC

Re: [PATCH v8 2/4] format-patch: add ability to use alt cover format

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 12, 2026, 16:52 UTC
Message-ID
<xmqq5x71gfci.fsf@gitster.g>
In-Reply-To
<225065cc0dd54d1a592939d41783a904a98fb2ad.1773331753.git.mroik@delayed.space>
Mirko Faina <mroik@delayed.space> writes:
> Often when sending patch series there's a need to clarify to the
> reviewer what's the purpose of said series, since it might be difficult
> to understand it from reading the commits messages one by one.
Yes, that is the whole point of having a cover letter.
Show 5 quoted lines
> "git format-patch" provides the useful "--cover-letter" flag to declare
> if we want it to generate a template for us to use. By default it will
> generate a "git shortlog" of the changes, which developers find less
> useful than they'd like, mainly because the shortlog groups commits by
> author, and gives no obvious chronological order.
Very true.
> To better reference relevant patches in the coverletter this patch
> introduces two new placeholders that can be used in the format spec:
"this patch introduces" -> "introduce" (imperative).
> %(count) and %(total). These are the chronological number of the patch
> in the series and the total amount of patches in the series. Note that
> the width of %(count) will always be the same witdh of %(total).
"total amount" -> "total number"?

"the width of %(count)..." -> "%(count) will zero-padded to the left to match the number of digits in %(total)".

But the paragraph "To better reference ..." up to this point should probably be moved a bit low? The punchline "Give format-patch the ability" to specify a custom format is the most important thing to tell readers, and %(count)/%(total) is an implementation detail of only one possible customized format.

Show 12 quoted lines
> Give format-patch the ability to specify an alternative format spec
> through the "--cover-letter-format" option. This option either takes
> "shortlog", which is the current format, or a format spec prefixed with
> "log:".
>
> Example:
>     git format-patch --cover-letter \
>         --cover-letter-format="[%(count)/%(total)] %s (%an)" HEAD~3
>
>     [1/3] this is a commit summary (Mirko Faina)
>     [2/3] this is another commit summary (Mirko Faina)
>     ...

The example does not use a format spec 'prefixed with "log:"', though?

> +--cover-letter-format=<format-spec>::
> +	Specify the format in which to generate the commit list of the patch
> +	series. This option is available if the user wants to use an
> +	alternative to the default `shortlog` format. The accepted values for

The second sentence reads funny. The option is available whether the user wants to use it or not. I'd suggest dropping the sentence, without which the paragraph reads just fine.

> +	format-spec are "shortlog" or a format string.
> +	e.g. `%s (%an)`

OK, so we are not requiring "log:"? This robs extensibility from future developers to introduce something other than "shortlog", no? If the version of Git in 'next' supports "longlog" and user gives "--cover-letter-format=longlog" to their version that does not yet support it, it would be mistaken by the version of the code here as a "log:longlog" without any placeholder that shows a fixed string "longlog" for each commit in the series? We'd rather want such an input to cause failure, no?

> +	If defined, defaults to the `format.commitListFormat` configuration
> +	variable.

s/If defined, d\(efaults.*variable\)\./D\1, if defined./ would avoid "if I define --cover-letter-format, why does it default to a configuration? do you mean 'if not given'?"

So, "If defined," -> "If not given" would be another possible improvement. I think I like it better, actually.

> +	This option is relevant only if a cover letter is generated.
> +

Hmph, an alternative that may make it easier to use is to make the command line option _imply_ "--cover-letter", so that the user does not have to give two similar looking command line options.

    git format-patch --cover-letter --cover-letter-format=...

Of course, the presence of the configuration variable should not imply generation of a cover letter. I.e.

    git -c format.commitListInCoverLetterFormat=shortlog \
	    format-patch -1 HEAD
should not imply --cover-letter.
Show 42 quoted lines
> diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
> index 21d6d0cd9e..631669c159 100755
> --- a/t/t4014-format-patch.sh
> +++ b/t/t4014-format-patch.sh
> @@ -380,6 +380,64 @@ test_expect_success 'filename limit applies only to basename' '
>  	done
>  '
>  
> +test_expect_success 'cover letter with subject, author and count' '
> +	rm -rf patches &&
> +	test_when_finished "git reset --hard HEAD~1" &&
> +	test_when_finished "rm -rf patches result test_file" &&
> +	touch test_file &&
> +	git add test_file &&
> +	git commit -m "This is a subject" &&
> +	git format-patch --cover-letter \
> +	--cover-letter-format="[%(count)/%(total)] %s (%an)" -o patches HEAD~1 &&
> +	test_grep "^\[1/1\] This is a subject (A U Thor)$" patches/0000-cover-letter.patch
> +'
> +
> +cat > expected <<EOF
> +
> +
> +
> +
> +
> +
> +
> +
> +
> +
> +A U Thor (1):
> +  This is a subject
> +
> +
> +
> +
> +
> +
> +
> +
> +EOF
Many issues.

In modern tests (written within the past 10 years), we try not to execute things outside text_expect_foo blocks. The golden output to compare with is customary called 'expect' (not 'expected'). A redirection operator ">", "<<", etc. has a single SP before but no SP after it, when there is no parameter interpolation happens in a HERE document, quote the "EOF" marker to show the intention of the author of the test that no parameter interpolation is expected.

i.e.,
    cat >expect <<\-EOF
	...
    EOF
and do so inside a set-up test_expect_success block.

Why do we have so many blank lines? Are the number of blank lines significant? Such a hidden and hard to count dependency would hurt maintainability of this test script.

Show 38 quoted lines
> +test_expect_success 'cover letter shortlog' '
> +	test_when_finished "git reset --hard HEAD~1" &&
> +	test_when_finished "rm -rf patches expected test_file result" &&
> +	touch test_file &&
> +	git add test_file &&
> +	git commit -m "This is a subject" &&
> +	git format-patch --cover-letter --cover-letter-format=shortlog \
> +	-o patches HEAD~1 &&
> +	sed -n -e "/^A U Thor (1):$\|^  This is a subject$/!s/.*//; /.*/p" patches/0000-cover-letter.patch >result &&
> +	test_cmp expected result
> +'
> +
> +test_expect_success 'cover letter no format' '
> +	test_when_finished "git reset --hard HEAD~1" &&
> +	test_when_finished "rm -rf patches result test_file" &&
> +	touch test_file &&
> +	git add test_file &&
> +	git commit -m "This is a subject" &&
> +	git format-patch --no-cover-letter-format --cover-letter -o patches HEAD~1 &&
> +	sed -n -e "/^A U Thor/p;" patches/0000-cover-letter.patch >result &&
> +	test_line_count = 1 result
> +'
> +
>  test_expect_success 'reroll count' '
>  	rm -fr patches &&
>  	git format-patch -o patches --cover-letter --reroll-count 4 main..side >list &&
> diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh
> index 964e1f1569..4f760a7468 100755
> --- a/t/t9902-completion.sh
> +++ b/t/t9902-completion.sh
> @@ -2774,6 +2774,7 @@ test_expect_success PERL 'send-email' '
>  	test_completion "git send-email --cov" <<-\EOF &&
>  	--cover-from-description=Z
>  	--cover-letter Z
> +	--cover-letter-format=Z
>  	EOF
>  	test_completion "git send-email --val" <<-\EOF &&
>  	--validate Z
Previous: Junio C HamanoNext: Junio C Hamano
Message 101 of 113 in “format-patch: better commit list for cover letter”
  1. format-patch: better commit list for cover letterMirko Faina, Feb 20, 2026
  2. format-patch: better commit list for cover letterMirko Faina, Feb 20, 2026
  3. Mirko FainaFeb 21, 2026
  4. Junio C HamanoFeb 21, 2026
  5. Mirko FainaFeb 21, 2026
  6. Junio C HamanoFeb 21, 2026
  7. Junio C HamanoFeb 21, 2026
  8. Mirko FainaFeb 21, 2026
  9. Junio C HamanoFeb 21, 2026
  10. Mirko FainaFeb 21, 2026
  11. 0/3 format-patch: add cover-letter-format optionMirko Faina, Feb 24, 2026
  12. 1/3 pretty.c: fix null pointer dereferenceMirko Faina, Feb 24, 2026
  13. 2/3 format-patch: add ability to use alt cover formatMirko Faina, Feb 24, 2026
  14. 3/3 format-patch: add commitListFormat configMirko Faina, Feb 24, 2026
  15. Mirko FainaFeb 24, 2026
  16. Junio C HamanoFeb 24, 2026
  17. Mirko FainaFeb 24, 2026
  18. Mirko FainaFeb 24, 2026
  19. Jeff KingFeb 24, 2026
  20. Jeff KingFeb 24, 2026
  21. Mirko FainaFeb 24, 2026
  22. Jeff KingFeb 24, 2026
  23. 0/2 format-patch: add cover-letter-format optionMirko Faina, Feb 24, 2026
  24. 1/2 format-patch: add ability to use alt cover formatMirko Faina, Feb 24, 2026
  25. 2/2 format-patch: add commitListFormat configMirko Faina, Feb 24, 2026
  26. Junio C HamanoFeb 24, 2026
  27. Junio C HamanoFeb 24, 2026
  28. Junio C HamanoFeb 24, 2026
  29. Junio C HamanoFeb 24, 2026
  30. Junio C HamanoFeb 24, 2026
  31. Mirko FainaFeb 24, 2026
  32. Mirko FainaFeb 25, 2026
  33. Mirko FainaFeb 25, 2026
  34. Junio C HamanoFeb 25, 2026
  35. Junio C HamanoFeb 25, 2026
  36. Jeff KingFeb 25, 2026
  37. Jeff KingFeb 25, 2026
  38. Junio C HamanoFeb 25, 2026
  39. Mirko FainaFeb 25, 2026
  40. Mirko FainaFeb 26, 2026
  41. Junio C HamanoFeb 26, 2026
  42. 1/4 pretty.c: add %(count) and %(total) placeholdersMirko Faina, Feb 27, 2026
  43. 0/4 format-patch: add cover-letter-format optionMirko Faina, Feb 27, 2026
  44. 2/4 format-patch: move cover letter summary generationMirko Faina, Feb 27, 2026
  45. 4/4 format-patch: add commitListFormat configMirko Faina, Feb 27, 2026
  46. 3/4 format-patch: add ability to use alt cover formatMirko Faina, Feb 27, 2026
  47. Junio C HamanoFeb 27, 2026
  48. Mirko FainaFeb 27, 2026
  49. 0/4 format-patch: add cover-letter-format optionMirko Faina, Feb 27, 2026
  50. 1/4 pretty.c: add %(count) and %(total) placeholdersMirko Faina, Feb 27, 2026
  51. 3/4 format-patch: add ability to use alt cover formatMirko Faina, Feb 27, 2026
  52. 2/4 format-patch: move cover letter summary generationMirko Faina, Feb 27, 2026
  53. 4/4 format-patch: add commitListFormat configMirko Faina, Feb 27, 2026
  54. 5/4 docs: add usage for the cover-letter fmt featureMirko Faina, Feb 27, 2026
  55. Junio C HamanoFeb 27, 2026
  56. Mirko FainaFeb 27, 2026
  57. Junio C HamanoFeb 27, 2026
  58. 0/5 format-patch: add cover-letter-format optionMirko Faina, Feb 27, 2026
  59. 1/5 pretty.c: add %(count) and %(total) placeholdersMirko Faina, Feb 27, 2026
  60. 2/5 format-patch: move cover letter summary generationMirko Faina, Feb 27, 2026
  61. 3/5 format-patch: add ability to use alt cover formatMirko Faina, Feb 27, 2026
  62. 4/5 format-patch: add commitListFormat configMirko Faina, Feb 27, 2026
  63. 5/5 docs: add usage for the cover-letter fmt featureMirko Faina, Feb 27, 2026
  64. Junio C HamanoMar 6, 2026
  65. Mirko FainaMar 6, 2026
  66. 1/5 pretty.c: add %(count) and %(total) placeholdersMirko Faina, Mar 6, 2026
  67. 0/5 format-patch: add cover-letter-format optionMirko Faina, Mar 6, 2026
  68. 2/5 format-patch: move cover letter summary generationMirko Faina, Mar 6, 2026
  69. 3/5 format-patch: add ability to use alt cover formatMirko Faina, Mar 6, 2026
  70. 4/5 format-patch: add commitListFormat configMirko Faina, Mar 6, 2026
  71. 5/5 docs: add usage for the cover-letter fmt featureMirko Faina, Mar 6, 2026
  72. Junio C HamanoMar 6, 2026
  73. 0/5 format-patch: add cover-letter-format optionMirko Faina, Mar 6, 2026
  74. 1/5 pretty.c: add %(count) and %(total) placeholdersMirko Faina, Mar 6, 2026
  75. 2/5 format-patch: move cover letter summary generationMirko Faina, Mar 6, 2026
  76. 3/5 format-patch: add ability to use alt cover formatMirko Faina, Mar 6, 2026
  77. 4/5 format-patch: add commitListFormat configMirko Faina, Mar 6, 2026
  78. 5/5 docs: add usage for the cover-letter fmt featureMirko Faina, Mar 6, 2026
  79. Bert WesargMar 10, 2026
  80. Phillip WoodMar 10, 2026
  81. Phillip WoodMar 10, 2026
  82. Phillip WoodMar 10, 2026
  83. Phillip WoodMar 10, 2026
  84. Junio C HamanoMar 10, 2026
  85. Mirko FainaMar 10, 2026
  86. MroikMar 10, 2026
  87. Mirko FainaMar 10, 2026
  88. Mirko FainaMar 10, 2026
  89. Junio C HamanoMar 10, 2026
  90. Mirko FainaMar 10, 2026
  91. Phillip WoodMar 11, 2026
  92. Phillip WoodMar 11, 2026
  93. Junio C HamanoMar 11, 2026
  94. Junio C HamanoMar 11, 2026
  95. 0/4 format-patch: add cover-letter-format optionMirko Faina, Mar 12, 2026
  96. 1/4 format-patch: move cover letter summary generationMirko Faina, Mar 12, 2026
  97. 2/4 format-patch: add ability to use alt cover formatMirko Faina, Mar 12, 2026
  98. 3/4 format-patch: add "chronological" format for coverMirko Faina, Mar 12, 2026
  99. 4/4 format-patch: add commitListFormat configMirko Faina, Mar 12, 2026
  100. Junio C HamanoMar 12, 2026
  101. Junio C HamanoMar 12, 2026
  102. Junio C HamanoMar 12, 2026
  103. Junio C HamanoMar 12, 2026
  104. Mirko FainaMar 12, 2026
  105. Junio C HamanoMar 12, 2026
  106. Junio C HamanoMar 12, 2026
  107. Junio C HamanoMar 12, 2026
  108. Mirko FainaMar 12, 2026
  109. Junio C HamanoMar 12, 2026
  110. Phillip WoodMar 13, 2026
  111. Junio C HamanoMar 13, 2026
  112. Mirko FainaMar 13, 2026
  113. Junio C HamanoMar 13, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.