Patchwork [02,of,10] bundle: move combineresults() from changegroup to bundle2

login
register
mail settings
Submitter via Mercurial-devel
Date June 24, 2017, 3:38 p.m.
Message ID <5067327cec7040b82dc8.1498318710@martinvonz.svl.corp.google.com>
Download mbox | patch
Permalink /patch/21666/
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 1498165100 25200
#      Thu Jun 22 13:58:20 2017 -0700
# Node ID 5067327cec7040b82dc87d093545532e28869763
# Parent  dff383987b37065f8dc35ee0e26d79dae842c362
bundle: move combineresults() from changegroup to bundle2

The results only need to be combined if they come from a bundle2. More
importantly, we'll change its argument to a bundleoperation soon, and
then it definitely will no longer belong in changegroup.py.

Patch

diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
--- a/mercurial/bundle2.py
+++ b/mercurial/bundle2.py
@@ -1478,6 +1478,25 @@ 
     # in case of sshrepo because we don't know the end of the stream
     return changegroup.writechunks(ui, chunkiter, filename, vfs=vfs)
 
+def combinechangegroupresults(results):
+    """logic to combine 0 or more addchangegroup results into one"""
+    changedheads = 0
+    result = 1
+    for ret in results:
+        # If any changegroup result is 0, return 0
+        if ret == 0:
+            result = 0
+            break
+        if ret < -1:
+            changedheads += ret + 1
+        elif ret > 1:
+            changedheads += ret - 1
+    if changedheads > 0:
+        result = 1 + changedheads
+    elif changedheads < 0:
+        result = -1 + changedheads
+    return result
+
 @parthandler('changegroup', ('version', 'nbchanges', 'treemanifest'))
 def handlechangegroup(op, inpart):
     """apply a changegroup part on the repo
diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -60,25 +60,6 @@ 
     """return a changegroup chunk header (string) for a zero-length chunk"""
     return struct.pack(">l", 0)
 
-def combineresults(results):
-    """logic to combine 0 or more addchangegroup results into one"""
-    changedheads = 0
-    result = 1
-    for ret in results:
-        # If any changegroup result is 0, return 0
-        if ret == 0:
-            result = 0
-            break
-        if ret < -1:
-            changedheads += ret + 1
-        elif ret > 1:
-            changedheads += ret - 1
-    if changedheads > 0:
-        result = 1 + changedheads
-    elif changedheads < 0:
-        result = -1 + changedheads
-    return result
-
 def writechunks(ui, chunks, filename, vfs=None):
     """Write chunks to a file and return its filename.
 
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -5216,7 +5216,7 @@ 
                                    "information"))
                 changes = [r.get('return', 0)
                            for r in op.records['changegroup']]
-                modheads = changegroup.combineresults(changes)
+                modheads = bundle2.combinechangegroupresults(changes)
             else:
                 txnname = 'unbundle\n%s' % util.hidepassword(url)
                 with repo.transaction(txnname) as tr:
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -1398,7 +1398,7 @@ 
 
     if pullop.fetch:
         results = [cg['return'] for cg in op.records['changegroup']]
-        pullop.cgresult = changegroup.combineresults(results)
+        pullop.cgresult = bundle2.combinechangegroupresults(results)
 
     # processing phases change
     for namespace, value in op.records['listkeys']: