mercurial/templatekw.py
author Anton Shestakov <av6@dwimlabs.net>
Sun, 14 Jan 2024 16:03:08 -0300
branchstable
changeset 51161 c7edfccfc11f
parent 49021 e6df205a876c
child 51186 9ff3d5395d6b
permissions -rw-r--r--
tests: don't use "status" operand of dd in test-censor.t (issue6858) Some implementations don't have this operand, let's just direct stderr into /dev/null, that's pretty cross-platform. Also specify bs=512 (the default for me), because the default might be different on different systems. Other uses of dd in the tests do specify it, so this is more consistent.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     1
# templatekw.py - common changeset template keywords
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     2
#
46819
d4ba4d51f85f contributor: change mentions of mpm to olivia
Raphaël Gomès <rgomes@octobus.net>
parents: 45957
diff changeset
     3
# Copyright 2005-2009 Olivia Mackall <olivia@selenic.com>
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     4
#
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms of the
10264
d6512b3e9ac0 Merge with stable
Matt Mackall <mpm@selenic.com>
parents: 10260
diff changeset
     6
# GNU General Public License version 2 or any later version.
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     7
25984
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
     8
31807
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31704
diff changeset
     9
from .i18n import _
32678
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
    10
from .node import (
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
    11
    hex,
39812
94ca3579e84e log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents: 39639
diff changeset
    12
    wdirrev,
32678
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
    13
)
55ff67ffcead scmutil: introduce binnode(ctx) as paired function with intrev(ctx)
Yuya Nishihara <yuya@tcha.org>
parents: 32676
diff changeset
    14
25984
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
    15
from . import (
38589
1c93e0237a24 diffutil: move the module out of utils package
Yuya Nishihara <yuya@tcha.org>
parents: 38588
diff changeset
    16
    diffutil,
28239
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
    17
    encoding,
25984
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
    18
    error,
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
    19
    hbisect,
35222
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35164
diff changeset
    20
    i18n,
32897
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
    21
    obsutil,
25984
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
    22
    patch,
32990
26e710f0468f py3: convert keys of kwargs in template keywords functions to bytes
Pulkit Goyal <7895pulkit@gmail.com>
parents: 32988
diff changeset
    23
    pycompat,
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
    24
    registrar,
25984
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
    25
    scmutil,
36927
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36663
diff changeset
    26
    templateutil,
25984
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
    27
    util,
c57509e88922 templatekw: use absolute_import
Gregory Szorc <gregory.szorc@gmail.com>
parents: 25740
diff changeset
    28
)
47073
6ce1af5f0764 template: use `list_paths` in `peerurls`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
    29
from .utils import (
6ce1af5f0764 template: use `list_paths` in `peerurls`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
    30
    stringutil,
6ce1af5f0764 template: use `list_paths` in `peerurls`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
    31
    urlutil,
6ce1af5f0764 template: use `list_paths` in `peerurls`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
    32
)
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    33
36927
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36663
diff changeset
    34
_hybrid = templateutil.hybrid
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36663
diff changeset
    35
hybriddict = templateutil.hybriddict
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36663
diff changeset
    36
hybridlist = templateutil.hybridlist
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36663
diff changeset
    37
compatdict = templateutil.compatdict
32f9b7e3f056 templater: move hybrid class and functions to templateutil module
Yuya Nishihara <yuya@tcha.org>
parents: 36663
diff changeset
    38
compatlist = templateutil.compatlist
37071
aa97e06a1912 templater: use template context to render old-style list template
Yuya Nishihara <yuya@tcha.org>
parents: 37022
diff changeset
    39
_showcompatlist = templateutil._showcompatlist
aa97e06a1912 templater: use template context to render old-style list template
Yuya Nishihara <yuya@tcha.org>
parents: 37022
diff changeset
    40
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
    41
36625
b5d39a09656a templatekw: switch latesttags template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36624
diff changeset
    42
def getlatesttags(context, mapping, pattern=None):
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    43
    '''return date, distance and name for the latest tag of rev'''
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    44
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    45
    ctx = context.resource(mapping, b'ctx')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    46
    cache = context.resource(mapping, b'cache')
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    47
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    48
    cachename = b'latesttags'
26482
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
    49
    if pattern is not None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    50
        cachename += b'-' + pattern
37087
f0b6fbea00cf stringutil: bulk-replace call sites to point to new module
Yuya Nishihara <yuya@tcha.org>
parents: 37077
diff changeset
    51
        match = stringutil.stringmatcher(pattern)[2]
26482
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
    52
    else:
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
    53
        match = util.always
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
    54
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
    55
    if cachename not in cache:
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    56
        # Cache mapping from rev to a tuple with tag date, tag
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    57
        # distance and tag name
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    58
        cache[cachename] = {-1: (0, 0, [b'null'])}
26482
d2e69584e330 templatekw: allow getlatesttags() to match a specific tag pattern
Matt Harbison <matt_harbison@yahoo.com>
parents: 26437
diff changeset
    59
    latesttags = cache[cachename]
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    60
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    61
    rev = ctx.rev()
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    62
    todo = [rev]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    63
    while todo:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    64
        rev = todo.pop()
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    65
        if rev in latesttags:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    66
            continue
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    67
        ctx = repo[rev]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
    68
        tags = [
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
    69
            t
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
    70
            for t in ctx.tags()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    71
            if (repo.tagtype(t) and repo.tagtype(t) != b'local' and match(t))
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
    72
        ]
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    73
        if tags:
25700
0fca47b206f6 templatekw: use a list of tags in getlatesttags() instead of joining them
Matt Harbison <matt_harbison@yahoo.com>
parents: 25663
diff changeset
    74
            latesttags[rev] = ctx.date()[0], 0, [t for t in sorted(tags)]
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    75
            continue
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    76
        try:
33670
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
    77
            ptags = [latesttags[p.rev()] for p in ctx.parents()]
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
    78
            if len(ptags) > 1:
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
    79
                if ptags[0][2] == ptags[1][2]:
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
    80
                    # The tuples are laid out so the right one can be found by
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
    81
                    # comparison in this case.
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
    82
                    pdate, pdist, ptag = max(ptags)
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
    83
                else:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
    84
33670
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
    85
                    def key(x):
41300
66102f6fa10a templatekw: fix crash on multiple latesttags resolution at wdir (issue6055)
Yuya Nishihara <yuya@tcha.org>
parents: 41130
diff changeset
    86
                        tag = x[2][0]
66102f6fa10a templatekw: fix crash on multiple latesttags resolution at wdir (issue6055)
Yuya Nishihara <yuya@tcha.org>
parents: 41130
diff changeset
    87
                        if ctx.rev() is None:
66102f6fa10a templatekw: fix crash on multiple latesttags resolution at wdir (issue6055)
Yuya Nishihara <yuya@tcha.org>
parents: 41130
diff changeset
    88
                            # only() doesn't support wdir
66102f6fa10a templatekw: fix crash on multiple latesttags resolution at wdir (issue6055)
Yuya Nishihara <yuya@tcha.org>
parents: 41130
diff changeset
    89
                            prevs = [c.rev() for c in ctx.parents()]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    90
                            changes = repo.revs(b'only(%ld, %s)', prevs, tag)
41300
66102f6fa10a templatekw: fix crash on multiple latesttags resolution at wdir (issue6055)
Yuya Nishihara <yuya@tcha.org>
parents: 41130
diff changeset
    91
                            changessincetag = len(changes) + 1
66102f6fa10a templatekw: fix crash on multiple latesttags resolution at wdir (issue6055)
Yuya Nishihara <yuya@tcha.org>
parents: 41130
diff changeset
    92
                        else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
    93
                            changes = repo.revs(b'only(%d, %s)', ctx.rev(), tag)
41300
66102f6fa10a templatekw: fix crash on multiple latesttags resolution at wdir (issue6055)
Yuya Nishihara <yuya@tcha.org>
parents: 41130
diff changeset
    94
                            changessincetag = len(changes)
33670
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
    95
                        # Smallest number of changes since tag wins. Date is
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
    96
                        # used as tiebreaker.
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
    97
                        return [-changessincetag, x[0]]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
    98
33670
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
    99
                    pdate, pdist, ptag = max(ptags, key=key)
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
   100
            else:
fb672eac2702 templatekw: choose {latesttag} by len(changes), not date (issue5659)
Martin von Zweigbergk <martinvonz@google.com>
parents: 33476
diff changeset
   101
                pdate, pdist, ptag = ptags[0]
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   102
        except KeyError:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   103
            # Cache miss - recurse
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   104
            todo.append(rev)
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   105
            todo.extend(p.rev() for p in ctx.parents())
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   106
            continue
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   107
        latesttags[rev] = pdate, pdist + 1, ptag
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   108
    return latesttags[rev]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   109
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   110
35222
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35164
diff changeset
   111
def getlogcolumns():
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35164
diff changeset
   112
    """Return a dict of log column labels"""
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35164
diff changeset
   113
    _ = pycompat.identity  # temporarily disable gettext
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35164
diff changeset
   114
    # i18n: column positioning for "hg log"
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   115
    columns = _(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   116
        b'bookmark:    %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   117
        b'branch:      %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   118
        b'changeset:   %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   119
        b'copies:      %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   120
        b'date:        %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   121
        b'extra:       %s=%s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   122
        b'files+:      %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   123
        b'files-:      %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   124
        b'files:       %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   125
        b'instability: %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   126
        b'manifest:    %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   127
        b'obsolete:    %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   128
        b'parent:      %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   129
        b'phase:       %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   130
        b'summary:     %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   131
        b'tag:         %s\n'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   132
        b'user:        %s\n'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   133
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   134
    return dict(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   135
        zip(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   136
            [s.split(b':', 1)[0] for s in columns.splitlines()],
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   137
            i18n._(columns).splitlines(True),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   138
        )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   139
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   140
35222
c7b45db8f317 log: translate column labels at once (issue5750)
Yuya Nishihara <yuya@tcha.org>
parents: 35164
diff changeset
   141
40524
2891ee3fcb86 templatekw: extract internal "{rev}:{node|formatnode}" template to constant
Yuya Nishihara <yuya@tcha.org>
parents: 39812
diff changeset
   142
# basic internal templates
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   143
_changeidtmpl = b'{rev}:{node|formatnode}'
40524
2891ee3fcb86 templatekw: extract internal "{rev}:{node|formatnode}" template to constant
Yuya Nishihara <yuya@tcha.org>
parents: 39812
diff changeset
   144
31181
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
   145
# default templates internally used for rendering of lists
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
   146
defaulttempl = {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   147
    b'parent': _changeidtmpl + b' ',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   148
    b'manifest': _changeidtmpl,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   149
    b'file_copy': b'{name} ({source})',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   150
    b'envvar': b'{key}={value}',
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   151
    b'extra': b'{key}={value|stringescape}',
31181
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
   152
}
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
   153
# filecopy is preserved for compatibility reasons
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   154
defaulttempl[b'filecopy'] = defaulttempl[b'file_copy']
31181
1ec89cf0ea49 templatekw: move defaulttmpl constant from changeset_templater
Yuya Nishihara <yuya@tcha.org>
parents: 30833
diff changeset
   155
36475
e8d37838f5df templatekw: add 'requires' flag to switch to exception-safe interface
Yuya Nishihara <yuya@tcha.org>
parents: 36472
diff changeset
   156
# keywords are callables (see registrar.templatekeyword for details)
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   157
keywords = {}
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   158
templatekeyword = registrar.templatekeyword(keywords)
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   159
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   160
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   161
@templatekeyword(b'author', requires={b'ctx'})
36475
e8d37838f5df templatekw: add 'requires' flag to switch to exception-safe interface
Yuya Nishihara <yuya@tcha.org>
parents: 36472
diff changeset
   162
def showauthor(context, mapping):
38986
390287321b4b templatekw: copy {author} to {user} and document {author} as an alias
Yuya Nishihara <yuya@tcha.org>
parents: 38815
diff changeset
   163
    """Alias for ``{user}``"""
390287321b4b templatekw: copy {author} to {user} and document {author} as an alias
Yuya Nishihara <yuya@tcha.org>
parents: 38815
diff changeset
   164
    return showuser(context, mapping)
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   165
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   166
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   167
@templatekeyword(b'bisect', requires={b'repo', b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   168
def showbisect(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   169
    """String. The changeset bisection status."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   170
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   171
    ctx = context.resource(mapping, b'ctx')
15155
f4a8d754cd0a templates: add 'bisect' keyword to return a cset's bisect status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 14437
diff changeset
   172
    return hbisect.label(repo, ctx.node())
f4a8d754cd0a templates: add 'bisect' keyword to return a cset's bisect status
"Yann E. MORIN" <yann.morin.1998@anciens.enib.fr>
parents: 14437
diff changeset
   173
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   174
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   175
@templatekeyword(b'branch', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   176
def showbranch(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   177
    """String. The name of the branch on which the changeset was
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   178
    committed.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   179
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   180
    ctx = context.resource(mapping, b'ctx')
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   181
    return ctx.branch()
13156
d79fdff55627 template: add showbranch template for {branch}
Eric Eisner <ede@mit.edu>
parents: 13114
diff changeset
   182
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   183
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   184
@templatekeyword(b'branches', requires={b'ctx'})
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36619
diff changeset
   185
def showbranches(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   186
    """List of strings. The name of the branch on which the
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   187
    changeset was committed. Will be empty if the branch name was
26437
4628b26f040e templatekw: hide help of "branches" by DEPRECATED marker
Yuya Nishihara <yuya@tcha.org>
parents: 26436
diff changeset
   188
    default. (DEPRECATED)
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   189
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   190
    ctx = context.resource(mapping, b'ctx')
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36619
diff changeset
   191
    branch = ctx.branch()
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   192
    if branch != b'default':
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   193
        return compatlist(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   194
            context, mapping, b'branch', [branch], plural=b'branches'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   195
        )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   196
    return compatlist(context, mapping, b'branch', [], plural=b'branches')
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   197
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   198
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   199
@templatekeyword(b'bookmarks', requires={b'repo', b'ctx'})
36627
c3f9d0c303e8 templatekw: switch remainder of _showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36626
diff changeset
   200
def showbookmarks(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   201
    """List of strings. Any bookmarks associated with the
25348
f26efa4f0eff templatekw: introduce active subkeyword from bookmarks keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25013
diff changeset
   202
    changeset. Also sets 'active', the name of the active bookmark.
13592
ad2ee188f4a5 templates: document missing keywords or filters
Patrick Mezard <pmezard@gmail.com>
parents: 13585
diff changeset
   203
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   204
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   205
    ctx = context.resource(mapping, b'ctx')
36627
c3f9d0c303e8 templatekw: switch remainder of _showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36626
diff changeset
   206
    bookmarks = ctx.bookmarks()
25348
f26efa4f0eff templatekw: introduce active subkeyword from bookmarks keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25013
diff changeset
   207
    active = repo._activebookmark
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   208
    makemap = lambda v: {b'bookmark': v, b'active': active, b'current': active}
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   209
    f = _showcompatlist(context, mapping, b'bookmark', bookmarks)
34335
dd28b1f55eb8 templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents: 34334
diff changeset
   210
    return _hybrid(f, bookmarks, makemap, pycompat.identity)
13386
f78bc5ddbe4f templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents: 13156
diff changeset
   211
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   212
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   213
@templatekeyword(b'children', requires={b'ctx'})
36550
c3692364b344 templatekw: add compatlist() as a replacement for showlist()
Yuya Nishihara <yuya@tcha.org>
parents: 36549
diff changeset
   214
def showchildren(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   215
    """List of strings. The children of the changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   216
    ctx = context.resource(mapping, b'ctx')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   217
    childrevs = [b'%d:%s' % (cctx.rev(), cctx) for cctx in ctx.children()]
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   218
    return compatlist(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   219
        context, mapping, b'children', childrevs, element=b'child'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   220
    )
11655
6faf015e0ba0 templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents: 10394
diff changeset
   221
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   222
25013
277aba2c151a templatekw: introduce activebookmark keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25012
diff changeset
   223
# Deprecated, but kept alive for help generation a purpose.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   224
@templatekeyword(b'currentbookmark', requires={b'repo', b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   225
def showcurrentbookmark(context, mapping):
34656
eb7fffdc6e5b help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents: 34581
diff changeset
   226
    """String. The active bookmark, if it is associated with the changeset.
eb7fffdc6e5b help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents: 34581
diff changeset
   227
    (DEPRECATED)"""
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   228
    return showactivebookmark(context, mapping)
25013
277aba2c151a templatekw: introduce activebookmark keyword
Ryan McElroy <rmcelroy@fb.com>
parents: 25012
diff changeset
   229
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   230
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   231
@templatekeyword(b'activebookmark', requires={b'repo', b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   232
def showactivebookmark(context, mapping):
34656
eb7fffdc6e5b help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents: 34581
diff changeset
   233
    """String. The active bookmark, if it is associated with the changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   234
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   235
    ctx = context.resource(mapping, b'ctx')
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   236
    active = repo._activebookmark
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   237
    if active and active in ctx.bookmarks():
25387
390a10b7843b templatekw: display active bookmark more consistently (issue4552) (BC)
Ryan McElroy <rmcelroy@fb.com>
parents: 25348
diff changeset
   238
        return active
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   239
    return b''
21896
2b41ee1b5ea1 templatekw: add 'currentbookmark' keyword to show current bookmark easily
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 20683
diff changeset
   240
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   241
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   242
@templatekeyword(b'date', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   243
def showdate(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   244
    """Date information. The date when the changeset was committed."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   245
    ctx = context.resource(mapping, b'ctx')
38310
88e7105b5cd9 templater: restore the original string format of {date}
Yuya Nishihara <yuya@tcha.org>
parents: 38297
diff changeset
   246
    # the default string format is '<float(unixtime)><tzoffset>' because
88e7105b5cd9 templater: restore the original string format of {date}
Yuya Nishihara <yuya@tcha.org>
parents: 38297
diff changeset
   247
    # python-hglib splits date at decimal separator.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   248
    return templateutil.date(ctx.date(), showfmt=b'%d.0%d')
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   249
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   250
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   251
@templatekeyword(b'desc', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   252
def showdescription(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   253
    """String. The text of the changeset description."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   254
    ctx = context.resource(mapping, b'ctx')
28239
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
   255
    s = ctx.description()
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
   256
    if isinstance(s, encoding.localstr):
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
   257
        # try hard to preserve utf-8 bytes
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
   258
        return encoding.tolocal(encoding.fromlocal(s).strip())
37991
3ea3c96ada54 encoding: introduce tagging type for non-lossy non-ASCII string
Yuya Nishihara <yuya@tcha.org>
parents: 37952
diff changeset
   259
    elif isinstance(s, encoding.safelocalstr):
3ea3c96ada54 encoding: introduce tagging type for non-lossy non-ASCII string
Yuya Nishihara <yuya@tcha.org>
parents: 37952
diff changeset
   260
        return encoding.safelocalstr(s.strip())
28239
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
   261
    else:
7279e0132347 templatekw: workaround for utf-8 round-trip of {desc}
Yuya Nishihara <yuya@tcha.org>
parents: 28178
diff changeset
   262
        return s.strip()
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   263
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   264
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   265
@templatekeyword(b'diffstat', requires={b'ui', b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   266
def showdiffstat(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   267
    """String. Statistics of changes with the following format:
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   268
    "modified files: +added/-removed lines"
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   269
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   270
    ui = context.resource(mapping, b'ui')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   271
    ctx = context.resource(mapping, b'ctx')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   272
    diffopts = diffutil.diffallopts(ui, {b'noprefix': False})
38565
64f15e22f4f8 template: directly instantiate diff options for diffstat
Boris Feld <boris.feld@octobus.net>
parents: 38556
diff changeset
   273
    diff = ctx.diff(opts=diffopts)
38523
4455e5d4d59c context: explicitly take diffopts in `context.diff` (API)
Boris Feld <boris.feld@octobus.net>
parents: 38315
diff changeset
   274
    stats = patch.diffstatdata(util.iterlines(diff))
14437
cbe13e6bdc34 patch: restore the previous output of 'diff --stat'
Steven Brown <StevenGBrown@gmail.com>
parents: 14403
diff changeset
   275
    maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   276
    return b'%d: +%d/-%d' % (len(stats), adds, removes)
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   277
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   278
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   279
@templatekeyword(b'envvars', requires={b'ui'})
36549
a7fbe11a5d59 templatekw: add compatdict() as a replacement for showdict()
Yuya Nishihara <yuya@tcha.org>
parents: 36548
diff changeset
   280
def showenvvars(context, mapping):
30833
bd5e9647f646 templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents: 30811
diff changeset
   281
    """A dictionary of environment variables. (EXPERIMENTAL)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   282
    ui = context.resource(mapping, b'ui')
36472
e46b24582fa0 templatekw: minimize resource dependency of {envvars} and {termwidth}
Yuya Nishihara <yuya@tcha.org>
parents: 36471
diff changeset
   283
    env = ui.exportableenviron()
30833
bd5e9647f646 templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents: 30811
diff changeset
   284
    env = util.sortdict((k, env[k]) for k in sorted(env))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   285
    return compatdict(context, mapping, b'envvar', env, plural=b'envvars')
30833
bd5e9647f646 templater: add '{envvars}' to access environment variables
Matt Harbison <matt_harbison@yahoo.com>
parents: 30811
diff changeset
   286
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   287
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   288
@templatekeyword(b'extras', requires={b'ctx'})
36627
c3f9d0c303e8 templatekw: switch remainder of _showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36626
diff changeset
   289
def showextras(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   290
    """List of dicts with key, value entries of the 'extras'
20015
ad27cdacc743 help: document about {extras} template keyword
Matthew Turk <matthewturk@gmail.com>
parents: 18970
diff changeset
   291
    field of this changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   292
    ctx = context.resource(mapping, b'ctx')
36627
c3f9d0c303e8 templatekw: switch remainder of _showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36626
diff changeset
   293
    extras = ctx.extra()
24237
9ad02823dc5b templatekw: convert list of key/value pairs to sortdict
Yuya Nishihara <yuya@tcha.org>
parents: 24157
diff changeset
   294
    extras = util.sortdict((k, extras[k]) for k in sorted(extras))
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   295
    makemap = lambda k: {b'key': k, b'value': extras[k]}
24238
49cee6d8573d templatekw: give name to lambda that constructs variables map of templater
Yuya Nishihara <yuya@tcha.org>
parents: 24237
diff changeset
   296
    c = [makemap(k) for k in extras]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   297
    f = _showcompatlist(context, mapping, b'extra', c, plural=b'extras')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   298
    return _hybrid(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   299
        f,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   300
        extras,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   301
        makemap,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   302
        lambda k: b'%s=%s' % (k, stringutil.escapestr(extras[k])),
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   303
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   304
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   305
48765
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   306
@templatekeyword(b'_fast_rank', requires={b'ctx'})
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   307
def fast_rank(context, mapping):
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   308
    """the rank of a changeset if cached
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   309
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   310
    The rank of a revision is the size of the sub-graph it defines as a head.
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   311
    Equivalently, the rank of a revision `r` is the size of the set
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   312
    `ancestors(r)`, `r` included.
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   313
    """
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   314
    ctx = context.resource(mapping, b'ctx')
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   315
    rank = ctx.fast_rank()
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   316
    if rank is None:
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   317
        return None
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   318
    return b"%d" % rank
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   319
d5121df04808 rank: add context and template keyword
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47198
diff changeset
   320
39615
a5da906306c9 templatekw: add option to include ignored/clean/unknown files in cache
Yuya Nishihara <yuya@tcha.org>
parents: 39614
diff changeset
   321
def _getfilestatus(context, mapping, listall=False):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   322
    ctx = context.resource(mapping, b'ctx')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   323
    revcache = context.resource(mapping, b'revcache')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   324
    if b'filestatus' not in revcache or revcache[b'filestatusall'] < listall:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   325
        stat = ctx.p1().status(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   326
            ctx, listignored=listall, listclean=listall, listunknown=listall
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   327
        )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   328
        revcache[b'filestatus'] = stat
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   329
        revcache[b'filestatusall'] = listall
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   330
    return revcache[b'filestatus']
39613
164827563426 templatekw: extract function that computes and caches file status
Yuya Nishihara <yuya@tcha.org>
parents: 39603
diff changeset
   331
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   332
39616
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   333
def _getfilestatusmap(context, mapping, listall=False):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   334
    revcache = context.resource(mapping, b'revcache')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   335
    if b'filestatusmap' not in revcache or revcache[b'filestatusall'] < listall:
39616
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   336
        stat = _getfilestatus(context, mapping, listall=listall)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   337
        revcache[b'filestatusmap'] = statmap = {}
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   338
        for char, files in zip(pycompat.iterbytestr(b'MAR!?IC'), stat):
39616
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   339
            statmap.update((f, char) for f in files)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   340
    return revcache[b'filestatusmap']  # {path: statchar}
39616
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   341
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   342
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   343
@templatekeyword(
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   344
    b'file_copies', requires={b'repo', b'ctx', b'cache', b'revcache'}
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   345
)
36619
0083e373e5f5 templatekw: switch showdict template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36603
diff changeset
   346
def showfilecopies(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   347
    """List of strings. Files copied in this changeset with
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   348
    their sources.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   349
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   350
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   351
    ctx = context.resource(mapping, b'ctx')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   352
    cache = context.resource(mapping, b'cache')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   353
    copies = context.resource(mapping, b'revcache').get(b'copies')
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   354
    if copies is None:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   355
        if b'getcopies' not in cache:
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   356
            cache[b'getcopies'] = scmutil.getcopiesfn(repo)
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   357
        getcopies = cache[b'getcopies']
42518
88ba0ff94605 copies: create helper for getting all copies for changeset
Martin von Zweigbergk <martinvonz@google.com>
parents: 42452
diff changeset
   358
        copies = getcopies(ctx)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   359
    return templateutil.compatfilecopiesdict(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   360
        context, mapping, b'file_copy', copies
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   361
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   362
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   363
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   364
# showfilecopiesswitch() displays file copies only if copy records are
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   365
# provided before calling the templater, usually with a --copies
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   366
# command line switch.
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   367
@templatekeyword(b'file_copies_switch', requires={b'revcache'})
36619
0083e373e5f5 templatekw: switch showdict template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36603
diff changeset
   368
def showfilecopiesswitch(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   369
    """List of strings. Like "file_copies" but displayed
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   370
    only if the --copied switch is set.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   371
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   372
    copies = context.resource(mapping, b'revcache').get(b'copies') or []
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   373
    return templateutil.compatfilecopiesdict(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   374
        context, mapping, b'file_copy', copies
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   375
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   376
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
   377
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   378
@templatekeyword(b'file_adds', requires={b'ctx', b'revcache'})
42393
b47e9712000b templatekw: move showfileadds() close to showfile{mods,dels}()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41790
diff changeset
   379
def showfileadds(context, mapping):
b47e9712000b templatekw: move showfileadds() close to showfile{mods,dels}()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41790
diff changeset
   380
    """List of strings. Files added by this changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   381
    ctx = context.resource(mapping, b'ctx')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   382
    return templateutil.compatfileslist(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   383
        context, mapping, b'file_add', ctx.filesadded()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   384
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   385
42393
b47e9712000b templatekw: move showfileadds() close to showfile{mods,dels}()
Martin von Zweigbergk <martinvonz@google.com>
parents: 41790
diff changeset
   386
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   387
@templatekeyword(b'file_dels', requires={b'ctx', b'revcache'})
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36619
diff changeset
   388
def showfiledels(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   389
    """List of strings. Files removed by this changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   390
    ctx = context.resource(mapping, b'ctx')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   391
    return templateutil.compatfileslist(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   392
        context, mapping, b'file_del', ctx.filesremoved()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   393
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   394
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   395
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   396
@templatekeyword(b'file_mods', requires={b'ctx', b'revcache'})
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36619
diff changeset
   397
def showfilemods(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   398
    """List of strings. Files modified by this changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   399
    ctx = context.resource(mapping, b'ctx')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   400
    return templateutil.compatfileslist(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   401
        context, mapping, b'file_mod', ctx.filesmodified()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   402
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   403
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   404
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   405
@templatekeyword(b'files', requires={b'ctx'})
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36619
diff changeset
   406
def showfiles(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   407
    """List of strings. All files modified, added, or removed by this
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   408
    changeset.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   409
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   410
    ctx = context.resource(mapping, b'ctx')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   411
    return templateutil.compatfileslist(context, mapping, b'file', ctx.files())
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   412
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   413
44379
14d0e89520a2 graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   414
@templatekeyword(b'graphnode', requires={b'repo', b'ctx', b'cache'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   415
def showgraphnode(context, mapping):
34656
eb7fffdc6e5b help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents: 34581
diff changeset
   416
    """String. The character representing the changeset node in an ASCII
eb7fffdc6e5b help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents: 34581
diff changeset
   417
    revision graph."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   418
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   419
    ctx = context.resource(mapping, b'ctx')
44379
14d0e89520a2 graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   420
    cache = context.resource(mapping, b'cache')
14d0e89520a2 graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   421
    return getgraphnode(repo, ctx, cache)
36542
6ad140dc4269 templatekw: extract non-templatekw function as getgraphnode()
Yuya Nishihara <yuya@tcha.org>
parents: 36531
diff changeset
   422
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   423
44379
14d0e89520a2 graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   424
def getgraphnode(repo, ctx, cache):
14d0e89520a2 graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   425
    return getgraphnodecurrent(repo, ctx, cache) or getgraphnodesymbol(ctx)
37952
8808d5d401ee templates: split getgraphnode() body into two functions
Anton Shestakov <av6@dwimlabs.net>
parents: 37707
diff changeset
   426
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   427
44379
14d0e89520a2 graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   428
def getgraphnodecurrent(repo, ctx, cache):
27215
5b8da5643a8a templatekw: avoid slow creation of changectx objects in showgraphnode()
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   429
    wpnodes = repo.dirstate.parents()
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
   430
    if wpnodes[1] == repo.nullid:
27215
5b8da5643a8a templatekw: avoid slow creation of changectx objects in showgraphnode()
Yuya Nishihara <yuya@tcha.org>
parents: 27214
diff changeset
   431
        wpnodes = wpnodes[:1]
27214
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
   432
    if ctx.node() in wpnodes:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   433
        return b'@'
37952
8808d5d401ee templates: split getgraphnode() body into two functions
Anton Shestakov <av6@dwimlabs.net>
parents: 37707
diff changeset
   434
    else:
44712
a825bfbf6642 templatekw: cache mergestate even if merge is not ongoing
Yuya Nishihara <yuya@tcha.org>
parents: 44597
diff changeset
   435
        merge_nodes = cache.get(b'merge_nodes')
a825bfbf6642 templatekw: cache mergestate even if merge is not ongoing
Yuya Nishihara <yuya@tcha.org>
parents: 44597
diff changeset
   436
        if merge_nodes is None:
44915
b7808443ed6a mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents: 44728
diff changeset
   437
            from . import mergestate as mergestatemod
44379
14d0e89520a2 graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   438
44915
b7808443ed6a mergestate: split out merge state handling code from main merge module
Augie Fackler <augie@google.com>
parents: 44728
diff changeset
   439
            mergestate = mergestatemod.mergestate.read(repo)
45459
85b03b1e4715 graphlog: use '%' only if there are *unresolved* conflicts
Martin von Zweigbergk <martinvonz@google.com>
parents: 44915
diff changeset
   440
            if mergestate.unresolvedcount():
44379
14d0e89520a2 graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   441
                merge_nodes = (mergestate.local, mergestate.other)
44712
a825bfbf6642 templatekw: cache mergestate even if merge is not ongoing
Yuya Nishihara <yuya@tcha.org>
parents: 44597
diff changeset
   442
            else:
a825bfbf6642 templatekw: cache mergestate even if merge is not ongoing
Yuya Nishihara <yuya@tcha.org>
parents: 44597
diff changeset
   443
                merge_nodes = ()
44379
14d0e89520a2 graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   444
            cache[b'merge_nodes'] = merge_nodes
14d0e89520a2 graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   445
14d0e89520a2 graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   446
        if ctx.node() in merge_nodes:
14d0e89520a2 graphlog: use '%' for other context in merge conflict
Martin von Zweigbergk <martinvonz@google.com>
parents: 43106
diff changeset
   447
            return b'%'
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   448
        return b''
37952
8808d5d401ee templates: split getgraphnode() body into two functions
Anton Shestakov <av6@dwimlabs.net>
parents: 37707
diff changeset
   449
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   450
37952
8808d5d401ee templates: split getgraphnode() body into two functions
Anton Shestakov <av6@dwimlabs.net>
parents: 37707
diff changeset
   451
def getgraphnodesymbol(ctx):
8808d5d401ee templates: split getgraphnode() body into two functions
Anton Shestakov <av6@dwimlabs.net>
parents: 37707
diff changeset
   452
    if ctx.obsolete():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   453
        return b'x'
35512
9b3f95d9783d graphlog: add another graph node type, unstable, using character "*" (BC)
Anton Shestakov <av6@dwimlabs.net>
parents: 35222
diff changeset
   454
    elif ctx.isunstable():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   455
        return b'*'
27214
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
   456
    elif ctx.closesbranch():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   457
        return b'_'
27214
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
   458
    else:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   459
        return b'o'
27214
60af96494a76 graphlog: extract "graphnode" template keyword that represents node symbol
Yuya Nishihara <yuya@tcha.org>
parents: 26486
diff changeset
   460
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   461
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   462
@templatekeyword(b'graphwidth', requires=())
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   463
def showgraphwidth(context, mapping):
33879
6f6c87888b22 log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents: 33872
diff changeset
   464
    """Integer. The width of the graph drawn by 'log --graph' or zero."""
36471
27cd83152d31 templatekw: simply override {graphwidth} function by mapping variable
Yuya Nishihara <yuya@tcha.org>
parents: 36431
diff changeset
   465
    # just hosts documentation; should be overridden by template mapping
27cd83152d31 templatekw: simply override {graphwidth} function by mapping variable
Yuya Nishihara <yuya@tcha.org>
parents: 36431
diff changeset
   466
    return 0
33879
6f6c87888b22 log: add a "graphwidth" template variable
Danny Hooper <hooper@google.com>
parents: 33872
diff changeset
   467
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   468
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   469
@templatekeyword(b'index', requires=())
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   470
def showindex(context, mapping):
31807
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31704
diff changeset
   471
    """Integer. The current iteration of the loop. (0 indexed)"""
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31704
diff changeset
   472
    # just hosts documentation; should be overridden by template mapping
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   473
    raise error.Abort(_(b"can't use index in this context"))
31807
e6eb86b154c5 templater: provide loop counter as "index" keyword
Yuya Nishihara <yuya@tcha.org>
parents: 31704
diff changeset
   474
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   475
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   476
@templatekeyword(b'latesttag', requires={b'repo', b'ctx', b'cache'})
36625
b5d39a09656a templatekw: switch latesttags template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36624
diff changeset
   477
def showlatesttag(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   478
    """List of strings. The global tags on the most recent globally
31850
f0d719e513fc templatekw: clarify the result of {latesttag} when no tag exists
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
   479
    tagged ancestor of this changeset.  If no such tags exist, the list
f0d719e513fc templatekw: clarify the result of {latesttag} when no tag exists
Matt Harbison <matt_harbison@yahoo.com>
parents: 31807
diff changeset
   480
    consists of the single string "null".
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   481
    """
36625
b5d39a09656a templatekw: switch latesttags template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36624
diff changeset
   482
    return showlatesttags(context, mapping, None)
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   483
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   484
36625
b5d39a09656a templatekw: switch latesttags template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36624
diff changeset
   485
def showlatesttags(context, mapping, pattern):
26484
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
   486
    """helper method for the latesttag keyword and function"""
36625
b5d39a09656a templatekw: switch latesttags template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36624
diff changeset
   487
    latesttags = getlatesttags(context, mapping, pattern)
26484
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
   488
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
   489
    # latesttag[0] is an implementation detail for sorting csets on different
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
   490
    # branches in a stable manner- it is the date the tagged cset was created,
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
   491
    # not the date the tag was created.  Therefore it isn't made visible here.
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
   492
    makemap = lambda v: {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   493
        b'changes': _showchangessincetag,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   494
        b'distance': latesttags[1],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   495
        b'latesttag': v,  # BC with {latesttag % '{latesttag}'}
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   496
        b'tag': v,
26484
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
   497
    }
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
   498
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
   499
    tags = latesttags[2]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   500
    f = _showcompatlist(context, mapping, b'latesttag', tags, separator=b':')
34335
dd28b1f55eb8 templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents: 34334
diff changeset
   501
    return _hybrid(f, tags, makemap, pycompat.identity)
26484
93c80e7ed8c8 templatekw: introduce showlatesttags() to handle {latesttag} keywords
Matt Harbison <matt_harbison@yahoo.com>
parents: 26483
diff changeset
   502
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   503
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   504
@templatekeyword(b'latesttagdistance', requires={b'repo', b'ctx', b'cache'})
36625
b5d39a09656a templatekw: switch latesttags template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36624
diff changeset
   505
def showlatesttagdistance(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   506
    """Integer. Longest path to the latest tag."""
36625
b5d39a09656a templatekw: switch latesttags template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36624
diff changeset
   507
    return getlatesttags(context, mapping)[1]
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   508
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   509
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   510
@templatekeyword(b'changessincelatesttag', requires={b'repo', b'ctx', b'cache'})
36625
b5d39a09656a templatekw: switch latesttags template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36624
diff changeset
   511
def showchangessincelatesttag(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   512
    """Integer. All ancestors not in the latest tag."""
37077
2891079fb0c0 templater: factor out function to create mapping dict for nested evaluation
Yuya Nishihara <yuya@tcha.org>
parents: 37074
diff changeset
   513
    tag = getlatesttags(context, mapping)[2][0]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   514
    mapping = context.overlaymap(mapping, {b'tag': tag})
36625
b5d39a09656a templatekw: switch latesttags template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36624
diff changeset
   515
    return _showchangessincetag(context, mapping)
26483
e94f93043a4e templatekw: factor out the changessincetag calculation to a private method
Matt Harbison <matt_harbison@yahoo.com>
parents: 26482
diff changeset
   516
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   517
36625
b5d39a09656a templatekw: switch latesttags template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36624
diff changeset
   518
def _showchangessincetag(context, mapping):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   519
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   520
    ctx = context.resource(mapping, b'ctx')
25724
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
   521
    offset = 0
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
   522
    revs = [ctx.rev()]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   523
    tag = context.symbol(mapping, b'tag')
25724
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
   524
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
   525
    # The only() revset doesn't currently support wdir()
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
   526
    if ctx.rev() is None:
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
   527
        offset = 1
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
   528
        revs = [p.rev() for p in ctx.parents()]
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
   529
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   530
    return len(repo.revs(b'only(%ld, %s)', revs, tag)) + offset
25724
4474a750413f templatekw: introduce the changessincelatesttag keyword
Matt Harbison <matt_harbison@yahoo.com>
parents: 25700
diff changeset
   531
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   532
36625
b5d39a09656a templatekw: switch latesttags template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36624
diff changeset
   533
# teach templater latesttags.changes is switched to (context, mapping) API
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   534
_showchangessincetag._requires = {b'repo', b'ctx'}
36625
b5d39a09656a templatekw: switch latesttags template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36624
diff changeset
   535
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   536
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   537
@templatekeyword(b'manifest', requires={b'repo', b'ctx'})
36626
d57f383516f6 templatekw: switch manifest template keyword to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36625
diff changeset
   538
def showmanifest(context, mapping):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   539
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   540
    ctx = context.resource(mapping, b'ctx')
24676
13c42a883e8b templatekw: have {manifest} use ctx.manifestnode() for consistency
Yuya Nishihara <yuya@tcha.org>
parents: 24337
diff changeset
   541
    mnode = ctx.manifestnode()
25736
8854ca3fa675 templatekw: apply manifest template only if ctx.manifestnode() exists
Yuya Nishihara <yuya@tcha.org>
parents: 25727
diff changeset
   542
    if mnode is None:
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
   543
        mnode = repo.nodeconstants.wdirid
39812
94ca3579e84e log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents: 39639
diff changeset
   544
        mrev = wdirrev
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
   545
        mhex = repo.nodeconstants.wdirhex
39812
94ca3579e84e log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents: 39639
diff changeset
   546
    else:
94ca3579e84e log: fill in pseudo rev and node as wdir() manifest identifiers
Yuya Nishihara <yuya@tcha.org>
parents: 39639
diff changeset
   547
        mrev = repo.manifestlog.rev(mnode)
47055
d55b71393907 node: replace nullid and friends with nodeconstants class
Joerg Sonnenberger <joerg@bec.de>
parents: 46819
diff changeset
   548
        mhex = hex(mnode)
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   549
    mapping = context.overlaymap(mapping, {b'rev': mrev, b'node': mhex})
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   550
    f = context.process(b'manifest', mapping)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   551
    return templateutil.hybriditem(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   552
        f, None, f, lambda x: {b'rev': mrev, b'node': mhex}
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   553
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   554
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   555
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   556
@templatekeyword(b'obsfate', requires={b'ui', b'repo', b'ctx'})
36623
59ee648870a7 templatekw: switch obsfate-related template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36622
diff changeset
   557
def showobsfate(context, mapping):
34847
e27f1f04c2cf templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents: 34657
diff changeset
   558
    # this function returns a list containing pre-formatted obsfate strings.
e27f1f04c2cf templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents: 34657
diff changeset
   559
    #
e27f1f04c2cf templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents: 34657
diff changeset
   560
    # This function will be replaced by templates fragments when we will have
e27f1f04c2cf templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents: 34657
diff changeset
   561
    # the verbosity templatekw available.
36623
59ee648870a7 templatekw: switch obsfate-related template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36622
diff changeset
   562
    succsandmarkers = showsuccsandmarkers(context, mapping)
34847
e27f1f04c2cf templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents: 34657
diff changeset
   563
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   564
    ui = context.resource(mapping, b'ui')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   565
    repo = context.resource(mapping, b'repo')
34847
e27f1f04c2cf templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents: 34657
diff changeset
   566
    values = []
e27f1f04c2cf templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents: 34657
diff changeset
   567
37503
49a8c2cc7978 templatekw: fix return type of {succsandmarkers} (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 37328
diff changeset
   568
    for x in succsandmarkers.tovalue(context, mapping):
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   569
        v = obsutil.obsfateprinter(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   570
            ui, repo, x[b'successors'], x[b'markers'], scmutil.formatchangeid
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   571
        )
37328
11d51e518808 obsutil: make obsfateprinter() less dependent on templater
Yuya Nishihara <yuya@tcha.org>
parents: 37276
diff changeset
   572
        values.append(v)
34847
e27f1f04c2cf templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents: 34657
diff changeset
   573
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   574
    return compatlist(context, mapping, b"fate", values)
34847
e27f1f04c2cf templatekw: introduce obsfate keyword
Boris Feld <boris.feld@octobus.net>
parents: 34657
diff changeset
   575
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   576
36622
900e5ee44307 templatekw: switch namespace template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
   577
def shownames(context, mapping, namespace):
27893
b42b2e86ef02 templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents: 27891
diff changeset
   578
    """helper method to generate a template keyword for a namespace"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   579
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   580
    ctx = context.resource(mapping, b'ctx')
44728
59ad165f6cdb templatekw: fix shownames() to check if namespace exists in repo (issue6301)
Yuya Nishihara <yuya@tcha.org>
parents: 44712
diff changeset
   581
    ns = repo.names.get(namespace)
59ad165f6cdb templatekw: fix shownames() to check if namespace exists in repo (issue6301)
Yuya Nishihara <yuya@tcha.org>
parents: 44712
diff changeset
   582
    if ns is None:
59ad165f6cdb templatekw: fix shownames() to check if namespace exists in repo (issue6301)
Yuya Nishihara <yuya@tcha.org>
parents: 44712
diff changeset
   583
        # namespaces.addnamespace() registers new template keyword, but
59ad165f6cdb templatekw: fix shownames() to check if namespace exists in repo (issue6301)
Yuya Nishihara <yuya@tcha.org>
parents: 44712
diff changeset
   584
        # the registered namespace might not exist in the current repo.
59ad165f6cdb templatekw: fix shownames() to check if namespace exists in repo (issue6301)
Yuya Nishihara <yuya@tcha.org>
parents: 44712
diff changeset
   585
        return
27893
b42b2e86ef02 templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents: 27891
diff changeset
   586
    names = ns.names(repo, ctx.node())
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   587
    return compatlist(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   588
        context, mapping, ns.templatename, names, plural=namespace
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   589
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   590
27893
b42b2e86ef02 templatekw: move shownames() helper to be sorted alphabetically
Yuya Nishihara <yuya@tcha.org>
parents: 27891
diff changeset
   591
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   592
@templatekeyword(b'namespaces', requires={b'repo', b'ctx'})
36622
900e5ee44307 templatekw: switch namespace template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
   593
def shownamespaces(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   594
    """Dict of lists. Names attached to this changeset per
27894
a94f7eef3199 templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 27893
diff changeset
   595
    namespace."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   596
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   597
    ctx = context.resource(mapping, b'ctx')
33059
de8e3681c402 templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33033
diff changeset
   598
de8e3681c402 templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33033
diff changeset
   599
    namespaces = util.sortdict()
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   600
34541
0a0a72c043ac templatekw: allow accessing to nested namespace item by its template name
Yuya Nishihara <yuya@tcha.org>
parents: 34540
diff changeset
   601
    def makensmapfn(ns):
0a0a72c043ac templatekw: allow accessing to nested namespace item by its template name
Yuya Nishihara <yuya@tcha.org>
parents: 34540
diff changeset
   602
        # 'name' for iterating over namespaces, templatename for local reference
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   603
        return lambda v: {b'name': v, ns.templatename: v}
33059
de8e3681c402 templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33033
diff changeset
   604
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
   605
    for k, ns in repo.names.items():
34541
0a0a72c043ac templatekw: allow accessing to nested namespace item by its template name
Yuya Nishihara <yuya@tcha.org>
parents: 34540
diff changeset
   606
        names = ns.names(repo, ctx.node())
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   607
        f = _showcompatlist(context, mapping, b'name', names)
34541
0a0a72c043ac templatekw: allow accessing to nested namespace item by its template name
Yuya Nishihara <yuya@tcha.org>
parents: 34540
diff changeset
   608
        namespaces[k] = _hybrid(f, names, makensmapfn(ns), pycompat.identity)
33059
de8e3681c402 templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33033
diff changeset
   609
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   610
    f = _showcompatlist(context, mapping, b'namespace', list(namespaces))
33059
de8e3681c402 templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33033
diff changeset
   611
de8e3681c402 templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33033
diff changeset
   612
    def makemap(ns):
de8e3681c402 templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33033
diff changeset
   613
        return {
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   614
            b'namespace': ns,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   615
            b'names': namespaces[ns],
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   616
            b'builtin': repo.names[ns].builtin,
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   617
            b'colorname': repo.names[ns].colorname,
33059
de8e3681c402 templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33033
diff changeset
   618
        }
de8e3681c402 templatekw: expose color name in {namespaces} entries
Gregory Szorc <gregory.szorc@gmail.com>
parents: 33033
diff changeset
   619
34335
dd28b1f55eb8 templatekw: just pass underlying value (or key) to joinfmt() function
Yuya Nishihara <yuya@tcha.org>
parents: 34334
diff changeset
   620
    return _hybrid(f, namespaces, makemap, pycompat.identity)
27894
a94f7eef3199 templatekw: add {namespaces} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 27893
diff changeset
   621
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   622
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   623
@templatekeyword(b'negrev', requires={b'repo', b'ctx'})
41733
37b33c34bf4f templatekw: add a {negrev} keyword
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 41419
diff changeset
   624
def shownegrev(context, mapping):
37b33c34bf4f templatekw: add a {negrev} keyword
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 41419
diff changeset
   625
    """Integer. The repository-local changeset negative revision number,
37b33c34bf4f templatekw: add a {negrev} keyword
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 41419
diff changeset
   626
    which counts in the opposite direction."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   627
    ctx = context.resource(mapping, b'ctx')
41737
36b62a522814 templatekw: make negrev return empty for wdir() and nullrev
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 41733
diff changeset
   628
    rev = ctx.rev()
36b62a522814 templatekw: make negrev return empty for wdir() and nullrev
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 41733
diff changeset
   629
    if rev is None or rev < 0:  # wdir() or nullrev?
36b62a522814 templatekw: make negrev return empty for wdir() and nullrev
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 41733
diff changeset
   630
        return None
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   631
    repo = context.resource(mapping, b'repo')
41737
36b62a522814 templatekw: make negrev return empty for wdir() and nullrev
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 41733
diff changeset
   632
    return rev - len(repo)
41733
37b33c34bf4f templatekw: add a {negrev} keyword
Jordi Gutiérrez Hermoso <jordigh@octave.org>
parents: 41419
diff changeset
   633
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   634
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   635
@templatekeyword(b'node', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   636
def shownode(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   637
    """String. The changeset identification hash, as a 40 hexadecimal
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   638
    digit string.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   639
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   640
    ctx = context.resource(mapping, b'ctx')
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   641
    return ctx.hex()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   642
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   643
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   644
@templatekeyword(b'obsolete', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   645
def showobsolete(context, mapping):
34657
bfb6fd93b637 help: hide template keywords of obsolescence as they are still experimental
Yuya Nishihara <yuya@tcha.org>
parents: 34656
diff changeset
   646
    """String. Whether the changeset is obsolete. (EXPERIMENTAL)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   647
    ctx = context.resource(mapping, b'ctx')
31704
568c4e7437b2 templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents: 31461
diff changeset
   648
    if ctx.obsolete():
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   649
        return b'obsolete'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   650
    return b''
31704
568c4e7437b2 templatekw: add an "obsolete" keyword
Denis Laxalde <denis@laxalde.org>
parents: 31461
diff changeset
   651
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   652
45883
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   653
@templatekeyword(b'onelinesummary', requires={b'ui', b'ctx'})
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   654
def showonelinesummary(context, mapping):
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   655
    """String. A one-line summary for the ctx (not including trailing newline).
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   656
    The default template be overridden in command-templates.oneline-summary."""
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   657
    # Avoid cycle:
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   658
    # mercurial.cmdutil -> mercurial.templatekw -> mercurial.cmdutil
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   659
    from . import cmdutil
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   660
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   661
    ui = context.resource(mapping, b'ui')
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   662
    ctx = context.resource(mapping, b'ctx')
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   663
    return cmdutil.format_changeset_summary(ui, ctx)
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   664
f67741e8264b templates: define a {onelinesummary} keyword
Martin von Zweigbergk <martinvonz@google.com>
parents: 45676
diff changeset
   665
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   666
@templatekeyword(b'path', requires={b'fctx'})
39398
3cd977d5a16b templatekw: add {path} keyword to host documentation
Yuya Nishihara <yuya@tcha.org>
parents: 39395
diff changeset
   667
def showpath(context, mapping):
3cd977d5a16b templatekw: add {path} keyword to host documentation
Yuya Nishihara <yuya@tcha.org>
parents: 39395
diff changeset
   668
    """String. Repository-absolute path of the current file. (EXPERIMENTAL)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   669
    fctx = context.resource(mapping, b'fctx')
39398
3cd977d5a16b templatekw: add {path} keyword to host documentation
Yuya Nishihara <yuya@tcha.org>
parents: 39395
diff changeset
   670
    return fctx.path()
3cd977d5a16b templatekw: add {path} keyword to host documentation
Yuya Nishihara <yuya@tcha.org>
parents: 39395
diff changeset
   671
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   672
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   673
@templatekeyword(b'peerurls', requires={b'repo'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   674
def showpeerurls(context, mapping):
33414
16ed67164002 templatekw: export ui.paths as {peerpaths}
Yuya Nishihara <yuya@tcha.org>
parents: 33276
diff changeset
   675
    """A dictionary of repository locations defined in the [paths] section
34539
f30e59703d98 templatekw: rename peerpaths to peerurls per naming convention (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 34538
diff changeset
   676
    of your configuration file."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   677
    repo = context.resource(mapping, b'repo')
33414
16ed67164002 templatekw: export ui.paths as {peerpaths}
Yuya Nishihara <yuya@tcha.org>
parents: 33276
diff changeset
   678
    # see commands.paths() for naming of dictionary keys
34538
ac38e889b33a templatekw: make experimental {peerpaths} return a single-level dict (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 34537
diff changeset
   679
    paths = repo.ui.paths
47073
6ce1af5f0764 template: use `list_paths` in `peerurls`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   680
    all_paths = urlutil.list_paths(repo.ui)
6ce1af5f0764 template: use `list_paths` in `peerurls`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47055
diff changeset
   681
    urls = util.sortdict((k, p.rawloc) for k, p in all_paths)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   682
34538
ac38e889b33a templatekw: make experimental {peerpaths} return a single-level dict (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 34537
diff changeset
   683
    def makemap(k):
47198
7531cc34713c urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47195
diff changeset
   684
        ps = paths[k]
7531cc34713c urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47195
diff changeset
   685
        d = {b'name': k}
7531cc34713c urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47195
diff changeset
   686
        if len(ps) == 1:
7531cc34713c urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47195
diff changeset
   687
            d[b'url'] = ps[0].rawloc
49021
e6df205a876c templatekw: remove pycompat.iteritems()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 49004
diff changeset
   688
            sub_opts = ps[0].suboptions.items()
47198
7531cc34713c urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47195
diff changeset
   689
            sub_opts = util.sortdict(sorted(sub_opts))
7531cc34713c urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47195
diff changeset
   690
            d.update(sub_opts)
47195
9c4d30b079e0 template: add a `paths` field to all entry in peerurls
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47074
diff changeset
   691
        path_dict = util.sortdict()
47198
7531cc34713c urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47195
diff changeset
   692
        for p in ps:
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
   693
            sub_opts = util.sortdict(sorted(p.suboptions.items()))
47198
7531cc34713c urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47195
diff changeset
   694
            path_dict[b'url'] = p.rawloc
7531cc34713c urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47195
diff changeset
   695
            path_dict.update(sub_opts)
7531cc34713c urlutil: make `paths` class old list of `path`
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47195
diff changeset
   696
            d[b'urls'] = [path_dict]
34538
ac38e889b33a templatekw: make experimental {peerpaths} return a single-level dict (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 34537
diff changeset
   697
        return d
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   698
47074
824ee4aaa09b template: make an explicit closure for formatting entry in peerurls
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47073
diff changeset
   699
    def format_one(k):
824ee4aaa09b template: make an explicit closure for formatting entry in peerurls
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47073
diff changeset
   700
        return b'%s=%s' % (k, urls[k])
824ee4aaa09b template: make an explicit closure for formatting entry in peerurls
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47073
diff changeset
   701
824ee4aaa09b template: make an explicit closure for formatting entry in peerurls
Pierre-Yves David <pierre-yves.david@octobus.net>
parents: 47073
diff changeset
   702
    return _hybrid(None, urls, makemap, format_one)
33414
16ed67164002 templatekw: export ui.paths as {peerpaths}
Yuya Nishihara <yuya@tcha.org>
parents: 33276
diff changeset
   703
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   704
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   705
@templatekeyword(b"predecessors", requires={b'repo', b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   706
def showpredecessors(context, mapping):
42452
dc5bd66a8270 doc: fix description of "predecessors" to match reality
Joerg Sonnenberger <joerg@bec.de>
parents: 42424
diff changeset
   707
    """Returns the list of the closest visible predecessors. (EXPERIMENTAL)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   708
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   709
    ctx = context.resource(mapping, b'ctx')
32897
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
   710
    predecessors = sorted(obsutil.closestpredecessors(repo, ctx.node()))
38315
523f64466a05 py3: fix map() use in templatekw.showpredecessors()
Yuya Nishihara <yuya@tcha.org>
parents: 38310
diff changeset
   711
    predecessors = pycompat.maplist(hex, predecessors)
32897
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
   712
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   713
    return _hybrid(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   714
        None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   715
        predecessors,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   716
        lambda x: {b'ctx': repo[x]},
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   717
        lambda x: scmutil.formatchangeid(repo[x]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   718
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   719
32897
1858fc2327ef template: add predecessors template
Boris Feld <boris.feld@octobus.net>
parents: 32678
diff changeset
   720
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   721
@templatekeyword(b'reporoot', requires={b'repo'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   722
def showreporoot(context, mapping):
36280
48a6b1a22ccf templatekw: add {reporoot} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 36148
diff changeset
   723
    """String. The root directory of the current repository."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   724
    repo = context.resource(mapping, b'repo')
36280
48a6b1a22ccf templatekw: add {reporoot} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 36148
diff changeset
   725
    return repo.root
48a6b1a22ccf templatekw: add {reporoot} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 36148
diff changeset
   726
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   727
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   728
@templatekeyword(b'size', requires={b'fctx'})
39603
918944f53aac templatekw: add {size} keyword as an example of fctx-based keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39398
diff changeset
   729
def showsize(context, mapping):
918944f53aac templatekw: add {size} keyword as an example of fctx-based keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39398
diff changeset
   730
    """Integer. Size of the current file in bytes. (EXPERIMENTAL)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   731
    fctx = context.resource(mapping, b'fctx')
39603
918944f53aac templatekw: add {size} keyword as an example of fctx-based keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39398
diff changeset
   732
    return fctx.size()
918944f53aac templatekw: add {size} keyword as an example of fctx-based keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39398
diff changeset
   733
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   734
39616
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   735
# requires 'fctx' to denote {status} depends on (ctx, path) pair
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   736
@templatekeyword(b'status', requires={b'ctx', b'fctx', b'revcache'})
39616
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   737
def showstatus(context, mapping):
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   738
    """String. Status code of the current file. (EXPERIMENTAL)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   739
    path = templateutil.runsymbol(context, mapping, b'path')
39616
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   740
    path = templateutil.stringify(context, mapping, path)
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   741
    if not path:
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   742
        return
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   743
    statmap = _getfilestatusmap(context, mapping)
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   744
    if path not in statmap:
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   745
        statmap = _getfilestatusmap(context, mapping, listall=True)
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   746
    return statmap.get(path)
87428152e820 templatekw: add experimental {status} keyword
Yuya Nishihara <yuya@tcha.org>
parents: 39615
diff changeset
   747
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   748
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   749
@templatekeyword(b"successorssets", requires={b'repo', b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   750
def showsuccessorssets(context, mapping):
34656
eb7fffdc6e5b help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents: 34581
diff changeset
   751
    """Returns a string of sets of successors for a changectx. Format used
40477
70e3e3da24be templatekw: fix documentation typos
Matt Harbison <matt_harbison@yahoo.com>
parents: 39812
diff changeset
   752
    is: [ctx1, ctx2], [ctx3] if ctx has been split into ctx1 and ctx2
34657
bfb6fd93b637 help: hide template keywords of obsolescence as they are still experimental
Yuya Nishihara <yuya@tcha.org>
parents: 34656
diff changeset
   753
    while also diverged into ctx3. (EXPERIMENTAL)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   754
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   755
    ctx = context.resource(mapping, b'ctx')
45676
f95b23283760 templatekw: make {successorssets} always return a list (issue6342)
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 45459
diff changeset
   756
    data = []
33276
89796a25d4bb template: add successors template
Boris Feld <boris.feld@octobus.net>
parents: 33060
diff changeset
   757
45676
f95b23283760 templatekw: make {successorssets} always return a list (issue6342)
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 45459
diff changeset
   758
    if ctx.obsolete():
f95b23283760 templatekw: make {successorssets} always return a list (issue6342)
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 45459
diff changeset
   759
        ssets = obsutil.successorssets(repo, ctx.node(), closest=True)
f95b23283760 templatekw: make {successorssets} always return a list (issue6342)
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 45459
diff changeset
   760
        ssets = [[hex(n) for n in ss] for ss in ssets]
33276
89796a25d4bb template: add successors template
Boris Feld <boris.feld@octobus.net>
parents: 33060
diff changeset
   761
45676
f95b23283760 templatekw: make {successorssets} always return a list (issue6342)
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 45459
diff changeset
   762
        for ss in ssets:
f95b23283760 templatekw: make {successorssets} always return a list (issue6342)
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 45459
diff changeset
   763
            h = _hybrid(
f95b23283760 templatekw: make {successorssets} always return a list (issue6342)
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 45459
diff changeset
   764
                None,
f95b23283760 templatekw: make {successorssets} always return a list (issue6342)
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 45459
diff changeset
   765
                ss,
f95b23283760 templatekw: make {successorssets} always return a list (issue6342)
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 45459
diff changeset
   766
                lambda x: {b'ctx': repo[x]},
f95b23283760 templatekw: make {successorssets} always return a list (issue6342)
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 45459
diff changeset
   767
                lambda x: scmutil.formatchangeid(repo[x]),
f95b23283760 templatekw: make {successorssets} always return a list (issue6342)
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 45459
diff changeset
   768
            )
f95b23283760 templatekw: make {successorssets} always return a list (issue6342)
Aay Jay Chan <aayjaychan@itopia.com.hk>
parents: 45459
diff changeset
   769
            data.append(h)
33276
89796a25d4bb template: add successors template
Boris Feld <boris.feld@octobus.net>
parents: 33060
diff changeset
   770
89796a25d4bb template: add successors template
Boris Feld <boris.feld@octobus.net>
parents: 33060
diff changeset
   771
    # Format the successorssets
89796a25d4bb template: add successors template
Boris Feld <boris.feld@octobus.net>
parents: 33060
diff changeset
   772
    def render(d):
37276
45987e2b64f0 templatekw: do not directly call .gen
Yuya Nishihara <yuya@tcha.org>
parents: 37106
diff changeset
   773
        return templateutil.stringify(context, mapping, d)
33276
89796a25d4bb template: add successors template
Boris Feld <boris.feld@octobus.net>
parents: 33060
diff changeset
   774
89796a25d4bb template: add successors template
Boris Feld <boris.feld@octobus.net>
parents: 33060
diff changeset
   775
    def gen(data):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   776
        yield b"; ".join(render(d) for d in data)
33276
89796a25d4bb template: add successors template
Boris Feld <boris.feld@octobus.net>
parents: 33060
diff changeset
   777
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   778
    return _hybrid(
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   779
        gen(data), data, lambda x: {b'successorset': x}, pycompat.identity
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   780
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   781
33276
89796a25d4bb template: add successors template
Boris Feld <boris.feld@octobus.net>
parents: 33060
diff changeset
   782
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   783
@templatekeyword(b"succsandmarkers", requires={b'repo', b'ctx'})
36623
59ee648870a7 templatekw: switch obsfate-related template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36622
diff changeset
   784
def showsuccsandmarkers(context, mapping):
34656
eb7fffdc6e5b help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents: 34581
diff changeset
   785
    """Returns a list of dict for each final successor of ctx. The dict
eb7fffdc6e5b help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents: 34581
diff changeset
   786
    contains successors node id in "successors" keys and the list of
eb7fffdc6e5b help: fix formatting of template keywords
Yuya Nishihara <yuya@tcha.org>
parents: 34581
diff changeset
   787
    obs-markers from ctx to the set of successors in "markers".
33930
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   788
    (EXPERIMENTAL)
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   789
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   790
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   791
    ctx = context.resource(mapping, b'ctx')
33930
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   792
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   793
    values = obsutil.successorsandmarkers(repo, ctx)
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   794
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   795
    if values is None:
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   796
        values = []
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   797
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   798
    # Format successors and markers to avoid exposing binary to templates
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   799
    data = []
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   800
    for i in values:
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   801
        # Format successors
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   802
        successors = i[b'successors']
33930
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   803
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   804
        successors = [hex(n) for n in successors]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   805
        successors = _hybrid(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   806
            None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   807
            successors,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   808
            lambda x: {b'ctx': repo[x]},
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   809
            lambda x: scmutil.formatchangeid(repo[x]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   810
        )
33930
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   811
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   812
        # Format markers
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   813
        finalmarkers = []
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   814
        for m in i[b'markers']:
33930
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   815
            hexprec = hex(m[0])
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   816
            hexsucs = tuple(hex(n) for n in m[1])
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   817
            hexparents = None
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   818
            if m[5] is not None:
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   819
                hexparents = tuple(hex(n) for n in m[5])
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   820
            newmarker = (hexprec, hexsucs) + m[2:5] + (hexparents,) + m[6:]
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   821
            finalmarkers.append(newmarker)
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   822
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   823
        data.append({b'successors': successors, b'markers': finalmarkers})
33930
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   824
37503
49a8c2cc7978 templatekw: fix return type of {succsandmarkers} (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 37328
diff changeset
   825
    return templateutil.mappinglist(data)
33930
e278d6d2d7d2 template: add minimal obsfate template function
Boris Feld <boris.feld@octobus.net>
parents: 33884
diff changeset
   826
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   827
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   828
@templatekeyword(b'p1', requires={b'ctx'})
40526
539efc88513b templatekw: add p1/p2 keywords which switches the current ctx
Yuya Nishihara <yuya@tcha.org>
parents: 40524
diff changeset
   829
def showp1(context, mapping):
539efc88513b templatekw: add p1/p2 keywords which switches the current ctx
Yuya Nishihara <yuya@tcha.org>
parents: 40524
diff changeset
   830
    """Changeset. The changeset's first parent. ``{p1.rev}`` for the revision
539efc88513b templatekw: add p1/p2 keywords which switches the current ctx
Yuya Nishihara <yuya@tcha.org>
parents: 40524
diff changeset
   831
    number, and ``{p1.node}`` for the identification hash."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   832
    ctx = context.resource(mapping, b'ctx')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   833
    return templateutil.mappingdict({b'ctx': ctx.p1()}, tmpl=_changeidtmpl)
40526
539efc88513b templatekw: add p1/p2 keywords which switches the current ctx
Yuya Nishihara <yuya@tcha.org>
parents: 40524
diff changeset
   834
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   835
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   836
@templatekeyword(b'p2', requires={b'ctx'})
40526
539efc88513b templatekw: add p1/p2 keywords which switches the current ctx
Yuya Nishihara <yuya@tcha.org>
parents: 40524
diff changeset
   837
def showp2(context, mapping):
539efc88513b templatekw: add p1/p2 keywords which switches the current ctx
Yuya Nishihara <yuya@tcha.org>
parents: 40524
diff changeset
   838
    """Changeset. The changeset's second parent. ``{p2.rev}`` for the revision
539efc88513b templatekw: add p1/p2 keywords which switches the current ctx
Yuya Nishihara <yuya@tcha.org>
parents: 40524
diff changeset
   839
    number, and ``{p2.node}`` for the identification hash."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   840
    ctx = context.resource(mapping, b'ctx')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   841
    return templateutil.mappingdict({b'ctx': ctx.p2()}, tmpl=_changeidtmpl)
40526
539efc88513b templatekw: add p1/p2 keywords which switches the current ctx
Yuya Nishihara <yuya@tcha.org>
parents: 40524
diff changeset
   842
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   843
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   844
@templatekeyword(b'p1rev', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   845
def showp1rev(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   846
    """Integer. The repository-local revision number of the changeset's
40527
592feb3f88b1 templatekw: deprecate p1rev/p2rev/p1node/p2node in favor of p1/p2
Yuya Nishihara <yuya@tcha.org>
parents: 40526
diff changeset
   847
    first parent, or -1 if the changeset has no parents. (DEPRECATED)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   848
    ctx = context.resource(mapping, b'ctx')
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
   849
    return ctx.p1().rev()
17355
c25531ed58b0 templatekw: add parent1, parent1node, parent2, parent2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
   850
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   851
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   852
@templatekeyword(b'p2rev', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   853
def showp2rev(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   854
    """Integer. The repository-local revision number of the changeset's
40527
592feb3f88b1 templatekw: deprecate p1rev/p2rev/p1node/p2node in favor of p1/p2
Yuya Nishihara <yuya@tcha.org>
parents: 40526
diff changeset
   855
    second parent, or -1 if the changeset has no second parent. (DEPRECATED)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   856
    ctx = context.resource(mapping, b'ctx')
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
   857
    return ctx.p2().rev()
17355
c25531ed58b0 templatekw: add parent1, parent1node, parent2, parent2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
   858
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   859
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   860
@templatekeyword(b'p1node', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   861
def showp1node(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   862
    """String. The identification hash of the changeset's first parent,
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
   863
    as a 40 digit hexadecimal string. If the changeset has no parents, all
40527
592feb3f88b1 templatekw: deprecate p1rev/p2rev/p1node/p2node in favor of p1/p2
Yuya Nishihara <yuya@tcha.org>
parents: 40526
diff changeset
   864
    digits are 0. (DEPRECATED)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   865
    ctx = context.resource(mapping, b'ctx')
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
   866
    return ctx.p1().hex()
17355
c25531ed58b0 templatekw: add parent1, parent1node, parent2, parent2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
   867
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   868
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   869
@templatekeyword(b'p2node', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   870
def showp2node(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   871
    """String. The identification hash of the changeset's second
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
   872
    parent, as a 40 digit hexadecimal string. If the changeset has no second
40527
592feb3f88b1 templatekw: deprecate p1rev/p2rev/p1node/p2node in favor of p1/p2
Yuya Nishihara <yuya@tcha.org>
parents: 40526
diff changeset
   873
    parent, all digits are 0. (DEPRECATED)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   874
    ctx = context.resource(mapping, b'ctx')
17357
bd605568c5a0 templatekw: add p1rev, p1node, p2rev, p2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
   875
    return ctx.p2().hex()
17355
c25531ed58b0 templatekw: add parent1, parent1node, parent2, parent2node keywords
epriestley <hg@yghe.net>
parents: 17187
diff changeset
   876
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   877
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   878
@templatekeyword(b'parents', requires={b'repo', b'ctx'})
36627
c3f9d0c303e8 templatekw: switch remainder of _showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36626
diff changeset
   879
def showparents(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   880
    """List of strings. The parents of the changeset in "rev:node"
26434
0a823de8d7b7 templatekw: reorder stub of showparents() function
Yuya Nishihara <yuya@tcha.org>
parents: 26234
diff changeset
   881
    format. If the changeset has only one "natural" parent (the predecessor
0a823de8d7b7 templatekw: reorder stub of showparents() function
Yuya Nishihara <yuya@tcha.org>
parents: 26234
diff changeset
   882
    revision) nothing is shown."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   883
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   884
    ctx = context.resource(mapping, b'ctx')
28270
650c9f69a744 templatekw: switch ctx of list expression to rev of {parents} (BC)
Yuya Nishihara <yuya@tcha.org>
parents: 28239
diff changeset
   885
    pctxs = scmutil.meaningfulparents(repo, ctx)
34581
ee0d74083a22 templater: store revisions as ints so min/max won't compare them as strings
Yuya Nishihara <yuya@tcha.org>
parents: 34541
diff changeset
   886
    prevs = [p.rev() for p in pctxs]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   887
    parents = [
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   888
        [(b'rev', p.rev()), (b'node', p.hex()), (b'phase', p.phasestr())]
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   889
        for p in pctxs
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   890
    ]
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   891
    f = _showcompatlist(context, mapping, b'parent', parents)
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   892
    return _hybrid(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   893
        f,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   894
        prevs,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   895
        lambda x: {b'ctx': repo[x]},
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   896
        lambda x: scmutil.formatchangeid(repo[x]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   897
        keytype=int,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   898
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   899
26434
0a823de8d7b7 templatekw: reorder stub of showparents() function
Yuya Nishihara <yuya@tcha.org>
parents: 26234
diff changeset
   900
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   901
@templatekeyword(b'phase', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   902
def showphase(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   903
    """String. The changeset phase name."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   904
    ctx = context.resource(mapping, b'ctx')
15823
a1f818a2b50d phases: ``{phase}`` template keyword display the phase name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15422
diff changeset
   905
    return ctx.phasestr()
a1f818a2b50d phases: ``{phase}`` template keyword display the phase name
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15422
diff changeset
   906
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   907
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   908
@templatekeyword(b'phaseidx', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   909
def showphaseidx(context, mapping):
35034
29e6513856ee help: hide phaseidx template keyword
Yuya Nishihara <yuya@tcha.org>
parents: 34847
diff changeset
   910
    """Integer. The changeset phase index. (ADVANCED)"""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   911
    ctx = context.resource(mapping, b'ctx')
15422
042e11c4e416 phases: add a phase template keyword
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15155
diff changeset
   912
    return ctx.phase()
042e11c4e416 phases: add a phase template keyword
Pierre-Yves David <pierre-yves.david@ens-lyon.org>
parents: 15155
diff changeset
   913
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   914
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   915
@templatekeyword(b'rev', requires={b'ctx'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   916
def showrev(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   917
    """Integer. The repository-local changeset revision number."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   918
    ctx = context.resource(mapping, b'ctx')
32676
4bec8cce6a09 scmutil: pass ctx object to intrev()
Yuya Nishihara <yuya@tcha.org>
parents: 32038
diff changeset
   919
    return scmutil.intrev(ctx)
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   920
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   921
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   922
@templatekeyword(b'subrepos', requires={b'ctx'})
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36619
diff changeset
   923
def showsubrepos(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   924
    """List of strings. Updated subrepositories in the changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   925
    ctx = context.resource(mapping, b'ctx')
21897
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
   926
    substate = ctx.substate
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
   927
    if not substate:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   928
        return compatlist(context, mapping, b'subrepo', [])
41419
0bd56c291359 cleanup: use p1() and p2() instead of parents()[0] and parents()[1]
Martin von Zweigbergk <martinvonz@google.com>
parents: 41300
diff changeset
   929
    psubstate = ctx.p1().substate or {}
21897
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
   930
    subrepos = []
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
   931
    for sub in substate:
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
   932
        if sub not in psubstate or substate[sub] != psubstate[sub]:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   933
            subrepos.append(sub)  # modified or newly added in ctx
21897
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
   934
    for sub in psubstate:
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
   935
        if sub not in substate:
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   936
            subrepos.append(sub)  # removed in ctx
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   937
    return compatlist(context, mapping, b'subrepo', sorted(subrepos))
21897
764adc332f6e templatekw: add 'subrepos' keyword to show updated subrepositories
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 21896
diff changeset
   938
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   939
23977
0870bb93573c templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23737
diff changeset
   940
# don't remove "showtags" definition, even though namespaces will put
0870bb93573c templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23737
diff changeset
   941
# a helper function for "tags" keyword into "keywords" map automatically,
0870bb93573c templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23737
diff changeset
   942
# because online help text is built without namespaces initialization
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   943
@templatekeyword(b'tags', requires={b'repo', b'ctx'})
36622
900e5ee44307 templatekw: switch namespace template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36620
diff changeset
   944
def showtags(context, mapping):
28539
119702a8b415 templatekw: use templatekeyword to mark a function as template keyword
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 28538
diff changeset
   945
    """List of strings. Any tags associated with the changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   946
    return shownames(context, mapping, b'tags')
23977
0870bb93573c templatekw: re-add showtags() to list tags keyword up in online help
FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
parents: 23737
diff changeset
   947
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   948
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   949
@templatekeyword(b'termwidth', requires={b'ui'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   950
def showtermwidth(context, mapping):
30088
d1f5f158768e template: provide a termwidth keyword (issue5395)
Simon Farnsworth <simonfar@fb.com>
parents: 29683
diff changeset
   951
    """Integer. The width of the current terminal."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   952
    ui = context.resource(mapping, b'ui')
36472
e46b24582fa0 templatekw: minimize resource dependency of {envvars} and {termwidth}
Yuya Nishihara <yuya@tcha.org>
parents: 36471
diff changeset
   953
    return ui.termwidth()
30088
d1f5f158768e template: provide a termwidth keyword (issue5395)
Simon Farnsworth <simonfar@fb.com>
parents: 29683
diff changeset
   954
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   955
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   956
@templatekeyword(b'user', requires={b'ctx'})
38986
390287321b4b templatekw: copy {author} to {user} and document {author} as an alias
Yuya Nishihara <yuya@tcha.org>
parents: 38815
diff changeset
   957
def showuser(context, mapping):
390287321b4b templatekw: copy {author} to {user} and document {author} as an alias
Yuya Nishihara <yuya@tcha.org>
parents: 38815
diff changeset
   958
    """String. The unmodified author of the changeset."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   959
    ctx = context.resource(mapping, b'ctx')
38986
390287321b4b templatekw: copy {author} to {user} and document {author} as an alias
Yuya Nishihara <yuya@tcha.org>
parents: 38815
diff changeset
   960
    return ctx.user()
390287321b4b templatekw: copy {author} to {user} and document {author} as an alias
Yuya Nishihara <yuya@tcha.org>
parents: 38815
diff changeset
   961
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   962
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   963
@templatekeyword(b'instabilities', requires={b'ctx'})
36620
121a20e5da56 templatekw: switch most of showlist template keywords to new API (issue5779)
Yuya Nishihara <yuya@tcha.org>
parents: 36619
diff changeset
   964
def showinstabilities(context, mapping):
33735
511d6ae462f3 template: rename troubles templatekw into instabilities
Boris Feld <boris.feld@octobus.net>
parents: 33476
diff changeset
   965
    """List of strings. Evolution instabilities affecting the changeset.
30712
5dde81de1e6d templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30385
diff changeset
   966
    (EXPERIMENTAL)
5dde81de1e6d templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30385
diff changeset
   967
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   968
    ctx = context.resource(mapping, b'ctx')
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   969
    return compatlist(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   970
        context,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   971
        mapping,
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   972
        b'instability',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   973
        ctx.instabilities(),
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   974
        plural=b'instabilities',
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   975
    )
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   976
30712
5dde81de1e6d templatekw: add a "troubles" template keyword
Denis Laxalde <denis.laxalde@logilab.fr>
parents: 30385
diff changeset
   977
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   978
@templatekeyword(b'verbosity', requires={b'ui'})
36543
7b74afec6772 templatekw: switch non-showlist template keywords to new API
Yuya Nishihara <yuya@tcha.org>
parents: 36542
diff changeset
   979
def showverbosity(context, mapping):
35036
625d5ebce066 templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents: 35035
diff changeset
   980
    """String. The current output verbosity in 'debug', 'quiet', 'verbose',
625d5ebce066 templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents: 35035
diff changeset
   981
    or ''."""
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   982
    ui = context.resource(mapping, b'ui')
35928
c8e2d6ed1f9e cmdutil: drop aliases for logcmdutil functions (API)
Yuya Nishihara <yuya@tcha.org>
parents: 35512
diff changeset
   983
    # see logcmdutil.changesettemplater for priority of these flags
35036
625d5ebce066 templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents: 35035
diff changeset
   984
    if ui.debugflag:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   985
        return b'debug'
35036
625d5ebce066 templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents: 35035
diff changeset
   986
    elif ui.quiet:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   987
        return b'quiet'
35036
625d5ebce066 templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents: 35035
diff changeset
   988
    elif ui.verbose:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   989
        return b'verbose'
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   990
    return b''
35036
625d5ebce066 templatekw: add verbosity keyword to select template by -q/-v/--debug flag
Yuya Nishihara <yuya@tcha.org>
parents: 35035
diff changeset
   991
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
   992
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   993
@templatekeyword(b'whyunstable', requires={b'repo', b'ctx'})
37685
76cd5816268e templates: add whyunstable template keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 37503
diff changeset
   994
def showwhyunstable(context, mapping):
76cd5816268e templates: add whyunstable template keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 37503
diff changeset
   995
    """List of dicts explaining all instabilities of a changeset.
76cd5816268e templates: add whyunstable template keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 37503
diff changeset
   996
    (EXPERIMENTAL)
76cd5816268e templates: add whyunstable template keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 37503
diff changeset
   997
    """
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   998
    repo = context.resource(mapping, b'repo')
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
   999
    ctx = context.resource(mapping, b'ctx')
37685
76cd5816268e templates: add whyunstable template keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 37503
diff changeset
  1000
76cd5816268e templates: add whyunstable template keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 37503
diff changeset
  1001
    def formatnode(ctx):
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1002
        return b'%s (%s)' % (scmutil.formatchangeid(ctx), ctx.phasestr())
37685
76cd5816268e templates: add whyunstable template keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 37503
diff changeset
  1003
76cd5816268e templates: add whyunstable template keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 37503
diff changeset
  1004
    entries = obsutil.whyunstable(repo, ctx)
76cd5816268e templates: add whyunstable template keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 37503
diff changeset
  1005
76cd5816268e templates: add whyunstable template keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 37503
diff changeset
  1006
    for entry in entries:
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1007
        if entry.get(b'divergentnodes'):
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1008
            dnodes = entry[b'divergentnodes']
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
  1009
            dnhybrid = _hybrid(
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
  1010
                None,
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
  1011
                [dnode.hex() for dnode in dnodes],
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1012
                lambda x: {b'ctx': repo[x]},
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
  1013
                lambda x: formatnode(repo[x]),
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
  1014
            )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1015
            entry[b'divergentnodes'] = dnhybrid
37685
76cd5816268e templates: add whyunstable template keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 37503
diff changeset
  1016
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
  1017
    tmpl = (
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1018
        b'{instability}:{if(divergentnodes, " ")}{divergentnodes} '
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1019
        b'{reason} {node|short}'
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
  1020
    )
43077
687b865b95ad formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents: 43076
diff changeset
  1021
    return templateutil.mappinglist(entries, tmpl=tmpl, sep=b'\n')
37685
76cd5816268e templates: add whyunstable template keyword
Anton Shestakov <av6@dwimlabs.net>
parents: 37503
diff changeset
  1022
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
  1023
35035
e2fc6cec0eff templatekw: move loadkeyword() to bottom
Yuya Nishihara <yuya@tcha.org>
parents: 35034
diff changeset
  1024
def loadkeyword(ui, extname, registrarobj):
45957
89a2afe31e82 formating: upgrade to black 20.8b1
Augie Fackler <raf@durin42.com>
parents: 45883
diff changeset
  1025
    """Load template keyword from specified registrarobj"""
49004
f254fc73d956 global: bulk replace simple pycompat.iteritems(x) with x.items()
Gregory Szorc <gregory.szorc@gmail.com>
parents: 48966
diff changeset
  1026
    for name, func in registrarobj._table.items():
35035
e2fc6cec0eff templatekw: move loadkeyword() to bottom
Yuya Nishihara <yuya@tcha.org>
parents: 35034
diff changeset
  1027
        keywords[name] = func
e2fc6cec0eff templatekw: move loadkeyword() to bottom
Yuya Nishihara <yuya@tcha.org>
parents: 35034
diff changeset
  1028
43076
2372284d9457 formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents: 42518
diff changeset
  1029
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
  1030
# tell hggettext to extract docstrings from these functions:
26436
a2291c9c85a1 templatekw: remove dockeywords hack
Yuya Nishihara <yuya@tcha.org>
parents: 26435
diff changeset
  1031
i18nfunctions = keywords.values()