hgext3rd/topic/compat.py
author Anton Shestakov <av6@dwimlabs.net>
Fri, 15 Nov 2019 11:37:34 +0700
changeset 4942 acc7e27fa5c6
parent 4929 bb2b4f6c99dc
child 4943 ad2a8a649b61
permissions -rw-r--r--
topic: drop compat.getmarkers() and use obsutil.getmarkers() directly The function in question was moved from obsolete to obsutil in a14e2e7f7d1f (hg 4.3). See also 6aff4bb3970d for hgext3rd/evolve.

# Copyright 2017 FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
"""
Compatibility module
"""
from __future__ import absolute_import

from mercurial import (
    obsolete,
    pycompat,
    registrar,
    util,
)

successorssets = None
try:
    from mercurial import obsutil
    successorssets = getattr(obsutil, 'successorssets', None)
except ImportError:
    pass

if successorssets is None:
    successorssets = obsolete.successorssets

if pycompat.ispy3:
    def branchmapitems(branchmap):
        return branchmap.items()
else:
    # py3-transform: off
    def branchmapitems(branchmap):
        return branchmap.iteritems()
    # py3-transform: on

# help category compatibility
# hg <= 4.7 (c303d65d2e34)
def helpcategorykwargs(categoryname):
    """Backwards-compatible specification of the helpategory argument."""
    category = getattr(registrar.command, categoryname, None)
    if not category:
        return {}
    return {'helpcategory': category}

# nodemap.get and index.[has_node|rev|get_rev]
# hg <= 5.3 (02802fa87b74)
def getgetrev(cl):
    """Returns index.get_rev or nodemap.get (for pre-5.3 Mercurial)."""
    if util.safehasattr(cl.index, 'get_rev'):
        return cl.index.get_rev
    return cl.nodemap.get