Mercurial > evolve
changeset 3248:07c9b6f445bf
stablerange: rework the debug command to allow for multiple method
Similar to what we did for the other debug command related to sorting, we
prepare for the arrival of multiple method to produce the result (including
simple implementation that are easy to read but do not scale).
author | Pierre-Yves David <pierre-yves.david@octobus.net> |
---|---|
date | Wed, 29 Nov 2017 10:53:21 -0500 |
parents | d8e6c5338053 |
children | 94f80f229a89 |
files | hgext3rd/evolve/obsdiscovery.py hgext3rd/evolve/stablerange.py |
diffstat | 2 files changed, 30 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext3rd/evolve/obsdiscovery.py Sat Dec 09 17:34:33 2017 +0100 +++ b/hgext3rd/evolve/obsdiscovery.py Wed Nov 29 10:53:21 2017 -0500 @@ -273,7 +273,7 @@ rangelength = repo.stablerange.rangelength depthrev = repo.stablerange.depthrev if opts['subranges']: - ranges = stablerange.subrangesclosure(repo, revs) + ranges = stablerange.subrangesclosure(repo, repo.stablerange, revs) else: ranges = [(r, 0) for r in revs] headers = ('rev', 'node', 'index', 'size', 'depth', 'obshash')
--- a/hgext3rd/evolve/stablerange.py Sat Dec 09 17:34:33 2017 +0100 +++ b/hgext3rd/evolve/stablerange.py Wed Nov 29 10:53:21 2017 -0500 @@ -52,12 +52,12 @@ """return highest power of two lower than 'i'""" return 2 ** int(math.log(i - 1, 2)) -def subrangesclosure(repo, heads): +def subrangesclosure(repo, stablerange, heads): """set of all standard subrange under heads This is intended for debug purposes. Range are returned from largest to smallest in terms of number of revision it contains.""" - subranges = repo.stablerange.subranges + subranges = stablerange.subranges toproceed = [(r, 0, ) for r in heads] ranges = set(toproceed) while toproceed: @@ -68,16 +68,22 @@ toproceed.append(r) ranges = list(ranges) n = repo.changelog.node - rangelength = repo.stablerange.rangelength + rangelength = stablerange.rangelength ranges.sort(key=lambda r: (-rangelength(repo, r), n(r[0]))) return ranges +_stablerangemethodmap = { + 'branchpoint': lambda repo: repo.stablerange, +} + @eh.command( 'debugstablerange', [ - ('', 'rev', [], 'operate on (rev, 0) ranges for rev in REVS'), + ('r', 'rev', [], 'operate on (rev, 0) ranges for rev in REVS'), ('', 'subranges', False, 'recursively display data for subranges too'), ('', 'verify', False, 'checks subranges content (EXPENSIVE)'), + ('', 'method', 'branchpoint', + 'method to use, one of "branchpoint", "mergepoint"') ], _('')) def debugstablerange(ui, repo, **opts): @@ -88,20 +94,8 @@ """ short = nodemod.short revs = scmutil.revrange(repo, opts['rev']) - # prewarm depth cache - unfi = repo.unfiltered() - node = unfi.changelog.node - stablerange = unfi.stablerange - depth = stablerange.depthrev - length = stablerange.rangelength - subranges = stablerange.subranges if not revs: raise error.Abort('no revisions specified') - repo.stablerange.warmup(repo, max(revs)) - if opts['subranges']: - ranges = subrangesclosure(repo, revs) - else: - ranges = [(r, 0) for r in revs] if ui.verbose: template = '%s-%d (%d, %d, %d)' @@ -121,6 +115,25 @@ short(node(rangeid[0])), rangeid[1], ) + # prewarm depth cache + unfi = repo.unfiltered() + node = unfi.changelog.node + + method = opts['method'] + getstablerange = _stablerangemethodmap.get(method) + if getstablerange is None: + raise error.Abort('unknown stable sort method: "%s"' % method) + + stablerange = getstablerange(unfi) + depth = stablerange.depthrev + length = stablerange.rangelength + subranges = stablerange.subranges + stablerange.warmup(repo, max(revs)) + + if opts['subranges']: + ranges = subrangesclosure(repo, stablerange, revs) + else: + ranges = [(r, 0) for r in revs] for r in ranges: subs = subranges(unfi, r)