]> git.ozlabs.org Git - patchwork/commitdiff
parser: Add support for rename-only patches
authorJeremy Kerr <jk@ozlabs.org>
Sun, 13 Oct 2013 05:40:00 +0000 (13:40 +0800)
committerJeremy Kerr <jk@ozlabs.org>
Sun, 13 Oct 2013 05:42:37 +0000 (13:42 +0800)
Yann E. MORIN reported a problem where patchwork drops patches with only
renames:

 http://lists.busybox.net/pipermail/buildroot/2013-October/079999.html

This change fixes the issue by adding a new state for patch 'meta'
headers: header test which is not parsed as a hunk, but has the same
behaviour as a hunk in that it will cause the patchbuf to be populated.

Signed-off-by: Jeremy Kerr <jk@ozlabs.org>
apps/patchwork/parser.py
apps/patchwork/tests/mail/0008-git-rename.mbox [new file with mode: 0644]
apps/patchwork/tests/mail/0009-git-rename-with-diff.mbox [new file with mode: 0644]
apps/patchwork/tests/patchparser.py

index f4605668e67a78f9f7cbd1a5e4018251ba2caf17..82959803adad45e8de0ee768ddd8e8c534cf1ca1 100644 (file)
@@ -45,6 +45,7 @@ def parse_patch(text):
     # 3: patch header line 2 (+++)
     # 4: patch hunk header line (@@ line)
     # 5: patch hunk content
+    # 6: patch meta header (rename from/rename to)
     #
     # valid transitions:
     #  0 -> 1 (diff, ===, Index:)
@@ -54,6 +55,9 @@ def parse_patch(text):
     #  3 -> 4 (@@ line)
     #  4 -> 5 (patch content)
     #  5 -> 1 (run out of lines from @@-specifed count)
+    #  1 -> 6 (rename from / rename to)
+    #  6 -> 2 (---)
+    #  6 -> 1 (other text)
     #
     # Suspected patch header is stored into buf, and appended to
     # patchbuf if we find a following hunk. Otherwise, append to
@@ -85,6 +89,9 @@ def parse_patch(text):
             if line.startswith('--- '):
                 state = 2
 
+            if line.startswith('rename from ') or line.startswith('rename to '):
+                state = 6
+
         elif state == 2:
             if line.startswith('+++ '):
                 state = 3
@@ -148,6 +155,20 @@ def parse_patch(text):
             else:
                 state = 5
 
+        elif state == 6:
+            if line.startswith('rename to ') or line.startswith('rename from '):
+                patchbuf += buf + line
+                buf = ''
+
+            elif line.startswith('--- '):
+                patchbuf += buf + line
+                buf = ''
+                state = 2
+
+            else:
+                buf += line
+                state = 1
+
         else:
             raise Exception("Unknown state %d! (line '%s')" % (state, line))
 
diff --git a/apps/patchwork/tests/mail/0008-git-rename.mbox b/apps/patchwork/tests/mail/0008-git-rename.mbox
new file mode 100644 (file)
index 0000000..8277049
--- /dev/null
@@ -0,0 +1,24 @@
+From: "Yann E. MORIN" <yann.morin.1998@free.fr>
+Subject: [Buildroot] [PATCH 01/11] package/rpi-userland: rename patches
+Date: Tue, 8 Oct 2013 22:09:47 +0000
+
+Rename patches to follow standard naming scheme.
+
+Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
+---
+ ...d-pkgconfig-files.patch => rpi-userland-000-add-pkgconfig-files.patch} | 0
+ ...erland-001-makefiles-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch} | 0
+ 2 files changed, 0 insertions(+), 0 deletions(-)
+ rename package/rpi-userland/{rpi-userland-add-pkgconfig-files.patch => rpi-userland-000-add-pkgconfig-files.patch} (100%)
+ rename package/rpi-userland/{rpi-userland-makefiles-0001-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch => rpi-userland-001-makefiles-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch} (100%)
+
+diff --git a/package/rpi-userland/rpi-userland-add-pkgconfig-files.patch b/package/rpi-userland/rpi-userland-000-add-pkgconfig-files.patch
+similarity index 100%
+rename from package/rpi-userland/rpi-userland-add-pkgconfig-files.patch
+rename to package/rpi-userland/rpi-userland-000-add-pkgconfig-files.patch
+diff --git a/package/rpi-userland/rpi-userland-makefiles-0001-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch b/package/rpi-userland/rpi-userland-001-makefiles-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch
+similarity index 100%
+rename from package/rpi-userland/rpi-userland-makefiles-0001-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch
+rename to package/rpi-userland/rpi-userland-001-makefiles-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch
+-- 
+1.8.1.2
diff --git a/apps/patchwork/tests/mail/0009-git-rename-with-diff.mbox b/apps/patchwork/tests/mail/0009-git-rename-with-diff.mbox
new file mode 100644 (file)
index 0000000..761cfc1
--- /dev/null
@@ -0,0 +1,32 @@
+From: "Yann E. MORIN" <yann.morin.1998@free.fr>
+Subject: [Buildroot] [PATCH 01/11] package/rpi-userland: rename patches
+Date: Tue, 8 Oct 2013 22:09:47 +0000
+
+Rename patches to follow standard naming scheme.
+
+Signed-off-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
+---
+ ...d-pkgconfig-files.patch => rpi-userland-000-add-pkgconfig-files.patch} | 0
+ ...erland-001-makefiles-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch} | 0
+ 2 files changed, 0 insertions(+), 0 deletions(-)
+ rename package/rpi-userland/{rpi-userland-add-pkgconfig-files.patch => rpi-userland-000-add-pkgconfig-files.patch} (100%)
+ rename package/rpi-userland/{rpi-userland-makefiles-0001-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch => rpi-userland-001-makefiles-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch} (100%)
+
+diff --git a/package/rpi-userland/rpi-userland-add-pkgconfig-files.patch b/package/rpi-userland/rpi-userland-000-add-pkgconfig-files.patch
+similarity index 100%
+rename from package/rpi-userland/rpi-userland-add-pkgconfig-files.patch
+rename to package/rpi-userland/rpi-userland-000-add-pkgconfig-files.patch
+@@ -100,7 +100,7 @@
+ a
+ a
+-a
++b
+ c
+ c
+ c
+diff --git a/package/rpi-userland/rpi-userland-makefiles-0001-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch b/package/rpi-userland/rpi-userland-001-makefiles-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch
+similarity index 100%
+rename from package/rpi-userland/rpi-userland-makefiles-0001-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch
+rename to package/rpi-userland/rpi-userland-001-makefiles-cmake-vmcs.cmake-allow-to-override-VMCS_IN.patch
+-- 
+1.8.1.2
index 523b9c0d5cf62e25ddd8c9ee8cfbac983ed3e9d9..5662389f09e64169d7a2d14809545e4c62f3ee50 100644 (file)
@@ -392,6 +392,27 @@ class GitPullSSHUrlTest(GitPullTest):
 class GitPullHTTPUrlTest(GitPullTest):
     mail_file = '0006-git-pull-request-http.mbox'
 
+class GitRenameOnlyTest(MBoxPatchTest):
+    mail_file = '0008-git-rename.mbox'
+
+    def testGitRename(self):
+        (patch, comment) = find_content(self.project, self.mail)
+        self.assertTrue(patch is not None)
+        self.assertTrue(comment is not None)
+        self.assertEqual(patch.content.count("\nrename from "), 2)
+        self.assertEqual(patch.content.count("\nrename to "), 2)
+
+class GitRenameWithDiffTest(MBoxPatchTest):
+    mail_file = '0009-git-rename-with-diff.mbox'
+
+    def testGitRename(self):
+        (patch, comment) = find_content(self.project, self.mail)
+        self.assertTrue(patch is not None)
+        self.assertTrue(comment is not None)
+        self.assertEqual(patch.content.count("\nrename from "), 2)
+        self.assertEqual(patch.content.count("\nrename to "), 2)
+        self.assertEqual(patch.content.count('\n-a\n+b'), 1)
+
 class CVSFormatPatchTest(MBoxPatchTest):
     mail_file = '0007-cvs-format-diff.mbox'