##// END OF EJS Templates
patch: propagate eolmode down to patchfile...
Martin Geisler -
r10101:155fe355 default
parent child Browse files
Show More
@@ -264,11 +264,13 b' class linereader(object):'
264 264 # @@ -start,len +start,len @@ or @@ -start +start @@ if len is 1
265 265 unidesc = re.compile('@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@')
266 266 contextdesc = re.compile('(---|\*\*\*) (\d+)(,(\d+))? (---|\*\*\*)')
267 eolmodes = ['strict', 'crlf', 'lf']
267 268
268 269 class patchfile(object):
269 def __init__(self, ui, fname, opener, missing=False, eol=None):
270 def __init__(self, ui, fname, opener, missing=False, eolmode='strict'):
270 271 self.fname = fname
271 self.eol = eol
272 self.eolmode = eolmode
273 self.eol = {'strict': None, 'crlf': '\r\n', 'lf': '\n'}[eolmode]
272 274 self.opener = opener
273 275 self.ui = ui
274 276 self.lines = []
@@ -296,7 +298,7 b' class patchfile(object):'
296 298 return [os.readlink(fname)]
297 299 fp = self.opener(fname, 'r')
298 300 try:
299 return list(linereader(fp, self.eol is not None))
301 return list(linereader(fp, self.eolmode != 'strict'))
300 302 finally:
301 303 fp.close()
302 304
@@ -939,7 +941,7 b' def iterhunks(ui, fp, sourcefile=None, t'
939 941 if hunknum == 0 and dopatch and not gitworkdone:
940 942 raise NoHunks
941 943
942 def applydiff(ui, fp, changed, strip=1, sourcefile=None, eol=None):
944 def applydiff(ui, fp, changed, strip=1, sourcefile=None, eolmode='strict'):
943 945 """
944 946 Reads a patch from fp and tries to apply it.
945 947
@@ -947,16 +949,16 b' def applydiff(ui, fp, changed, strip=1, '
947 949 by the patch. Returns 0 for a clean patch, -1 if any rejects were
948 950 found and 1 if there was any fuzz.
949 951
950 If 'eol' is None, the patch content and patched file are read in
951 binary mode. Otherwise, line endings are ignored when patching then
952 normalized to 'eol' (usually '\n' or \r\n').
952 If 'eolmode' is 'strict', the patch content and patched file are
953 read in binary mode. Otherwise, line endings are ignored when
954 patching then normalized according to 'eolmode'.
953 955 """
954 956 rejects = 0
955 957 err = 0
956 958 current_file = None
957 959 gitpatches = None
958 960 opener = util.opener(os.getcwd())
959 textmode = eol is not None
961 textmode = eolmode != 'strict'
960 962
961 963 def closefile():
962 964 if not current_file:
@@ -979,11 +981,11 b' def applydiff(ui, fp, changed, strip=1, '
979 981 afile, bfile, first_hunk = values
980 982 try:
981 983 if sourcefile:
982 current_file = patchfile(ui, sourcefile, opener, eol=eol)
984 current_file = patchfile(ui, sourcefile, opener, eolmode=eolmode)
983 985 else:
984 986 current_file, missing = selectfile(afile, bfile, first_hunk,
985 987 strip)
986 current_file = patchfile(ui, current_file, opener, missing, eol)
988 current_file = patchfile(ui, current_file, opener, missing, eolmode)
987 989 except PatchError, err:
988 990 ui.warn(str(err) + '\n')
989 991 current_file, current_hunk = None, None
@@ -1104,10 +1106,9 b' def internalpatch(patchobj, ui, strip, c'
1104 1106 files = {}
1105 1107 if eolmode is None:
1106 1108 eolmode = ui.config('patch', 'eol', 'strict')
1107 try:
1108 eol = {'strict': None, 'crlf': '\r\n', 'lf': '\n'}[eolmode.lower()]
1109 except KeyError:
1109 if eolmode.lower() not in eolmodes:
1110 1110 raise util.Abort(_('Unsupported line endings type: %s') % eolmode)
1111 eolmode = eolmode.lower()
1111 1112
1112 1113 try:
1113 1114 fp = open(patchobj, 'rb')
@@ -1117,7 +1118,7 b' def internalpatch(patchobj, ui, strip, c'
1117 1118 curdir = os.getcwd()
1118 1119 os.chdir(cwd)
1119 1120 try:
1120 ret = applydiff(ui, fp, files, strip=strip, eol=eol)
1121 ret = applydiff(ui, fp, files, strip=strip, eolmode=eolmode)
1121 1122 finally:
1122 1123 if cwd:
1123 1124 os.chdir(curdir)
General Comments 0
You need to be logged in to leave comments. Login now