# HG changeset patch # User Laurent Charignon # Date 1438924280 25200 # Node ID 1ffd97cbf9a2f4bb50903c6040f13bc266a8a95a # Parent 6f4a280298c13c56cf0f982f1082b69f6aaa765a reachableroots: default to the C implementation This patch is part of a series of patches to speed up the computation of revset.reachableroots by introducing a C implementation. The main motivation is to speed up smartlog on big repositories. At the end of the series, on our big repositories the computation of reachableroots is 10-50x faster and smartlog on is 2x-5x faster. Before this patch, reachableroots was computed in pure Python by default. This patch makes the C implementation the default and provides a speedup for reachableroots. diff -r 6f4a280298c1 -r 1ffd97cbf9a2 mercurial/revset.py --- a/mercurial/revset.py Thu Aug 06 22:10:31 2015 -0700 +++ b/mercurial/revset.py Thu Aug 06 22:11:20 2015 -0700 @@ -87,7 +87,7 @@ return generatorset(iterate(), iterasc=True) -def reachableroots(repo, roots, heads, includepath=False): +def reachablerootspure(repo, minroot, roots, heads, includepath): """return (heads(:: and ::)) If includepath is True, return (::).""" @@ -97,10 +97,6 @@ visit = list(heads) reachable = set() seen = {} - # XXX this should be 'parentset.min()' assuming 'parentset' is a smartset - # (and if it is not, it should.) - minroot = min(roots) - roots = set(roots) # prefetch all the things! (because python is slow) reached = reachable.add dovisit = visit.append @@ -128,6 +124,22 @@ reached(rev) return baseset(sorted(reachable)) +def reachableroots(repo, roots, heads, includepath=False): + """return (heads(:: and ::)) + + If includepath is True, return (::).""" + if not roots: + return baseset() + # XXX this should be 'parentset.min()' assuming 'parentset' is a smartset + # (and if it is not, it should.) + minroot = min(roots) + roots = set(roots) + heads = list(heads) + try: + return repo.changelog.reachableroots(minroot, heads, roots, includepath) + except AttributeError: + return reachablerootspure(repo, minroot, roots, heads, includepath) + elements = { # token-type: binding-strength, primary, prefix, infix, suffix "(": (21, None, ("group", 1, ")"), ("func", 1, ")"), None),