changeset 27796:f7f3958d39c0

with: use context manager for I/O in changedfiles in patch
author Bryan O'Sullivan <bryano@fb.com>
date Fri, 15 Jan 2016 13:14:50 -0800
parents 3e0d27d298b7
children 054abf2377e8
files mercurial/patch.py
diffstat 1 files changed, 1 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Fri Jan 15 13:14:45 2016 -0800
+++ b/mercurial/patch.py	Fri Jan 15 13:14:50 2016 -0800
@@ -2099,8 +2099,7 @@
 
 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 @@
             elif state not in ('hunk', 'git'):
                 raise error.Abort(_('unsupported parser state: %s') % state)
         return changed
-    finally:
-        fp.close()
 
 class GitDiffRequired(Exception):
     pass