Pierre-Yves David avatar Pierre-Yves David committed 9ac56d3

obsolete: add latecomer computation and display

Comments (0)

Files changed (2)

hgext/obsolete.py

 
 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
 #############################
     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"""
     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
     else:
         return None # break recursion
 
+def wrapclearcache(orig, repo, *args, **kwargs):
+    try:
+        return orig(repo, *args, **kwargs)
+    finally:
+        repo._clearobsoletecache()
+
 
 ### New commands
 #############################
     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)
 
             """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
                 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>"""

tests/test-obsolete.t

   adding file changes
   added 1 changesets with 1 changes to 1 files (+1 heads)
   $ cd ..
+
+check latecomer detection
+(make an obsolete changeset public)
+
+  $ cd local
+  $ hg phase --public 11
+  $ hg --config extensions.graphlog=glog glog --template='{rev} - ({phase}) {node|short} {desc}\n'
+  @  12 - (draft) 6db5e282cb91 add obsol_d'''
+  |
+  | o  11 - (public) 9468a5f5d8b2 add obsol_d''
+  |/
+  o  10 - (public) 2033b4e49474 add obsol_c
+  |
+  o  4 - (public) 725c380fe99b add obsol_c'
+  |
+  o  1 - (public) 7c3bad9141dc add b
+  |
+  o  0 - (public) 1f0dee641bb7 add a
+  
+  $ hg log -r 'latecomer()'
+  changeset:   12:6db5e282cb91
+  tag:         tip
+  parent:      10:2033b4e49474
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     add obsol_d'''
+  
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.