aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKonstantin Ryabitsev <konstantin@linuxfoundation.org>2024-05-09 10:45:20 -0400
committerKonstantin Ryabitsev <konstantin@linuxfoundation.org>2024-05-09 10:45:20 -0400
commitf3d47b4f92dfbd09106b06ade5020458a339d960 (patch)
treedb264fdf05f1f2b6ced34613ac719c61661393bd
parent87f09a292ae55d15f9f9d543b8136a35b8593f51 (diff)
downloadb4-master.tar.gz
am: fix incorrect parsing of non-git diffs with commentsHEADmaster
We were not properly handling patches that were a) not generated with "git format-patch" and b) contained a comment after the main commit message (where the diffstat would normally go). This fixes it and adds a test case to make sure we catch it in the future. Reported-by: Andrew Cooper <andrew.cooper3@citrix.com> Closes: https://bugzilla.kernel.org/show_bug.cgi?id=218824 Signed-off-by: Konstantin Ryabitsev <konstantin@linuxfoundation.org>
-rw-r--r--src/b4/__init__.py5
-rw-r--r--src/tests/samples/trailers-followup-non-git-patch-with-comments-ref-defaults.txt32
-rw-r--r--src/tests/samples/trailers-followup-non-git-patch-with-comments.mbox45
-rw-r--r--src/tests/test___init__.py1
4 files changed, 81 insertions, 2 deletions
diff --git a/src/b4/__init__.py b/src/b4/__init__.py
index aa65c43..fea7498 100644
--- a/src/b4/__init__.py
+++ b/src/b4/__init__.py
@@ -2093,10 +2093,11 @@ class LoreMessage:
if len(basement):
if not len(trailers):
body += '\n'
- if DIFFSTAT_RE.search(basement):
+ if (DIFFSTAT_RE.search(basement)
+ or not (basement.strip().startswith('diff --git') or basement.lstrip().startswith('--- '))):
body += '---\n'
else:
- # If we don't have a diffstat, then we don't need to add a ---
+ # We don't need to add a ---
body += '\n'
body += basement.strip('\r\n') + '\n'
diff --git a/src/tests/samples/trailers-followup-non-git-patch-with-comments-ref-defaults.txt b/src/tests/samples/trailers-followup-non-git-patch-with-comments-ref-defaults.txt
new file mode 100644
index 0000000..1c13bca
--- /dev/null
+++ b/src/tests/samples/trailers-followup-non-git-patch-with-comments-ref-defaults.txt
@@ -0,0 +1,32 @@
+From git@z Thu Jan 1 00:00:00 1970
+Subject: [PATCH] Simple test
+From: Test Test <test@example.com>
+Date: Tue, 30 Aug 2022 11:19:07 -0400
+Message-Id: <orig-message@example.com>
+MIME-Version: 1.0
+Content-Type: text/plain; charset="utf-8"
+Content-Transfer-Encoding: 7bit
+
+Follow-up trailer collating test.
+
+Fixes: abcdef01234567890
+Reviewed-by: Original Reviewer <original-reviewer@example.com>
+Link: https://msgid.link/some@msgid.here
+Signed-off-by: Original Submitter <original-submitter@example.com>
+Reviewed-by: Followup Reviewer1 <followup-reviewer1@example.com>
+---
+This contains comments that are included below the message, but there is
+no diffstat.
+
+--- a/b4/junk.py
++++ b/b4/junk.py
+@@@ -1,1 +1,1 @@ def junk():
+
+
+-junk1
++junk2
+
+
+--
+2.wong.fu
+
diff --git a/src/tests/samples/trailers-followup-non-git-patch-with-comments.mbox b/src/tests/samples/trailers-followup-non-git-patch-with-comments.mbox
new file mode 100644
index 0000000..5df6a8d
--- /dev/null
+++ b/src/tests/samples/trailers-followup-non-git-patch-with-comments.mbox
@@ -0,0 +1,45 @@
+From foo@z Thu Jan 1 00:00:00 1970
+From: Test Test <test@example.com>
+Subject: [PATCH] Simple test
+To: Some List <list-1@lists.example.com>
+Cc: Dev Eloper1 <dev-eloper1@example.com>,
+ Dev Eloper2 <dev-eloper2@example.com>
+Date: Tue, 30 Aug 2022 11:19:07 -0400
+Message-Id: <orig-message@example.com>
+
+Follow-up trailer collating test.
+
+Fixes: abcdef01234567890
+Reviewed-by: Original Reviewer <original-reviewer@example.com>
+Link: https://msgid.link/some@msgid.here
+Signed-off-by: Original Submitter <original-submitter@example.com>
+---
+This contains comments that are included below the message, but there is
+no diffstat.
+
+--- a/b4/junk.py
++++ b/b4/junk.py
+@@@ -1,1 +1,1 @@ def junk():
+
+
+-junk1
++junk2
+
+
+--
+2.wong.fu
+
+From foo@z Thu Jan 1 00:00:00 1970
+From: Followup Reviewer1 <followup-reviewer1@example.com>
+Subject: Re: [PATCH] Simple test
+Date: Tue, 30 Aug 2022 11:19:07 -0400
+Message-Id: <fwup-message-1@example.com>
+In-Reply-To: <orig-message@example.com>
+References: <orig-message@example.com>
+
+> This is a simple trailer parsing test.
+
+Reviewed-by: Followup Reviewer1 <followup-reviewer1@example.com>
+
+--
+My sig
diff --git a/src/tests/test___init__.py b/src/tests/test___init__.py
index a43d308..dba3bc2 100644
--- a/src/tests/test___init__.py
+++ b/src/tests/test___init__.py
@@ -101,6 +101,7 @@ def test_parse_trailers(sampledir, source, expected):
('partial-reroll', {}, {'addmysob': True}, 'defaults', {}),
('nore', {}, {}, 'defaults', {}),
('non-git-patch', {}, {}, 'defaults', {}),
+ ('non-git-patch-with-comments', {}, {}, 'defaults', {}),
('with-diffstat', {}, {}, 'defaults', {}),
('name-parens', {}, {}, 'defaults', {}),
('bare-address', {}, {}, 'defaults', {}),