# HG changeset patch # User Patrick Mezard # Date 2010-01-03 18:47:07 # Node ID 6e26e3c2083fa67987cca6849bf6f86221c31e7e # Parent d2847c4523e8fb21bec23a2ad04e2d3f9cdcae73 patch: explicitely close input patch files when leaving If applydiff() raises an exception, the opened patch file is kept alive in the exception context. If it is a temporary file (for instance supplied by import command with stdin input), Windows cannot clean it up. diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1126,6 +1126,8 @@ def internalpatch(patchobj, ui, strip, c finally: if cwd: os.chdir(curdir) + if fp != patchobj: + fp.close() if ret < 0: raise PatchError return ret > 0