[PATCH 10 of 10] phases: allow phase name in phases.new-commit settings

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Mon Jan 30 10:49:44 CST 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1327941975 -3600
# Branch stable
# Node ID e2fe1f1f0fdf1b3328d00efdb8af039480a3854d
# Parent  440ddb63f450c1fc662517205bf4148529118f9e
phases: allow phase name in phases.new-commit settings

Before this commit only phase index where accepted

diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -1266,12 +1266,11 @@ class localrepository(repo.repository):
             xp1, xp2 = p1.hex(), p2 and p2.hex() or ''
             self.hook('pretxncommit', throw=True, node=hex(n), parent1=xp1,
                       parent2=xp2, pending=p)
             self.changelog.finalize(trp)
             # set the new commit is proper phase
-            targetphase = self.ui.configint('phases', 'new-commit',
-                                            phases.draft)
+            targetphase = phases.newcommitphase(self.ui)
             if targetphase:
                 # retract boundary do not alter parent changeset.
                 # if a parent have higher the resulting phase will
                 # be compliant anyway
                 #
diff --git a/mercurial/phases.py b/mercurial/phases.py
--- a/mercurial/phases.py
+++ b/mercurial/phases.py
@@ -296,5 +296,22 @@ def newheads(repo, heads, roots):
     * `rroots`: define the second we substract to the first"""
     revset = repo.set('heads((%ln + parents(%ln)) - (%ln::%ln))',
                       heads, roots, roots, heads)
     return [c.node() for c in revset]
 
+
+def newcommitphase(ui):
+    """helper to get the target phase of new commit
+
+    Handle all possible values for the phases.new-commit options.
+
+    """
+    v = ui.config('phases', 'new-commit', draft)
+    try:
+        return phasenames.index(v)
+    except ValueError:
+        try:
+            return int(v)
+        except ValueError:
+            msg = _("phases.new-commit: not a valid phase name ('%s')")
+            raise error.ConfigError(msg % v)
+
diff --git a/tests/test-phases.t b/tests/test-phases.t
--- a/tests/test-phases.t
+++ b/tests/test-phases.t
@@ -40,11 +40,11 @@ Draft commit are properly created over p
   1 0 B
   0 0 A
 
 Test creating changeset as secret
 
-  $ mkcommit E --config phases.new-commit=2
+  $ mkcommit E --config phases.new-commit='secret'
   $ hglog
   4 2 E
   3 1 D
   2 1 C
   1 0 B


More information about the Mercurial-devel mailing list