mercurial/templatekw.py
author Patrick Mezard <pmezard@gmail.com>
Wed, 23 Dec 2009 19:31:48 +0100
changeset 10131 ef5b537433da
parent 10060 f780b1098efc
child 10260 fe699ca08a45
permissions -rw-r--r--
patch: drop unused hunk.newctrl()
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
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
     6
# GNU General Public License version 2, incorporated herein by reference.
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
10053
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    10
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    11
def showlist(templ, name, values, plural=None, **args):
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    12
    '''expand set of values.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    13
    name is name of key in template map.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    14
    values is list of strings or dicts.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    15
    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
    16
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    17
    expansion works like this, given name 'foo'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    18
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    19
    if values is empty, expand 'no_foos'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    20
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    21
    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
    22
    joined by space.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    23
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    24
    expand 'start_foos'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    25
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    26
    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
    27
    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
    28
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    29
    expand 'end_foos'.
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    30
    '''
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    31
    if plural: names = plural
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    32
    else: names = name + 's'
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    33
    if not values:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    34
        noname = 'no_' + names
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    35
        if noname in templ:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    36
            yield templ(noname, **args)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    37
        return
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    38
    if name not in templ:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    39
        if isinstance(values[0], str):
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    40
            yield ' '.join(values)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    41
        else:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    42
            for v in values:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    43
                yield dict(v, **args)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    44
        return
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    45
    startname = 'start_' + names
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    46
    if startname in templ:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    47
        yield templ(startname, **args)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    48
    vargs = args.copy()
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    49
    def one(v, tag=name):
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    50
        try:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    51
            vargs.update(v)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    52
        except (AttributeError, ValueError):
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
                for a, b in v:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    55
                    vargs[a] = b
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    56
            except ValueError:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    57
                vargs[name] = v
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    58
        return templ(tag, **vargs)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    59
    lastname = 'last_' + name
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    60
    if lastname in templ:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    61
        last = values.pop()
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    62
    else:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    63
        last = None
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    64
    for v in values:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    65
        yield one(v)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    66
    if last is not None:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    67
        yield one(last, tag=lastname)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    68
    endname = 'end_' + names
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    69
    if endname in templ:
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    70
        yield templ(endname, **args)
5c5c6295533d cmdutil: replace showlist() closure with a function
Patrick Mezard <pmezard@gmail.com>
parents:
diff changeset
    71
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
    72
def getfiles(repo, ctx, revcache):
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
    73
    if 'files' not in revcache:
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
    74
        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
    75
                                        ctx.node())[:3]
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
    76
    return revcache['files']
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
    77
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    78
def getlatesttags(repo, ctx, cache):
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    79
    '''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
    80
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    81
    if 'latesttags' not in cache:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    82
        # 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
    83
        # distance and tag name
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    84
        cache['latesttags'] = {-1: (0, 0, 'null')}
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    85
    latesttags = cache['latesttags']
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    86
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    87
    rev = ctx.rev()
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    88
    todo = [rev]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    89
    while todo:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    90
        rev = todo.pop()
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    91
        if rev in latesttags:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    92
            continue
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    93
        ctx = repo[rev]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    94
        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
    95
        if tags:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    96
            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
    97
            continue
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    98
        try:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
    99
            # 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
   100
            # comparison.
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   101
            pdate, pdist, ptag = max(
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   102
                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
   103
        except KeyError:
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   104
            # Cache miss - recurse
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   105
            todo.append(rev)
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   106
            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
   107
            continue
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   108
        latesttags[rev] = pdate, pdist + 1, ptag
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   109
    return latesttags[rev]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   110
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   111
def getrenamedfn(repo, endrev=None):
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   112
    rcache = {}
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   113
    if endrev is None:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   114
        endrev = len(repo)
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   115
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   116
    def getrenamed(fn, rev):
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   117
        '''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
   118
        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
   119
        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
   120
        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
   121
        if fn not in rcache:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   122
            rcache[fn] = {}
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   123
            fl = repo.file(fn)
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   124
            for i in fl:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   125
                lr = fl.linkrev(i)
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   126
                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
   127
                rcache[fn][lr] = renamed
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   128
                if lr >= endrev:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   129
                    break
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   130
        if rev in rcache[fn]:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   131
            return rcache[fn][rev]
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   132
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   133
        # 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
   134
        # filectx logic.
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   135
        try:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   136
            return repo[rev][fn].renamed()
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   137
        except error.LookupError:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   138
            return None
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   139
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   140
    return getrenamed
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   141
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   142
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   143
def showauthor(repo, ctx, templ, **args):
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   144
    return ctx.user()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   145
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   146
def showbranches(repo, ctx, templ, **args):
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   147
    branch = ctx.branch()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   148
    if branch != 'default':
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   149
        branch = encoding.tolocal(branch)
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   150
        return showlist(templ, 'branch', [branch], plural='branches', **args)
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   151
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   152
def showdate(repo, ctx, templ, **args):
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   153
    return ctx.date()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   154
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   155
def showdescription(repo, ctx, templ, **args):
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   156
    return ctx.description().strip()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   157
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   158
def showdiffstat(repo, ctx, templ, **args):
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   159
    diff = patch.diff(repo, ctx.parents()[0].node(), ctx.node())
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   160
    files, adds, removes = 0, 0, 0
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   161
    for i in patch.diffstatdata(util.iterlines(diff)):
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   162
        files += 1
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   163
        adds += i[1]
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   164
        removes += i[2]
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   165
    return '%s: +%s/-%s' % (files, adds, removes)
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   166
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   167
def showextras(repo, ctx, templ, **args):
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   168
    for key, value in sorted(ctx.extra().items()):
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   169
        args = args.copy()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   170
        args.update(dict(key=key, value=value))
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   171
        yield templ('extra', **args)
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   172
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   173
def showfileadds(repo, ctx, templ, revcache, **args):
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   174
    return showlist(templ, 'file_add', getfiles(repo, ctx, revcache)[1], **args)
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   175
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   176
def showfilecopies(repo, ctx, templ, cache, revcache, **args):
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   177
    copies = revcache.get('copies')
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   178
    if copies is None:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   179
        if 'getrenamed' not in cache:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   180
            cache['getrenamed'] = getrenamedfn(repo)
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   181
        copies = []
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   182
        getrenamed = cache['getrenamed']
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   183
        for fn in ctx.files():
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   184
            rename = getrenamed(fn, ctx.rev())
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   185
            if rename:
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   186
                copies.append((fn, rename[0]))
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   187
            
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   188
    c = [{'name': x[0], 'source': x[1]} for x in copies]
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   189
    return showlist(templ, 'file_copy', c, plural='file_copies', **args)
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   190
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   191
# 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
   192
# 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
   193
# command line switch.
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   194
def showfilecopiesswitch(repo, ctx, templ, cache, revcache, **args):
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   195
    copies = revcache.get('copies') or []
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   196
    c = [{'name': x[0], 'source': x[1]} for x in copies]
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
   197
    return showlist(templ, 'file_copy', c, plural='file_copies', **args)
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
   198
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   199
def showfiledels(repo, ctx, templ, revcache, **args):
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   200
    return showlist(templ, 'file_del', getfiles(repo, ctx, revcache)[2], **args)
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   201
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   202
def showfilemods(repo, ctx, templ, revcache, **args):
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   203
    return showlist(templ, 'file_mod', getfiles(repo, ctx, revcache)[0], **args)
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   204
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   205
def showfiles(repo, ctx, templ, **args):
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   206
    return showlist(templ, 'file', ctx.files(), **args)
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   207
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   208
def showlatesttag(repo, ctx, templ, cache, **args):
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   209
    return getlatesttags(repo, ctx, cache)[2]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   210
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   211
def showlatesttagdistance(repo, ctx, templ, cache, **args):
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   212
    return getlatesttags(repo, ctx, cache)[1]
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   213
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   214
def showmanifest(repo, ctx, templ, **args):
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   215
    args = args.copy()
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   216
    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
   217
                     node=hex(ctx.changeset()[0])))
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   218
    return templ('manifest', **args)
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   219
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   220
def shownode(repo, ctx, templ, **args):
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   221
    return ctx.hex()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   222
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   223
def showrev(repo, ctx, templ, **args):
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   224
    return ctx.rev()
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   225
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   226
def showtags(repo, ctx, templ, **args):
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   227
    return showlist(templ, 'tag', ctx.tags(), **args)
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   228
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   229
keywords = {
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   230
    'author': showauthor,
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   231
    'branches': showbranches,
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   232
    'date': showdate,
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   233
    'desc': showdescription,
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   234
    'diffstat': showdiffstat,
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   235
    'extras': showextras,
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   236
    'file_adds': showfileadds,
10058
c829563b3118 cmdutil: extract file copies closure into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10057
diff changeset
   237
    'file_copies': showfilecopies,
10060
f780b1098efc templatekw: change {file_copies} behaviour, add {file_copies_switch}
Patrick Mezard <pmezard@gmail.com>
parents: 10058
diff changeset
   238
    'file_copies_switch': showfilecopiesswitch,
10056
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   239
    'file_dels': showfiledels,
1a114aca93fa cmdutil: extract file changes closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10055
diff changeset
   240
    'file_mods': showfilemods,
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   241
    'files': showfiles,
10057
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   242
    'latesttag': showlatesttag,
babc00a82c5e cmdutil: extract latest tags closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10056
diff changeset
   243
    'latesttagdistance': showlatesttagdistance,
10055
e400a511e63a cmdutil: extract repo dependent closures in templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10054
diff changeset
   244
    'manifest': showmanifest,
10054
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   245
    'node': shownode,
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   246
    'rev': showrev,
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   247
    'tags': showtags,
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   248
}
1a85861f59af cmdutil: extract ctx dependent closures into templatekw
Patrick Mezard <pmezard@gmail.com>
parents: 10053
diff changeset
   249