Skip to content

Commit 86f645a

Browse files
mpejk-ozlabs
authored andcommitted
parser: Fix parsing of patches with a trailing no-newline marker
If a patch ends with a "No newline at end of file" marker, it is incorrectly considered part of the comment. Add a testcase which shows the bug, and then fix the parser. The parser fix is hopefully sufficiently specific so as to not break any other unrelated case. But .. Signed-off-by: Michael Ellerman <[email protected]>
1 parent 93aa30e commit 86f645a

File tree

3 files changed

+65
-0
lines changed

3 files changed

+65
-0
lines changed

apps/patchwork/parser.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,11 @@ def fn(x):
126126
buf = ''
127127
state = 2
128128

129+
elif hunk and line.startswith('\ No newline at end of file'):
130+
# If we had a hunk and now we see this, it's part of the patch,
131+
# and we're still expecting another @@ line.
132+
patchbuf += line
133+
129134
elif hunk:
130135
state = 1
131136
buf += line
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Subject: [PATCH v3 5/5] selftests, powerpc: Add test for VPHN
2+
From: Greg Kurz <[email protected]>
3+
To: Michael Ellerman <[email protected]>
4+
Cc: Benjamin Herrenschmidt <[email protected]>,
5+
6+
Date: Mon, 23 Feb 2015 16:14:44 +0100
7+
MIME-Version: 1.0
8+
Content-Type: text/plain; charset="utf-8"
9+
Content-Transfer-Encoding: 8bit
10+
11+
The goal is to verify vphn_unpack_associativity() parses VPHN numbers
12+
correctly. We feed it with a variety of input values and compare with
13+
expected results.
14+
15+
diff --git a/tools/testing/selftests/powerpc/Makefile b/tools/testing/selftests/powerpc/Makefile
16+
index 1d5e7ad..476b8dd 100644
17+
--- a/tools/testing/selftests/powerpc/Makefile
18+
+++ b/tools/testing/selftests/powerpc/Makefile
19+
@@ -13,7 +13,7 @@ CFLAGS := -Wall -O2 -flto -Wall -Werror -DGIT_VERSION='"$(GIT_VERSION)"' -I$(CUR
20+
21+
export CC CFLAGS
22+
23+
-TARGETS = pmu copyloops mm tm primitives stringloops
24+
+TARGETS = pmu copyloops mm tm primitives stringloops vphn
25+
26+
endif
27+
28+
diff --git a/tools/testing/selftests/powerpc/vphn/vphn.c b/tools/testing/selftests/powerpc/vphn/vphn.c
29+
new file mode 120000
30+
index 0000000..186b906
31+
--- /dev/null
32+
+++ b/tools/testing/selftests/powerpc/vphn/vphn.c
33+
@@ -0,0 +1 @@
34+
+../../../../../arch/powerpc/mm/vphn.c
35+
\ No newline at end of file
36+
diff --git a/tools/testing/selftests/powerpc/vphn/vphn.h b/tools/testing/selftests/powerpc/vphn/vphn.h
37+
new file mode 120000
38+
index 0000000..7131efe
39+
--- /dev/null
40+
+++ b/tools/testing/selftests/powerpc/vphn/vphn.h
41+
@@ -0,0 +1 @@
42+
+../../../../../arch/powerpc/mm/vphn.h
43+
\ No newline at end of file
44+
45+

apps/patchwork/tests/test_patchparser.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,21 @@ def testPatch(self):
433433
self.assertTrue(patch is not None)
434434
self.assertTrue(comment is not None)
435435

436+
class NoNewlineAtEndOfFilePatchTest(MBoxPatchTest):
437+
mail_file = '0011-no-newline-at-end-of-file.mbox'
438+
439+
def testPatch(self):
440+
(patch, comment) = find_content(self.project, self.mail)
441+
self.assertTrue(patch is not None)
442+
self.assertTrue(comment is not None)
443+
self.assertTrue(patch.content.startswith('diff --git a/tools/testing/selftests/powerpc/Makefile'))
444+
# Confirm the trailing no newline marker doesn't end up in the comment
445+
self.assertFalse(comment.content.rstrip().endswith('\ No newline at end of file'))
446+
# Confirm it's instead at the bottom of the patch
447+
self.assertTrue(patch.content.rstrip().endswith('\ No newline at end of file'))
448+
# Confirm we got both markers
449+
self.assertEqual(2, patch.content.count('\ No newline at end of file'))
450+
436451
class DelegateRequestTest(TestCase):
437452
patch_filename = '0001-add-line.patch'
438453
msgid = '<[email protected]>'

0 commit comments

Comments
 (0)