comparison mercurial/patch.py @ 14418:0174d1f79280

patch: remove EOL support from linereader class This was only used when reading patched files which is now done by backends.
author Patrick Mezard <pmezard@gmail.com>
date Tue, 24 May 2011 14:21:04 +0200
parents f03f08240c32
children 5f6090e559fa
comparison
equal deleted inserted replaced
14417:25137d99a5ed 14418:0174d1f79280
328 328
329 return gitpatches 329 return gitpatches
330 330
331 class linereader(object): 331 class linereader(object):
332 # simple class to allow pushing lines back into the input stream 332 # simple class to allow pushing lines back into the input stream
333 def __init__(self, fp, textmode=False): 333 def __init__(self, fp):
334 self.fp = fp 334 self.fp = fp
335 self.buf = [] 335 self.buf = []
336 self.textmode = textmode
337 self.eol = None
338 336
339 def push(self, line): 337 def push(self, line):
340 if line is not None: 338 if line is not None:
341 self.buf.append(line) 339 self.buf.append(line)
342 340
343 def readline(self): 341 def readline(self):
344 if self.buf: 342 if self.buf:
345 l = self.buf[0] 343 l = self.buf[0]
346 del self.buf[0] 344 del self.buf[0]
347 return l 345 return l
348 l = self.fp.readline() 346 return self.fp.readline()
349 if not self.eol:
350 if l.endswith('\r\n'):
351 self.eol = '\r\n'
352 elif l.endswith('\n'):
353 self.eol = '\n'
354 if self.textmode and l.endswith('\r\n'):
355 l = l[:-2] + '\n'
356 return l
357 347
358 def __iter__(self): 348 def __iter__(self):
359 while 1: 349 while 1:
360 l = self.readline() 350 l = self.readline()
361 if not l: 351 if not l:
1095 try: 1085 try:
1096 pos = lr.fp.tell() 1086 pos = lr.fp.tell()
1097 fp = lr.fp 1087 fp = lr.fp
1098 except IOError: 1088 except IOError:
1099 fp = cStringIO.StringIO(lr.fp.read()) 1089 fp = cStringIO.StringIO(lr.fp.read())
1100 gitlr = linereader(fp, lr.textmode) 1090 gitlr = linereader(fp)
1101 gitlr.push(firstline) 1091 gitlr.push(firstline)
1102 gitpatches = readgitpatch(gitlr) 1092 gitpatches = readgitpatch(gitlr)
1103 fp.seek(pos) 1093 fp.seek(pos)
1104 return gitpatches 1094 return gitpatches
1105 1095