mercurial/obsutil.py
changeset 32879 1858fc2327ef
child 33142 4f49810a1011
equal deleted inserted replaced
32878:a3a36bcf122e 32879:1858fc2327ef
       
     1 # obsutil.py - utility functions for obsolescence
       
     2 #
       
     3 # Copyright 2017 Boris Feld <boris.feld@octobus.net>
       
     4 #
       
     5 # This software may be used and distributed according to the terms of the
       
     6 # GNU General Public License version 2 or any later version.
       
     7 
       
     8 from __future__ import absolute_import
       
     9 
       
    10 def closestpredecessors(repo, nodeid):
       
    11     """yield the list of next predecessors pointing on visible changectx nodes
       
    12 
       
    13     This function respect the repoview filtering, filtered revision will be
       
    14     considered missing.
       
    15     """
       
    16 
       
    17     precursors = repo.obsstore.precursors
       
    18     stack = [nodeid]
       
    19     seen = set(stack)
       
    20 
       
    21     while stack:
       
    22         current = stack.pop()
       
    23         currentpreccs = precursors.get(current, ())
       
    24 
       
    25         for prec in currentpreccs:
       
    26             precnodeid = prec[0]
       
    27 
       
    28             # Basic cycle protection
       
    29             if precnodeid in seen:
       
    30                 continue
       
    31             seen.add(precnodeid)
       
    32 
       
    33             if precnodeid in repo:
       
    34                 yield precnodeid
       
    35             else:
       
    36                 stack.append(precnodeid)