##// END OF EJS Templates
patch: consolidate two different regexes for parsing of git diffs
Dirkjan Ochtman -
r7199:dd891d0d default
parent child Browse files
Show More
@@ -12,6 +12,8 b' import base85, cmdutil, mdiff, util, rev'
12 12 import cStringIO, email.Parser, os, re, errno
13 13 import sys, tempfile, zlib
14 14
15 gitre = re.compile('diff --git a/(.*) b/(.*)')
16
15 17 class PatchError(Exception):
16 18 pass
17 19
@@ -170,7 +172,6 b' def readgitpatch(lr):'
170 172 """extract git-style metadata about patches from <patchname>"""
171 173
172 174 # Filter patch for git information
173 gitre = re.compile('diff --git a/(.*) b/(.*)')
174 175 gp = None
175 176 gitpatches = []
176 177 # Can have a git patch with only metadata, causing patch to complain
@@ -823,9 +824,7 b' def iterhunks(ui, fp, sourcefile=None):'
823 824 state = None
824 825 hunknum = 0
825 826 emitfile = False
826
827 827 git = False
828 gitre = re.compile('diff --git (a/.*) (b/.*)')
829 828
830 829 # our states
831 830 BFILE = 1
@@ -853,7 +852,7 b' def iterhunks(ui, fp, sourcefile=None):'
853 852 try:
854 853 if context == None and x.startswith('***************'):
855 854 context = True
856 gpatch = changed.get(bfile[2:])
855 gpatch = changed.get(bfile)
857 856 create = afile == '/dev/null' or gpatch and gpatch.op == 'ADD'
858 857 remove = bfile == '/dev/null' or gpatch and gpatch.op == 'DELETE'
859 858 current_hunk = hunk(x, hunknum + 1, lr, context, create, remove)
@@ -866,11 +865,11 b' def iterhunks(ui, fp, sourcefile=None):'
866 865 emitfile = False
867 866 yield 'file', (afile, bfile, current_hunk)
868 867 elif state == BFILE and x.startswith('GIT binary patch'):
869 current_hunk = binhunk(changed[bfile[2:]])
868 current_hunk = binhunk(changed[bfile])
870 869 hunknum += 1
871 870 if emitfile:
872 871 emitfile = False
873 yield 'file', (afile, bfile, current_hunk)
872 yield 'file', ('a/' + afile, 'b/' + bfile, current_hunk)
874 873 current_hunk.extract(lr)
875 874 elif x.startswith('diff --git'):
876 875 # check for git diff, scanning the whole patch file if needed
@@ -885,7 +884,7 b' def iterhunks(ui, fp, sourcefile=None):'
885 884 changed[gp.path] = gp
886 885 # else error?
887 886 # copy/rename + modify should modify target, not source
888 gp = changed.get(bfile[2:])
887 gp = changed.get(bfile)
889 888 if gp and gp.op in ('COPY', 'DELETE', 'RENAME'):
890 889 afile = bfile
891 890 gitworkdone = True
General Comments 0
You need to be logged in to leave comments. Login now