Skip to content

Commit 9f24264

Browse files
pevikstephenfin
authored andcommitted
parser: Remove duplicity
commit fc1d750 copied lines added in 753e457. Make sense to define it on single place (DRY). Signed-off-by: Petr Vorel <[email protected]> Reviewed-by: Stephen Finucane <[email protected]> (cherry picked from commit ecbe3fc)
1 parent f205495 commit 9f24264

File tree

1 file changed

+11
-21
lines changed

1 file changed

+11
-21
lines changed

patchwork/parser.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,15 @@
5252

5353
SERIES_DELAY_INTERVAL = 10
5454

55+
# @see https://git-scm.com/docs/git-diff#_generating_patches_with_p
56+
EXTENDED_HEADER_LINES = (
57+
'old mode ', 'new mode ',
58+
'deleted file mode ', 'new file mode ',
59+
'copy from ', 'copy to ',
60+
'rename from ', 'rename to ',
61+
'similarity index ', 'dissimilarity index ',
62+
'new file mode ', 'index ')
63+
5564
logger = logging.getLogger(__name__)
5665

5766

@@ -789,17 +798,7 @@ def parse_patch(content):
789798
buf += line
790799
if line.startswith('--- '):
791800
state = 2
792-
793-
# extended header lines
794-
# @see https://git-scm.com/docs/git-diff#_generating_patches_with_p
795-
if line.startswith(('old mode ', 'new mode ',
796-
'deleted file mode ',
797-
'new file mode ',
798-
'copy from ', 'copy to ',
799-
'rename from ', 'rename to ',
800-
'similarity index ',
801-
'dissimilarity index ',
802-
'new file mode ', 'index ')):
801+
if line.startswith(EXTENDED_HEADER_LINES):
803802
state = 6
804803
elif state == 2:
805804
if line.startswith('+++ '):
@@ -860,16 +859,7 @@ def fn(x):
860859
else:
861860
state = 5
862861
elif state == 6:
863-
# extended header lines
864-
# @see https://git-scm.com/docs/git-diff#_generating_patches_with_p
865-
if line.startswith(('old mode ', 'new mode ',
866-
'deleted file mode ',
867-
'new file mode ',
868-
'copy from ', 'copy to ',
869-
'rename from ', 'rename to ',
870-
'similarity index ',
871-
'dissimilarity index ',
872-
'new file mode ', 'index ')):
862+
if line.startswith(EXTENDED_HEADER_LINES):
873863
patchbuf += buf + line
874864
buf = ''
875865
elif line.startswith('--- '):

0 commit comments

Comments
 (0)