Patchwork [3,of,5] context: add 'hidden' method to check if the changeset is hidden

login
register
mail settings
Submitter Paul Tonelli
Date May 22, 2014, 1:50 p.m.
Message ID <e4bfec889df7bf01a694.1400766621@crater1.logilab.fr>
Download mbox | patch
Permalink /patch/4853/
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 1400159533 -7200
#      Thu May 15 15:12:13 2014 +0200
# Node ID e4bfec889df7bf01a694c0aaa867c84e5952181f
# Parent  18994cc42773b3b6af970a8165b720f72fe3fa88
context: add 'hidden' method to check if the changeset is hidden

This method should not be a static property obtained at creation as the hidden
status may change.

Patch

diff -r 18994cc42773 -r e4bfec889df7 hglib/context.py
--- a/hglib/context.py	Thu May 22 15:23:12 2014 +0200
+++ b/hglib/context.py	Thu May 15 15:12:13 2014 +0200
@@ -194,6 +194,11 @@ 
     def bookmarks(self):
         return self._bookmarks
 
+    def hidden(self):
+        """return True if the changeset is hidden, else False"""
+        return bool(self._repo.log(revrange='%s and hidden()' % self._node,
+                                   hidden=True))
+
     def children(self):
         """return contexts for each child changeset"""
         for c in self._repo.log('children(%s)' % self._node):
diff -r 18994cc42773 -r e4bfec889df7 tests/test-hidden.py
--- a/tests/test-hidden.py	Thu May 22 15:23:12 2014 +0200
+++ b/tests/test-hidden.py	Thu May 15 15:12:13 2014 +0200
@@ -2,7 +2,7 @@ 
 from hglib.error import CommandError
 
 class test_obsolete_reference(common.basetest):
-    '''make sure obsolete changesets are disabled'''
+    """make sure obsolete changesets are disabled"""
     def test_debugobsolete_failure(self):
         f = open('gna1','w')
         f.write('g')
@@ -13,21 +13,25 @@ 
             self.client.rawcommand(['debugobsolete', cs])
 
 
-class test_obsolete(common.basetest):
-    '''test a few client methods with obsolete changesets enabled'''
+class test_obsolete_baselib(common.basetest):
+    """base test class with obsolete changesets enabled"""
     def setUp(self):
         #create an extension which only activates obsolete
-        super(test_obsolete, self).setUp()
-        self.append('.hg/obs.py','''import mercurial.obsolete\nmercurial.obsolete._enabled = True''')
+        super(test_obsolete_baselib, self).setUp()
+        self.append('.hg/obs.py',"""import mercurial.obsolete\nmercurial.obsolete._enabled = True""")
         self.append('.hg/hgrc','\n[extensions]\nobs=.hg/obs.py')
 
+class test_obsolete_client(test_obsolete_baselib):
+    """check client methods with obsolete changesets enabled"""
     def test_debugobsolete_success(self):
+        """check the obsolete extension is available"""
         self.append('gna1','ga')
         self.client.add('gna1')
         cs = self.client.commit('gna1')[1] #get id
         self.client.rawcommand(['debugobsolete', cs])
 
     def test_obsolete_in(self):
+        """test the 'hidden' keyword with the 'in' method"""
         self.append('gna1','ga')
         self.client.add('gna1')
         cs0 = self.client.commit('gna1')[1] #get id
@@ -41,3 +45,21 @@ 
         self.client.hidden = True
         self.assertTrue(cs1 in self.client)
 
+class test_hidden_context(test_obsolete_baselib):
+    """test the "hidden" context method with obsolete changesets enabled on
+    hidden and visible changesets"""
+    def test_hidden(self):
+        self.append('gna1','ga')
+        self.client.add('gna1')
+        cs0 = self.client.commit('gna1')[1] #get id
+        ctx0 = self.client[cs0]
+        self.append('gna2','gaaa')
+        self.client.add('gna2')
+        cs1 = self.client.commit('gna2')[1] #get id
+        ctx1 = self.client[cs1]
+        self.client.rawcommand(['debugobsolete', cs1])
+        self.client.update(cs0)
+        self.assertTrue(ctx1.hidden())
+        self.assertFalse(ctx0.hidden())
+
+