Skip to content

Commit d63a0b5

Browse files
sunshinecogitster
authored andcommitted
format-patch: allow --range-diff to apply to a lone-patch
When submitting a revised version of a patch or series, it can be helpful (to reviewers) to include a summary of changes since the previous attempt in the form of a range-diff, typically in the cover letter. However, it is occasionally useful, despite making for a noisy read, to insert a range-diff into the commentary section of the lone patch of a 1-patch series. Therefore, extend "git format-patch --range-diff=<refspec>" to insert a range-diff into the commentary section of a lone patch rather than requiring a cover letter. Implementation note: Generating a range-diff for insertion into the commentary section of a patch which itself is currently being generated requires invoking the diffing machinery recursively. However, the machinery does not (presently) support this since it uses global state. Consequently, we need to take care to stash away the state of the in-progress operation while generating the range-diff, and restore it after. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 10d99bf commit d63a0b5

File tree

3 files changed

+22
-5
lines changed

3 files changed

+22
-5
lines changed

Documentation/git-format-patch.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,8 @@ feeding the result to `git send-email`.
241241

242242
--range-diff=<previous>::
243243
As a reviewer aid, insert a range-diff (see linkgit:git-range-diff[1])
244-
into the cover letter showing the differences between the previous
244+
into the cover letter, or as commentary of the lone patch of a
245+
1-patch series, showing the differences between the previous
245246
version of the patch series and the series currently being formatted.
246247
`previous` can be a single revision naming the tip of the previous
247248
series if it shares a common base with the series being formatted (for

builtin/log.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
15751575
N_("show changes against <rev> in cover letter or single patch"),
15761576
parse_opt_object_name),
15771577
OPT_STRING(0, "range-diff", &rdiff_prev, N_("refspec"),
1578-
N_("show changes against <refspec> in cover letter")),
1578+
N_("show changes against <refspec> in cover letter or single patch")),
15791579
OPT_INTEGER(0, "creation-factor", &creation_factor,
15801580
N_("percentage by which creation is weighted")),
15811581
OPT_END()
@@ -1816,8 +1816,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
18161816
die(_("--creation-factor requires --range-diff"));
18171817

18181818
if (rdiff_prev) {
1819-
if (!cover_letter)
1820-
die(_("--range-diff requires --cover-letter"));
1819+
if (!cover_letter && total != 1)
1820+
die(_("--range-diff requires --cover-letter or single patch"));
18211821

18221822
infer_range_diff_ranges(&rdiff1, &rdiff2, rdiff_prev,
18231823
origin, list[0]);
@@ -1866,8 +1866,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
18661866
print_signature(rev.diffopt.file);
18671867
total++;
18681868
start_number--;
1869-
/* interdiff in cover-letter; omit from patches */
1869+
/* interdiff/range-diff in cover-letter; omit from patches */
18701870
rev.idiff_oid1 = NULL;
1871+
rev.rdiff1 = NULL;
18711872
}
18721873
rev.add_signoff = do_signoff;
18731874

log-tree.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "line-log.h"
1616
#include "help.h"
1717
#include "interdiff.h"
18+
#include "range-diff.h"
1819

1920
static struct decoration name_decoration = { "object names" };
2021
static int decoration_loaded;
@@ -750,6 +751,20 @@ void show_log(struct rev_info *opt)
750751

751752
memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
752753
}
754+
755+
if (cmit_fmt_is_mail(ctx.fmt) && opt->rdiff1) {
756+
struct diff_queue_struct dq;
757+
758+
memcpy(&dq, &diff_queued_diff, sizeof(diff_queued_diff));
759+
DIFF_QUEUE_CLEAR(&diff_queued_diff);
760+
761+
next_commentary_block(opt, NULL);
762+
fprintf_ln(opt->diffopt.file, "%s", opt->rdiff_title);
763+
show_range_diff(opt->rdiff1, opt->rdiff2,
764+
opt->creation_factor, 1, &opt->diffopt);
765+
766+
memcpy(&diff_queued_diff, &dq, sizeof(diff_queued_diff));
767+
}
753768
}
754769

755770
int log_tree_diff_flush(struct rev_info *opt)

0 commit comments

Comments
 (0)