[PATCH 05 of 10] bundle: add a applybundle1() method

Martin von Zweigbergk martinvonz at google.com
Sat Jun 24 11:38:33 EDT 2017


# HG changeset patch
# User Martin von Zweigbergk <martinvonz at google.com>
# Date 1497633911 25200
#      Fri Jun 16 10:25:11 2017 -0700
# Node ID 658fd0f583788ccfbfe39118cea4be345c80f1eb
# Parent  98852ad1ee3d67aeb6fc59961aa3b2329b9f216b
bundle: add a applybundle1() method

This is one step towards removing a bunch of "if isinstance(gen,
unbundle20)" by treating bundle1 and bundle2 more similarly.

The name may sounds ironic for a method in the bundle2 module, but I
didn't think it was worth it yet to create a new 'bundle' module that
depends on the 'bundle2' module. Besides, we'll inline the method
again later.

diff --git a/hgext/histedit.py b/hgext/histedit.py
--- a/hgext/histedit.py
+++ b/hgext/histedit.py
@@ -1199,7 +1199,9 @@
             gen = exchange.readbundle(ui, f, backupfile)
             with repo.transaction('histedit.abort') as tr:
                 if not isinstance(gen, bundle2.unbundle20):
-                    gen.apply(repo, tr, 'histedit', 'bundle:' + backupfile)
+                    bundle2.applybundle1(repo, gen, tr,
+                                         source='histedit',
+                                         url='bundle:' + backupfile)
                 else:
                     bundle2.applybundle(repo, gen, tr,
                                         source='histedit',
diff --git a/hgext/shelve.py b/hgext/shelve.py
--- a/hgext/shelve.py
+++ b/hgext/shelve.py
@@ -127,9 +127,11 @@
         try:
             gen = exchange.readbundle(self.repo.ui, fp, self.fname, self.vfs)
             if not isinstance(gen, bundle2.unbundle20):
-                gen.apply(self.repo, self.repo.currenttransaction(), 'unshelve',
-                          'bundle:' + self.vfs.join(self.fname),
-                          targetphase=phases.secret)
+                bundle2.applybundle1(self.repo, gen,
+                                     self.repo.currenttransaction(),
+                                     source='unshelve',
+                                     url='bundle:' + self.vfs.join(self.fname),
+                                     targetphase=phases.secret)
             else:
                 bundle2.applybundle(self.repo, gen,
                                     self.repo.currenttransaction(),
diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -310,6 +310,10 @@
     to be created"""
     raise TransactionUnavailable()
 
+def applybundle1(repo, cg, tr, source, url, **kwargs):
+    ret, addednodes = cg.apply(repo, tr, source, url, **kwargs)
+    return ret
+
 def applybundle(repo, unbundler, tr, source=None, url=None):
     # transform me into unbundler.apply() as soon as the freeze is lifted
     tr.hookargs['bundle2'] = '1'
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5218,7 +5218,9 @@
             else:
                 txnname = 'unbundle\n%s' % util.hidepassword(url)
                 with repo.transaction(txnname) as tr:
-                    modheads, addednodes = gen.apply(repo, tr, 'unbundle', url)
+                    modheads = bundle2.applybundle1(repo, gen, tr,
+                                                    source='unbundle',
+                                                    url=url)
 
     return postincoming(ui, repo, modheads, opts.get(r'update'), None, None)
 
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1448,7 +1448,7 @@
                            "changegroupsubset."))
     else:
         cg = pullop.remote.changegroupsubset(pullop.fetch, pullop.heads, 'pull')
-    pullop.cgresult, addednodes = cg.apply(pullop.repo, tr, 'pull',
+    pullop.cgresult = bundle2.applybundle1(pullop.repo, cg, tr, 'pull',
                                            pullop.remote.url())
 
 def _pullphase(pullop):
@@ -1737,7 +1737,7 @@
             # legacy case: bundle1 (changegroup 01)
             txnname = "\n".join([source, util.hidepassword(url)])
             with repo.lock(), repo.transaction(txnname) as tr:
-                r, addednodes = cg.apply(repo, tr, source, url)
+                r = bundle2.applybundle1(repo, cg, tr, source, url)
         else:
             r = None
             try:
@@ -2002,7 +2002,7 @@
             elif isinstance(cg, streamclone.streamcloneapplier):
                 cg.apply(repo)
             else:
-                cg.apply(repo, tr, 'clonebundles', url)
+                bundle2.applybundle1(repo, cg, tr, 'clonebundles', url)
             return True
         except urlerr.httperror as e:
             ui.warn(_('HTTP error fetching bundle: %s\n') % str(e))
diff --git a/mercurial/repair.py b/mercurial/repair.py
--- a/mercurial/repair.py
+++ b/mercurial/repair.py
@@ -214,7 +214,8 @@
             else:
                 txnname = "strip\n%s" % util.hidepassword(tmpbundleurl)
                 with repo.transaction(txnname) as tr:
-                    gen.apply(repo, tr, 'strip', tmpbundleurl, True)
+                    bundle2.applybundle1(repo, gen, tr, 'strip', tmpbundleurl,
+                                         emptyok=True)
             if not repo.ui.verbose:
                 repo.ui.popbuffer()
             f.close()


More information about the Mercurial-devel mailing list