[PATCH 5 of 9 phases] phase: add mechanism to store phase data into dirstate
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Wed Jan 4 19:25:42 CST 2012
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at ens-lyon.org>
# Date 1325725382 -3600
# Node ID 9bedf170a2c4753b01296db5f8dc8141cd3a64ed
# Parent 6b460b7a2e2a2788031c4c5e8dd37160ddbd7ad8
phase: add mechanism to store phase data into dirstate
diff --git a/mercurial/dirstate.py b/mercurial/dirstate.py
--- a/mercurial/dirstate.py
+++ b/mercurial/dirstate.py
@@ -7,7 +7,7 @@
from node import nullid
from i18n import _
-import scmutil, util, ignore, osutil, parsers, encoding
+import scmutil, util, ignore, osutil, parsers, encoding, phases
import struct, os, stat, errno
import cStringIO
@@ -220,6 +220,27 @@
def branch(self):
return encoding.tolocal(self._branch)
+ @propertycache
+ def phasedata(self):
+ """a two tuple attributs (phase, force)
+
+ phase is any phase we wish the commit of this state to be in.
+
+ When force is True, the next commit is required to be exactly in the
+ specified phase.
+ """
+ try:
+ content = self._opener.read("phase").strip()
+ except IOError:
+ content = ''
+ if content:
+ phase, force = content.split()
+ phase = int(phase)
+ force = bool(int(force))
+ else:
+ phase, force = None, False
+ return phase, force
+
def setparents(self, p1, p2=nullid):
self._dirty = self._dirtypl = True
self._pl = p1, p2
@@ -230,6 +251,25 @@
self._branch = encoding.fromlocal(branch)
self._opener.write("branch", self._branch + '\n')
+ def setphase(self, phase, force=False):
+ """Set phase data to be used for next commit
+
+ phase a valid phase index or None
+
+ if force is false, the next commit will be at least in the provided
+ phase but other factor as new-commit option or parent phase may result
+ in higher used phase.
+ """
+ if phase in phases.allphases:
+ self.phasedata = (phase, force)
+ self._opener.write('phase', '%i %i\n' % self.phasedata)
+ elif phase is None:
+ self._opener.write('phase', '')
+ else:
+ raise ValueError('Invalid phase %r' % phase)
+
+
+
def _read(self):
self._map = {}
self._copymap = {}
More information about the Mercurial-devel
mailing list