unbundle: use context manager for transaction
authorMartin von Zweigbergk <martinvonz@google.com>
Thu, 15 Jun 2017 14:47:18 -0700
changeset 32844 76bb53f8d374
parent 32843 a470bbb4e3af
child 32845 58a6f64a7018
unbundle: use context manager for transaction
mercurial/commands.py
--- a/mercurial/commands.py	Thu Jun 15 17:00:32 2017 -0700
+++ b/mercurial/commands.py	Thu Jun 15 14:47:18 2017 -0700
@@ -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)