##// END OF EJS Templates
revlog: choose a consistent ancestor when there's a tie...
Bryan O'Sullivan -
r18987:3605d4e7 default
parent child Browse files
Show More
@@ -5,7 +5,7 b''
5 5 # This software may be used and distributed according to the terms of the
6 6 # GNU General Public License version 2 or any later version.
7 7
8 import error, heapq, util
8 import heapq, util
9 9 from node import nullrev
10 10
11 11 def ancestors(pfunc, *orignodes):
@@ -213,51 +213,6 b' def genericancestor(a, b, pfunc):'
213 213 except StopIteration:
214 214 return None
215 215
216 def finddepths(nodes, pfunc):
217 visit = list(nodes)
218 rootpl = [nullrev, nullrev]
219 depth = {}
220 while visit:
221 vertex = visit[-1]
222 pl = pfunc(vertex)
223 if not pl or pl == rootpl:
224 depth[vertex] = 0
225 visit.pop()
226 else:
227 for p in pl:
228 if p != nullrev and p not in depth:
229 visit.append(p)
230 if visit[-1] == vertex:
231 dp = [depth[p] for p in pl if p != nullrev]
232 if dp:
233 depth[vertex] = max(dp) + 1
234 else:
235 depth[vertex] = 0
236 visit.pop()
237 return depth
238
239 def ancestor(a, b, pfunc):
240 xs = ancestors(pfunc, a, b)
241 y = genericancestor(a, b, pfunc)
242 if y == -1:
243 y = None
244 if not xs:
245 if y is None:
246 return None
247 print xs, y
248 raise error.RepoError('ancestors disagree on whether a gca exists')
249 elif y is None:
250 print xs, y
251 raise error.RepoError('ancestors disagree on whether a gca exists')
252 if y in xs:
253 return y
254 xds = finddepths(xs, pfunc)
255 xds = [ds[x] for x in xs]
256 yd = finddepths([y], pfunc)[y]
257 if len([xd != yd for xd in xds]) > 0:
258 raise error.RepoError('ancestor depths do not match')
259 return xs.pop()
260
261 216 def missingancestors(revs, bases, pfunc):
262 217 """Return all the ancestors of revs that are not ancestors of bases.
263 218
@@ -705,17 +705,12 b' class revlog(object):'
705 705 def ancestor(self, a, b):
706 706 """calculate the least common ancestor of nodes a and b"""
707 707
708 # fast path, check if it is a descendant
709 708 a, b = self.rev(a), self.rev(b)
710 start, end = sorted((a, b))
711 if self.descendant(start, end):
712 return self.node(start)
713
714 c = ancestor.ancestor(a, b, self.parentrevs)
715 if c is None:
716 return nullid
717
718 return self.node(c)
709 ancs = ancestor.ancestors(self.parentrevs, a, b)
710 if ancs:
711 # choose a consistent winner when there's a tie
712 return min(map(self.node, ancs))
713 return nullid
719 714
720 715 def _match(self, id):
721 716 if isinstance(id, int):
General Comments 0
You need to be logged in to leave comments. Login now