diff hgext/obsolete.py @ 307:9ac56d36d6ff

obsolete: add latecomer computation and display
author Pierre-Yves David <pierre-yves.david@logilab.fr>
date Tue, 26 Jun 2012 11:33:39 +0200
parents 8cfa3163dfaa
children 23ef1c71d164
line wrap: on
line diff
--- a/hgext/obsolete.py	Tue Jun 26 11:13:46 2012 +0200
+++ b/hgext/obsolete.py	Tue Jun 26 11:33:39 2012 +0200
@@ -138,6 +138,14 @@
 
 context.changectx.extinct = extinct
 
+def latecomer(ctx):
+    """is the changeset latecomer (Try to succeed to public change)"""
+    if ctx.node() is None:
+        return False
+    return ctx.rev() in ctx._repo._latecomerset
+
+context.changectx.latecomer = latecomer
+
 
 ### revset
 #############################
@@ -170,6 +178,10 @@
     args = revset.getargs(x, 0, 0, 'unstable takes no arguments')
     return [r for r in subset if r in repo._extinctset]
 
+def revsetlatecomer(repo, subset, x):
+    """latecomer, Try to succeed to public change"""
+    args = revset.getargs(x, 0, 0, 'unstable takes no arguments')
+    return [r for r in subset if r in repo._latecomerset]
 
 def _precursors(repo, s):
     """Precursor of a changeset"""
@@ -367,6 +379,7 @@
     revset.symbols["unstable"] = revsetunstable
     revset.symbols["suspended"] = revsetsuspended
     revset.symbols["extinct"] = revsetextinct
+    revset.symbols["latecomer"] = revsetlatecomer
     revset.symbols["obsparents"] = revsetprecursors  # DEPR
     revset.symbols["precursors"] = revsetprecursors
     revset.symbols["obsancestors"] = revsetallprecursors  # DEPR
@@ -509,6 +522,12 @@
     else:
         return None # break recursion
 
+def wrapclearcache(orig, repo, *args, **kwargs):
+    try:
+        return orig(repo, *args, **kwargs)
+    finally:
+        repo._clearobsoletecache()
+
 
 ### New commands
 #############################
@@ -606,6 +625,7 @@
     extensions.wrapfunction(discovery, 'findcommonoutgoing', wrapfindcommonoutgoing)
     extensions.wrapfunction(discovery, 'checkheads', wrapcheckheads)
     extensions.wrapfunction(phases, 'visibleheads', noextinctsvisibleheads)
+    extensions.wrapfunction(phases, 'advanceboundary', wrapclearcache)
     if util.safehasattr(phases, 'visiblebranchmap'):
         extensions.wrapfunction(phases, 'visiblebranchmap', wrapvisiblebranchmap)
 
@@ -840,6 +860,11 @@
             """the set of obsolete parent without non obsolete descendant"""
             return set(self.revs('obsolete() - obsolete()::unstable()'))
 
+        @util.propertycache
+        def _latecomerset(self):
+            """the set of rev trying to obsolete public revision"""
+            return set(self.revs('allsuccessors(public()) - obsolete()'))
+
         def _clearobsoletecache(self):
             if '_obsoleteset' in vars(self):
                 del self._obsoleteset
@@ -856,6 +881,8 @@
                 del self._suspendedset
             if '_extinctset' in vars(self):
                 del self._extinctset
+            if '_latecomerset' in vars(self):
+                del self._latecomerset
 
         def addobsolete(self, sub, obj):
             """Add a relation marking that node <sub> is a new version of <obj>"""