[PATCH] unbundle: use context manager for transaction

Martin von Zweigbergk martinvonz at google.com
Fri Jun 16 05:26:23 UTC 2017


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# 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)


More information about the Mercurial-devel mailing list