Speedup revlog.ancestors for the linear case

revlog.ancestors can be expensive on big repos.  This cuts down the overall
time for hg update by ~19% by short cutting revlog.ancestors when one of the
revisions is reachable from another.
This commit is contained in:
Chris Mason 2006-04-06 20:13:09 -04:00
parent b9b0249b14
commit d59976bf1f

View File

@ -940,6 +940,24 @@ class revlog(object):
def ancestor(self, a, b):
"""calculate the least common ancestor of nodes a and b"""
# start with some short cuts for the linear cases
if a == b:
return a
ra = self.rev(a)
rb = self.rev(b)
if ra < rb:
last = b
first = a
else:
last = a
first = b
# reachable won't include stop in the list, so we have to use a parent
reachable = self.reachable(last, stop=self.parents(first)[0])
if first in reachable:
return first
# calculate the distance of every node from root
dist = {nullid: 0}
for i in xrange(self.count()):