]> git.ipfire.org Git - thirdparty/patchwork.git/commitdiff
parser: Remove duplicity
authorPetr Vorel <petr.vorel@gmail.com>
Tue, 4 Jun 2019 15:56:39 +0000 (17:56 +0200)
committerStephen Finucane <stephen@that.guru>
Wed, 5 Jun 2019 10:29:47 +0000 (11:29 +0100)
commit fc1d750 copied lines added in 753e457.
Make sense to define it on single place (DRY).

Signed-off-by: Petr Vorel <petr.vorel@gmail.com>
Reviewed-by: Stephen Finucane <stephen@that.guru>
(cherry picked from commit ecbe3fc5f1c91cfa19dab77d527897e2122f5096)

patchwork/parser.py

index fb4b3a0abc060b758c7f19c11fc6e9fa5f48f99f..01bdd9f9f815d8da5ad3ef2e59d3965b79af1c4c 100644 (file)
@@ -52,6 +52,15 @@ list_id_headers = ['List-ID', 'X-Mailing-List', 'X-list']
 
 SERIES_DELAY_INTERVAL = 10
 
+# @see https://git-scm.com/docs/git-diff#_generating_patches_with_p
+EXTENDED_HEADER_LINES = (
+    'old mode ', 'new mode ',
+    'deleted file mode ', 'new file mode ',
+    'copy from ', 'copy to ',
+    'rename from ', 'rename to ',
+    'similarity index ', 'dissimilarity index ',
+    'new file mode ', 'index ')
+
 logger = logging.getLogger(__name__)
 
 
@@ -789,17 +798,7 @@ def parse_patch(content):
             buf += line
             if line.startswith('--- '):
                 state = 2
-
-            # extended header lines
-            # @see https://git-scm.com/docs/git-diff#_generating_patches_with_p
-            if line.startswith(('old mode ', 'new mode ',
-                                'deleted file mode ',
-                                'new file mode ',
-                                'copy from ', 'copy to ',
-                                'rename from ', 'rename to ',
-                                'similarity index ',
-                                'dissimilarity index ',
-                                'new file mode ', 'index ')):
+            if line.startswith(EXTENDED_HEADER_LINES):
                 state = 6
         elif state == 2:
             if line.startswith('+++ '):
@@ -860,16 +859,7 @@ def parse_patch(content):
             else:
                 state = 5
         elif state == 6:
-            # extended header lines
-            # @see https://git-scm.com/docs/git-diff#_generating_patches_with_p
-            if line.startswith(('old mode ', 'new mode ',
-                                'deleted file mode ',
-                                'new file mode ',
-                                'copy from ', 'copy to ',
-                                'rename from ', 'rename to ',
-                                'similarity index ',
-                                'dissimilarity index ',
-                                'new file mode ', 'index ')):
+            if line.startswith(EXTENDED_HEADER_LINES):
                 patchbuf += buf + line
                 buf = ''
             elif line.startswith('--- '):