From patchwork Wed Mar 18 03:39:24 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Ellerman X-Patchwork-Id: 453113 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 97CFE14015A for ; Sun, 22 Mar 2015 23:44:51 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 842651A2AA8 for ; Sun, 22 Mar 2015 23:44:51 +1100 (AEDT) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from ozlabs.org (ozlabs.org [103.22.144.67]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 21B641A0198 for ; Wed, 18 Mar 2015 14:39:31 +1100 (AEDT) Received: by ozlabs.org (Postfix, from userid 1034) id 522DC14011D; Wed, 18 Mar 2015 14:39:30 +1100 (AEDT) From: Michael Ellerman To: patchwork@lists.ozlabs.org Subject: [PATCH] parser: Fix parsing of patches with a trailing no-newline marker Date: Wed, 18 Mar 2015 14:39:24 +1100 Message-Id: <1426649964-19052-1-git-send-email-mpe@ellerman.id.au> X-Mailer: git-send-email 2.1.0 X-Mailman-Approved-At: Sun, 22 Mar 2015 23:44:29 +1100 Cc: Jeremy Kerr X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" 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 --- apps/patchwork/parser.py | 5 +++ .../tests/mail/0011-no-newline-at-end-of-file.mbox | 45 ++++++++++++++++++++++ apps/patchwork/tests/test_patchparser.py | 15 ++++++++ 3 files changed, 65 insertions(+) create mode 100644 apps/patchwork/tests/mail/0011-no-newline-at-end-of-file.mbox diff --git a/apps/patchwork/parser.py b/apps/patchwork/parser.py index 82959803adad..336e7224dc6d 100644 --- a/apps/patchwork/parser.py +++ b/apps/patchwork/parser.py @@ -126,6 +126,11 @@ def parse_patch(text): buf = '' state = 2 + elif hunk and line.startswith('\ No newline at end of file'): + # If we had a hunk and now we see this, it's part of the patch, + # and we're still expecting another @@ line. + patchbuf += line + elif hunk: state = 1 buf += line diff --git a/apps/patchwork/tests/mail/0011-no-newline-at-end-of-file.mbox b/apps/patchwork/tests/mail/0011-no-newline-at-end-of-file.mbox new file mode 100644 index 000000000000..314268a847e4 --- /dev/null +++ b/apps/patchwork/tests/mail/0011-no-newline-at-end-of-file.mbox @@ -0,0 +1,45 @@ +Subject: [PATCH v3 5/5] selftests, powerpc: Add test for VPHN +From: Greg Kurz +To: Michael Ellerman +Cc: Benjamin Herrenschmidt , + linuxppc-dev@lists.ozlabs.org +Date: Mon, 23 Feb 2015 16:14:44 +0100 +MIME-Version: 1.0 +Content-Type: text/plain; charset="utf-8" +Content-Transfer-Encoding: 8bit + +The goal is to verify vphn_unpack_associativity() parses VPHN numbers +correctly. We feed it with a variety of input values and compare with +expected results. + +diff --git a/tools/testing/selftests/powerpc/Makefile b/tools/testing/selftests/powerpc/Makefile +index 1d5e7ad..476b8dd 100644 +--- a/tools/testing/selftests/powerpc/Makefile ++++ b/tools/testing/selftests/powerpc/Makefile +@@ -13,7 +13,7 @@ CFLAGS := -Wall -O2 -flto -Wall -Werror -DGIT_VERSION='"$(GIT_VERSION)"' -I$(CUR + + export CC CFLAGS + +-TARGETS = pmu copyloops mm tm primitives stringloops ++TARGETS = pmu copyloops mm tm primitives stringloops vphn + + endif + +diff --git a/tools/testing/selftests/powerpc/vphn/vphn.c b/tools/testing/selftests/powerpc/vphn/vphn.c +new file mode 120000 +index 0000000..186b906 +--- /dev/null ++++ b/tools/testing/selftests/powerpc/vphn/vphn.c +@@ -0,0 +1 @@ ++../../../../../arch/powerpc/mm/vphn.c +\ No newline at end of file +diff --git a/tools/testing/selftests/powerpc/vphn/vphn.h b/tools/testing/selftests/powerpc/vphn/vphn.h +new file mode 120000 +index 0000000..7131efe +--- /dev/null ++++ b/tools/testing/selftests/powerpc/vphn/vphn.h +@@ -0,0 +1 @@ ++../../../../../arch/powerpc/mm/vphn.h +\ No newline at end of file + + diff --git a/apps/patchwork/tests/test_patchparser.py b/apps/patchwork/tests/test_patchparser.py index d9a24c1933b8..119936acab1e 100644 --- a/apps/patchwork/tests/test_patchparser.py +++ b/apps/patchwork/tests/test_patchparser.py @@ -433,6 +433,21 @@ class CharsetFallbackPatchTest(MBoxPatchTest): self.assertTrue(patch is not None) self.assertTrue(comment is not None) +class NoNewlineAtEndOfFilePatchTest(MBoxPatchTest): + mail_file = '0011-no-newline-at-end-of-file.mbox' + + def testPatch(self): + (patch, comment) = find_content(self.project, self.mail) + self.assertTrue(patch is not None) + self.assertTrue(comment is not None) + self.assertTrue(patch.content.startswith('diff --git a/tools/testing/selftests/powerpc/Makefile')) + # Confirm the trailing no newline marker doesn't end up in the comment + self.assertFalse(comment.content.rstrip().endswith('\ No newline at end of file')) + # Confirm it's instead at the bottom of the patch + self.assertTrue(patch.content.rstrip().endswith('\ No newline at end of file')) + # Confirm we got both markers + self.assertEqual(2, patch.content.count('\ No newline at end of file')) + class DelegateRequestTest(TestCase): patch_filename = '0001-add-line.patch' msgid = '<1@example.com>'