Patchwork [07,of,10] unbundle: move BundleUnknownFeatureError exception handling out

login
register
mail settings
Submitter via Mercurial-devel
Date June 24, 2017, 3:38 p.m.
Message ID <0e791a5d805adf64d905.1498318715@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21670/
State Accepted
Headers show

Comments

via Mercurial-devel - June 24, 2017, 3:38 p.m.
# HG changeset patch
# User Martin von Zweigbergk <martinvonz@google.com>
# Date 1498168993 25200
#      Thu Jun 22 15:03:13 2017 -0700
# Node ID 0e791a5d805adf64d9056f7ee7be1f084c7ca10b
# Parent  a57900f80358f016d3b84dfe85a53c1530136673
unbundle: move BundleUnknownFeatureError exception handling out

This just moves the BundleUnknownFeatureError exception handling one
level up so we collect the bundle2.applybundle{,1}() calls
together. applybundle1() will never throw the exception, so it should
have no functional consequence.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5202,23 +5202,23 @@ 
                           '"hg unbundle"'),
                         hint=_('use "hg debugapplystreamclonebundle"'))
             url = 'bundle:' + fname
-            if isinstance(gen, bundle2.unbundle20):
-                with repo.transaction('unbundle') as tr:
-                    try:
+            try:
+                if isinstance(gen, bundle2.unbundle20):
+                    with repo.transaction('unbundle') as tr:
                         op = bundle2.applybundle(repo, gen, tr,
                                                  source='unbundle',
                                                  url=url)
-                    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"))
-            else:
-                txnname = 'unbundle\n%s' % util.hidepassword(url)
-                with repo.transaction(txnname) as tr:
-                    op = bundle2.applybundle1(repo, gen, tr, source='unbundle',
-                                              url=url)
+                else:
+                    txnname = 'unbundle\n%s' % util.hidepassword(url)
+                    with repo.transaction(txnname) as tr:
+                        op = bundle2.applybundle1(repo, gen, tr,
+                                                  source='unbundle', url=url)
+            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"))
             modheads = bundle2.combinechangegroupresults(op)
 
     return postincoming(ui, repo, modheads, opts.get(r'update'), None, None)