Patchwork [08,of,10] bundle: transpose transaction scope with bundle type switch

login
register
mail settings
Submitter via Mercurial-devel
Date June 24, 2017, 3:38 p.m.
Message ID <15326b3ffdaf861d6c7d.1498318716@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21672/
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 1498192077 25200
#      Thu Jun 22 21:27:57 2017 -0700
# Node ID 15326b3ffdaf861d6c7dd9dad850f8790a869427
# Parent  0e791a5d805adf64d9056f7ee7be1f084c7ca10b
bundle: transpose transaction scope with bundle type switch

This moves the transaction with-statements outside of the
per-bundle-version switches, so the next patch will be a little
simpler.

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5203,14 +5203,15 @@ 
                         hint=_('use "hg debugapplystreamclonebundle"'))
             url = 'bundle:' + fname
             try:
-                if isinstance(gen, bundle2.unbundle20):
-                    with repo.transaction('unbundle') as tr:
+                txnname = 'unbundle'
+                if not isinstance(gen, bundle2.unbundle20):
+                    txnname = 'unbundle\n%s' % util.hidepassword(url)
+                with repo.transaction(txnname) as tr:
+                    if isinstance(gen, bundle2.unbundle20):
                         op = bundle2.applybundle(repo, gen, tr,
                                                  source='unbundle',
                                                  url=url)
-                else:
-                    txnname = 'unbundle\n%s' % util.hidepassword(url)
-                    with repo.transaction(txnname) as tr:
+                    else:
                         op = bundle2.applybundle1(repo, gen, tr,
                                                   source='unbundle', url=url)
             except error.BundleUnknownFeatureError as exc:
diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -207,13 +207,14 @@ 
                 # silence internal shuffling chatter
                 repo.ui.pushbuffer()
             tmpbundleurl = 'bundle:' + vfs.join(tmpbundlefile)
-            if isinstance(gen, bundle2.unbundle20):
-                with repo.transaction('strip') as tr:
+            txnname = 'strip'
+            if not isinstance(gen, bundle2.unbundle20):
+                txnname = "strip\n%s" % util.hidepassword(tmpbundleurl)
+            with repo.transaction(txnname) as tr:
+                if isinstance(gen, bundle2.unbundle20):
                     bundle2.applybundle(repo, gen, tr, source='strip',
                                         url=tmpbundleurl)
-            else:
-                txnname = "strip\n%s" % util.hidepassword(tmpbundleurl)
-                with repo.transaction(txnname) as tr:
+                else:
                     bundle2.applybundle1(repo, gen, tr, 'strip', tmpbundleurl,
                                          emptyok=True)
             if not repo.ui.verbose: