From patchwork Fri Jun 16 05:26:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: unbundle: use context manager for transaction From: via Mercurial-devel X-Patchwork-Id: 21425 Message-Id: <585b29c114886021ab30.1497590783@martinvonz.svl.corp.google.com> To: mercurial-devel@mercurial-scm.org Date: Thu, 15 Jun 2017 22:26:23 -0700 # HG changeset patch # User Martin von Zweigbergk # Date 1497563238 25200 # Thu Jun 15 14:47:18 2017 -0700 # Node ID 585b29c114886021ab30d9fa63f87c30f5e92436 # Parent 0e8c0d532d926c2e92790a081de043c025a841d4 unbundle: use context manager for transaction diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -5317,20 +5317,17 @@ f = hg.openpath(ui, fname) gen = exchange.readbundle(ui, f, fname) if isinstance(gen, bundle2.unbundle20): - tr = repo.transaction('unbundle') - try: - op = bundle2.applybundle(repo, gen, tr, source='unbundle', - url='bundle:' + fname) - tr.close() - except error.BundleUnknownFeatureError as exc: - raise error.Abort(_('%s: unknown bundle feature, %s') - % (fname, exc), - hint=_("see https://mercurial-scm.org/" - "wiki/BundleFeature for more " - "information")) - finally: - if tr: - tr.release() + with repo.transaction('unbundle') as tr: + try: + op = bundle2.applybundle(repo, gen, tr, + source='unbundle', + url='bundle:' + fname) + except error.BundleUnknownFeatureError as exc: + raise error.Abort( + _('%s: unknown bundle feature, %s') % (fname, exc), + hint=_("see https://mercurial-scm.org/" + "wiki/BundleFeature for more " + "information")) changes = [r.get('return', 0) for r in op.records['changegroup']] modheads = changegroup.combineresults(changes)