[PATCH 8 of 9 phases] phases: mark content pushed as public in local repo on push

Pierre-Yves David pierre-yves.david at ens-lyon.org
Mon Nov 7 11:43:20 CST 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1320067583 -3600
# Node ID 648b3733e5b9241867d7ebeb3f2c0923c7098448
# Parent  682c1e048a56933150bcde05a06166fed42843e4
phases: mark content pushed as public in local repo on push

diff --git a/mercurial/discovery.py b/mercurial/discovery.py
--- a/mercurial/discovery.py
+++ b/mercurial/discovery.py
@@ -67,14 +67,18 @@
     on circumstances:
 
     If we are not going to push anything, return a tuple (None,
-    outgoing) where outgoing is 0 if there are no outgoing
+    outgoing, common) where outgoing is 0 if there are no outgoing
     changesets and 1 if there are, but we refuse to push them
-    (e.g. would create new remote heads).
+    (e.g. would create new remote heads). The third element "common"
+    is the list of heads of the common set between local and remote.
 
-    Otherwise, return a tuple (changegroup, remoteheads), where
-    changegroup is a readable file-like object whose read() returns
-    successive changegroup chunks ready to be sent over the wire and
-    remoteheads is the list of remote heads.'''
+    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.
+    '''
     commoninc = findcommonincoming(repo, remote, force=force)
     common, revs = findcommonoutgoing(repo, remote, onlyheads=revs,
                                       commoninc=commoninc, force=force)
@@ -85,7 +89,7 @@
 
     if not outg:
         repo.ui.status(_("no changes found\n"))
-        return None, 1
+        return None, 1, common
 
     if not force and remoteheads != [nullid]:
         if remote.capable('branchmap'):
@@ -189,4 +193,10 @@
         cg = repo._changegroup(outg, 'push')
     else:
         cg = repo.getbundle('push', heads=revs, common=common)
-    return cg, remoteheads
+    # 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
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1554,24 +1554,32 @@
         if not unbundle:
             lock = remote.lock()
         try:
-            cg, remote_heads = discovery.prepush(self, remote, force, revs,
-                                                 newbranch)
-            ret = remote_heads
-            if cg is not None:
-                if unbundle:
-                    # local repo finds heads on server, finds out what
-                    # revs it must push. once revs transferred, if server
-                    # finds it has different heads (someone else won
-                    # commit/push race), server aborts.
-                    if force:
-                        remote_heads = ['force']
-                    # ssh: return remote's addchangegroup()
-                    # http: return remote's addchangegroup() or 0 for error
-                    ret = remote.unbundle(cg, remote_heads, 'push')
-                else:
-                    # we return an integer indicating remote head count change
-                    ret = remote.addchangegroup(cg, 'push', self.url(),
-                                                lock=lock)
+            # 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
+                if cg is not None:
+                    if unbundle:
+                        # local repo finds heads on server, finds out what
+                        # revs it must push. once revs transferred, if server
+                        # finds it has different heads (someone else won
+                        # commit/push race), server aborts.
+                        if force:
+                            remote_heads = ['force']
+                        # ssh: return remote's addchangegroup()
+                        # http: return remote's addchangegroup() or 0 for error
+                        ret = remote.unbundle(cg, remote_heads, 'push')
+                    else:
+                        # we return an integer indicating remote head count change
+                        ret = remote.addchangegroup(cg, 'push', self.url(),
+                                                    lock=lock)
+                # if we don't push, the common data is already useful
+                # everything exchange is public for now
+                phases.moveboundary(self, 0, fut)
+            finally:
+                locallock.release()
         finally:
             if lock is not None:
                 lock.release()
diff --git a/tests/test-phases-exchange.t b/tests/test-phases-exchange.t
--- a/tests/test-phases-exchange.t
+++ b/tests/test-phases-exchange.t
@@ -30,6 +30,12 @@
   adding manifests
   adding file changes
   added 2 changesets with 2 changes to 2 files
+  $ hgph
+  3 1 a-D
+  2 1 a-C
+  1 0 a-B
+  0 0 a-A
+
   $ cd ../beta
   $ hgph
   1 0 a-B
@@ -55,4 +61,22 @@
   1 0 a-B
   0 0 a-A
 
+pull did not updated ../alpha state.
+push from alpha to beta should update phase even if nothing is transfered
 
+  $ cd ../alpha
+  $ hgph # not updated by remote pull
+  3 1 a-D
+  2 1 a-C
+  1 0 a-B
+  0 0 a-A
+  $ hg push ../beta
+  pushing to ../beta
+  searching for changes
+  no changes found
+  $ hgph
+  3 0 a-D
+  2 0 a-C
+  1 0 a-B
+  0 0 a-A
+


More information about the Mercurial-devel mailing list