Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlog.py @ 10325:bc72e21f9dc8
revlog: add a fast path for checking ancestry
author | Dirkjan Ochtman <dirkjan@ochtman.nl> |
---|---|
date | Sat, 06 Feb 2010 11:27:22 +0100 |
parents | d9a2bc2f776b |
children | ae0ae8691e47 |
comparison
equal
deleted
inserted
replaced
10324:55d134ef8ab7 | 10325:bc72e21f9dc8 |
---|---|
1135 | 1135 |
1136 if type(text) == str: # only accept immutable objects | 1136 if type(text) == str: # only accept immutable objects |
1137 self._cache = (node, curr, text) | 1137 self._cache = (node, curr, text) |
1138 return node | 1138 return node |
1139 | 1139 |
1140 def descendant(self, a, b): | |
1141 if a > b: | |
1142 return False | |
1143 for i in self.descendants(a): | |
1144 if i == b: | |
1145 return True | |
1146 elif i > b: | |
1147 break | |
1148 return False | |
1149 | |
1140 def ancestor(self, a, b): | 1150 def ancestor(self, a, b): |
1141 """calculate the least common ancestor of nodes a and b""" | 1151 """calculate the least common ancestor of nodes a and b""" |
1142 | 1152 |
1143 # fast path, check if it is a descendant | |
1144 a, b = self.rev(a), self.rev(b) | |
1145 start, end = sorted((a, b)) | 1153 start, end = sorted((a, b)) |
1146 for i in self.descendants(start): | 1154 if self.descendant(a, b): |
1147 if i == end: | 1155 return self.node(start) |
1148 return self.node(start) | |
1149 elif i > end: | |
1150 break | |
1151 | 1156 |
1152 def parents(rev): | 1157 def parents(rev): |
1153 return [p for p in self.parentrevs(rev) if p != nullrev] | 1158 return [p for p in self.parentrevs(rev) if p != nullrev] |
1154 | 1159 |
1155 c = ancestor.ancestor(a, b, parents) | 1160 c = ancestor.ancestor(a, b, parents) |