Skip to content

Commit d9219fc

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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0207b97 commit d9219fc

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
@@ -1447,12 +1447,21 @@ static const char *diff_title(struct strbuf *sb, int reroll_count,
14471447
static void infer_range_diff_ranges(struct strbuf *r1,
14481448
struct strbuf *r2,
14491449
const char *prev,
1450+
struct commit *origin,
14501451
struct commit *head)
14511452
{
14521453
const char *head_oid = oid_to_hex(&head->object.oid);
14531454

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

14581467
int cmd_format_patch(int argc, const char **argv, const char *prefix)
@@ -1801,7 +1810,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
18011810
if (!cover_letter)
18021811
die(_("--range-diff requires --cover-letter"));
18031812

1804-
infer_range_diff_ranges(&rdiff1, &rdiff2, rdiff_prev, list[0]);
1813+
infer_range_diff_ranges(&rdiff1, &rdiff2, rdiff_prev,
1814+
origin, list[0]);
18051815
rev.rdiff1 = rdiff1.buf;
18061816
rev.rdiff2 = rdiff2.buf;
18071817
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)