comparison mercurial/patch.py @ 7148:7d84e5b00e29

patch: extract and rename gitpatch into patchmeta, document
author Patrick Mezard <pmezard@gmail.com>
date Sat, 18 Oct 2008 23:45:45 +0200
parents 94cf0d1f48a3
children 01a056c54385
comparison
equal deleted inserted replaced
7147:94cf0d1f48a3 7148:7d84e5b00e29
141 141
142 GP_PATCH = 1 << 0 # we have to run patch 142 GP_PATCH = 1 << 0 # we have to run patch
143 GP_FILTER = 1 << 1 # there's some copy/rename operation 143 GP_FILTER = 1 << 1 # there's some copy/rename operation
144 GP_BINARY = 1 << 2 # there's a binary patch 144 GP_BINARY = 1 << 2 # there's a binary patch
145 145
146 class patchmeta:
147 """Patched file metadata
148
149 'op' is the performed operation within ADD, DELETE, RENAME, MODIFY
150 or COPY. 'path' is patched file path. 'oldpath' is set to the
151 origin file when 'op' is either COPY or RENAME, None
152 otherwise. 'mode' is set to the new mode of patched file or None.
153 """
154 def __init__(self, path):
155 self.path = path
156 self.oldpath = None
157 self.mode = None
158 self.op = 'MODIFY'
159 self.lineno = 0
160 self.binary = False
161
146 def readgitpatch(fp, firstline=None): 162 def readgitpatch(fp, firstline=None):
147 """extract git-style metadata about patches from <patchname>""" 163 """extract git-style metadata about patches from <patchname>"""
148 class gitpatch:
149 "op is one of ADD, DELETE, RENAME, MODIFY or COPY"
150 def __init__(self, path):
151 self.path = path
152 self.oldpath = None
153 self.mode = None
154 self.op = 'MODIFY'
155 self.lineno = 0
156 self.binary = False
157 164
158 def reader(fp, firstline): 165 def reader(fp, firstline):
159 if firstline is not None: 166 if firstline is not None:
160 yield firstline 167 yield firstline
161 for line in fp: 168 for line in fp:
175 m = gitre.match(line) 182 m = gitre.match(line)
176 if m: 183 if m:
177 if gp: 184 if gp:
178 gitpatches.append(gp) 185 gitpatches.append(gp)
179 src, dst = m.group(1, 2) 186 src, dst = m.group(1, 2)
180 gp = gitpatch(dst) 187 gp = patchmeta(dst)
181 gp.lineno = lineno 188 gp.lineno = lineno
182 elif gp: 189 elif gp:
183 if line.startswith('--- '): 190 if line.startswith('--- '):
184 if gp.op in ('COPY', 'RENAME'): 191 if gp.op in ('COPY', 'RENAME'):
185 dopatch |= GP_FILTER 192 dopatch |= GP_FILTER