# HG changeset patch # User Bryan O'Sullivan # Date 2016-01-15 21:14:50 # Node ID f7f3958d39c037be5f3a13e8037aebd481c15c50 # Parent 3e0d27d298b7dab677df58383d7e307dff753336 with: use context manager for I/O in changedfiles in patch diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -2099,8 +2099,7 @@ def patch(ui, repo, patchname, strip=1, def changedfiles(ui, repo, patchpath, strip=1): backend = fsbackend(ui, repo.root) - fp = open(patchpath, 'rb') - try: + with open(patchpath, 'rb') as fp: changed = set() for state, values in iterhunks(fp): if state == 'file': @@ -2118,8 +2117,6 @@ def changedfiles(ui, repo, patchpath, st elif state not in ('hunk', 'git'): raise error.Abort(_('unsupported parser state: %s') % state) return changed - finally: - fp.close() class GitDiffRequired(Exception): pass