##// END OF EJS Templates
patch: drop eol normalization fast-path for 'lf' and 'crlf'...
Patrick Mezard -
r10128:ea7c392f default
parent child Browse files
Show More
@@ -434,12 +434,11 b' class patchfile(object):'
434 434 return 0
435 435
436 436 horig = h
437 if self.eolmode == 'auto' and self.eol:
438 # If eolmode == 'auto' and target file exists and has line
439 # endings we have to normalize input data before patching.
440 # Otherwise, patchfile operates in 'strict' mode. If
441 # eolmode is set to 'crlf' or 'lf', input hunk is already
442 # normalized to avoid data copy.
437 if (self.eolmode in ('crlf', 'lf')
438 or self.eolmode == 'auto' and self.eol):
439 # If new eols are going to be normalized, then normalize
440 # hunk data before patching. Otherwise, preserve input
441 # line-endings.
443 442 h = h.getnormalized()
444 443
445 444 # fast case first, no offsets, no fuzz
@@ -870,15 +869,13 b' def scangitpatch(lr, firstline):'
870 869 fp.seek(pos)
871 870 return dopatch, gitpatches
872 871
873 def iterhunks(ui, fp, sourcefile=None, textmode=False):
872 def iterhunks(ui, fp, sourcefile=None):
874 873 """Read a patch and yield the following events:
875 874 - ("file", afile, bfile, firsthunk): select a new target file.
876 875 - ("hunk", hunk): a new hunk is ready to be applied, follows a
877 876 "file" event.
878 877 - ("git", gitchanges): current diff is in git format, gitchanges
879 878 maps filenames to gitpatch records. Unique event.
880
881 If textmode is True, input line-endings are normalized to LF.
882 879 """
883 880 changed = {}
884 881 current_hunk = None
@@ -892,7 +889,7 b' def iterhunks(ui, fp, sourcefile=None, t'
892 889 # our states
893 890 BFILE = 1
894 891 context = None
895 lr = linereader(fp, textmode)
892 lr = linereader(fp)
896 893 dopatch = True
897 894 # gitworkdone is True if a git operation (copy, rename, ...) was
898 895 # performed already for the current file. Useful when the file
@@ -1009,10 +1006,6 b' def applydiff(ui, fp, changed, strip=1, '
1009 1006 current_file = None
1010 1007 gitpatches = None
1011 1008 opener = util.opener(os.getcwd())
1012 # In 'auto' mode, we must preserve original eols if target file
1013 # eols are undefined. Otherwise, hunk data will be normalized
1014 # later.
1015 textmode = eolmode not in ('strict', 'auto')
1016 1009
1017 1010 def closefile():
1018 1011 if not current_file:
@@ -1020,7 +1013,7 b' def applydiff(ui, fp, changed, strip=1, '
1020 1013 current_file.close()
1021 1014 return len(current_file.rej)
1022 1015
1023 for state, values in iterhunks(ui, fp, sourcefile, textmode):
1016 for state, values in iterhunks(ui, fp, sourcefile):
1024 1017 if state == 'hunk':
1025 1018 if not current_file:
1026 1019 continue
@@ -20,7 +20,7 b" w(' c\\r\\n')"
20 20 w(' d\n')
21 21 w('-e\n')
22 22 w('\ No newline at end of file\n')
23 w('+z\r\n')
23 w('+z\n')
24 24 w('\ No newline at end of file\r\n')
25 25 EOF
26 26
General Comments 0
You need to be logged in to leave comments. Login now