changeset 27775:3ea35a0769fe

shelve: use a context manager for file I/O in listcmd
author Bryan O'Sullivan <bryano@fb.com>
date Tue, 12 Jan 2016 14:47:21 -0800
parents 8ceaaf63ca80
children 6fe2da48a6dd
files hgext/shelve.py
diffstat 1 files changed, 1 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/shelve.py	Tue Jan 12 14:31:02 2016 -0800
+++ b/hgext/shelve.py	Tue Jan 12 14:47:21 2016 -0800
@@ -424,8 +424,7 @@
         ui.write(age, label='shelve.age')
         ui.write(' ' * (12 - len(age)))
         used += 12
-        fp = open(name + '.patch', 'rb')
-        try:
+        with open(name + '.patch', 'rb') as fp:
             while True:
                 line = fp.readline()
                 if not line:
@@ -447,8 +446,6 @@
                 for chunk, label in patch.diffstatui(difflines, width=width,
                                                      git=True):
                     ui.write(chunk, label=label)
-        finally:
-            fp.close()
 
 def singlepatchcmds(ui, repo, pats, opts, subcommand):
     """subcommand that displays a single shelf"""