[PATCH 1 of 4 phases] phases: store phase values in constant instead of using raw integer
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Tue Jan 3 18:19:57 CST 2012
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1325098119 -3600
# Node ID 5bd197de486d13680484560fb56425bb503715ff
# Parent 371cff9610cdf6d6a7e1a6238ce75441b8107f03
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.
diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -7,6 +7,7 @@
from node import nullid, nullrev, short, hex
from i18n import _
+from phases import public, draft
import ancestor, mdiff, error, util, scmutil, subrepo, patch, encoding
import match as matchmod
import os, errno, stat
@@ -119,13 +120,13 @@
return self._repo.nodebookmarks(self._node)
def phase(self):
if self._rev == -1:
- return 0
+ return 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] > public
def hidden(self):
return self._rev in self._repo.changelog.hiddenrevs
@@ -812,7 +813,7 @@
return b
def phase(self):
- phase = 1 # default phase to draft
+ phase = draft # default phase to draft
for p in self.parents():
phase = max(phase, p.phase())
return phase
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -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)
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -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)
More information about the Mercurial-devel
mailing list