# HG changeset patch # User Eric Sumner # Date 1421441625 28800 # Node ID 7817059917d0c4196e4c85bafac434149bc4e510 # Parent 3831e9b3750a3984e2e942d90df698b4e3cae0f0 pullbundle2: extract addchangegroup result combining into its own function This will also be used for 'hg unbundle' diff -r 3831e9b3750a -r 7817059917d0 mercurial/changegroup.py --- a/mercurial/changegroup.py Fri Jan 16 15:31:45 2015 -0500 +++ b/mercurial/changegroup.py Fri Jan 16 12:53:45 2015 -0800 @@ -42,6 +42,25 @@ """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 + class nocompress(object): def compress(self, x): return x diff -r 3831e9b3750a -r 7817059917d0 mercurial/exchange.py --- a/mercurial/exchange.py Fri Jan 16 15:31:45 2015 -0500 +++ b/mercurial/exchange.py Fri Jan 16 12:53:45 2015 -0800 @@ -992,22 +992,8 @@ raise util.Abort('missing support for %s' % exc) if pullop.fetch: - 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 + results = [cg['return'] for cg in op.records['changegroup']] + pullop.cgresult = changegroup.combineresults(results) # processing phases change for namespace, value in op.records['listkeys']: