# HG changeset patch # User Benoit Boissinot # Date 1157411474 -7200 # Node ID d16b93f4a6ca732bfbde7d810166d0d590050ef0 # Parent 6848528f7ebd6c429e5ed38f0ba2dce8023e21c2 unlink temporary patch files even when an exception is raised diff -r 6848528f7ebd -r d16b93f4a6ca mercurial/patch.py --- a/mercurial/patch.py Wed Aug 30 13:42:57 2006 -0700 +++ b/mercurial/patch.py Tue Sep 05 01:11:14 2006 +0200 @@ -227,14 +227,14 @@ """apply the patch to the working directory. a list of patched files is returned""" - (dopatch, gitpatches) = readgitpatch(patchname) + # helper function + def __patch(patchname): + """patch and updates the files and fuzz variables""" + files = {} + fuzz = False - files = {} - fuzz = False - if dopatch: - if dopatch == 'filter': - patchname = dogitpatch(patchname, gitpatches, cwd=cwd) - patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), 'patch') + patcher = util.find_in_path('gpatch', os.environ.get('PATH', ''), + 'patch') args = [] if cwd: args.append('-d %s' % util.shellquote(cwd)) @@ -261,14 +261,24 @@ ui.warn(pf + '\n') printed_file = True ui.warn(line + '\n') - - if dopatch == 'filter': - os.unlink(patchname) - code = fp.close() if code: raise util.Abort(_("patch command failed: %s") % util.explain_exit(code)[0]) + return files, fuzz + + (dopatch, gitpatches) = readgitpatch(patchname) + + if dopatch: + if dopatch == 'filter': + patchname = dogitpatch(patchname, gitpatches, cwd=cwd) + try: + files, fuzz = __patch(patchname) + finally: + if dopatch == 'filter': + os.unlink(patchname) + else: + files, fuzz = {}, False for gp in gitpatches: files[gp.path] = (gp.op, gp)