mirror of
https://github.com/facebook/sapling.git
synced 2024-10-07 15:27:13 +03:00
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:
parent
b9b0249b14
commit
d59976bf1f
@ -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()):
|
||||
|
Loading…
Reference in New Issue
Block a user