[PATCH 11 of 18] phase: ensure new commit are not public and in a state compatible with parent

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Mon Oct 10 07:28:07 CDT 2011


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1318206274 -7200
# Node ID c28e325a7325a284626665cc147bde7d34aa729e
# Parent  2c6dd7ebf171c43006b552a41f9c37d7f6a82ebe
phase: ensure new commit are not public and in a state compatible with parent

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1142,10 +1142,16 @@ class localrepository(repo.repository):
             # (e.g. by a pretxncommit hook).  Leave the content alone on
             # the assumption that the user will use the same editor again.
             msgfn = self.savecommitmessage(cctx._text)
 
             p1, p2 = self.dirstate.parents()
+            # compute newphase before adding the changeset to prevent
+            # issue with the repo.heads() default value
+            newphase = max(1, self.nodephase(p1))
+            if p2 != nullid:
+                newphase = max(newphase, self.nodephase(p2))
+
             hookp1, hookp2 = hex(p1), (p2 != nullid and hex(p2) or '')
             try:
                 self.hook("precommit", throw=True, parent1=hookp1, parent2=hookp2)
                 ret = self.commitctx(cctx, True)
             except:
@@ -1153,10 +1159,12 @@ class localrepository(repo.repository):
                     self.ui.write(
                         _('note: commit message saved in %s\n') % msgfn)
                 raise
 
             # update bookmarks, dirstate and mergestate
+            if phases.asboundary(self, newphase, [ret]):
+                phases.writeheads(self) # XXX be smarter about cache here
             bookmarks.update(self, p1, ret)
             for f in changes[0] + changes[1]:
                 self.dirstate.normal(f)
             for f in changes[2]:
                 self.dirstate.drop(f)
diff --git a/tests/test-phases.t b/tests/test-phases.t
--- a/tests/test-phases.t
+++ b/tests/test-phases.t
@@ -51,15 +51,35 @@ Simpliest test: change the phase of the 
   4 1 E
   3 1 D
   2 0 C
   1 0 B
   0 0 A
- 
-  $ hg phase -p 0 -r 4
+
+  $ mkcommit F
   $ hglog
+  5 1 F
+  4 1 E
+  3 1 D
+  2 0 C
+  1 0 B
+  0 0 A
+
+  $ hg phase -p 0 -r 5
+  $ hglog
+  5 0 F
   4 0 E
   3 0 D
   2 0 C
   1 0 B
   0 0 A
 
+  $ mkcommit G
+  $ hglog
+  6 1 G
+  5 0 F
+  4 0 E
+  3 0 D
+  2 0 C
+  1 0 B
+  0 0 A
 
+


More information about the Mercurial-devel mailing list