# HG changeset patch # User Pierre-Yves David # Date 1489252100 28800 # Node ID 28241509ff6f20ed0b852914dab6b5d30e38de00 # Parent 6d61c5ed3bfad48da8cb79644a703a483017e4f3 obsdiscovery: extract a smarted depth in utility The function is reusing previous depth for ancestors unless this is a merge. diff --git a/hgext3rd/evolve/obsdiscovery.py b/hgext3rd/evolve/obsdiscovery.py --- a/hgext3rd/evolve/obsdiscovery.py +++ b/hgext3rd/evolve/obsdiscovery.py @@ -500,15 +500,6 @@ d = (r.head, s(n(r.head)), r.index, len(r), r.depth, node.short(r.obshash)) ui.status('%3d %s %5d %4d %5d %s\n' % d) -_depthcache = {} -def _depth(repo, rev): - cl = repo.changelog - n = cl.node(rev) - depth = _depthcache.get(n, None) - if depth is None: - depth = _depthcache[n] = len(list(cl.ancestors([rev], inclusive=True))) - return depth - def _hlp2(i): """return highest power of two lower than 'i'""" return 2 ** int(math.log(i - 1, 2)) @@ -552,7 +543,7 @@ @util.propertycache def depth(self): - return _depth(self._repo, self.head) + return utility.depth(self._repo, self.head) @util.propertycache def _revs(self): @@ -571,14 +562,14 @@ result = [] if len(bheads) == 1: newhead = bottom[-1] - newstart = _depth(self._repo, newhead) - len(bottom) + newstart = utility.depth(self._repo, newhead) - len(bottom) result.append(_range(self._repo, newhead, newstart, bottom)) else: cl = self._repo.changelog for h in bheads: subset = cl.ancestors([h], inclusive=True) hrevs = [r for r in bottom if r in subset] - start = _depth(self._repo, h) - len(hrevs) + start = utility.depth(self._repo, h) - len(hrevs) entry = _range(self._repo, h, start, [r for r in bottom if r in subset]) result.append(entry) result.append(_range(self._repo, self.head, globalindex, top)) diff --git a/hgext3rd/evolve/utility.py b/hgext3rd/evolve/utility.py --- a/hgext3rd/evolve/utility.py +++ b/hgext3rd/evolve/utility.py @@ -4,6 +4,7 @@ # # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. +from mercurial import node def obsexcmsg(ui, message, important=False): verbose = ui.configbool('experimental', 'verbose-obsolescence-exchange', @@ -18,3 +19,20 @@ if ui.configbool('experimental', 'verbose-obsolescence-exchange', False): topic = 'OBSEXC' ui.progress(topic, *args, **kwargs) + +_depthcache = {} +def depth(repo, rev): + cl = repo.changelog + n = cl.node(rev) + revdepth = _depthcache.get(n, None) + if revdepth is None: + p1, p2 = cl.parentrevs(rev) + if p1 == node.nullrev: + revdepth = 1 + elif p2 == node.nullrev: + revdepth = depth(repo, p1) + 1 + else: + # XXX we should just find the common ancestors + revdepth = len(list(cl.ancestors([rev], inclusive=True))) + _depthcache[n] = revdepth + return revdepth