Patchwork [06,of,10] bundle: make applybundle1() return a bundleoperation

login
register
mail settings
Submitter via Mercurial-devel
Date June 24, 2017, 3:38 p.m.
Message ID <a57900f80358f016d3b8.1498318714@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21671/
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 1498104528 25200
#      Wed Jun 21 21:08:48 2017 -0700
# Node ID a57900f80358f016d3b84dfe85a53c1530136673
# Parent  658fd0f583788ccfbfe39118cea4be345c80f1eb
bundle: make applybundle1() return a bundleoperation

See previous commit for motivation. It already lets us share a little
bit more code in commands.py.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -311,8 +311,10 @@ 
     raise TransactionUnavailable()
 
 def applybundle1(repo, cg, tr, source, url, **kwargs):
-    ret, addednodes = cg.apply(repo, tr, source, url, **kwargs)
-    return ret
+    # the transactiongetter won't be used, but we might as well set it
+    op = bundleoperation(repo, lambda: tr)
+    _processchangegroup(op, cg, tr, source, url, **kwargs)
+    return op
 
 def applybundle(repo, unbundler, tr, source=None, url=None):
     # transform me into unbundler.apply() as soon as the freeze is lifted
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5214,13 +5214,12 @@ 
                             hint=_("see https://mercurial-scm.org/"
                                    "wiki/BundleFeature for more "
                                    "information"))
-                modheads = bundle2.combinechangegroupresults(op)
             else:
                 txnname = 'unbundle\n%s' % util.hidepassword(url)
                 with repo.transaction(txnname) as tr:
-                    modheads = bundle2.applybundle1(repo, gen, tr,
-                                                    source='unbundle',
-                                                    url=url)
+                    op = bundle2.applybundle1(repo, gen, tr, source='unbundle',
+                                              url=url)
+            modheads = bundle2.combinechangegroupresults(op)
 
     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,8 +1448,9 @@ 
                            "changegroupsubset."))
     else:
         cg = pullop.remote.changegroupsubset(pullop.fetch, pullop.heads, 'pull')
-    pullop.cgresult = bundle2.applybundle1(pullop.repo, cg, tr, 'pull',
-                                           pullop.remote.url())
+    bundleop = bundle2.applybundle1(pullop.repo, cg, tr, 'pull',
+                                    pullop.remote.url())
+    pullop.cgresult = bundle2.combinechangegroupresults(bundleop)
 
 def _pullphase(pullop):
     # Get remote phases data from remote
@@ -1737,7 +1738,8 @@ 
             # legacy case: bundle1 (changegroup 01)
             txnname = "\n".join([source, util.hidepassword(url)])
             with repo.lock(), repo.transaction(txnname) as tr:
-                r = bundle2.applybundle1(repo, cg, tr, source, url)
+                op = bundle2.applybundle1(repo, cg, tr, source, url)
+                r = bundle2.combinechangegroupresults(op)
         else:
             r = None
             try: