Patchwork [1,of,2] pullbundle2: extract addchangegroup result comining into its own function

login
register
mail settings
Submitter Eric Sumner
Date Jan. 16, 2015, 9:06 p.m.
Message ID <27a61fc3498b0bae606c.1421442365@dev911.prn1.facebook.com>
Download mbox | patch
Permalink /patch/7495/
State Superseded
Headers show

Comments

Eric Sumner - Jan. 16, 2015, 9:06 p.m.
# HG changeset patch
# User Eric Sumner <ericsumner@fb.com>
# Date 1421441625 28800
#      Fri Jan 16 12:53:45 2015 -0800
# Node ID 27a61fc3498b0bae606cbc92801a9103015090d4
# Parent  e07587a186a859fdb065b9475afd0470e2ae4508
pullbundle2: extract addchangegroup result comining into its own function

This will also be used for 'hg unbundle'
Eric Sumner - Jan. 16, 2015, 9:08 p.m.
This is quite incorrect; I'll try again in a moment.

  -- Eric

On 1/16/15, 1:06 PM, "Eric Sumner" <ericsumner@fb.com> wrote:

># HG changeset patch
># User Eric Sumner <ericsumner@fb.com>
># Date 1421441625 28800
>#      Fri Jan 16 12:53:45 2015 -0800
># Node ID 27a61fc3498b0bae606cbc92801a9103015090d4
># Parent  e07587a186a859fdb065b9475afd0470e2ae4508
>pullbundle2: extract addchangegroup result comining into its own function
>
>This will also be used for 'hg unbundle'
>
>diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
>--- a/mercurial/changegroup.py
>+++ b/mercurial/changegroup.py
>@@ -42,6 +42,24 @@
>     """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
>+    for ret in results:
>+        # If any changegroup result is 0, return 0
>+        if ret == 0:
>+            return 0
>+        if ret < -1:
>+            changedheads += ret + 1
>+        elif ret > 1:
>+            changedheads += ret - 1
>+    if changedheads > 0:
>+        return 1 + changedheads
>+    elif changedheads < 0:
>+        return -1 + changedheads
>+    else:
>+        return 0
>+
> class nocompress(object):
>     def compress(self, x):
>         return x
>diff --git a/mercurial/exchange.py b/mercurial/exchange.py
>--- a/mercurial/exchange.py
>+++ b/mercurial/exchange.py
>@@ -992,6 +992,8 @@
>         raise util.Abort('missing support for %s' % exc)
> 
>     if pullop.fetch:
>+        results = [cg['return'] for cg in op.records['changegroup']]
>+        pullop.cgresult = changegroup.combineresults(results)
>         changedheads = 0
>         pullop.cgresult = 1
>         for cg in op.records['changegroup']:
>_______________________________________________
>Mercurial-devel mailing list
>Mercurial-devel@selenic.com
>http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff --git a/mercurial/changegroup.py b/mercurial/changegroup.py
--- a/mercurial/changegroup.py
+++ b/mercurial/changegroup.py
@@ -42,6 +42,24 @@ 
     """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
+    for ret in results:
+        # If any changegroup result is 0, return 0
+        if ret == 0:
+            return 0
+        if ret < -1:
+            changedheads += ret + 1
+        elif ret > 1:
+            changedheads += ret - 1
+    if changedheads > 0:
+        return 1 + changedheads
+    elif changedheads < 0:
+        return -1 + changedheads
+    else:
+        return 0
+
 class nocompress(object):
     def compress(self, x):
         return x
diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -992,6 +992,8 @@ 
         raise util.Abort('missing support for %s' % exc)
 
     if pullop.fetch:
+        results = [cg['return'] for cg in op.records['changegroup']]
+        pullop.cgresult = changegroup.combineresults(results)
         changedheads = 0
         pullop.cgresult = 1
         for cg in op.records['changegroup']: