format-patch: add --reroll-count=$N option

The --reroll-count=$N option, when given a positive integer: - Adds " v$N" to the subject prefix specified. As the default subject prefix string is "PATCH", --reroll-count=2 makes it "PATCH v2". - Prefixes "v$N-" to the names used for output files. The cover letter, whose name is usually 0000-cover-letter.patch, becomes v2-0000-cover-letter.patch when given --reroll-count=2. This allows users to use the same --output-directory for multiple iterations of the same series, without letting the output for a newer round overwrite output files from the earlier rounds. The user can incorporate materials from earlier rounds to update the newly minted iteration, and use "send-email v2-*.patch" to send out the patches belonging to the second iteration easily. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Dec 22, 2012 at 00:21 UTC 5fe10fe80a04a57affbaa35258f498bc1acb05e9
3 files changed +14
builtin/log.c
+11
@@ -1061,6 +1061,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1061 struct strbuf buf = STRBUF_INIT;
1062 int use_patch_format = 0;
1063 int quiet = 0;
1064 + int reroll_count = -1;
1065 char *branch_name = NULL;
1066 const struct option builtin_format_patch_options[] = {
1067 { OPTION_CALLBACK, 'n', "numbered", &numbered, NULL,
@@ -1080,6 +1081,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1081 N_("use <sfx> instead of '.patch'")),
1082 OPT_INTEGER(0, "start-number", &start_number,
1083 N_("start numbering patches at <n> instead of 1")),
1084 + OPT_INTEGER(0, "reroll-count", &reroll_count,
1085 + N_("mark the series as Nth re-roll")),
1086 { OPTION_CALLBACK, 0, "subject-prefix", &rev, N_("prefix"),
1087 N_("Use [<prefix>] instead of [PATCH]"),
1088 PARSE_OPT_NONEG, subject_prefix_callback },
@@ -1152,6 +1155,14 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1155 PARSE_OPT_KEEP_ARGV0 | PARSE_OPT_KEEP_UNKNOWN |
1156 PARSE_OPT_KEEP_DASHDASH);
1157
1158 + if (0 < reroll_count) {
1159 + struct strbuf sprefix = STRBUF_INIT;
1160 + strbuf_addf(&sprefix, "%s v%d",
1161 + rev.subject_prefix, reroll_count);
1162 + rev.reroll_count = reroll_count;
1163 + rev.subject_prefix = strbuf_detach(&sprefix, NULL);
1164 + }
1165 +
1166 if (do_signoff) {
1167 const char *committer;
1168 const char *endpos;
log-tree.c
+2
@@ -308,6 +308,8 @@ void fmt_output_subject(struct strbuf *filename,
308 int start_len = filename->len;
309 int max_len = start_len + FORMAT_PATCH_NAME_MAX - (strlen(suffix) + 1);
310
311 + if (0 < info->reroll_count)
312 + strbuf_addf(filename, "v%d-", info->reroll_count);
313 strbuf_addf(filename, "%04d-%s", nr, subject);
314
315 if (max_len < filename->len)
revision.h
+1
@@ -134,6 +134,7 @@ struct rev_info {
134 const char *mime_boundary;
135 const char *patch_suffix;
136 int numbered_files;
137 + int reroll_count;
138 char *message_id;
139 struct string_list *ref_message_ids;
140 const char *add_signoff;