[PATCH 2 of 9 phases] phases: add a moveboundary function to move phases boundaries
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Mon Nov 7 11:43:14 CST 2011
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1320671461 -3600
# Node ID a0fe3423a8529ef611dc1439bcc243f2e6781691
# Parent 6baae333d2575d053a0b00d02c7928e6b8d64826
phases: add a moveboundary function to move phases boundaries
Also include logic to detect when to write phases data.
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -36,6 +36,7 @@
self.wopener = scmutil.opener(self.root)
self.baseui = baseui
self.ui = baseui.copy()
+ self._dirtyphases = False
try:
self.ui.readconfig(self.join("hgrc"), self.root)
@@ -172,6 +173,7 @@
@filecache('phaseroots')
def _phaseroots(self):
+ self._dirtyphases = False
return phases.readroots(self)
@propertycache
@@ -910,6 +912,8 @@
def unlock():
self.store.write()
+ if self._dirtyphases:
+ phases.writeroots(self)
for k, ce in self._filecache.items():
if k == 'dirstate':
continue
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -37,5 +37,30 @@
for phase, roots in enumerate(repo._phaseroots):
for h in roots:
f.write('%i %s\n' % (phase, hex(h)))
+ repo._dirtyphases = False
finally:
f.close()
+
+def moveboundary(repo, target_phase, nodes):
+ """Add nodes to a phase changing other nodes phases if necessary.
+
+ Simplify boundary to contains phase roots only."""
+
+ # move roots of lower states
+ for phase in xrange(target_phase + 1, len(allphases)):
+ # filter nodes that are not in a compatible phase already
+ # XXX rev phase cache might have been invalidated by a previous loop
+ # XXX we need to be smarter here
+ nodes = [n for n in nodes if repo[n].phase() >= phase]
+ if not nodes:
+ break # no roots to move anymore
+ roots = repo._phaseroots[phase]
+ olds = roots.copy()
+ ctxs = list(repo.set('roots((%ln::) - (%ln::%ln))', olds, olds, nodes))
+ roots.clear()
+ roots.update(ctx.node() for ctx in ctxs)
+ if olds != roots:
+ # invalidate cache (we probably could be smarter here
+ if '_phaserev' in vars(repo):
+ del repo._phaserev
+ repo._dirtyphases = True
More information about the Mercurial-devel
mailing list