[PATCH 09 of 11 (19 more to go)] push: move push return value in the push object

pierre-yves.david at ens-lyon.org pierre-yves.david at ens-lyon.org
Mon Feb 10 18:01:37 CST 2014


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1391139808 28800
#      Thu Jan 30 19:43:28 2014 -0800
# Node ID 7dfa48719256385ab66aa5a666891bde653c8eb5
# Parent  f07aad217fedbb12406be847e6d4e6bf18c8c878
push: move push return value in the push object

The return code convey information about the success of changeset push. This is
used by phases to compute the new common set between local and remote. So we
need to move it into the object to extract the phase sync from the god
function.

Note that this information will be used by obsolescence markers too.

diff --git a/mercurial/exchange.py b/mercurial/exchange.py
--- a/mercurial/exchange.py
+++ b/mercurial/exchange.py
@@ -33,10 +33,17 @@ class pushoperation(object):
         self.revs = revs
         # allow push of new branch
         self.newbranch = newbranch
         # did a local lock get acquired?
         self.locallocked = None
+        # Integer version of the push result
+        # - None means nothing to push
+        # - 0 means HTTP error
+        # - 1 means we pushed and remote head count is unchanged *or*
+        #   we have outgoing changesets but refused to push
+        # - other values as described by addchangegroup()
+        self.ret = None
 
 def push(repo, remote, force=False, revs=None, newbranch=False):
     '''Push outgoing changesets (limited by revs) from a local
     repository to remote. Return an integer:
       - None means nothing to push
@@ -97,11 +104,10 @@ def push(repo, remote, force=False, revs
 
 
             if not outgoing.missing:
                 # nothing to push
                 scmutil.nochangesfound(unfi.ui, unfi, outgoing.excluded)
-                ret = None
             else:
                 # something to push
                 if not pushop.force:
                     # if repo.obsstore == False --> no obsolete
                     # then, save the iteration
@@ -154,18 +160,19 @@ def push(repo, remote, force=False, revs
                     # commit/push race), server aborts.
                     if pushop.force:
                         remoteheads = ['force']
                     # ssh: return remote's addchangegroup()
                     # http: return remote's addchangegroup() or 0 for error
-                    ret = pushop.remote.unbundle(cg, remoteheads, 'push')
+                    pushop.ret = pushop.remote.unbundle(cg, remoteheads,
+                                                        'push')
                 else:
                     # we return an integer indicating remote head count
                     # change
-                    ret = pushop.remote.addchangegroup(cg, 'push',
-                                                       pushop.repo.url())
+                    pushop.ret = pushop.remote.addchangegroup(cg, 'push',
+                                                              pushop.repo.url())
 
-            if ret:
+            if pushop.ret:
                 # push succeed, synchronize target of the push
                 cheads = outgoing.missingheads
             elif pushop.revs is None:
                 # All out push fails. synchronize all common
                 cheads = outgoing.commonheads
@@ -195,11 +202,11 @@ def push(repo, remote, force=False, revs
                 cheads.extend(c.node() for c in revset)
             # even when we don't push, exchanging phase data is useful
             remotephases = pushop.remote.listkeys('phases')
             if (pushop.ui.configbool('ui', '_usedassubrepo', False)
                 and remotephases    # server supports phases
-                and ret is None # nothing was pushed
+                and pushop.ret is None # nothing was pushed
                 and remotephases.get('publishing', False)):
                 # When:
                 # - this is a subrepo push
                 # - and remote support phase
                 # - and no changeset was pushed
@@ -244,11 +251,11 @@ def push(repo, remote, force=False, revs
     finally:
         if locallock is not None:
             locallock.release()
 
     _pushbookmark(pushop)
-    return ret
+    return pushop.ret
 
 def _localphasemove(pushop, nodes, phase=phases.public):
     """move <nodes> to <phase> in the local source repo"""
     if pushop.locallocked:
         phases.advanceboundary(pushop.repo, phase, nodes)


More information about the Mercurial-devel mailing list