From 126facf8219177bc265be725a8579c86ebdf99a5 Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sun, 22 Jul 2018 05:57:05 -0400 Subject: format-patch: add --interdiff option to embed diff in cover letter When submitting a revised version of a patch series, it can be helpful (to reviewers) to include a summary of changes since the previous attempt in the form of an interdiff, however, doing so involves manually copy/pasting the diff into the cover letter. Add an --interdiff option to automate this process. The argument to --interdiff specifies the tip of the previous attempt against which to generate the interdiff. For example: git format-patch --cover-letter --interdiff=v1 -3 v2 The previous attempt and the patch series being formatted must share a common base. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- t/t4014-format-patch.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 't/t4014-format-patch.sh') diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 53880da7bb..57b46322aa 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -1717,4 +1717,21 @@ test_expect_success 'format-patch --pretty=mboxrd' ' test_cmp expect actual ' +test_expect_success 'interdiff: setup' ' + git checkout -b boop master && + test_commit fnorp blorp && + test_commit fleep blorp +' + +test_expect_success 'interdiff: cover-letter' ' + sed "y/q/ /" >expect <<-\EOF && + +fleep + --q + EOF + git format-patch --cover-letter --interdiff=boop~2 -1 boop && + test_i18ngrep "^Interdiff:$" 0000-cover-letter.patch && + sed "1,/^@@ /d; /^-- $/q" <0000-cover-letter.patch >actual && + test_cmp expect actual +' + test_done -- cgit v1.2.3 From 5ac290f9c00edb8963585c322fae9fb06a98167d Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sun, 22 Jul 2018 05:57:06 -0400 Subject: format-patch: teach --interdiff to respect -v/--reroll-count 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 Signed-off-by: Junio C Hamano --- t/t4014-format-patch.sh | 5 +++++ 1 file changed, 5 insertions(+) (limited to 't/t4014-format-patch.sh') 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 -- cgit v1.2.3 From ee6cbf712edcbd1dc14993ab2452fbe882dc524a Mon Sep 17 00:00:00 2001 From: Eric Sunshine Date: Sun, 22 Jul 2018 05:57:09 -0400 Subject: format-patch: allow --interdiff 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 an interdiff, typically in the cover letter. However, it is occasionally useful, despite making for a noisy read, to insert an interdiff into the commentary section of the lone patch of a 1-patch series. Therefore, extend "git format-patch --interdiff=" to insert an interdiff into the commentary section of a lone patch rather than requiring a cover letter. The interdiff is indented to avoid confusing git-am and human readers into considering it part of the patch proper. Implementation note: Generating an interdiff 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 interdiff, and restore it after. Signed-off-by: Eric Sunshine Signed-off-by: Junio C Hamano --- t/t4014-format-patch.sh | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 't/t4014-format-patch.sh') diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh index 5950890d30..909c743c13 100755 --- a/t/t4014-format-patch.sh +++ b/t/t4014-format-patch.sh @@ -1730,6 +1730,7 @@ test_expect_success 'interdiff: cover-letter' ' EOF git format-patch --cover-letter --interdiff=boop~2 -1 boop && test_i18ngrep "^Interdiff:$" 0000-cover-letter.patch && + test_i18ngrep ! "^Interdiff:$" 0001-fleep.patch && sed "1,/^@@ /d; /^-- $/q" <0000-cover-letter.patch >actual && test_cmp expect actual ' @@ -1739,4 +1740,15 @@ test_expect_success 'interdiff: reroll-count' ' test_i18ngrep "^Interdiff ..* v1:$" v2-0000-cover-letter.patch ' +test_expect_success 'interdiff: solo-patch' ' + cat >expect <<-\EOF && + +fleep + + EOF + git format-patch --interdiff=boop~2 -1 boop && + test_i18ngrep "^Interdiff:$" 0001-fleep.patch && + sed "1,/^ @@ /d; /^$/q" <0001-fleep.patch >actual && + test_cmp expect actual +' + test_done -- cgit v1.2.3