Patchwork [5,of,5] context: add 'phase' getter

login
register
mail settings
Submitter Paul Tonelli
Date May 22, 2014, 1:50 p.m.
Message ID <8b491d46899dfff40cac.1400766623@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/4852/
State Superseded
Headers show

Comments

Paul Tonelli - May 22, 2014, 1:50 p.m.
# HG changeset patch
# User Paul Tonelli <paul.tonelli@logilab.fr>
# Date 1400667930 -7200
#      Wed May 21 12:25:30 2014 +0200
# Node ID 8b491d46899dfff40cac0c2771498a94c164e1e3
# Parent  18986e5692bc00065ae18600f87b636d65a60df7
context: add 'phase' getter

This method must be dynamic as the phase can change during the lifetime of the
changeset.
Matt Mackall - May 27, 2014, 10:53 p.m.
On Thu, 2014-05-22 at 15:50 +0200, Paul Tonelli wrote:
> # HG changeset patch
> # User Paul Tonelli <paul.tonelli@logilab.fr>
> # Date 1400667930 -7200
> #      Wed May 21 12:25:30 2014 +0200
> # Node ID 8b491d46899dfff40cac0c2771498a94c164e1e3
> # Parent  18986e5692bc00065ae18600f87b636d65a60df7
> context: add 'phase' getter

These are queued for hglib, thanks (with your revised 1 of 5).

Patch

diff -r 18986e5692bc -r 8b491d46899d hglib/context.py
--- a/hglib/context.py	Fri May 16 18:21:12 2014 +0200
+++ b/hglib/context.py	Wed May 21 12:25:30 2014 +0200
@@ -199,6 +199,10 @@ 
         return bool(self._repo.log(revrange='%s and hidden()' % self._node,
                                    hidden=True))
 
+    def phase(self):
+        """return the phase of the changeset (public, draft or secret)"""
+        return self._repo.phase(str(self._rev))[0][1]
+
     def children(self):
         """return contexts for each child changeset"""
         for c in self._repo.log('children(%s)' % self._node):
diff -r 18986e5692bc -r 8b491d46899d tests/test-phase.py
--- a/tests/test-phase.py	Fri May 16 18:21:12 2014 +0200
+++ b/tests/test-phase.py	Wed May 21 12:25:30 2014 +0200
@@ -7,25 +7,32 @@ 
         self.append('a', 'a')
         rev, node0 = self.client.commit('first', addremove=True)
         self.assertEqual([(0, 'draft')], self.client.phase(node0))
+        ctx = self.client[rev]
+        self.assertEqual('draft', ctx.phase())
 
     def test_phase_public(self):
-        """phase change from draft to public"""
+        """test phase change from draft to public"""
         self.append('a', 'a')
         rev, node0 = self.client.commit('first', addremove=True)
         self.client.phase(node0, public=True)
         self.assertEqual([(0, 'public')], self.client.phase(node0))
+        ctx = self.client[rev]
+        self.assertEqual('public', ctx.phase())
 
     def test_phase_secret(self):
-        """phase change from draft to secret"""
+        """test phase change from draft to secret"""
         self.append('a', 'a')
         rev, node0 = self.client.commit('first', addremove=True)
         with self.assertRaises(hglib.error.CommandError):
             self.client.phase(node0, secret=True)
         self.client.phase(node0, secret=True, force=True)
         self.assertEqual([(0, 'secret')], self.client.phase(node0))
+        ctx = self.client[rev]
+        self.assertEqual('secret', ctx.phase())
+
 
     def test_phase_multiple(self):
-        """phase changes and show the phases of the different changesets"""
+        """test phase changes and show the phases of the different changesets"""
         self.append('a', 'a')
         rev, node0 = self.client.commit('a', addremove=True)
         self.client.phase(node0, public=True)