1
  C   5ˆl–äY>”JeJe@†à¸Û*bÑ¿�þ^xN,Ü¡p¬ˆ$‘¦�üÿÛ„e§›kÚ_ŠI|¥�+Wé3ž¯ÃÙ ?÷     5# templatekw.py - common changeset template keywords
#
# Copyright 2005-2009 Olivia Mackall <olivia@selenic.com>
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.


from .i18n import _
from .node import (
    hex,
    wdirrev,
)

from . import (
    diffutil,
    encoding,
    error,
    hbisect,
    i18n,
    obsutil,
    patch,
    pycompat,
    registrar,
    scmutil,
    templateutil,
    util,
)
from .utils import (
    stringutil,
    urlutil,
)

_hybrid = templateutil.hybrid
hybriddict = templateutil.hybriddict
hybridlist = templateutil.hybridlist
compatdict = templateutil.compatdict
compatlist = templateutil.compatlist
_showcompatlist = templateutil._showcompatlist


def getlatesttags(context, mapping, pattern=None):
    '''return date, distance and name for the latest tag of rev'''
    repo = context.resource(mapping, b'repo')
    ctx = context.resource(mapping, b'ctx')
    cache = context.resource(mapping, b'cache')

    cachename = b'latesttags'
    if pattern is not None:
        cachename += b'-' + pattern
        match = stringutil.stringmatcher(pattern)[2]
    else:
        match = util.always

    if cachename not in cache:
        # Cache mapping from rev to a tuple with tag date, tag
        # distance and tag name
        cache[cachename] = {-1: (0, 0, [b'null'])}
    latesttags = cache[cachename]

    rev = ctx.rev()
    todo = [rev]
    while todo:
        rev = todo.pop()
        if rev in latesttags:
            continue
        ctx = repo[rev]
        tags = [
            t
            for t in ctx.tags()
            if (repo.tagtype(t) and repo.tagtype(t) != b'local' and match(t))
        ]
        if tags:
            latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)]
            continue
        try:
            ptags = [latesttags[p.rev()] for p in ctx.parents()]
            if len(ptags) > 1:
                if ptags[0][2] == ptags[1][2]:
                    # The tuples are laid out so the right one can be found by
                    # comparison in this case.
                    pdate, pdist, ptag = max(ptags)
                else:

                    def key(x):
                        tag = x[2][0]
                        if ctx.rev() is None:
                            # only() doesn't support wdir
                            prevs = [c.rev() for c in ctx.parents()]
                            changes = repo.revs(b'only(%ld, %s)', prevs, tag)
                            changessincetag = len(changes) + 1
                        else:
                            changes = repo.revs(b'only(%d, %s)', ctx.rev(), tag)
                            changessincetag = len(changes)
                        # Smallest number of changes since tag wins. Date is
                        # used as tiebreaker.
                        return [-changessincetag, x[0]]

                    pdate, pdist, ptag = max(ptags, key=key)
            else:
                pdate, pdist, ptag = ptags[0]
        except KeyError:
            # Cache miss - recurse
            todo.append(rev)
            todo.extend(p.rev() for p in ctx.parents())
            continue
        latesttags[rev] = pdate, pdist + 1, ptag
    return latesttags[rev]


def getlogcolumns():
    """Return a dict of log column labels"""
    _ = pycompat.identity  # temporarily disable gettext
    # i18n: column positioning for "hg log"
    columns = _(
        b'bookmark:    %s\n'
        b'branch:      %s\n'
        b'changeset:   %s\n'
        b'copies:      %s\n'
        b'date:        %s\n'
        b'extra:       %s=%s\n'
        b'files+:      %s\n'
        b'files-:      %s\n'
        b'files:       %s\n'
        b'instability: %s\n'
        b'manifest:    %s\n'
        b'obsolete:    %s\n'
        b'parent:      %s\n'
        b'phase:       %s\n'
        b'summary:     %s\n'
        b'tag:         %s\n'
        b'user:        %s\n'
    )
    return dict(
    