hgext/obsolete.py
changeset 306 8cfa3163dfaa
parent 305 0b444d7c5c96
child 307 9ac56d36d6ff
equal deleted inserted replaced
305:0b444d7c5c96 306:8cfa3163dfaa
   211 
   211 
   212 def revsetallprecursors(repo, subset, x):
   212 def revsetallprecursors(repo, subset, x):
   213     """obsolete parents"""
   213     """obsolete parents"""
   214     s = revset.getset(repo, range(len(repo)), x)
   214     s = revset.getset(repo, range(len(repo)), x)
   215     cs = _allprecursors(repo, s)
   215     cs = _allprecursors(repo, s)
       
   216     return [r for r in subset if r in cs]
       
   217 
       
   218 def _successors(repo, s):
       
   219     """Successors of a changeset"""
       
   220     cs = set()
       
   221     nm = repo.changelog.nodemap
       
   222     markerbyobj = repo.obsoletestore.objects
       
   223     for r in s:
       
   224         for p in markerbyobj.get(repo[r].node(), ()):
       
   225             for sub in p['subjects']:
       
   226                 sr = nm.get(sub)
       
   227                 if sr is not None:
       
   228                     cs.add(sr)
       
   229     return cs
       
   230 
       
   231 def revsetsuccessors(repo, subset, x):
       
   232     """successors of a subset"""
       
   233     s = revset.getset(repo, range(len(repo)), x)
       
   234     cs = _successors(repo, s)
       
   235     return [r for r in subset if r in cs]
       
   236 
       
   237 def _allsuccessors(repo, s):  # XXX we need a better naming
       
   238     """transitive successors of a subset"""
       
   239     toproceed = [repo[r].node() for r in s]
       
   240     seen = set()
       
   241     allobjects = repo.obsoletestore.objects
       
   242     while toproceed:
       
   243         nc = toproceed.pop()
       
   244         for mark in allobjects.get(nc, ()):
       
   245             for sub in mark['subjects']:
       
   246                 if sub not in seen:
       
   247                     seen.add(sub)
       
   248                     toproceed.append(sub)
       
   249     nm = repo.changelog.nodemap
       
   250     cs = set()
       
   251     for s in seen:
       
   252         sr = nm.get(s)
       
   253         if sr is not None:
       
   254             cs.add(sr)
       
   255     return cs
       
   256 
       
   257 def revsetallsuccessors(repo, subset, x):
       
   258     """obsolete parents"""
       
   259     s = revset.getset(repo, range(len(repo)), x)
       
   260     cs = _allsuccessors(repo, s)
   216     return [r for r in subset if r in cs]
   261     return [r for r in subset if r in cs]
   217 
   262 
   218 
   263 
   219 ### template keywords
   264 ### template keywords
   220 #####################
   265 #####################
   324     revset.symbols["extinct"] = revsetextinct
   369     revset.symbols["extinct"] = revsetextinct
   325     revset.symbols["obsparents"] = revsetprecursors  # DEPR
   370     revset.symbols["obsparents"] = revsetprecursors  # DEPR
   326     revset.symbols["precursors"] = revsetprecursors
   371     revset.symbols["precursors"] = revsetprecursors
   327     revset.symbols["obsancestors"] = revsetallprecursors  # DEPR
   372     revset.symbols["obsancestors"] = revsetallprecursors  # DEPR
   328     revset.symbols["allprecursors"] = revsetallprecursors  # bad name
   373     revset.symbols["allprecursors"] = revsetallprecursors  # bad name
       
   374     revset.symbols["successors"] = revsetsuccessors
       
   375     revset.symbols["allsuccessors"] = revsetallsuccessors  # bad name
   329 
   376 
   330     templatekw.keywords['obsolete'] = obsoletekw
   377     templatekw.keywords['obsolete'] = obsoletekw
   331 
   378 
   332     try:
   379     try:
   333         rebase = extensions.find('rebase')
   380         rebase = extensions.find('rebase')