comparison mercurial/patch.py @ 3055:efd26ceedafb

Fix git patch application when cwd != repo.root
author Brendan Cully <brendan@kublai.com>
date Wed, 30 Aug 2006 13:12:26 -0700
parents 6ba3409f9725
children 6848528f7ebd
comparison
equal deleted inserted replaced
3054:51b7f792e473 3055:efd26ceedafb
180 if not gitpatches: 180 if not gitpatches:
181 dopatch = True 181 dopatch = True
182 182
183 return (dopatch, gitpatches) 183 return (dopatch, gitpatches)
184 184
185 def dogitpatch(patchname, gitpatches): 185 def dogitpatch(patchname, gitpatches, cwd=None):
186 """Preprocess git patch so that vanilla patch can handle it""" 186 """Preprocess git patch so that vanilla patch can handle it"""
187 pf = file(patchname) 187 pf = file(patchname)
188 pfline = 1 188 pfline = 1
189 189
190 fd, patchname = tempfile.mkstemp(prefix='hg-patch-') 190 fd, patchname = tempfile.mkstemp(prefix='hg-patch-')
194 for i in range(len(gitpatches)): 194 for i in range(len(gitpatches)):
195 p = gitpatches[i] 195 p = gitpatches[i]
196 if not p.copymod: 196 if not p.copymod:
197 continue 197 continue
198 198
199 copyfile(p.oldpath, p.path) 199 copyfile(p.oldpath, p.path, basedir=cwd)
200 200
201 # rewrite patch hunk 201 # rewrite patch hunk
202 while pfline < p.lineno: 202 while pfline < p.lineno:
203 tmpfp.write(pf.readline()) 203 tmpfp.write(pf.readline())
204 pfline += 1 204 pfline += 1
231 231
232 files = {} 232 files = {}
233 fuzz = False 233 fuzz = False
234 if dopatch: 234 if dopatch:
235 if dopatch == 'filter': 235 if dopatch == 'filter':
236 patchname = dogitpatch(patchname, gitpatches) 236 patchname = dogitpatch(patchname, gitpatches, cwd=cwd)
237 patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') 237 patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch')
238 args = [] 238 args = []
239 if cwd: 239 if cwd:
240 args.append('-d %s' % util.shellquote(cwd)) 240 args.append('-d %s' % util.shellquote(cwd))
241 fp = os.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip, 241 fp = os.popen('%s %s -p%d < %s' % (patcher, ' '.join(args), strip,