diff mercurial/exchange.py @ 22961:a67ea4959ef5

bundle2: merge return values when bundle contains multiple changegroups A bundle2 may contain multiple parts adding changegroups, in which case there are multiple operation records for changegroups, each with its own return value. Those multiple return values are aggregated in a single cgresult value for the whole operation. As can be seen in the associated test case, the situation with hooks is not really the best, but without deeper thoughts and changes, we can't do much better. Hopefully, things will be improved before bundle2 is enabled by default. In the meanwhile, multiple changegroups is not expected to be in widespread use, and even less expected to be used for pushes. Also, not many clients cloning or pulling bundle2 with multiple changesets are not expected to have changegroup hooks anyways.
author Mike Hommey <mh@glandium.org>
date Thu, 16 Oct 2014 16:03:04 +0900
parents b1d694d3975e
children 3fe571c74b27
line wrap: on
line diff
--- a/mercurial/exchange.py	Thu Oct 16 15:54:53 2014 +0900
+++ b/mercurial/exchange.py	Thu Oct 16 16:03:04 2014 +0900
@@ -944,8 +944,22 @@
         raise util.Abort('missing support for %s' % exc)
 
     if pullop.fetch:
-        assert len(op.records['changegroup']) == 1
-        pullop.cgresult = op.records['changegroup'][0]['return']
+        changedheads = 0
+        pullop.cgresult = 1
+        for cg in op.records['changegroup']:
+            ret = cg['return']
+            # If any changegroup result is 0, return 0
+            if ret == 0:
+                pullop.cgresult = 0
+                break
+            if ret < -1:
+                changedheads += ret + 1
+            elif ret > 1:
+                changedheads += ret - 1
+        if changedheads > 0:
+            pullop.cgresult = 1 + changedheads
+        elif changedheads < 0:
+            pullop.cgresult = -1 + changedheads
 
     # processing phases change
     for namespace, value in op.records['listkeys']: