obsolete: compute unstable changeset
authorPierre-Yves David <pierre-yves.david@logilab.fr>
Fri, 06 Jul 2012 00:18:09 +0200
changeset 17171 9c750c3e4fac
parent 17170 63a4a3871607
child 17172 12fdaa30063a
obsolete: compute unstable changeset An unstable changeset is a changeset *not* obsolete but with some obsolete ancestors. The current logic to decide if a changeset is unstable is naive and very inefficient. A better solution is to compute the set of unstable changeset with a simple revset and to cache the result. But this require cache invalidation logic. Simpler version goes first.
mercurial/context.py
mercurial/revset.py
tests/test-obsolete.t
--- a/mercurial/context.py	Fri Jul 06 19:29:10 2012 +0200
+++ b/mercurial/context.py	Fri Jul 06 00:18:09 2012 +0200
@@ -235,6 +235,21 @@
         return (self.node() in self._repo.obsstore.precursors
                 and self.phase() > phases.public)
 
+    def unstable(self):
+        """True if the changeset is not obsolete but it's ancestor are"""
+        # We should just compute /(obsolete()::) - obsolete()/
+        # and keep it in a cache.
+        #
+        # But this naive implementation does not require cache
+        if self.phase() <= phases.public:
+            return False
+        if self.obsolete():
+            return False
+        for anc in self.ancestors():
+            if anc.obsolete():
+                return True
+        return False
+
     def _fileinfo(self, path):
         if '_manifest' in self.__dict__:
             try:
--- a/mercurial/revset.py	Fri Jul 06 19:29:10 2012 +0200
+++ b/mercurial/revset.py	Fri Jul 06 00:18:09 2012 +0200
@@ -1317,6 +1317,14 @@
 def tagged(repo, subset, x):
     return tag(repo, subset, x)
 
+def unstable(repo, subset, x):
+    """``unstable()``
+    Unstable changesets are non-obsolete with obsolete descendants."""
+    getargs(x, 0, 0, _("obsolete takes no arguments"))
+    unstableset = set(repo.revs('(obsolete()::) - obsolete()'))
+    return [r for r in subset if r in unstableset]
+
+
 def user(repo, subset, x):
     """``user(string)``
     User name contains string. The match is case-insensitive.
@@ -1393,6 +1401,7 @@
     "tag": tag,
     "tagged": tagged,
     "user": user,
+    "unstable": unstable,
     "_list": _list,
 }
 
--- a/tests/test-obsolete.t	Fri Jul 06 19:29:10 2012 +0200
+++ b/tests/test-obsolete.t	Fri Jul 06 00:18:09 2012 +0200
@@ -1,4 +1,10 @@
-
+  $ cat >> $HGRCPATH << EOF
+  > [extensions]
+  > graphlog=
+  > [phases]
+  > # public changeset are not obsolete
+  > publish=false
+  > EOF
   $ mkcommit() {
   >    echo "$1" > "$1"
   >    hg add "$1"
@@ -62,7 +68,7 @@
 
 Check that graphlog detect that a changeset is obsolete:
 
-  $ hg --config 'extensions.graphlog=' glog
+  $ hg glog
   @  changeset:   5:5601fb93a350
   |  tag:         tip
   |  parent:      1:7c3bad9141dc
@@ -230,6 +236,7 @@
   ca819180edb99ed25ceafb3e9584ac287e240b00 1337133713371337133713371337133713371337 0 {'date': '1338 0', 'user': 'test'}
   1337133713371337133713371337133713371337 5601fb93a350734d935195fee37f4054c529ff39 0 {'date': '1339 0', 'user': 'test'}
 
+
 On push
 
   $ hg push ../tmpc
@@ -243,3 +250,68 @@
   ca819180edb99ed25ceafb3e9584ac287e240b00 1337133713371337133713371337133713371337 0 {'date': '1338 0', 'user': 'test'}
   1337133713371337133713371337133713371337 5601fb93a350734d935195fee37f4054c529ff39 0 {'date': '1339 0', 'user': 'test'}
   2448244824482448244824482448244824482448 1339133913391339133913391339133913391339 0 {'date': '1339 0', 'user': 'test'}
+
+detect outgoing obsolete and unstable
+---------------------------------------
+
+  $ hg glog
+  o  changeset:   5:5601fb93a350
+  |  tag:         tip
+  |  parent:      1:7c3bad9141dc
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     add new_3_c
+  |
+  | x  changeset:   4:ca819180edb9
+  |/   parent:      1:7c3bad9141dc
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     add new_2_c
+  |
+  | x  changeset:   3:cdbce2fbb163
+  |/   parent:      1:7c3bad9141dc
+  |    user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     add new_c
+  |
+  | o  changeset:   2:245bde4270cd
+  |/   user:        test
+  |    date:        Thu Jan 01 00:00:00 1970 +0000
+  |    summary:     add original_c
+  |
+  o  changeset:   1:7c3bad9141dc
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     add b
+  |
+  o  changeset:   0:1f0dee641bb7
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     add a
+  
+  $ hg up -q 'desc("new_2_c")'
+  $ mkcommit original_d
+  $ hg glog -r '::unstable()'
+  @  changeset:   6:7878242aeece
+  |  tag:         tip
+  |  parent:      4:ca819180edb9
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     add original_d
+  |
+  x  changeset:   4:ca819180edb9
+  |  parent:      1:7c3bad9141dc
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     add new_2_c
+  |
+  o  changeset:   1:7c3bad9141dc
+  |  user:        test
+  |  date:        Thu Jan 01 00:00:00 1970 +0000
+  |  summary:     add b
+  |
+  o  changeset:   0:1f0dee641bb7
+     user:        test
+     date:        Thu Jan 01 00:00:00 1970 +0000
+     summary:     add a
+