format-patch: removing unconditional wrapping

Using format-patch with --commit-list-format different than shortlog, causes the commit entry lines to wrap if they get longer than MAIL_DEFAULT_WRAP (72 characters). While this might be sensible for many when sending changes through email, it forces this decision of wrapping on the user, reducing the control granularity of --commit-list-format. Teach generate_commit_list_cover() to respect commit entry line lengths and place this wrapping rule on the "modern" preset format instead. Signed-off-by: Mirko Faina <mroik@delayed.space> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mirko Faina committed Mar 27, 2026 at 20:48 UTC 0284046ad01e22b5e794a864a96925791f75353c
2 files changed +3 -8
Documentation/git-format-patch.adoc
+1 -1
@@ -327,7 +327,7 @@ feeding the result to `git send-email`.
327 Specify the format in which to generate the commit list of the patch
328 series. The accepted values for format-spec are `shortlog`, `modern` or
329 a format-string prefixed with `log:`. E.g. `log: %s (%an)`.
330 - `modern` is the same as `log:[%(count)/%(total)] %s`.
330 + `modern` is the same as `log:%w(72)[%(count)/%(total)] %s`.
331 The `log:` prefix can be omitted if the format-string has a `%` in it
332 (expecting that it is part of `%<placeholder>`).
333 Defaults to the `format.commitListFormat` configuration variable, if
builtin/log.c
+2 -7
@@ -1365,7 +1365,6 @@ static void generate_commit_list_cover(FILE *cover_file, const char *format,
1365 struct commit **list, int n)
1366 {
1367 struct strbuf commit_line = STRBUF_INIT;
1368 - struct strbuf wrapped_line = STRBUF_INIT;
1368 struct pretty_print_context ctx = {0};
1369 struct rev_info rev = REV_INFO_INIT;
1370
@@ -1375,16 +1374,12 @@ static void generate_commit_list_cover(FILE *cover_file, const char *format,
1374 rev.nr = i;
1375 repo_format_commit_message(the_repository, list[n - i], format,
1376 &commit_line, &ctx);
1378 - strbuf_add_wrapped_text(&wrapped_line, commit_line.buf, 0, 0,
1379 - MAIL_DEFAULT_WRAP);
1380 - fprintf(cover_file, "%s\n", wrapped_line.buf);
1377 + fprintf(cover_file, "%s\n", commit_line.buf);
1378 strbuf_reset(&commit_line);
1382 - strbuf_reset(&wrapped_line);
1379 }
1380 fprintf(cover_file, "\n");
1381
1382 strbuf_release(&commit_line);
1387 - strbuf_release(&wrapped_line);
1383 }
1384
1385 static void make_cover_letter(struct rev_info *rev, int use_separate_file,
@@ -1446,7 +1441,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
1441 else if (!strcmp(format, "shortlog"))
1442 generate_shortlog_cover_letter(&log, rev, list, nr);
1443 else if (!strcmp(format, "modern"))
1449 - generate_commit_list_cover(rev->diffopt.file, "[%(count)/%(total)] %s",
1444 + generate_commit_list_cover(rev->diffopt.file, "%w(72)[%(count)/%(total)] %s",
1445 list, nr);
1446 else if (strchr(format, '%'))
1447 generate_commit_list_cover(rev->diffopt.file, format, list, nr);