mercurial/revlog.py
changeset 18081 f88c60e740a1
parent 17975 c56b5b65430d
child 18083 717c692fa449
equal deleted inserted replaced
18080:486bfb200b3f 18081:f88c60e740a1
   339 
   339 
   340         t = self.revision(self.node(rev))
   340         t = self.revision(self.node(rev))
   341         return len(t)
   341         return len(t)
   342     size = rawsize
   342     size = rawsize
   343 
   343 
   344     def ancestors(self, revs, stoprev=0):
   344     def ancestors(self, revs, stoprev=0, inclusive=False):
   345         """Generate the ancestors of 'revs' in reverse topological order.
   345         """Generate the ancestors of 'revs' in reverse topological order.
   346         Does not generate revs lower than stoprev.
   346         Does not generate revs lower than stoprev.
   347 
   347 
   348         Yield a sequence of revision numbers starting with the parents
   348         If inclusive is False, yield a sequence of revision numbers starting
   349         of each revision in revs, i.e., each revision is *not* considered
   349         with the parents of each revision in revs, i.e., each revision is *not*
   350         an ancestor of itself.  Results are in breadth-first order:
   350         considered an ancestor of itself.  Results are in breadth-first order:
   351         parents of each rev in revs, then parents of those, etc.  Result
   351         parents of each rev in revs, then parents of those, etc.
   352         does not include the null revision."""
   352 
       
   353         If inclusive is True, yield all the revs first (ignoring stoprev),
       
   354         then yield all the ancestors of revs as when inclusive is False.
       
   355         If an element in revs is an ancestor of a different rev it is not
       
   356         yielded again.
       
   357 
       
   358         Result does not include the null revision."""
   353         visit = util.deque(revs)
   359         visit = util.deque(revs)
   354         seen = set([nullrev])
   360         seen = set([nullrev])
       
   361         if inclusive:
       
   362             for rev in revs:
       
   363                 yield rev
       
   364             seen.update(revs)
   355         while visit:
   365         while visit:
   356             for parent in self.parentrevs(visit.popleft()):
   366             for parent in self.parentrevs(visit.popleft()):
   357                 if parent < stoprev:
   367                 if parent < stoprev:
   358                     continue
   368                     continue
   359                 if parent not in seen:
   369                 if parent not in seen:
   362                     yield parent
   372                     yield parent
   363 
   373 
   364     def incancestors(self, revs, stoprev=0):
   374     def incancestors(self, revs, stoprev=0):
   365         """Identical to ancestors() except it also generates the
   375         """Identical to ancestors() except it also generates the
   366         revisions, 'revs'"""
   376         revisions, 'revs'"""
   367         for rev in revs:
   377         return self.ancestors(revs, stoprev, inclusive=True)
   368             yield rev
       
   369         for rev in self.ancestors(revs, stoprev):
       
   370             yield rev
       
   371 
   378 
   372     def descendants(self, revs):
   379     def descendants(self, revs):
   373         """Generate the descendants of 'revs' in revision order.
   380         """Generate the descendants of 'revs' in revision order.
   374 
   381 
   375         Yield a sequence of revision numbers starting with a child of
   382         Yield a sequence of revision numbers starting with a child of