mercurial/ancestor.py
changeset 39474 a60dae060bc8
parent 39473 b6db2e80a9ce
child 39476 7eadc9407867
equal deleted inserted replaced
39473:b6db2e80a9ce 39474:a60dae060bc8
   307         with the parents of each revision in revs, i.e., each revision is
   307         with the parents of each revision in revs, i.e., each revision is
   308         *not* considered an ancestor of itself. Results are emitted in reverse
   308         *not* considered an ancestor of itself. Results are emitted in reverse
   309         revision number order. That order is also topological: a child is
   309         revision number order. That order is also topological: a child is
   310         always emitted before its parent.
   310         always emitted before its parent.
   311 
   311 
   312         If inclusive is True, yield all the revs first (ignoring stoprev),
   312         If inclusive is True, the source revisions are also yielded. The
   313         then yield all the ancestors of revs as when inclusive is False. If an
   313         reverse revision number order is still enforced."""
   314         element in revs is an ancestor of a different rev it is not yielded
       
   315         again."""
       
   316         seen = set()
   314         seen = set()
   317         revs = self._initrevs
   315         revs = self._initrevs
   318         if self._inclusive:
       
   319             for rev in revs:
       
   320                 yield rev
       
   321             seen.update(revs)
       
   322 
   316 
   323         parentrevs = self._parentrevs
   317         parentrevs = self._parentrevs
   324         stoprev = self._stoprev
   318         stoprev = self._stoprev
   325         visit = []
       
   326         heapq.heapify(visit)
       
   327         schedule = heapq.heappush
   319         schedule = heapq.heappush
   328         nextitem = heapq.heappop
   320         nextitem = heapq.heappop
   329         see = seen.add
   321         see = seen.add
   330         see(nullrev)
   322         see(nullrev)
   331 
   323 
   332         for r in revs:
   324         if self._inclusive:
   333             for parent in parentrevs(r):
   325             visit = [-r for r in revs]
   334                 if parent not in seen:
   326             seen.update(revs)
   335                     schedule(visit, -parent)
   327             heapq.heapify(visit)
   336                     see(parent)
   328         else:
       
   329             visit = []
       
   330             heapq.heapify(visit)
       
   331             for r in revs:
       
   332                 for parent in parentrevs(r):
       
   333                     if parent not in seen:
       
   334                         schedule(visit, -parent)
       
   335                         see(parent)
   337 
   336 
   338         while visit:
   337         while visit:
   339             current = -nextitem(visit)
   338             current = -nextitem(visit)
   340             if current >= stoprev:
   339             if current >= stoprev:
   341                 yield current
   340                 yield current