format-patch: add --creation-factor tweak for --range-diff

When generating a range-diff, matching up commits between two version of a patch series involves heuristics, thus may give unexpected results. git-range-diff allows tweaking the heuristic via --creation-factor. Follow suit by accepting --creation-factor in combination with --range-diff when generating a range-diff for a cover-letter. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jul 22, 2018 at 05:57 UTC 8631bf1cdd7296684deebab2708761bfc8085fc2
2 files changed +16 -2
Documentation/git-format-patch.txt
+7 -1
@@ -24,7 +24,7 @@ SYNOPSIS
24 [--to=<email>] [--cc=<email>]
25 [--[no-]cover-letter] [--quiet] [--notes[=<ref>]]
26 [--interdiff=<previous>]
27 - [--range-diff=<previous>]
27 + [--range-diff=<previous> [--creation-factor=<percent>]]
28 [--progress]
29 [<common diff options>]
30 [ <since> | <revision range> ]
@@ -250,6 +250,12 @@ feeding the result to `git send-email`.
250 disjoint (for example `git format-patch --cover-letter
251 --range-diff=feature/v1~3..feature/v1 -3 feature/v2`).
252
253 +--creation-factor=<percent>::
254 + Used with `--range-diff`, tweak the heuristic which matches up commits
255 + between the previous and current series of patches by adjusting the
256 + creation/deletion cost fudge factor. See linkgit:git-range-diff[1])
257 + for details.
258 +
259 --notes[=<ref>]::
260 Append the notes (see linkgit:git-notes[1]) for the commit
261 after the three-dash line.
builtin/log.c
+9 -1
@@ -1498,6 +1498,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1498 struct strbuf rdiff1 = STRBUF_INIT;
1499 struct strbuf rdiff2 = STRBUF_INIT;
1500 struct strbuf rdiff_title = STRBUF_INIT;
1501 + int creation_factor = -1;
1502
1503 const struct option builtin_format_patch_options[] = {
1504 { OPTION_CALLBACK, 'n', "numbered", &numbered, NULL,
@@ -1576,6 +1577,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1577 parse_opt_object_name),
1578 OPT_STRING(0, "range-diff", &rdiff_prev, N_("refspec"),
1579 N_("show changes against <refspec> in cover letter")),
1580 + OPT_INTEGER(0, "creation-factor", &creation_factor,
1581 + N_("percentage by which creation is weighted")),
1582 OPT_END()
1583 };
1584
@@ -1808,6 +1811,11 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1811 _("Interdiff against v%d:"));
1812 }
1813
1814 + if (creation_factor < 0)
1815 + creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
1816 + else if (!rdiff_prev)
1817 + die(_("--creation-factor requires --range-diff"));
1818 +
1819 if (rdiff_prev) {
1820 if (!cover_letter)
1821 die(_("--range-diff requires --cover-letter"));
@@ -1816,7 +1824,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1824 origin, list[0]);
1825 rev.rdiff1 = rdiff1.buf;
1826 rev.rdiff2 = rdiff2.buf;
1819 - rev.creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT;
1827 + rev.creation_factor = creation_factor;
1828 rev.rdiff_title = diff_title(&rdiff_title, reroll_count,
1829 _("Range-diff:"),
1830 _("Range-diff against v%d:"));