mercurial/templatekw.py
author Patrick Mezard <pmezard@gmail.com>
Sat, 12 Mar 2011 12:46:31 +0100
changeset 13585 2e80d495592a
parent 13386 f78bc5ddbe4f
child 13592 ad2ee188f4a5
permissions -rw-r--r--
templates: generate keyword help dynamically
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
#
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     3
# Copyright 2005-2009 Matt Mackall <mpm@selenic.com>
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
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
     8
from node import hex
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
     9
import encoding, patch, util, error
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
    10
from i18n import gettext
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    11
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
    12
def showlist(name, values, plural=None, **args):
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    13
    '''expand set of values.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    14
    name is name of key in template map.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    15
    values is list of strings or dicts.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    16
    plural is plural of name, if not simply name + 's'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    17
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    18
    expansion works like this, given name 'foo'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    19
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    20
    if values is empty, expand 'no_foos'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    21
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    22
    if 'foo' not in template map, return values as a string,
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    23
    joined by space.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    24
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    25
    expand 'start_foos'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    26
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    27
    for each value, expand 'foo'. if 'last_foo' in template
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    28
    map, expand it instead of 'foo' for last key.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    29
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    30
    expand 'end_foos'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    31
    '''
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
    32
    templ = args['templ']
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
    33
    if plural:
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
    34
        names = plural
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    35
    else: names = name + 's'
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    36
    if not values:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    37
        noname = 'no_' + names
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    38
        if noname in templ:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    39
            yield templ(noname, **args)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    40
        return
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    41
    if name not in templ:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    42
        if isinstance(values[0], str):
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    43
            yield ' '.join(values)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    44
        else:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    45
            for v in values:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    46
                yield dict(v, **args)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    47
        return
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    48
    startname = 'start_' + names
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    49
    if startname in templ:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    50
        yield templ(startname, **args)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    51
    vargs = args.copy()
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    52
    def one(v, tag=name):
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    53
        try:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    54
            vargs.update(v)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    55
        except (AttributeError, ValueError):
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    56
            try:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    57
                for a, b in v:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    58
                    vargs[a] = b
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    59
            except ValueError:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    60
                vargs[name] = v
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    61
        return templ(tag, **vargs)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    62
    lastname = 'last_' + name
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    63
    if lastname in templ:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    64
        last = values.pop()
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    65
    else:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    66
        last = None
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    67
    for v in values:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    68
        yield one(v)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    69
    if last is not None:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    70
        yield one(last, tag=lastname)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    71
    endname = 'end_' + names
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    72
    if endname in templ:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    73
        yield templ(endname, **args)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    74
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
    75
def getfiles(repo, ctx, revcache):
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
    76
    if 'files' not in revcache:
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
    77
        revcache['files'] = repo.status(ctx.parents()[0].node(),
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
    78
                                        ctx.node())[:3]
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
    79
    return revcache['files']
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
    80
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    81
def getlatesttags(repo, ctx, cache):
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    82
    '''return date, distance and name for the latest tag of rev'''
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    83
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    84
    if 'latesttags' not in cache:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    85
        # 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
    86
        # distance and tag name
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    87
        cache['latesttags'] = {-1: (0, 0, 'null')}
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    88
    latesttags = cache['latesttags']
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    89
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    90
    rev = ctx.rev()
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    91
    todo = [rev]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    92
    while todo:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    93
        rev = todo.pop()
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    94
        if rev in latesttags:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    95
            continue
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    96
        ctx = repo[rev]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    97
        tags = [t for t in ctx.tags() if repo.tagtype(t) == 'global']
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    98
        if tags:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    99
            latesttags[rev] = ctx.date()[0], 0, ':'.join(sorted(tags))
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   100
            continue
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   101
        try:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   102
            # The tuples are laid out so the right one can be found by
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   103
            # comparison.
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   104
            pdate, pdist, ptag = max(
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   105
                latesttags[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
        except KeyError:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   107
            # Cache miss - recurse
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   108
            todo.append(rev)
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   109
            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
   110
            continue
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   111
        latesttags[rev] = pdate, pdist + 1, ptag
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   112
    return latesttags[rev]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   113
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   114
def getrenamedfn(repo, endrev=None):
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   115
    rcache = {}
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   116
    if endrev is None:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   117
        endrev = len(repo)
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   118
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   119
    def getrenamed(fn, rev):
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   120
        '''looks up all renames for a file (up to endrev) the first
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   121
        time the file is given. It indexes on the changerev and only
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   122
        parses the manifest if linkrev != changerev.
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   123
        Returns rename info for fn at changerev rev.'''
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   124
        if fn not in rcache:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   125
            rcache[fn] = {}
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   126
            fl = repo.file(fn)
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   127
            for i in fl:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   128
                lr = fl.linkrev(i)
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   129
                renamed = fl.renamed(fl.node(i))
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   130
                rcache[fn][lr] = renamed
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   131
                if lr >= endrev:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   132
                    break
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   133
        if rev in rcache[fn]:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   134
            return rcache[fn][rev]
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   135
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   136
        # If linkrev != rev (i.e. rev not found in rcache) fallback to
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   137
        # filectx logic.
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   138
        try:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   139
            return repo[rev][fn].renamed()
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   140
        except error.LookupError:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   141
            return None
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   142
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   143
    return getrenamed
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   144
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   145
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   146
def showauthor(repo, ctx, templ, **args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   147
    """:author: String. The unmodified author of the changeset."""
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   148
    return ctx.user()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   149
13156
d79fdff55627 template: add showbranch template for {branch}
Eric Eisner <ede@mit.edu>
parents: 13114
diff changeset
   150
def showbranch(**args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   151
    """:branch: String. The name of the branch on which the changeset was
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   152
    committed.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   153
    """
13156
d79fdff55627 template: add showbranch template for {branch}
Eric Eisner <ede@mit.edu>
parents: 13114
diff changeset
   154
    return args['ctx'].branch()
d79fdff55627 template: add showbranch template for {branch}
Eric Eisner <ede@mit.edu>
parents: 13114
diff changeset
   155
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   156
def showbranches(**args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   157
    """:branches: List of strings. The name of the branch on which the
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   158
    changeset was committed. Will be empty if the branch name was
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   159
    default.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   160
    """
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   161
    branch = args['ctx'].branch()
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   162
    if branch != 'default':
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   163
        return showlist('branch', [branch], plural='branches', **args)
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   164
13386
f78bc5ddbe4f templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents: 13156
diff changeset
   165
def showbookmarks(**args):
f78bc5ddbe4f templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents: 13156
diff changeset
   166
    bookmarks = args['ctx'].bookmarks()
f78bc5ddbe4f templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents: 13156
diff changeset
   167
    return showlist('bookmark', bookmarks, **args)
f78bc5ddbe4f templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents: 13156
diff changeset
   168
11655
6faf015e0ba0 templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents: 10394
diff changeset
   169
def showchildren(**args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   170
    """:children: List of strings. The children of the changeset."""
11655
6faf015e0ba0 templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents: 10394
diff changeset
   171
    ctx = args['ctx']
6faf015e0ba0 templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents: 10394
diff changeset
   172
    childrevs = ['%d:%s' % (cctx, cctx) for cctx in ctx.children()]
6faf015e0ba0 templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents: 10394
diff changeset
   173
    return showlist('children', childrevs, **args)
6faf015e0ba0 templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents: 10394
diff changeset
   174
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   175
def showdate(repo, ctx, templ, **args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   176
    """:date: Date information. The date when the changeset was committed."""
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   177
    return ctx.date()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   178
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   179
def showdescription(repo, ctx, templ, **args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   180
    """:desc: String. The text of the changeset description."""
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   181
    return ctx.description().strip()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   182
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   183
def showdiffstat(repo, ctx, templ, **args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   184
    """:diffstat: String. Statistics of changes with the following format:
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   185
    "modified files: +added/-removed lines"
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   186
    """
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   187
    files, adds, removes = 0, 0, 0
13114
8f29a08e7bbc templatekw.showdiffstat: use ctx.diff() instead of calling patch
Alexander Solovyov <alexander@solovyov.net>
parents: 13047
diff changeset
   188
    for i in patch.diffstatdata(util.iterlines(ctx.diff())):
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   189
        files += 1
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   190
        adds += i[1]
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   191
        removes += i[2]
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   192
    return '%s: +%s/-%s' % (files, adds, removes)
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   193
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   194
def showextras(**args):
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   195
    templ = args['templ']
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   196
    for key, value in sorted(args['ctx'].extra().items()):
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   197
        args = args.copy()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   198
        args.update(dict(key=key, value=value))
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   199
        yield templ('extra', **args)
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   200
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   201
def showfileadds(**args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   202
    """:file_adds: List of strings. Files added by this changeset."""
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   203
    repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   204
    return showlist('file_add', getfiles(repo, ctx, revcache)[1], **args)
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   205
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   206
def showfilecopies(**args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   207
    """:file_copies: List of strings. Files copied in this changeset with
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   208
    their sources.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   209
    """
10394
4612cded5176 fix coding style (reported by pylint)
Benoit Boissinot <benoit.boissinot@ens-lyon.org>
parents: 10282
diff changeset
   210
    cache, ctx = args['cache'], args['ctx']
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   211
    copies = args['revcache'].get('copies')
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   212
    if copies is None:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   213
        if 'getrenamed' not in cache:
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   214
            cache['getrenamed'] = getrenamedfn(args['repo'])
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   215
        copies = []
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   216
        getrenamed = cache['getrenamed']
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   217
        for fn in ctx.files():
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   218
            rename = getrenamed(fn, ctx.rev())
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   219
            if rename:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   220
                copies.append((fn, rename[0]))
10282
08a0f04b56bd many, many trivial check-code fixups
Matt Mackall <mpm@selenic.com>
parents: 10264
diff changeset
   221
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   222
    c = [{'name': x[0], 'source': x[1]} for x in copies]
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   223
    return showlist('file_copy', c, plural='file_copies', **args)
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   224
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   225
# 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
   226
# 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
   227
# command line switch.
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   228
def showfilecopiesswitch(**args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   229
    """:file_copies_switch: List of strings. Like "file_copies" but displayed
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   230
    only if the --copied switch is set.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   231
    """
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   232
    copies = args['revcache'].get('copies') or []
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   233
    c = [{'name': x[0], 'source': x[1]} for x in copies]
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   234
    return showlist('file_copy', c, plural='file_copies', **args)
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
   235
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   236
def showfiledels(**args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   237
    """:file_dels: List of strings. Files removed by this changeset."""
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   238
    repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   239
    return showlist('file_del', getfiles(repo, ctx, revcache)[2], **args)
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   240
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   241
def showfilemods(**args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   242
    """:file_mods: List of strings. Files modified by this changeset."""
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   243
    repo, ctx, revcache = args['repo'], args['ctx'], args['revcache']
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   244
    return showlist('file_mod', getfiles(repo, ctx, revcache)[0], **args)
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   245
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   246
def showfiles(**args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   247
    """:files: List of strings. All files modified, added, or removed by this
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   248
    changeset.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   249
    """
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   250
    return showlist('file', args['ctx'].files(), **args)
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   251
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   252
def showlatesttag(repo, ctx, templ, cache, **args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   253
    """:latesttag: String. Most recent global tag in the ancestors of this
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   254
    changeset.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   255
    """
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   256
    return getlatesttags(repo, ctx, cache)[2]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   257
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   258
def showlatesttagdistance(repo, ctx, templ, cache, **args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   259
    """:latesttagdistance: Integer. Longest path to the latest tag."""
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   260
    return getlatesttags(repo, ctx, cache)[1]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   261
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   262
def showmanifest(**args):
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   263
    repo, ctx, templ = args['repo'], args['ctx'], args['templ']
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   264
    args = args.copy()
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   265
    args.update(dict(rev=repo.manifest.rev(ctx.changeset()[0]),
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   266
                     node=hex(ctx.changeset()[0])))
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   267
    return templ('manifest', **args)
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   268
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   269
def shownode(repo, ctx, templ, **args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   270
    """:node: String. The changeset identification hash, as a 40 hexadecimal
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   271
    digit string.
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   272
    """
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   273
    return ctx.hex()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   274
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   275
def showrev(repo, ctx, templ, **args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   276
    """:rev: Integer. The repository-local changeset revision number."""
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   277
    return ctx.rev()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   278
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   279
def showtags(**args):
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   280
    """:tags: List of strings. Any tags associated with the changeset."""
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   281
    return showlist('tag', args['ctx'].tags(), **args)
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   282
10260
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   283
# keywords are callables like:
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   284
# fn(repo, ctx, templ, cache, revcache, **args)
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   285
# with:
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   286
# repo - current repository instance
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   287
# ctx - the changectx being displayed
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   288
# templ - the templater instance
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   289
# cache - a cache dictionary for the whole templater run
fe699ca08a45 templatekw: fix extras, manifest and showlist args (issue1989)
Patrick Mezard <pmezard@gmail.com>
parents: 10060
diff changeset
   290
# revcache - a cache dictionary for the current revision
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   291
keywords = {
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   292
    'author': showauthor,
13156
d79fdff55627 template: add showbranch template for {branch}
Eric Eisner <ede@mit.edu>
parents: 13114
diff changeset
   293
    'branch': showbranch,
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   294
    'branches': showbranches,
13386
f78bc5ddbe4f templater: add bookmarks to templates and default output
David Soria Parra <dsp@php.net>
parents: 13156
diff changeset
   295
    'bookmarks': showbookmarks,
11655
6faf015e0ba0 templates: 'children' keyword
Jason Harris <jason@jasonfharris.com>
parents: 10394
diff changeset
   296
    'children': showchildren,
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   297
    'date': showdate,
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   298
    'desc': showdescription,
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   299
    'diffstat': showdiffstat,
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   300
    'extras': showextras,
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   301
    'file_adds': showfileadds,
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
   302
    'file_copies': showfilecopies,
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   303
    'file_copies_switch': showfilecopiesswitch,
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   304
    'file_dels': showfiledels,
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   305
    'file_mods': showfilemods,
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   306
    'files': showfiles,
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   307
    'latesttag': showlatesttag,
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   308
    'latesttagdistance': showlatesttagdistance,
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   309
    'manifest': showmanifest,
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   310
    'node': shownode,
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   311
    'rev': showrev,
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   312
    'tags': showtags,
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   313
}
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   314
13585
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   315
def makedoc(topic, doc):
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   316
    """Generate and include keyword help in templating topic."""
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   317
    kw = []
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   318
    for name in sorted(keywords):
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   319
        text = (keywords[name].__doc__ or '').rstrip()
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   320
        if not text:
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   321
            continue
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   322
        text = gettext(text)
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   323
        lines = text.splitlines()
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   324
        lines[1:] = [('  ' + l.strip()) for l in lines[1:]]
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   325
        kw.append('\n'.join(lines))
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   326
    kw = '\n\n'.join(kw)
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   327
    doc = doc.replace('.. keywordsmarker', kw)
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   328
    return doc
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   329
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   330
# tell hggettext to extract docstrings from these functions:
2e80d495592a templates: generate keyword help dynamically
Patrick Mezard <pmezard@gmail.com>
parents: 13386
diff changeset
   331
i18nfunctions = keywords.values()