comparison mercurial/patch.py @ 8778:c5f36402daad

use new style classes
author Benoit Boissinot <benoit.boissinot@ens-lyon.org>
date Wed, 10 Jun 2009 15:10:21 +0200
parents 0289f384e1e5
children ac92775b3b80
comparison
equal deleted inserted replaced
8777:012be286b2c4 8778:c5f36402daad
145 145
146 GP_PATCH = 1 << 0 # we have to run patch 146 GP_PATCH = 1 << 0 # we have to run patch
147 GP_FILTER = 1 << 1 # there's some copy/rename operation 147 GP_FILTER = 1 << 1 # there's some copy/rename operation
148 GP_BINARY = 1 << 2 # there's a binary patch 148 GP_BINARY = 1 << 2 # there's a binary patch
149 149
150 class patchmeta: 150 class patchmeta(object):
151 """Patched file metadata 151 """Patched file metadata
152 152
153 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY 153 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY
154 or COPY. 'path' is patched file path. 'oldpath' is set to the 154 or COPY. 'path' is patched file path. 'oldpath' is set to the
155 origin file when 'op' is either COPY or RENAME, None otherwise. If 155 origin file when 'op' is either COPY or RENAME, None otherwise. If
230 230
231 # @@ -start,len +start,len @@ or @@ -start +start @@ if len is 1 231 # @@ -start,len +start,len @@ or @@ -start +start @@ if len is 1
232 unidesc = re.compile('@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@') 232 unidesc = re.compile('@@ -(\d+)(,(\d+))? \+(\d+)(,(\d+))? @@')
233 contextdesc = re.compile('(---|\*\*\*) (\d+)(,(\d+))? (---|\*\*\*)') 233 contextdesc = re.compile('(---|\*\*\*) (\d+)(,(\d+))? (---|\*\*\*)')
234 234
235 class patchfile: 235 class patchfile(object):
236 def __init__(self, ui, fname, opener, missing=False): 236 def __init__(self, ui, fname, opener, missing=False):
237 self.fname = fname 237 self.fname = fname
238 self.opener = opener 238 self.opener = opener
239 self.ui = ui 239 self.ui = ui
240 self.lines = [] 240 self.lines = []
430 self.printfile(True) 430 self.printfile(True)
431 self.ui.warn(_("Hunk #%d FAILED at %d\n") % (h.number, orig_start)) 431 self.ui.warn(_("Hunk #%d FAILED at %d\n") % (h.number, orig_start))
432 self.rej.append(h) 432 self.rej.append(h)
433 return -1 433 return -1
434 434
435 class hunk: 435 class hunk(object):
436 def __init__(self, desc, num, lr, context, create=False, remove=False): 436 def __init__(self, desc, num, lr, context, create=False, remove=False):
437 self.number = num 437 self.number = num
438 self.desc = desc 438 self.desc = desc
439 self.hunk = [ desc ] 439 self.hunk = [ desc ]
440 self.a = [] 440 self.a = []
780 else: 780 else:
781 raise PatchError(_("undefined source and destination files")) 781 raise PatchError(_("undefined source and destination files"))
782 782
783 return fname, missing 783 return fname, missing
784 784
785 class linereader: 785 class linereader(object):
786 # simple class to allow pushing lines back into the input stream 786 # simple class to allow pushing lines back into the input stream
787 def __init__(self, fp): 787 def __init__(self, fp):
788 self.fp = fp 788 self.fp = fp
789 self.buf = [] 789 self.buf = []
790 790