[PATCH 3 of 4] discovery: simplify discovery.prepush return value by using and outgoing object

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Jan 13 15:58:16 CST 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1326490853 -3600
# Node ID 11eda234598fa3849faeae573970b8e447a436b2
# Parent  7f2d2a5ceb19de2cfa76d766fc62c02c60f0a637
discovery: simplify discovery.prepush return value by using and outgoing object

This simplify the return value and provides much more data to caller.

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -136,19 +136,16 @@
 
 def prepush(repo, remote, force, revs, newbranch):
     '''Analyze the local and remote repositories and determine which
-    changesets need to be pushed to the remote. Return value depends
-    on circumstances:
+    changesets need to be pushed to the remote.
 
-    If we are not going to push anything, return a tuple (None, 1,
-    common) The third element "common" is the list of heads of the
-    common set between local and remote.
+    Return a tuple (changegroup, outgoing) where outgoing is an
+    discovery.outgoing object are returned by find common outgoing.
 
-    Otherwise, return a tuple (changegroup, remoteheads, futureheads),
-    where changegroup is a readable file-like object whose read()
-    returns successive changegroup chunks ready to be sent over the
-    wire, remoteheads is the list of remote heads and futureheads is
-    the list of heads of the common set between local and remote to
-    be after push completion.
+    If we are going to push anything, changegroup is a readable file-like
+    object whose read() returns successive changegroup chunks ready to be sent
+    over the wire.
+
+    If we are not going to push, changegroup is None.
     '''
     commoninc = findcommonincoming(repo, remote, force=force)
     outgoing = findcommonoutgoing(repo, remote, onlyheads=revs,
@@ -157,7 +154,6 @@
 
     cl = repo.changelog
     outg = outgoing.missing
-    common = outgoing.commonheads
 
     if not outg:
         if outgoing.excluded:
@@ -165,7 +161,7 @@
                            % len(outgoing.excluded))
         else:
             repo.ui.status(_("no changes found\n"))
-        return None, 1, common
+        return None, outgoing
 
     if not force and remoteheads != [nullid]:
         if remote.capable('branchmap'):
@@ -270,10 +266,4 @@
         cg = repo._changegroup(outg, 'push')
     else:
         cg = repo.getlocalbundle('push', outgoing)
-    # no need to compute outg ancestor. All node in outg have either:
-    # - parents in outg
-    # - parents in common
-    # - nullid parent
-    rset = repo.set('heads(%ln + %ln)', common, outg)
-    futureheads = [ctx.node() for ctx in rset]
-    return cg, remoteheads, futureheads
+    return cg, outgoing
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1602,12 +1602,11 @@
             # get local lock as we might write phase data
             locallock = self.lock()
             try:
-                cg, remote_heads, fut = discovery.prepush(self, remote, force,
-                                                           revs, newbranch)
-                ret = remote_heads
-                # create a callback for addchangegroup.
-                # If will be used branch of the conditionnal too.
-                if cg is not None:
+                cg, outgoing = discovery.prepush(self, remote, force,
+                                                 revs, newbranch)
+                if cg is None:
+                    ret = 1
+                else:
                     if unbundle:
                         # local repo finds heads on server, finds out what
                         # revs it must push. once revs transferred, if server
@@ -1615,6 +1614,8 @@
                         # commit/push race), server aborts.
                         if force:
                             remote_heads = ['force']
+                        else:
+                            remote_heads = outgoing.remoteheads
                         # ssh: return remote's addchangegroup()
                         # http: return remote's addchangegroup() or 0 for error
                         ret = remote.unbundle(cg, remote_heads, 'push')
@@ -1622,6 +1623,8 @@
                         # we return an integer indicating remote head count change
                         ret = remote.addchangegroup(cg, 'push', self.url())
 
+                fut = outgoing.commonheads + outgoing.missingheads
+
                 # even when we don't push, exchanging phase data is useful
                 remotephases = remote.listkeys('phases')
                 if not remotephases: # old server or public only repo


More information about the Mercurial-devel mailing list