mercurial/ancestor.py
changeset 23332 194508240dc9
parent 23328 3a7d9c0c57a5
child 23333 9a2489015592
equal deleted inserted replaced
23331:3b1b8f25443e 23332:194508240dc9
   153     if not basesvisit:
   153     if not basesvisit:
   154         basesvisit.add(nullrev)
   154         basesvisit.add(nullrev)
   155     start = max(max(revsvisit), max(basesvisit))
   155     start = max(max(revsvisit), max(basesvisit))
   156     bothvisit = revsvisit.intersection(basesvisit)
   156     bothvisit = revsvisit.intersection(basesvisit)
   157     revsvisit.difference_update(bothvisit)
   157     revsvisit.difference_update(bothvisit)
   158     basesvisit.difference_update(bothvisit)
       
   159     # At this point, we hold the invariants that:
   158     # At this point, we hold the invariants that:
   160     # - revsvisit is the set of nodes we know are an ancestor of at least one
   159     # - revsvisit is the set of nodes we know are an ancestor of at least one
   161     #   of the nodes in revs
   160     #   of the nodes in revs
   162     # - basesvisit is the same for bases
   161     # - basesvisit is the same for bases
   163     # - bothvisit is the set of nodes we know are ancestors of at least one of
   162     # - bothvisit is the set of nodes we know are ancestors of at least one of
   164     #   the nodes in revs and one of the nodes in bases
   163     #   the nodes in revs and one of the nodes in bases, and that are smaller
   165     # - a node may be in none or one, but not more, of revsvisit, basesvisit
   164     #   than curr. bothvisit and revsvisit are mutually exclusive, but bothvisit
   166     #   and bothvisit at any given time
   165     #   is a subset of basesvisit.
   167     # Now we walk down in reverse topo order, adding parents of nodes already
   166     # Now we walk down in reverse topo order, adding parents of nodes already
   168     # visited to the sets while maintaining the invariants. When a node is
   167     # visited to the sets while maintaining the invariants. When a node is found
   169     # found in both revsvisit and basesvisit, it is removed from them and
   168     # in both revsvisit and basesvisit, it is removed from revsvisit and added
   170     # added to bothvisit instead. When revsvisit becomes empty, there are no
   169     # to bothvisit. When revsvisit becomes empty, there are no more ancestors of
   171     # more ancestors of revs that aren't also ancestors of bases, so exit.
   170     # revs that aren't also ancestors of bases, so exit.
   172 
   171 
   173     missing = []
   172     missing = []
   174     for curr in xrange(start, nullrev, -1):
   173     for curr in xrange(start, nullrev, -1):
   175         if not revsvisit:
   174         if not revsvisit:
   176             break
   175             break
   177 
   176 
   178         if curr in bothvisit:
   177         if curr in bothvisit:
   179             bothvisit.remove(curr)
   178             bothvisit.remove(curr)
   180             # curr's parents might have made it into revsvisit or basesvisit
   179             # curr's parents might have made it into revsvisit through another
   181             # through another path
   180             # path
   182             for p in pfunc(curr):
   181             for p in pfunc(curr):
   183                 revsvisit.discard(p)
   182                 revsvisit.discard(p)
   184                 basesvisit.discard(p)
   183                 basesvisit.add(p)
   185                 bothvisit.add(p)
   184                 bothvisit.add(p)
   186             continue
   185             continue
   187 
   186 
   188         # curr will never be in both revsvisit and basesvisit, since if it
       
   189         # were it'd have been pushed to bothvisit
       
   190         if curr in revsvisit:
   187         if curr in revsvisit:
   191             missing.append(curr)
   188             missing.append(curr)
       
   189             revsvisit.remove(curr)
   192             thisvisit = revsvisit
   190             thisvisit = revsvisit
   193             othervisit = basesvisit
   191             othervisit = basesvisit
   194         elif curr in basesvisit:
   192         elif curr in basesvisit:
   195             thisvisit = basesvisit
   193             thisvisit = basesvisit
   196             othervisit = revsvisit
   194             othervisit = revsvisit
   197         else:
   195         else:
   198             # not an ancestor of revs or bases: ignore
   196             # not an ancestor of revs or bases: ignore
   199             continue
   197             continue
   200 
   198 
   201         thisvisit.remove(curr)
       
   202         for p in pfunc(curr):
   199         for p in pfunc(curr):
   203             if p == nullrev:
   200             if p == nullrev:
   204                 pass
   201                 pass
   205             elif p in othervisit or p in bothvisit:
   202             elif p in othervisit or p in bothvisit:
   206                 # p is implicitly in thisvisit. This means p is or should be
   203                 # p is implicitly in thisvisit. This means p is or should be
   207                 # in bothvisit
   204                 # in bothvisit
   208                 revsvisit.discard(p)
   205                 revsvisit.discard(p)
   209                 basesvisit.discard(p)
   206                 basesvisit.add(p)
   210                 bothvisit.add(p)
   207                 bothvisit.add(p)
   211             else:
   208             else:
   212                 # visit later
   209                 # visit later
   213                 thisvisit.add(p)
   210                 thisvisit.add(p)
   214 
   211