From: Petr Vorel Date: Tue, 4 Jun 2019 15:56:39 +0000 (+0200) Subject: parser: Remove duplicity X-Git-Tag: v2.1.3~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9f24264144df514d7ea6b9ee082a4530a083039b;p=thirdparty%2Fpatchwork.git parser: Remove duplicity commit fc1d750 copied lines added in 753e457. Make sense to define it on single place (DRY). Signed-off-by: Petr Vorel Reviewed-by: Stephen Finucane (cherry picked from commit ecbe3fc5f1c91cfa19dab77d527897e2122f5096) --- diff --git a/patchwork/parser.py b/patchwork/parser.py index fb4b3a0a..01bdd9f9 100644 --- a/patchwork/parser.py +++ b/patchwork/parser.py @@ -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('--- '):