format-patch: move cover letter summary generation

As of now format-patch allows generation of a template cover letter for patch series through "--cover-letter". Move shortlog summary code generation to its own function. This is done in preparation to other patches where we enable the user to format the commit list using thier own format string. Signed-off-by: Mirko Faina <mroik@delayed.space> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Mirko Faina committed Mar 7, 2026 at 00:34 UTC 2af59cbcf4375f4d7c61954a19244d130de0a0db
1 file changed +20 -12
builtin/log.c
+20 -12
@@ -1324,6 +1324,25 @@ static void get_notes_args(struct strvec *arg, struct rev_info *rev)
1324 }
1325 }
1326
1327 +static void generate_shortlog_cover_letter(struct shortlog *log,
1328 + struct rev_info *rev,
1329 + struct commit **list,
1330 + int nr)
1331 +{
1332 + shortlog_init(log);
1333 + log->wrap_lines = 1;
1334 + log->wrap = MAIL_DEFAULT_WRAP;
1335 + log->in1 = 2;
1336 + log->in2 = 4;
1337 + log->file = rev->diffopt.file;
1338 + log->groups = SHORTLOG_GROUP_AUTHOR;
1339 + shortlog_finish_setup(log);
1340 + for (int i = 0; i < nr; i++)
1341 + shortlog_add_commit(log, list[i]);
1342 +
1343 + shortlog_output(log);
1344 +}
1345 +
1346 static void make_cover_letter(struct rev_info *rev, int use_separate_file,
1347 struct commit *origin,
1348 int nr, struct commit **list,
@@ -1377,18 +1396,7 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
1396 free(pp.after_subject);
1397 strbuf_release(&sb);
1398
1380 - shortlog_init(&log);
1381 - log.wrap_lines = 1;
1382 - log.wrap = MAIL_DEFAULT_WRAP;
1383 - log.in1 = 2;
1384 - log.in2 = 4;
1385 - log.file = rev->diffopt.file;
1386 - log.groups = SHORTLOG_GROUP_AUTHOR;
1387 - shortlog_finish_setup(&log);
1388 - for (i = 0; i < nr; i++)
1389 - shortlog_add_commit(&log, list[i]);
1390 -
1391 - shortlog_output(&log);
1399 + generate_shortlog_cover_letter(&log, rev, list, nr);
1400
1401 /* We can only do diffstat with a unique reference point */
1402 if (origin)