[PATCH 07 of 10] shelve: use a context manager for file I/O in listcmd
Bryan O'Sullivan
bos at serpentine.com
Tue Jan 12 22:50:10 UTC 2016
# HG changeset patch
# User Bryan O'Sullivan <bryano at fb.com>
# Date 1452638841 28800
# Tue Jan 12 14:47:21 2016 -0800
# Node ID 63ae5a1bb483de42ed15023e83fea38c579aaffa
# Parent 34ea2e74309843f6f1ca761b986498faabb1cdd3
shelve: use a context manager for file I/O in listcmd
diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -424,8 +424,7 @@ def listcmd(ui, repo, pats, opts):
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 @@ def listcmd(ui, repo, pats, opts):
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"""
More information about the Mercurial-devel
mailing list