[PATCH 5 of 9 V2] obsolete: compute unstable changeset

pierre-yves.david at logilab.fr pierre-yves.david at logilab.fr
Fri Jul 6 12:54:06 CDT 2012


# HG changeset patch
# User Pierre-Yves David <pierre-yves.david at logilab.fr>
# Date 1341526689 -7200
# Node ID 8373a40bd8d6beb57da7dd560aab872623849246
# Parent  4ca4a3e795c04628fcefc6bfdb2b74b3f6a8f30b
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.

diff --git a/mercurial/context.py b/mercurial/context.py
--- a/mercurial/context.py
+++ b/mercurial/context.py
@@ -233,10 +233,25 @@ class changectx(object):
     def obsolete(self):
         """True if the changeset is obsolete"""
         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:
                 return self._manifest[path], self._manifest.flags(path)
             except KeyError:
diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1315,10 +1315,18 @@ def tag(repo, subset, x):
     return [r for r in subset if r in s]
 
 def tagged(repo, subset, x):
     return tag(repo, subset, x)
 
+def unstable(repo, subset, x):
+    """``unstable()``
+    Unstable changeset are non obsolete changeset with obsolete descendant."""
+    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.
 
     If `string` starts with `re:`, the remainder of the string is treated as
@@ -1391,10 +1399,11 @@ symbols = {
     "secret": secret,
     "matching": matching,
     "tag": tag,
     "tagged": tagged,
     "user": user,
+    "unstable": unstable,
     "_list": _list,
 }
 
 methods = {
     "range": rangeset,
diff --git a/tests/test-obsolete.t b/tests/test-obsolete.t
--- a/tests/test-obsolete.t
+++ b/tests/test-obsolete.t
@@ -1,6 +1,12 @@
-
+  $ cat >> $HGRCPATH << EOF
+  > [extensions]
+  > graphlog=
+  > [phases]
+  > # public changeset are not obsolete
+  > publish=false
+  > EOF
   $ mkcommit() {
   >    echo "$1" > "$1"
   >    hg add "$1"
   >    hg ci -m "add $1"
   > }
@@ -60,11 +66,11 @@ Register two markers with a missing node
   ca819180edb99ed25ceafb3e9584ac287e240b00 1337133713371337133713371337133713371337 0 {'date': '1338 0', 'user': 'test'}
   1337133713371337133713371337133713371337 5601fb93a350734d935195fee37f4054c529ff39 0 {'date': '1339 0', 'user': 'test'}
 
 Check that graphlog detect that a changeset is obsolete:
 
-  $ hg --config 'extensions.graphlog=' glog
+  $ hg glog
   @  changeset:   5:5601fb93a350
   |  tag:         tip
   |  parent:      1:7c3bad9141dc
   |  user:        test
   |  date:        Thu Jan 01 00:00:00 1970 +0000
@@ -222,5 +228,70 @@ On push
   ca819180edb99ed25ceafb3e9584ac287e240b00 1337133713371337133713371337133713371337 0 {'date': '1338 0', 'user': 'test'}
   cdbce2fbb16313928851e97e0d85413f3f7eb77f ca819180edb99ed25ceafb3e9584ac287e240b00 0 {'date': '1337 0', 'user': 'test'}
   245bde4270cd1072a27757984f9cda8ba26f08ca cdbce2fbb16313928851e97e0d85413f3f7eb77f 0 {'date': '56 12', '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
+  


More information about the Mercurial-devel mailing list