view hgext3rd/evolve/utility.py @ 2086:28241509ff6f

obsdiscovery: extract a smarted depth in utility The function is reusing previous depth for ancestors unless this is a merge.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Sat, 11 Mar 2017 09:08:20 -0800
parents f9d65d24b9f9
children 0c2371542687
line wrap: on
line source

# Various utility function for the evolve extension
#
# Copyright 2017 Pierre-Yves David <pierre-yves.david@ens-lyon.org>
#
# 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',
                            False)
    if verbose:
        message = 'OBSEXC: ' + message
    if important or verbose:
        ui.status(message)

def obsexcprg(ui, *args, **kwargs):
    topic = 'obsmarkers exchange'
    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