changeset 15818:57241845a4bb

phases: store phase values in constant instead of using raw integer Phases constant are named after the phase name. Usage of integer have been replaced by proper constant.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Fri, 06 Jan 2012 09:51:35 +0100
parents 8f377751b510
children 33ca11b010e2
files mercurial/context.py mercurial/localrepo.py mercurial/phases.py
diffstat 3 files changed, 14 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Mon Jan 09 14:56:05 2012 +0100
+++ b/mercurial/context.py	Fri Jan 06 09:51:35 2012 +0100
@@ -7,7 +7,7 @@
 
 from node import nullid, nullrev, short, hex
 from i18n import _
-import ancestor, mdiff, error, util, scmutil, subrepo, patch, encoding
+import ancestor, mdiff, error, util, scmutil, subrepo, patch, encoding, phases
 import match as matchmod
 import os, errno, stat
 
@@ -119,13 +119,13 @@
         return self._repo.nodebookmarks(self._node)
     def phase(self):
         if self._rev == -1:
-            return 0
+            return phases.public
         if self._rev >= len(self._repo._phaserev):
             # outdated cache
             del self._repo._phaserev
         return self._repo._phaserev[self._rev]
     def mutable(self):
-        return self._repo._phaserev[self._rev] > 0
+        return self._repo._phaserev[self._rev] > phases.public
     def hidden(self):
         return self._rev in self._repo.changelog.hiddenrevs
 
@@ -812,7 +812,7 @@
         return b
 
     def phase(self):
-        phase = 1 # default phase to draft
+        phase = phases.draft # default phase to draft
         for p in self.parents():
             phase = max(phase, p.phase())
         return phase
--- a/mercurial/localrepo.py	Mon Jan 09 14:56:05 2012 +0100
+++ b/mercurial/localrepo.py	Fri Jan 06 09:51:35 2012 +0100
@@ -181,7 +181,7 @@
 
     @propertycache
     def _phaserev(self):
-        cache = [0] * len(self)
+        cache = [phases.public] * len(self)
         for phase in phases.trackedphases:
             roots = map(self.changelog.rev, self._phaseroots[phase])
             if roots:
@@ -1253,7 +1253,8 @@
                       parent2=xp2, pending=p)
             self.changelog.finalize(trp)
             # set the new commit is proper phase
-            targetphase = self.ui.configint('phases', 'new-commit', 1)
+            targetphase = self.ui.configint('phases', 'new-commit',
+                                            phases.draft)
             if targetphase:
                 # retract boundary do not alter parent changeset.
                 # if a parent have higher the resulting phase will
@@ -1554,7 +1555,7 @@
             else:
                 # Remote is old or publishing all common changesets
                 # should be seen as public
-                phases.advanceboundary(self, 0, common + added)
+                phases.advanceboundary(self, phases.public, common + added)
         finally:
             lock.release()
 
@@ -1615,14 +1616,14 @@
                 # even when we don't push, exchanging phase data is useful
                 remotephases = remote.listkeys('phases')
                 if not remotephases: # old server or public only repo
-                    phases.advanceboundary(self, 0, fut)
+                    phases.advanceboundary(self, phases.public, fut)
                     # don't push any phase data as there is nothing to push
                 else:
                     ana = phases.analyzeremotephases(self, fut, remotephases)
                     rheads, rroots = ana
                     ### Apply remote phase on local
                     if remotephases.get('publishing', False):
-                        phases.advanceboundary(self, 0, fut)
+                        phases.advanceboundary(self, phases.public, fut)
                     else: # publish = False
                         for phase, rpheads in enumerate(rheads):
                             phases.advanceboundary(self, phase, rpheads)
@@ -2057,9 +2058,9 @@
             if publishing and srctype == 'push':
                 # Old server can not push the boundary themself.
                 # This clause ensure pushed changeset are alway marked as public
-                phases.advanceboundary(self, 0, added)
+                phases.advanceboundary(self, phases.public, added)
             elif srctype != 'strip': # strip should not touch boundary at all
-                phases.retractboundary(self, 1, added)
+                phases.retractboundary(self, phases.draft, added)
 
             # make changelog see real files again
             cl.finalize(trp)
--- a/mercurial/phases.py	Mon Jan 09 14:56:05 2012 +0100
+++ b/mercurial/phases.py	Fri Jan 06 09:51:35 2012 +0100
@@ -102,7 +102,7 @@
 from node import nullid, bin, hex, short
 from i18n import _
 
-allphases = range(3)
+allphases = public, draft, secret = range(3)
 trackedphases = allphases[1:]
 
 def readroots(repo):
@@ -242,7 +242,7 @@
 def visibleheads(repo):
     """return the set of visible head of this repo"""
     # XXX we want a cache on this
-    sroots = repo._phaseroots[2]
+    sroots = repo._phaseroots[secret]
     if sroots:
         # XXX very slow revset. storing heads or secret "boundary" would help.
         revset = repo.set('heads(not (%ln::))', sroots)