All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eric Sunshine <sunshine@sunshineco.com>
To: git@vger.kernel.org
Cc: "Johannes Schindelin" <Johannes.Schindelin@gmx.de>,
	"Duy Nguyen" <pclouds@gmail.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Stefan Beller" <sbeller@google.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>
Subject: [PATCH 03/14] format-patch: teach --interdiff to respect -v/--reroll-count
Date: Sun, 22 Jul 2018 05:57:06 -0400	[thread overview]
Message-ID: <20180722095717.17912-4-sunshine@sunshineco.com> (raw)
In-Reply-To: <20180722095717.17912-1-sunshine@sunshineco.com>

The --interdiff option introduces the embedded interdiff generically as
"Interdiff:", however, we can do better when --reroll-count is specified
by emitting "Interdiff against v{n}:" instead.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
---
 builtin/log.c           | 17 ++++++++++++++++-
 revision.h              |  1 +
 t/t4014-format-patch.sh |  5 +++++
 3 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/builtin/log.c b/builtin/log.c
index 1020b78477..99ddfe8bb0 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1085,7 +1085,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
 		show_diffstat(rev, origin, head);
 
 	if (rev->idiff_oid1) {
-		fprintf_ln(rev->diffopt.file, "%s", _("Interdiff:"));
+		fprintf_ln(rev->diffopt.file, "%s", rev->idiff_title);
 		show_interdiff(rev);
 	}
 }
@@ -1427,6 +1427,16 @@ static void print_bases(struct base_tree_info *bases, FILE *file)
 	oidclr(&bases->base_commit);
 }
 
+static const char *diff_title(struct strbuf *sb, int reroll_count,
+		       const char *generic, const char *rerolled)
+{
+	if (reroll_count <= 0)
+		strbuf_addstr(sb, generic);
+	else /* RFC may be v0, so allow -v1 to diff against v0 */
+		strbuf_addf(sb, rerolled, reroll_count - 1);
+	return sb->buf;
+}
+
 int cmd_format_patch(int argc, const char **argv, const char *prefix)
 {
 	struct commit *commit;
@@ -1455,6 +1465,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 	int show_progress = 0;
 	struct progress *progress = NULL;
 	struct oid_array idiff_prev = OID_ARRAY_INIT;
+	struct strbuf idiff_title = STRBUF_INIT;
 
 	const struct option builtin_format_patch_options[] = {
 		{ OPTION_CALLBACK, 'n', "numbered", &numbered, NULL,
@@ -1758,6 +1769,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 			die(_("--interdiff requires --cover-letter"));
 		rev.idiff_oid1 = &idiff_prev.oid[idiff_prev.nr - 1];
 		rev.idiff_oid2 = get_commit_tree_oid(list[0]);
+		rev.idiff_title = diff_title(&idiff_title, reroll_count,
+					     _("Interdiff:"),
+					     _("Interdiff against v%d:"));
 	}
 
 	if (!signature) {
@@ -1880,6 +1894,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 
 done:
 	oid_array_clear(&idiff_prev);
+	strbuf_release(&idiff_title);
 	return 0;
 }
 
diff --git a/revision.h b/revision.h
index 61931fbac5..ffeadc261a 100644
--- a/revision.h
+++ b/revision.h
@@ -215,6 +215,7 @@ struct rev_info {
 	/* interdiff */
 	const struct object_id *idiff_oid1;
 	const struct object_id *idiff_oid2;
+	const char *idiff_title;
 
 	/* commit counts */
 	int count_left;
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index 57b46322aa..5950890d30 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1734,4 +1734,9 @@ test_expect_success 'interdiff: cover-letter' '
 	test_cmp expect actual
 '
 
+test_expect_success 'interdiff: reroll-count' '
+	git format-patch --cover-letter --interdiff=boop~2 -v2 -1 boop &&
+	test_i18ngrep "^Interdiff ..* v1:$" v2-0000-cover-letter.patch
+'
+
 test_done
-- 
2.18.0.345.g5c9ce644c3


  parent reply	other threads:[~2018-07-22  9:58 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-22  9:57 [PATCH 00/14] format-patch: add --interdiff and --range-diff options Eric Sunshine
2018-07-22  9:57 ` [PATCH 01/14] format-patch: allow additional generated content in make_cover_letter() Eric Sunshine
2018-07-22  9:57 ` [PATCH 02/14] format-patch: add --interdiff option to embed diff in cover letter Eric Sunshine
2018-07-22 10:31   ` Eric Sunshine
2018-07-23 16:02   ` Duy Nguyen
2018-07-23 19:18     ` Eric Sunshine
2018-07-23 21:36       ` Junio C Hamano
2018-07-22  9:57 ` Eric Sunshine [this message]
2018-07-23 16:12   ` [PATCH 03/14] format-patch: teach --interdiff to respect -v/--reroll-count Duy Nguyen
2018-07-23 19:32     ` Eric Sunshine
2018-07-22  9:57 ` [PATCH 04/14] interdiff: teach show_interdiff() to indent interdiff Eric Sunshine
2018-07-22  9:57 ` [PATCH 05/14] log-tree: show_log: make commentary block delimiting reusable Eric Sunshine
2018-07-22  9:57 ` [PATCH 06/14] format-patch: allow --interdiff to apply to a lone-patch Eric Sunshine
2018-07-23 16:22   ` Duy Nguyen
2018-07-23 19:46     ` Eric Sunshine
2018-07-22  9:57 ` [PATCH 07/14] range-diff: respect diff_option.file rather than assuming 'stdout' Eric Sunshine
2018-07-23 22:59   ` Stefan Beller
2018-07-23 23:20     ` Eric Sunshine
2018-07-25 18:25       ` Junio C Hamano
2018-07-22  9:57 ` [PATCH 08/14] range-diff: publish default creation factor Eric Sunshine
2018-07-22  9:57 ` [PATCH 09/14] range-diff: relieve callers of low-level configuration burden Eric Sunshine
2018-07-22  9:57 ` [PATCH 10/14] format-patch: add --range-diff option to embed diff in cover letter Eric Sunshine
2018-07-23 16:28   ` Duy Nguyen
2018-07-23 19:58     ` Eric Sunshine
2018-07-25 17:29       ` Junio C Hamano
2018-07-25 19:30         ` Eric Sunshine
2018-07-25 20:32           ` Junio C Hamano
2018-07-25 17:38       ` Duy Nguyen
2018-07-22  9:57 ` [PATCH 11/14] format-patch: extend --range-diff to accept revision range Eric Sunshine
2018-07-25 20:53   ` Junio C Hamano
2018-09-07  9:15     ` Eric Sunshine
2018-07-22  9:57 ` [PATCH 12/14] format-patch: teach --range-diff to respect -v/--reroll-count Eric Sunshine
2018-07-22  9:57 ` [PATCH 13/14] format-patch: add --creation-factor tweak for --range-diff Eric Sunshine
2018-07-22  9:57 ` [PATCH 14/14] format-patch: allow --range-diff to apply to a lone-patch Eric Sunshine
2018-07-25 21:07   ` Junio C Hamano
2018-09-07  8:46     ` Eric Sunshine
2018-07-23 16:32 ` [PATCH 00/14] format-patch: add --interdiff and --range-diff options Duy Nguyen
2018-07-23 20:03   ` Eric Sunshine

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180722095717.17912-4-sunshine@sunshineco.com \
    --to=sunshine@sunshineco.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=pclouds@gmail.com \
    --cc=sbeller@google.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.