[PATCH 5 of 6 REPHASE-VIEW] phases: exchange phase boundaries on pull \nAdd an extra argument to addchangegroup to all phase code to execute\nbefore the lock is released

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Wed Oct 26 07:56:29 CDT 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1319633662 -7200
# Node ID 594dd18b4d361c39c2b95d69fded97e9f0de3e69
# Parent  511027cf334fdcf090950ecdc189d70b304eed70
phases: exchange phase boundaries on pull \nAdd an extra argument to addchangegroup to all phase code to execute\nbefore the lock is released.

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1474,12 +1474,28 @@ class localrepository(repo.repository):
         lock = self.lock()
         try:
             tmp = discovery.findcommonincoming(self, remote, heads=heads,
                                                force=force)
             common, fetch, rheads = tmp
+            # Get remote phases data from remote
+            remotephases = remote.listkeys('phaseroots')
+            # if remote publish === False
+            if remotephases:
+                def phasescallback(added=[]):
+                    subset = common + added
+                    boundaries = phases.computeheads(self, subset, remotephases)
+                    for phase, boundary in enumerate(boundaries):
+                        phases.moveboundary(self, phase, boundary)
+            # else everything common shall be frozen
+            else:
+                def phasescallback(added=[]):
+                    # Remote is old or publishing all common changesets
+                    # should be seen as public
+                    phases.moveboundary(self, 0, common + added)
             if not fetch:
                 self.ui.status(_("no changes found\n"))
+                phasescallback()
                 result = 0
             else:
                 if heads is None and list(common) == [nullid]:
                     self.ui.status(_("requesting all changes\n"))
                 elif heads is None and remote.capable('changegroupsubset'):
@@ -1496,12 +1512,11 @@ class localrepository(repo.repository):
                                            "other repository doesn't support "
                                            "changegroupsubset."))
                 else:
                     cg = remote.changegroupsubset(fetch, heads, 'pull')
                 result = self.addchangegroup(cg, 'pull', remote.url(),
-                                             lock=lock)
-            phases.moveboundary(self, 0, common)
+                                             lock=lock, finalizehook=phasescallback)
         finally:
             lock.release()
 
         return result
 
@@ -1817,16 +1832,20 @@ class localrepository(repo.repository):
             if nodes:
                 self.hook('outgoing', node=hex(nodes[0]), source=source)
 
         return changegroup.unbundle10(util.chunkbuffer(gengroup()), 'UN')
 
-    def addchangegroup(self, source, srctype, url, emptyok=False, lock=None):
+    def addchangegroup(self, source, srctype, url, emptyok=False, lock=None,
+                       finalizehook=None):
         """Add the changegroup returned by source.read() to this repo.
         srctype is a string like 'push', 'pull', or 'unbundle'.  url is
         the URL of the repo where this changegroup is coming from.
         If lock is not None, the function takes ownership of the lock
-        and releases it after the changegroup is added.
+        and releases it after the changegroup is added. The finalizehook
+        arg is an optional function to be called right before changelog
+        is finalize and the transaction it close. It takes the list of
+        added node as an argument.
 
         Return an integer summarizing the change to this repo:
         - nothing changed or no source: 0
         - more heads than before: 1+added heads (2..n)
         - fewer heads than before: -1-removed heads (-2..-n)
@@ -1967,10 +1986,12 @@ class localrepository(repo.repository):
                           url=url, pending=p)
 
             added = [cl.node(r) for r in xrange(clstart, clend)]
             if self.ui.configbool('phases', 'publish', True):
                 phases.moveboundary(self, 0, added)
+            if finalizehook is not None:
+                finalizehook(added)
             # make changelog see real files again
             cl.finalize(trp)
 
             tr.close()
         finally:
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
@@ -110,10 +110,13 @@ update must update phase of common chang
   0 0 a-A - 054250a37db4
 
 Publish configuration option
 ----------------------------
 
+Pull
+````
+
 changegroup are added without phase movement
 
   $ hg bundle -a ../base.bundle
   5 changesets found
   $ cd ..
@@ -135,5 +138,135 @@ changegroup are added without phase move
   2 1 b-A - f54f1bb90ff3
   1 1 a-B - 548a3d25dbf0
   0 1 a-A - 054250a37db4
   $ cd ..
 
+Pulling from publish=False to publish=False does not move boundary.
+
+  $ hg init nu
+  $ cd nu
+  $ cat > .hg/hgrc << EOF
+  > [phases]
+  > publish=0
+  > EOF
+  $ hg pull ../mu -r 54acac6f23ab
+  pulling from ../mu
+  adding changesets
+  adding manifests
+  adding file changes
+  added 3 changesets with 3 changes to 3 files
+  (run 'hg update' to get a working copy)
+  $ hgph
+  2 1 a-C - 54acac6f23ab
+  1 1 a-B - 548a3d25dbf0
+  0 1 a-A - 054250a37db4
+
+Even for common
+
+  $ hg pull ../mu -r f54f1bb90ff3
+  pulling from ../mu
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files (+1 heads)
+  (run 'hg heads' to see heads, 'hg merge' to merge)
+  $ hgph
+  3 1 b-A - f54f1bb90ff3
+  2 1 a-C - 54acac6f23ab
+  1 1 a-B - 548a3d25dbf0
+  0 1 a-A - 054250a37db4
+
+
+Pulling from Publish=True to Publish=False move boundary in common set.
+we are in nu
+
+  $ hg pull ../alpha -r b555f63b6063
+  pulling from ../alpha
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 1 changesets with 1 changes to 1 files
+  (run 'hg update' to get a working copy)
+  $ hgph
+  4 0 a-D - b555f63b6063
+  3 0 b-A - f54f1bb90ff3
+  2 0 a-C - 54acac6f23ab
+  1 0 a-B - 548a3d25dbf0
+  0 0 a-A - 054250a37db4
+
+pulling from Publish=False to publish=False with some public
+
+  $ hg up -q f54f1bb90ff3
+  $ mkcommit n-A
+  $ mkcommit n-B
+  $ hgph
+  6 1 n-B - 145e75495359
+  5 1 n-A - d6bcb4f74035
+  4 0 a-D - b555f63b6063
+  3 0 b-A - f54f1bb90ff3
+  2 0 a-C - 54acac6f23ab
+  1 0 a-B - 548a3d25dbf0
+  0 0 a-A - 054250a37db4
+  $ cd ../mu
+  $ hg pull ../nu
+  pulling from ../nu
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files
+  (run 'hg update' to get a working copy)
+  $ hgph
+  6 1 n-B - 145e75495359
+  5 1 n-A - d6bcb4f74035
+  4 0 a-D - b555f63b6063
+  3 0 a-C - 54acac6f23ab
+  2 0 b-A - f54f1bb90ff3
+  1 0 a-B - 548a3d25dbf0
+  0 0 a-A - 054250a37db4
+  $ cd ..
+
+pulling into publish=True
+
+  $ cd alpha
+  $ hgph
+  4 0 b-A - f54f1bb90ff3
+  3 0 a-D - b555f63b6063
+  2 0 a-C - 54acac6f23ab
+  1 0 a-B - 548a3d25dbf0
+  0 0 a-A - 054250a37db4
+  $ hg pull ../mu
+  pulling from ../mu
+  searching for changes
+  adding changesets
+  adding manifests
+  adding file changes
+  added 2 changesets with 2 changes to 2 files
+  (run 'hg update' to get a working copy)
+  $ hgph
+  6 0 n-B - 145e75495359
+  5 0 n-A - d6bcb4f74035
+  4 0 b-A - f54f1bb90ff3
+  3 0 a-D - b555f63b6063
+  2 0 a-C - 54acac6f23ab
+  1 0 a-B - 548a3d25dbf0
+  0 0 a-A - 054250a37db4
+  $ cd ..
+
+pulling back into original repo
+
+  $ cd nu
+  $ hg pull ../alpha
+  pulling from ../alpha
+  searching for changes
+  no changes found
+  $ hgph
+  6 0 n-B - 145e75495359
+  5 0 n-A - d6bcb4f74035
+  4 0 a-D - b555f63b6063
+  3 0 b-A - f54f1bb90ff3
+  2 0 a-C - 54acac6f23ab
+  1 0 a-B - 548a3d25dbf0
+  0 0 a-A - 054250a37db4
+  $ cd ..


More information about the Mercurial-devel mailing list