shelve: use a context manager for file I/O in listcmd
authorBryan O'Sullivan <bryano@fb.com>
Tue, 12 Jan 2016 14:47:21 -0800
changeset 27775 3ea35a0769fe
parent 27774 8ceaaf63ca80
child 27776 6fe2da48a6dd
shelve: use a context manager for file I/O in listcmd
hgext/shelve.py
--- 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"""