mercurial/ancestor.py
branchstable
changeset 49366 288de6f5d724
parent 49284 d44e3c45f0e4
equal deleted inserted replaced
49364:e8ea403b1c46 49366:288de6f5d724
     3 # Copyright 2006 Olivia Mackall <olivia@selenic.com>
     3 # Copyright 2006 Olivia Mackall <olivia@selenic.com>
     4 #
     4 #
     5 # This software may be used and distributed according to the terms of the
     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.
     6 # GNU General Public License version 2 or any later version.
     7 
     7 
     8 from __future__ import absolute_import
       
     9 
     8 
    10 import heapq
     9 import heapq
    11 
    10 
    12 from .node import nullrev
    11 from .node import nullrev
    13 from . import (
    12 from . import (
    14     dagop,
    13     dagop,
    15     policy,
    14     policy,
    16     pycompat,
       
    17 )
    15 )
    18 
    16 
    19 parsers = policy.importmod('parsers')
    17 parsers = policy.importmod('parsers')
    20 
    18 
    21 
    19 
   145     if len(gca) <= 1:
   143     if len(gca) <= 1:
   146         return gca
   144         return gca
   147     return deepest(gca)
   145     return deepest(gca)
   148 
   146 
   149 
   147 
   150 class incrementalmissingancestors(object):
   148 class incrementalmissingancestors:
   151     """persistent state used to calculate missing ancestors incrementally
   149     """persistent state used to calculate missing ancestors incrementally
   152 
   150 
   153     Although similar in spirit to lazyancestors below, this is a separate class
   151     Although similar in spirit to lazyancestors below, this is a separate class
   154     because trying to support contains and missingancestors operations with the
   152     because trying to support contains and missingancestors operations with the
   155     same internal data structures adds needless complexity."""
   153     same internal data structures adds needless complexity."""
   186         keepcount = sum(1 for r in revs if r > start)
   184         keepcount = sum(1 for r in revs if r > start)
   187         if len(revs) == keepcount:
   185         if len(revs) == keepcount:
   188             # no revs to consider
   186             # no revs to consider
   189             return
   187             return
   190 
   188 
   191         for curr in pycompat.xrange(start, min(revs) - 1, -1):
   189         for curr in range(start, min(revs) - 1, -1):
   192             if curr not in bases:
   190             if curr not in bases:
   193                 continue
   191                 continue
   194             revs.discard(curr)
   192             revs.discard(curr)
   195             bases.update(pfunc(curr))
   193             bases.update(pfunc(curr))
   196             if len(revs) == keepcount:
   194             if len(revs) == keepcount:
   227         # revsvisit and added to bothvisit. When revsvisit becomes empty, there
   225         # revsvisit and added to bothvisit. When revsvisit becomes empty, there
   228         # are no more ancestors of revs that aren't also ancestors of bases, so
   226         # are no more ancestors of revs that aren't also ancestors of bases, so
   229         # exit.
   227         # exit.
   230 
   228 
   231         missing = []
   229         missing = []
   232         for curr in pycompat.xrange(start, nullrev, -1):
   230         for curr in range(start, nullrev, -1):
   233             if not revsvisit:
   231             if not revsvisit:
   234                 break
   232                 break
   235 
   233 
   236             if curr in bothvisit:
   234             if curr in bothvisit:
   237                 bothvisit.remove(curr)
   235                 bothvisit.remove(curr)
   315         if p2 not in seen:
   313         if p2 not in seen:
   316             heappush(visit, -p2)
   314             heappush(visit, -p2)
   317             see(p2)
   315             see(p2)
   318 
   316 
   319 
   317 
   320 class lazyancestors(object):
   318 class lazyancestors:
   321     def __init__(self, pfunc, revs, stoprev=0, inclusive=False):
   319     def __init__(self, pfunc, revs, stoprev=0, inclusive=False):
   322         """Create a new object generating ancestors for the given revs. Does
   320         """Create a new object generating ancestors for the given revs. Does
   323         not generate revs lower than stoprev.
   321         not generate revs lower than stoprev.
   324 
   322 
   325         This is computed lazily starting from revs. The object supports
   323         This is computed lazily starting from revs. The object supports