Skip to content

Commit 2e6fd71

Browse files
sunshinecogitster
authored andcommitted
format-patch: extend --range-diff to accept revision range
When submitting a revised a patch series, the --range-diff option embeds a range-diff in the cover letter showing changes since the previous version of the patch series. The argument to --range-diff is a simple revision naming the tip of the previous series, which works fine if the previous and current versions of the patch series share a common base. However, it fails if the revision ranges of the old and new versions of the series are disjoint. To address this shortcoming, extend --range-diff to also accept an explicit revision range for the previous series. For example: git format-patch --cover-letter --range-diff=v1~3..v1 -3 v2 Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 31e2617 commit 2e6fd71

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

Documentation/git-format-patch.txt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,12 @@ feeding the result to `git send-email`.
243243
As a reviewer aid, insert a range-diff (see linkgit:git-range-diff[1])
244244
into the cover letter showing the differences between the previous
245245
version of the patch series and the series currently being formatted.
246-
`previous` is a single revision naming the tip of the previous
247-
series which shares a common base with the series being formatted (for
246+
`previous` can be a single revision naming the tip of the previous
247+
series if it shares a common base with the series being formatted (for
248248
example `git format-patch --cover-letter --range-diff=feature/v1 -3
249-
feature/v2`).
249+
feature/v2`), or a revision range if the two versions of the series are
250+
disjoint (for example `git format-patch --cover-letter
251+
--range-diff=feature/v1~3..feature/v1 -3 feature/v2`).
250252

251253
--notes[=<ref>]::
252254
Append the notes (see linkgit:git-notes[1]) for the commit

builtin/log.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,12 +1448,21 @@ static const char *diff_title(struct strbuf *sb, int reroll_count,
14481448
static void infer_range_diff_ranges(struct strbuf *r1,
14491449
struct strbuf *r2,
14501450
const char *prev,
1451+
struct commit *origin,
14511452
struct commit *head)
14521453
{
14531454
const char *head_oid = oid_to_hex(&head->object.oid);
14541455

1455-
strbuf_addf(r1, "%s..%s", head_oid, prev);
1456-
strbuf_addf(r2, "%s..%s", prev, head_oid);
1456+
if (!strstr(prev, "..")) {
1457+
strbuf_addf(r1, "%s..%s", head_oid, prev);
1458+
strbuf_addf(r2, "%s..%s", prev, head_oid);
1459+
} else if (!origin) {
1460+
die(_("failed to infer range-diff ranges"));
1461+
} else {
1462+
strbuf_addstr(r1, prev);
1463+
strbuf_addf(r2, "%s..%s",
1464+
oid_to_hex(&origin->object.oid), head_oid);
1465+
}
14571466
}
14581467

14591468
int cmd_format_patch(int argc, const char **argv, const char *prefix)
@@ -1802,7 +1811,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
18021811
if (!cover_letter)
18031812
die(_("--range-diff requires --cover-letter"));
18041813

1805-
infer_range_diff_ranges(&rdiff1, &rdiff2, rdiff_prev, list[0]);
1814+
infer_range_diff_ranges(&rdiff1, &rdiff2, rdiff_prev,
1815+
origin, list[0]);
18061816
rev.rdiff1 = rdiff1.buf;
18071817
rev.rdiff2 = rdiff2.buf;
18081818
rev.creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;

t/t3206-range-diff.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ test_expect_success 'changed message' '
142142
test_cmp expected actual
143143
'
144144

145-
for prev in topic
145+
for prev in topic master..topic
146146
do
147147
test_expect_success "format-patch --range-diff=$prev" '
148148
git format-patch --stdout --cover-letter --range-diff=$prev \

0 commit comments

Comments
 (0)