mercurial/revlog.py
changeset 3923 27230c29bfec
parent 3755 05120e210c65
child 3928 4df475e22248
child 4215 90bb1ab53a85
equal deleted inserted replaced
3919:5f0e00224cde 3923:27230c29bfec
   715         assert orderedout
   715         assert orderedout
   716         assert roots
   716         assert roots
   717         assert heads
   717         assert heads
   718         return (orderedout, roots, heads)
   718         return (orderedout, roots, heads)
   719 
   719 
   720     def heads(self, start=None):
   720     def heads(self, start=None, stop=None):
   721         """return the list of all nodes that have no children
   721         """return the list of all nodes that have no children
   722 
   722 
   723         if start is specified, only heads that are descendants of
   723         if start is specified, only heads that are descendants of
   724         start will be returned
   724         start will be returned
   725 
   725         if stop is specified, it will consider all the revs from stop
       
   726         as if they had no children
   726         """
   727         """
   727         if start is None:
   728         if start is None:
   728             start = nullid
   729             start = nullid
       
   730         if stop is None:
       
   731             stop = []
       
   732         stoprevs = dict.fromkeys([self.rev(n) for n in stop])
   729         startrev = self.rev(start)
   733         startrev = self.rev(start)
   730         reachable = {startrev: 1}
   734         reachable = {startrev: 1}
   731         heads = {startrev: 1}
   735         heads = {startrev: 1}
   732 
   736 
   733         parentrevs = self.parentrevs
   737         parentrevs = self.parentrevs
   734         for r in xrange(startrev + 1, self.count()):
   738         for r in xrange(startrev + 1, self.count()):
   735             for p in parentrevs(r):
   739             for p in parentrevs(r):
   736                 if p in reachable:
   740                 if p in reachable:
   737                     reachable[r] = 1
   741                     if r not in stoprevs:
       
   742                         reachable[r] = 1
   738                     heads[r] = 1
   743                     heads[r] = 1
   739                 if p in heads:
   744                 if p in heads and p not in stoprevs:
   740                     del heads[p]
   745                     del heads[p]
       
   746 
   741         return [self.node(r) for r in heads]
   747         return [self.node(r) for r in heads]
   742 
   748 
   743     def children(self, node):
   749     def children(self, node):
   744         """find the children of a given node"""
   750         """find the children of a given node"""
   745         c = []
   751         c = []