[PATCH 3 of 5] commands: use context manager for opened bundle file
Gregory Szorc
gregory.szorc at gmail.com
Fri Jan 15 01:01:51 CST 2016
# HG changeset patch
# User Gregory Szorc <gregory.szorc at gmail.com>
# Date 1452835673 28800
# Thu Jan 14 21:27:53 2016 -0800
# Node ID f550f2d4fa1553430185069d3e2954366b8ded13
# Parent e074e8078dee56d5be493344197ea00818d51830
commands: use context manager for opened bundle file
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2013,18 +2013,17 @@ def debugbuilddag(ui, repo, text=None,
release(tr, lock)
@command('debugbundle',
[('a', 'all', None, _('show all details'))],
_('FILE'),
norepo=True)
def debugbundle(ui, bundlepath, all=None, **opts):
"""lists the contents of a bundle"""
- f = hg.openpath(ui, bundlepath)
- try:
+ with hg.openpath(ui, bundlepath) as f:
gen = exchange.readbundle(ui, f, bundlepath)
if isinstance(gen, bundle2.unbundle20):
return _debugbundle2(ui, gen, all=all, **opts)
if all:
ui.write(("format: id, p1, p2, cset, delta base, len(delta)\n"))
def showchunks(named):
ui.write("\n%s\n" % named)
@@ -2061,18 +2060,16 @@ def debugbundle(ui, bundlepath, all=None
chain = None
while True:
chunkdata = gen.deltachunk(chain)
if not chunkdata:
break
node = chunkdata['node']
ui.write("%s\n" % hex(node))
chain = node
- finally:
- f.close()
def _debugbundle2(ui, gen, **opts):
"""lists the contents of a bundle2"""
if not isinstance(gen, bundle2.unbundle20):
raise error.Abort(_('not a bundle2 file'))
ui.write(('Stream params: %s\n' % repr(gen.params)))
for part in gen.iterparts():
ui.write('%s -- %r\n' % (part.type, repr(part.params)))
More information about the Mercurial-devel
mailing list