Skip to content

Commit 8a4394d

Browse files
committed
Merge branch 'zh/format-patch-fractional-reroll-count'
"git format-patch -v<n>" learned to allow a reroll count that is not an integer. * zh/format-patch-fractional-reroll-count: format-patch: allow a non-integral version numbers
2 parents 861794b + db91988 commit 8a4394d

File tree

6 files changed

+88
-12
lines changed

6 files changed

+88
-12
lines changed

Documentation/git-format-patch.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,11 @@ populated with placeholder text.
238238
`--subject-prefix` option) has ` v<n>` appended to it. E.g.
239239
`--reroll-count=4` may produce `v4-0001-add-makefile.patch`
240240
file that has "Subject: [PATCH v4 1/20] Add makefile" in it.
241+
`<n>` does not have to be an integer (e.g. "--reroll-count=4.4",
242+
or "--reroll-count=4rev2" are allowed), but the downside of
243+
using such a reroll-count is that the range-diff/interdiff
244+
with the previous version does not state exactly which
245+
version the new interation is compared against.
241246

242247
--to=<email>::
243248
Add a `To:` header to the email headers. This is in addition

builtin/log.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,13 +1662,19 @@ static void print_bases(struct base_tree_info *bases, FILE *file)
16621662
oidclr(&bases->base_commit);
16631663
}
16641664

1665-
static const char *diff_title(struct strbuf *sb, int reroll_count,
1666-
const char *generic, const char *rerolled)
1665+
static const char *diff_title(struct strbuf *sb,
1666+
const char *reroll_count,
1667+
const char *generic,
1668+
const char *rerolled)
16671669
{
1668-
if (reroll_count <= 0)
1670+
int v;
1671+
1672+
/* RFC may be v0, so allow -v1 to diff against v0 */
1673+
if (reroll_count && !strtol_i(reroll_count, 10, &v) &&
1674+
v >= 1)
1675+
strbuf_addf(sb, rerolled, v - 1);
1676+
else
16691677
strbuf_addstr(sb, generic);
1670-
else /* RFC may be v0, so allow -v1 to diff against v0 */
1671-
strbuf_addf(sb, rerolled, reroll_count - 1);
16721678
return sb->buf;
16731679
}
16741680

@@ -1717,7 +1723,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
17171723
struct strbuf buf = STRBUF_INIT;
17181724
int use_patch_format = 0;
17191725
int quiet = 0;
1720-
int reroll_count = -1;
1726+
const char *reroll_count = NULL;
17211727
char *cover_from_description_arg = NULL;
17221728
char *branch_name = NULL;
17231729
char *base_commit = NULL;
@@ -1751,7 +1757,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
17511757
N_("use <sfx> instead of '.patch'")),
17521758
OPT_INTEGER(0, "start-number", &start_number,
17531759
N_("start numbering patches at <n> instead of 1")),
1754-
OPT_INTEGER('v', "reroll-count", &reroll_count,
1760+
OPT_STRING('v', "reroll-count", &reroll_count, N_("reroll-count"),
17551761
N_("mark the series as Nth re-roll")),
17561762
OPT_INTEGER(0, "filename-max-length", &fmt_patch_name_max,
17571763
N_("max length of output filename")),
@@ -1862,9 +1868,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
18621868
if (cover_from_description_arg)
18631869
cover_from_description_mode = parse_cover_from_description(cover_from_description_arg);
18641870

1865-
if (0 < reroll_count) {
1871+
if (reroll_count) {
18661872
struct strbuf sprefix = STRBUF_INIT;
1867-
strbuf_addf(&sprefix, "%s v%d",
1873+
1874+
strbuf_addf(&sprefix, "%s v%s",
18681875
rev.subject_prefix, reroll_count);
18691876
rev.reroll_count = reroll_count;
18701877
rev.subject_prefix = strbuf_detach(&sprefix, NULL);

log-tree.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -369,8 +369,14 @@ void fmt_output_subject(struct strbuf *filename,
369369
int start_len = filename->len;
370370
int max_len = start_len + info->patch_name_max - (strlen(suffix) + 1);
371371

372-
if (0 < info->reroll_count)
373-
strbuf_addf(filename, "v%d-", info->reroll_count);
372+
if (info->reroll_count) {
373+
struct strbuf temp = STRBUF_INIT;
374+
375+
strbuf_addf(&temp, "v%s", info->reroll_count);
376+
format_sanitized_subject(filename, temp.buf, temp.len);
377+
strbuf_addstr(filename, "-");
378+
strbuf_release(&temp);
379+
}
374380
strbuf_addf(filename, "%04d-%s", nr, subject);
375381

376382
if (max_len < filename->len)

revision.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ struct rev_info {
236236
const char *mime_boundary;
237237
const char *patch_suffix;
238238
int numbered_files;
239-
int reroll_count;
239+
const char *reroll_count;
240240
char *message_id;
241241
struct ident_split from_ident;
242242
struct string_list *ref_message_ids;

t/t3206-range-diff.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,30 @@ test_expect_success 'format-patch --range-diff as commentary' '
521521
grep "> 1: .* new message" 0001-*
522522
'
523523

524+
test_expect_success 'format-patch --range-diff reroll-count with a non-integer' '
525+
git format-patch --range-diff=HEAD~1 -v2.9 HEAD~1 >actual &&
526+
test_when_finished "rm v2.9-0001-*" &&
527+
test_line_count = 1 actual &&
528+
test_i18ngrep "^Range-diff:$" v2.9-0001-* &&
529+
grep "> 1: .* new message" v2.9-0001-*
530+
'
531+
532+
test_expect_success 'format-patch --range-diff reroll-count with a integer' '
533+
git format-patch --range-diff=HEAD~1 -v2 HEAD~1 >actual &&
534+
test_when_finished "rm v2-0001-*" &&
535+
test_line_count = 1 actual &&
536+
test_i18ngrep "^Range-diff ..* v1:$" v2-0001-* &&
537+
grep "> 1: .* new message" v2-0001-*
538+
'
539+
540+
test_expect_success 'format-patch --range-diff with v0' '
541+
git format-patch --range-diff=HEAD~1 -v0 HEAD~1 >actual &&
542+
test_when_finished "rm v0-0001-*" &&
543+
test_line_count = 1 actual &&
544+
test_i18ngrep "^Range-diff:$" v0-0001-* &&
545+
grep "> 1: .* new message" v0-0001-*
546+
'
547+
524548
test_expect_success 'range-diff overrides diff.noprefix internally' '
525549
git -c diff.noprefix=true range-diff HEAD^...
526550
'

t/t4014-format-patch.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -386,6 +386,30 @@ test_expect_success 'reroll count (-v)' '
386386
! grep -v "^Subject: \[PATCH v4 [0-3]/3\] " subjects
387387
'
388388

389+
test_expect_success 'reroll count (-v) with a fractional number' '
390+
rm -fr patches &&
391+
git format-patch -o patches --cover-letter -v4.4 main..side >list &&
392+
! grep -v "^patches/v4.4-000[0-3]-" list &&
393+
sed -n -e "/^Subject: /p" $(cat list) >subjects &&
394+
! grep -v "^Subject: \[PATCH v4.4 [0-3]/3\] " subjects
395+
'
396+
397+
test_expect_success 'reroll (-v) count with a non number' '
398+
rm -fr patches &&
399+
git format-patch -o patches --cover-letter -v4rev2 main..side >list &&
400+
! grep -v "^patches/v4rev2-000[0-3]-" list &&
401+
sed -n -e "/^Subject: /p" $(cat list) >subjects &&
402+
! grep -v "^Subject: \[PATCH v4rev2 [0-3]/3\] " subjects
403+
'
404+
405+
test_expect_success 'reroll (-v) count with a non-pathname character' '
406+
rm -fr patches &&
407+
git format-patch -o patches --cover-letter -v4---..././../--1/.2// main..side >list &&
408+
! grep -v "patches/v4-\.-\.-\.-1-\.2-000[0-3]-" list &&
409+
sed -n -e "/^Subject: /p" $(cat list) >subjects &&
410+
! grep -v "^Subject: \[PATCH v4---\.\.\./\./\.\./--1/\.2// [0-3]/3\] " subjects
411+
'
412+
389413
check_threading () {
390414
expect="$1" &&
391415
shift &&
@@ -2255,6 +2279,16 @@ test_expect_success 'interdiff: reroll-count' '
22552279
test_i18ngrep "^Interdiff ..* v1:$" v2-0000-cover-letter.patch
22562280
'
22572281

2282+
test_expect_success 'interdiff: reroll-count with a non-integer' '
2283+
git format-patch --cover-letter --interdiff=boop~2 -v2.2 -1 boop &&
2284+
test_i18ngrep "^Interdiff:$" v2.2-0000-cover-letter.patch
2285+
'
2286+
2287+
test_expect_success 'interdiff: reroll-count with a integer' '
2288+
git format-patch --cover-letter --interdiff=boop~2 -v2 -1 boop &&
2289+
test_i18ngrep "^Interdiff ..* v1:$" v2-0000-cover-letter.patch
2290+
'
2291+
22582292
test_expect_success 'interdiff: solo-patch' '
22592293
cat >expect <<-\EOF &&
22602294
+fleep

0 commit comments

Comments
 (0)