All of lore.kernel.org
 help / color / mirror / Atom feed
From: Denton Liu <liu.denton@gmail.com>
To: Git Mailing List <git@vger.kernel.org>
Cc: Johannes Schindelin <Johannes.Schindelin@gmx.de>,
	Thomas Gummerer <t.gummerer@gmail.com>,
	Junio C Hamano <gitster@pobox.com>
Subject: [PATCH v2 8/8] format-patch: pass notes configuration to range-diff
Date: Tue, 19 Nov 2019 15:55:47 -0800	[thread overview]
Message-ID: <0b7fd66b4dc91947542b56441782766f8ad81690.1574207673.git.liu.denton@gmail.com> (raw)
In-Reply-To: <cover.1574207673.git.liu.denton@gmail.com>

Since format-patch accepts `--[no-]notes`, one would expect the
range-diff generated to also respect the setting. Unfortunately, the
range-diff we currently generate only uses the default option (which
always outputs default notes, even when notes are not being used
elsewhere).

Pass the notes configuration to range-diff so that it can honor it.

Signed-off-by: Denton Liu <liu.denton@gmail.com>
---
 builtin/log.c         |  24 +++++++++-
 t/t3206-range-diff.sh | 101 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 123 insertions(+), 2 deletions(-)

diff --git a/builtin/log.c b/builtin/log.c
index 047ac4594d..e192f219d9 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1111,6 +1111,25 @@ static void prepare_cover_text(struct pretty_print_context *pp,
 	strbuf_release(&subject_sb);
 }
 
+static int get_notes_refs(struct string_list_item *item, void *arg)
+{
+	argv_array_pushf(arg, "--notes=%s", item->string);
+	return 0;
+}
+
+static void get_notes_args(struct argv_array *arg, struct rev_info *rev)
+{
+	if (!rev->show_notes) {
+		argv_array_push(arg, "--no-notes");
+	} else if (rev->notes_opt.use_default_notes > 0 ||
+		   (rev->notes_opt.use_default_notes == -1 &&
+		    !rev->notes_opt.extra_notes_refs.nr)) {
+		argv_array_push(arg, "--notes");
+	} else {
+		for_each_string_list(&rev->notes_opt.extra_notes_refs, get_notes_refs, arg);
+	}
+}
+
 static void make_cover_letter(struct rev_info *rev, int use_stdout,
 			      struct commit *origin,
 			      int nr, struct commit **list,
@@ -1183,13 +1202,16 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout,
 		 * can be added later if deemed desirable.
 		 */
 		struct diff_options opts;
+		struct argv_array other_arg = ARGV_ARRAY_INIT;
 		diff_setup(&opts);
 		opts.file = rev->diffopt.file;
 		opts.use_color = rev->diffopt.use_color;
 		diff_setup_done(&opts);
 		fprintf_ln(rev->diffopt.file, "%s", rev->rdiff_title);
+		get_notes_args(&other_arg, rev);
 		show_range_diff(rev->rdiff1, rev->rdiff2,
-				rev->creation_factor, 1, &opts, NULL);
+				rev->creation_factor, 1, &opts, &other_arg);
+		argv_array_clear(&other_arg);
 	}
 }
 
diff --git a/t/t3206-range-diff.sh b/t/t3206-range-diff.sh
index cea1846282..abbf1efc20 100755
--- a/t/t3206-range-diff.sh
+++ b/t/t3206-range-diff.sh
@@ -576,7 +576,7 @@ test_expect_success 'range-diff with multiple --notes' '
 	test_cmp expect actual
 '
 
-test_expect_success 'format-patch --range-diff compares notes by default' '
+test_expect_success 'format-patch --range-diff does not compare notes by default' '
 	git notes add -m "topic note" topic &&
 	git notes add -m "unmodified note" unmodified &&
 	test_when_finished git notes remove topic unmodified &&
@@ -588,6 +588,40 @@ test_expect_success 'format-patch --range-diff compares notes by default' '
 	grep "= 1: .* s/5/A" 0000-* &&
 	grep "= 2: .* s/4/A" 0000-* &&
 	grep "= 3: .* s/11/B" 0000-* &&
+	grep "= 4: .* s/12/B" 0000-* &&
+	! grep "Notes" 0000-* &&
+	! grep "note" 0000-*
+'
+
+test_expect_success 'format-patch --range-diff with --no-notes' '
+	git notes add -m "topic note" topic &&
+	git notes add -m "unmodified note" unmodified &&
+	test_when_finished git notes remove topic unmodified &&
+	git format-patch --no-notes --cover-letter --range-diff=$prev \
+		master..unmodified >actual &&
+	test_when_finished "rm 000?-*" &&
+	test_line_count = 5 actual &&
+	test_i18ngrep "^Range-diff:$" 0000-* &&
+	grep "= 1: .* s/5/A" 0000-* &&
+	grep "= 2: .* s/4/A" 0000-* &&
+	grep "= 3: .* s/11/B" 0000-* &&
+	grep "= 4: .* s/12/B" 0000-* &&
+	! grep "Notes" 0000-* &&
+	! grep "note" 0000-*
+'
+
+test_expect_success 'format-patch --range-diff with --notes' '
+	git notes add -m "topic note" topic &&
+	git notes add -m "unmodified note" unmodified &&
+	test_when_finished git notes remove topic unmodified &&
+	git format-patch --notes --cover-letter --range-diff=$prev \
+		master..unmodified >actual &&
+	test_when_finished "rm 000?-*" &&
+	test_line_count = 5 actual &&
+	test_i18ngrep "^Range-diff:$" 0000-* &&
+	grep "= 1: .* s/5/A" 0000-* &&
+	grep "= 2: .* s/4/A" 0000-* &&
+	grep "= 3: .* s/11/B" 0000-* &&
 	grep "! 4: .* s/12/B" 0000-* &&
 	sed s/Z/\ /g >expect <<-EOF &&
 	    @@ Commit message
@@ -604,4 +638,69 @@ test_expect_success 'format-patch --range-diff compares notes by default' '
 	test_cmp expect actual
 '
 
+test_expect_success 'format-patch --range-diff with --notes' '
+	git notes add -m "topic note" topic &&
+	git notes add -m "unmodified note" unmodified &&
+	test_when_finished git notes remove topic unmodified &&
+	test_config format.notes true &&
+	git format-patch --cover-letter --range-diff=$prev \
+		master..unmodified >actual &&
+	test_when_finished "rm 000?-*" &&
+	test_line_count = 5 actual &&
+	test_i18ngrep "^Range-diff:$" 0000-* &&
+	grep "= 1: .* s/5/A" 0000-* &&
+	grep "= 2: .* s/4/A" 0000-* &&
+	grep "= 3: .* s/11/B" 0000-* &&
+	grep "! 4: .* s/12/B" 0000-* &&
+	sed s/Z/\ /g >expect <<-EOF &&
+	    @@ Commit message
+	    Z
+	    Z
+	    Z ## Notes ##
+	    -    topic note
+	    +    unmodified note
+	    Z
+	    Z ## file ##
+	    Z@@ file: A
+	EOF
+	sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
+	test_cmp expect actual
+'
+
+test_expect_success 'format-patch --range-diff with multiple notes' '
+	git notes --ref=note1 add -m "topic note1" topic &&
+	git notes --ref=note1 add -m "unmodified note1" unmodified &&
+	test_when_finished git notes --ref=note1 remove topic unmodified &&
+	git notes --ref=note2 add -m "topic note2" topic &&
+	git notes --ref=note2 add -m "unmodified note2" unmodified &&
+	test_when_finished git notes --ref=note2 remove topic unmodified &&
+	git format-patch --notes=note1 --notes=note2 --cover-letter --range-diff=$prev \
+		master..unmodified >actual &&
+	test_when_finished "rm 000?-*" &&
+	test_line_count = 5 actual &&
+	test_i18ngrep "^Range-diff:$" 0000-* &&
+	grep "= 1: .* s/5/A" 0000-* &&
+	grep "= 2: .* s/4/A" 0000-* &&
+	grep "= 3: .* s/11/B" 0000-* &&
+	grep "! 4: .* s/12/B" 0000-* &&
+	sed s/Z/\ /g >expect <<-EOF &&
+	    @@ Commit message
+	    Z
+	    Z
+	    Z ## Notes (note1) ##
+	    -    topic note1
+	    +    unmodified note1
+	    Z
+	    Z
+	    Z ## Notes (note2) ##
+	    -    topic note2
+	    +    unmodified note2
+	    Z
+	    Z ## file ##
+	    Z@@ file: A
+	EOF
+	sed "/@@ Commit message/,/@@ file: A/!d" 0000-* >actual &&
+	test_cmp expect actual
+'
+
 test_done
-- 
2.24.0.420.g9ac4901264


  parent reply	other threads:[~2019-11-19 23:55 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-19  1:06 [PATCH 0/3] range-diff: don't compare notes Denton Liu
2019-11-19  1:06 ` [PATCH 1/3] t3206: remove spaces after redirect operators Denton Liu
2019-11-19  1:06 ` [PATCH 2/3] t3206: demonstrate failure with notes Denton Liu
2019-11-19  3:03   ` Junio C Hamano
2019-11-19  1:06 ` [PATCH 3/3] range-diff: use --no-notes to generate patches Denton Liu
2019-11-19  2:56 ` [PATCH 0/3] range-diff: don't compare notes Junio C Hamano
2019-11-19 23:55 ` [PATCH v2 0/8] range-diff: learn `--notes` Denton Liu
2019-11-19 23:55   ` [PATCH v2 1/8] argv-array: add space after `while` Denton Liu
2019-11-19 23:55   ` [PATCH v2 2/8] rev-list-options.txt: remove reference to --show-notes Denton Liu
2019-11-19 23:55   ` [PATCH v2 3/8] t3206: remove spaces after redirect operators Denton Liu
2019-11-20  0:20     ` Eric Sunshine
2019-11-19 23:55   ` [PATCH v2 4/8] t3206: s/expected/expect/ Denton Liu
2019-11-19 23:55   ` [PATCH v2 5/8] t3206: demonstrate current notes behavior Denton Liu
2019-11-20  4:17     ` Junio C Hamano
2019-11-19 23:55   ` [PATCH v2 6/8] range-diff: output `## Notes ##` header Denton Liu
2019-11-19 23:55   ` [PATCH v2 7/8] range-diff: passthrough --[no-]notes to `git log` Denton Liu
2019-11-20  4:26     ` Junio C Hamano
2019-11-20 19:12       ` Denton Liu
2019-11-21 12:43         ` Eric Sunshine
2019-11-21 18:35           ` Denton Liu
2019-11-19 23:55   ` Denton Liu [this message]
2019-11-20 21:18   ` [PATCH v3 00/10] range-diff: learn `--notes` Denton Liu
2019-11-20 21:18     ` [PATCH v3 01/10] argv-array: add space after `while` Denton Liu
2019-11-20 21:18     ` [PATCH v3 02/10] rev-list-options.txt: remove reference to --show-notes Denton Liu
2019-11-20 21:18     ` [PATCH v3 03/10] pretty-options.txt: --notes accepts a ref instead of treeish Denton Liu
2019-11-20 21:18     ` [PATCH v3 04/10] t3206: remove spaces after redirect operators Denton Liu
2019-11-20 21:18     ` [PATCH v3 05/10] t3206: disable parameter substitution in heredoc Denton Liu
2019-11-20 21:18     ` [PATCH v3 06/10] t3206: s/expected/expect/ Denton Liu
2019-11-20 21:18     ` [PATCH v3 07/10] t3206: range-diff compares logs with commit notes Denton Liu
2019-11-20 21:18     ` [PATCH v3 08/10] range-diff: output `## Notes ##` header Denton Liu
2019-11-20 21:18     ` [PATCH v3 09/10] range-diff: pass through --notes to `git log` Denton Liu
2019-11-20 21:18     ` [PATCH v3 10/10] format-patch: pass notes configuration to range-diff Denton Liu

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=0b7fd66b4dc91947542b56441782766f8ad81690.1574207673.git.liu.denton@gmail.com \
    --to=liu.denton@gmail.com \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=t.gummerer@gmail.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.