Mercurial > public > mercurial-scm > hg
comparison mercurial/patch.py @ 3057:d16b93f4a6ca
unlink temporary patch files even when an exception is raised
author | Benoit Boissinot <benoit.boissinot@ens-lyon.org> |
---|---|
date | Tue, 05 Sep 2006 01:11:14 +0200 |
parents | 6848528f7ebd |
children | 035fd2029575 |
comparison
equal
deleted
inserted
replaced
3056:6848528f7ebd | 3057:d16b93f4a6ca |
---|---|
225 | 225 |
226 def patch(patchname, ui, strip=1, cwd=None): | 226 def patch(patchname, ui, strip=1, cwd=None): |
227 """apply the patch <patchname> to the working directory. | 227 """apply the patch <patchname> to the working directory. |
228 a list of patched files is returned""" | 228 a list of patched files is returned""" |
229 | 229 |
230 (dopatch, gitpatches) = readgitpatch(patchname) | 230 # helper function |
231 | 231 def __patch(patchname): |
232 files = {} | 232 """patch and updates the files and fuzz variables""" |
233 fuzz = False | 233 files = {} |
234 if dopatch: | 234 fuzz = False |
235 if dopatch == 'filter': | 235 |
236 patchname = dogitpatch(patchname, gitpatches, cwd=cwd) | 236 patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), |
237 patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') | 237 '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, |
242 util.shellquote(patchname))) | 242 util.shellquote(patchname))) |
259 elif line.find('FAILED') >= 0: | 259 elif line.find('FAILED') >= 0: |
260 if not printed_file: | 260 if not printed_file: |
261 ui.warn(pf + '\n') | 261 ui.warn(pf + '\n') |
262 printed_file = True | 262 printed_file = True |
263 ui.warn(line + '\n') | 263 ui.warn(line + '\n') |
264 | |
265 if dopatch == 'filter': | |
266 os.unlink(patchname) | |
267 | |
268 code = fp.close() | 264 code = fp.close() |
269 if code: | 265 if code: |
270 raise util.Abort(_("patch command failed: %s") % | 266 raise util.Abort(_("patch command failed: %s") % |
271 util.explain_exit(code)[0]) | 267 util.explain_exit(code)[0]) |
268 return files, fuzz | |
269 | |
270 (dopatch, gitpatches) = readgitpatch(patchname) | |
271 | |
272 if dopatch: | |
273 if dopatch == 'filter': | |
274 patchname = dogitpatch(patchname, gitpatches, cwd=cwd) | |
275 try: | |
276 files, fuzz = __patch(patchname) | |
277 finally: | |
278 if dopatch == 'filter': | |
279 os.unlink(patchname) | |
280 else: | |
281 files, fuzz = {}, False | |
272 | 282 |
273 for gp in gitpatches: | 283 for gp in gitpatches: |
274 files[gp.path] = (gp.op, gp) | 284 files[gp.path] = (gp.op, gp) |
275 | 285 |
276 return (files, fuzz) | 286 return (files, fuzz) |