hgext/keyword.py
author Christian Ebert <blacktrash@gmx.net>
Mon, 04 Feb 2008 18:27:36 +0100
changeset 6021 717881b400b3
parent 5976 9f1e6ab76069
child 6022 e5b5010ff7da
permissions -rw-r--r--
keyword: allow keyword expansion on clone If [keyword] filename patterns are specified in a global hgrc keywords will be expanded in clone. This behaviour is more consistent but also more dangerous. Specifying global, and thus more complicted, [keyword] patterns might slow things down as well. Mention this in help?
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     1
# keyword.py - $Keyword$ expansion for Mercurial
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     2
#
5831
4a40b7066525 keyword: fix some doc strings; update copyright
Christian Ebert <blacktrash@gmx.net>
parents: 5825
diff changeset
     3
# Copyright 2007, 2008 Christian Ebert <blacktrash@gmx.net>
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     4
#
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     5
# This software may be used and distributed according to the terms
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     6
# of the GNU General Public License, incorporated herein by reference.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     7
#
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     8
# $Id$
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
     9
#
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    10
# Keyword expansion hack against the grain of a DSCM
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    11
#
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    12
# There are many good reasons why this is not needed in a distributed
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    13
# SCM, still it may be useful in very small projects based on single
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    14
# files (like LaTeX packages), that are mostly addressed to an audience
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    15
# not running a version control system.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    16
#
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    17
# For in-depth discussion refer to
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    18
# <http://www.selenic.com/mercurial/wiki/index.cgi/KeywordPlan>.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    19
#
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    20
# Keyword expansion is based on Mercurial's changeset template mappings.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    21
#
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    22
# Binary files are not touched.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    23
#
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    24
# Setup in hgrc:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    25
#
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    26
#   [extensions]
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    27
#   # enable extension
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    28
#   hgext.keyword =
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    29
#
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    30
# Files to act upon/ignore are specified in the [keyword] section.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    31
# Customized keyword template mappings in the [keywordmaps] section.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    32
#
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    33
# Run "hg help keyword" and "hg kwdemo" to get info on configuration.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    34
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    35
'''keyword expansion in local repositories
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    36
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    37
This extension expands RCS/CVS-like or self-customized $Keywords$
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    38
in tracked text files selected by your configuration.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    39
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    40
Keywords are only expanded in local repositories and not stored in
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    41
the change history. The mechanism can be regarded as a convenience
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    42
for the current user or for archive distribution.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    43
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    44
Configuration is done in the [keyword] and [keywordmaps] sections
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    45
of hgrc files.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    46
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    47
Example:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    48
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    49
    [keyword]
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    50
    # expand keywords in every python file except those matching "x*"
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    51
    **.py =
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    52
    x*    = ignore
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    53
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    54
Note: the more specific you are in your filename patterns
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    55
      the less you lose speed in huge repos.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    56
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    57
For [keywordmaps] template mapping and expansion demonstration and
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    58
control run "hg kwdemo".
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    59
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    60
An additional date template filter {date|utcdate} is provided.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    61
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    62
The default template mappings (view with "hg kwdemo -d") can be replaced
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    63
with customized keywords and templates.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    64
Again, run "hg kwdemo" to control the results of your config changes.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    65
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    66
Before changing/disabling active keywords, run "hg kwshrink" to avoid
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    67
the risk of inadvertedly storing expanded keywords in the change history.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    68
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    69
To force expansion after enabling it, or a configuration change, run
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    70
"hg kwexpand".
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    71
5884
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
    72
Also, when committing with the record extension or using mq's qrecord, be aware
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
    73
that keywords cannot be updated. Again, run "hg kwexpand" on the files in
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
    74
question to update keyword expansions after all changes have been checked in.
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
    75
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    76
Expansions spanning more than one line and incremental expansions,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    77
like CVS' $Log$, are not supported. A keyword template map
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    78
"Log = {desc}" expands to the first line of the changeset description.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    79
'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    80
5976
9f1e6ab76069 templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents: 5961
diff changeset
    81
from mercurial import commands, cmdutil, context, dispatch, filelog, revlog
9f1e6ab76069 templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents: 5961
diff changeset
    82
from mercurial import patch, localrepo, templater, templatefilters, util
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    83
from mercurial.node import *
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    84
from mercurial.i18n import _
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    85
import re, shutil, sys, tempfile, time
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    86
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    87
commands.optionalrepo += ' kwdemo'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    88
5961
ed4d55c2366f keyword: detect restricted commands thru variable
Christian Ebert <blacktrash@gmx.net>
parents: 5946
diff changeset
    89
# hg commands that trigger expansion only when writing to working dir,
ed4d55c2366f keyword: detect restricted commands thru variable
Christian Ebert <blacktrash@gmx.net>
parents: 5946
diff changeset
    90
# not when reading filelog, and unexpand when reading from working dir
ed4d55c2366f keyword: detect restricted commands thru variable
Christian Ebert <blacktrash@gmx.net>
parents: 5946
diff changeset
    91
restricted = ('diff1', 'record',
ed4d55c2366f keyword: detect restricted commands thru variable
Christian Ebert <blacktrash@gmx.net>
parents: 5946
diff changeset
    92
              'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord')
ed4d55c2366f keyword: detect restricted commands thru variable
Christian Ebert <blacktrash@gmx.net>
parents: 5946
diff changeset
    93
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    94
def utcdate(date):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    95
    '''Returns hgdate in cvs-like UTC format.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    96
    return time.strftime('%Y/%m/%d %H:%M:%S', time.gmtime(date[0]))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    97
5884
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
    98
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    99
_kwtemplater = None
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   100
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   101
class kwtemplater(object):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   102
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   103
    Sets up keyword templates, corresponding keyword regex, and
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   104
    provides keyword substitution functions.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   105
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   106
    templates = {
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   107
        'Revision': '{node|short}',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   108
        'Author': '{author|user}',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   109
        'Date': '{date|utcdate}',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   110
        'RCSFile': '{file|basename},v',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   111
        'Source': '{root}/{file},v',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   112
        'Id': '{file|basename},v {node|short} {date|utcdate} {author|user}',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   113
        'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   114
    }
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   115
5884
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   116
    def __init__(self, ui, repo, inc, exc, hgcmd):
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   117
        self.ui = ui
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   118
        self.repo = repo
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   119
        self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
5884
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   120
        self.hgcmd = hgcmd
5823
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   121
        self.commitnode = None
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   122
        self.path = ''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   123
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   124
        kwmaps = self.ui.configitems('keywordmaps')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   125
        if kwmaps: # override default templates
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   126
            kwmaps = [(k, templater.parsestring(v, quoted=False))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   127
                      for (k, v) in kwmaps]
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   128
            self.templates = dict(kwmaps)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   129
        escaped = map(re.escape, self.templates.keys())
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   130
        kwpat = r'\$(%s)(: [^$\n\r]*? )??\$' % '|'.join(escaped)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   131
        self.re_kw = re.compile(kwpat)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   132
5976
9f1e6ab76069 templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents: 5961
diff changeset
   133
        templatefilters.filters['utcdate'] = utcdate
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   134
        self.ct = cmdutil.changeset_templater(self.ui, self.repo,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   135
                                              False, '', False)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   136
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   137
    def substitute(self, node, data, subfunc):
5823
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   138
        '''Obtains file's changenode if commit node not given,
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   139
        and calls given substitution function.'''
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   140
        if self.commitnode:
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   141
            fnode = self.commitnode
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   142
        else:
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   143
            c = context.filectx(self.repo, self.path, fileid=node)
5823
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   144
            fnode = c.node()
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   145
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   146
        def kwsub(mobj):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   147
            '''Substitutes keyword using corresponding template.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   148
            kw = mobj.group(1)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   149
            self.ct.use_template(self.templates[kw])
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   150
            self.ui.pushbuffer()
5823
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   151
            self.ct.show(changenode=fnode, root=self.repo.root, file=self.path)
5976
9f1e6ab76069 templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents: 5961
diff changeset
   152
            return '$%s: %s $' % (kw, templatefilters.firstline(
9f1e6ab76069 templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents: 5961
diff changeset
   153
                self.ui.popbuffer()))
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   154
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   155
        return subfunc(kwsub, data)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   156
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   157
    def expand(self, node, data):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   158
        '''Returns data with keywords expanded.'''
5961
ed4d55c2366f keyword: detect restricted commands thru variable
Christian Ebert <blacktrash@gmx.net>
parents: 5946
diff changeset
   159
        if util.binary(data) or self.hgcmd in restricted:
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   160
            return data
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   161
        return self.substitute(node, data, self.re_kw.sub)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   162
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   163
    def process(self, node, data, expand):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   164
        '''Returns a tuple: data, count.
5831
4a40b7066525 keyword: fix some doc strings; update copyright
Christian Ebert <blacktrash@gmx.net>
parents: 5825
diff changeset
   165
        Count is number of keywords/keyword substitutions,
4a40b7066525 keyword: fix some doc strings; update copyright
Christian Ebert <blacktrash@gmx.net>
parents: 5825
diff changeset
   166
        telling caller whether to act on file containing data.'''
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   167
        if util.binary(data):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   168
            return data, None
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   169
        if expand:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   170
            return self.substitute(node, data, self.re_kw.subn)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   171
        return data, self.re_kw.search(data)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   172
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   173
    def shrink(self, text):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   174
        '''Returns text with all keyword substitutions removed.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   175
        if util.binary(text):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   176
            return text
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   177
        return self.re_kw.sub(r'$\1$', text)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   178
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   179
class kwfilelog(filelog.filelog):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   180
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   181
    Subclass of filelog to hook into its read, add, cmp methods.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   182
    Keywords are "stored" unexpanded, and processed on reading.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   183
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   184
    def __init__(self, opener, path):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   185
        super(kwfilelog, self).__init__(opener, path)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   186
        _kwtemplater.path = path
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   187
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   188
    def kwctread(self, node, expand):
5831
4a40b7066525 keyword: fix some doc strings; update copyright
Christian Ebert <blacktrash@gmx.net>
parents: 5825
diff changeset
   189
        '''Reads expanding and counting keywords, called from _overwrite.'''
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   190
        data = super(kwfilelog, self).read(node)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   191
        return _kwtemplater.process(node, data, expand)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   192
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   193
    def read(self, node):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   194
        '''Expands keywords when reading filelog.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   195
        data = super(kwfilelog, self).read(node)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   196
        return _kwtemplater.expand(node, data)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   197
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   198
    def add(self, text, meta, tr, link, p1=None, p2=None):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   199
        '''Removes keyword substitutions when adding to filelog.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   200
        text = _kwtemplater.shrink(text)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   201
        return super(kwfilelog, self).add(text, meta, tr, link, p1=p1, p2=p2)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   202
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   203
    def cmp(self, node, text):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   204
        '''Removes keyword substitutions for comparison.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   205
        text = _kwtemplater.shrink(text)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   206
        if self.renamed(node):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   207
            t2 = super(kwfilelog, self).read(node)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   208
            return t2 != text
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   209
        return revlog.revlog.cmp(self, node, text)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   210
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   211
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   212
# store original patch.patchfile.__init__
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   213
_patchfile_init = patch.patchfile.__init__
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   214
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   215
def _kwpatchfile_init(self, ui, fname, missing=False):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   216
    '''Monkeypatch/wrap patch.patchfile.__init__ to avoid
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   217
    rejects or conflicts due to expanded keywords in working dir.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   218
    _patchfile_init(self, ui, fname, missing=missing)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   219
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   220
    if _kwtemplater.matcher(self.fname):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   221
        # shrink keywords read from working dir
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   222
        kwshrunk = _kwtemplater.shrink(''.join(self.lines))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   223
        self.lines = kwshrunk.splitlines(True)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   224
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   225
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   226
def _iskwfile(f, link):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   227
    return not link(f) and _kwtemplater.matcher(f)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   228
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   229
def _status(ui, repo, *pats, **opts):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   230
    '''Bails out if [keyword] configuration is not active.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   231
    Returns status of working directory.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   232
    if _kwtemplater:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   233
        files, match, anypats = cmdutil.matchpats(repo, pats, opts)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   234
        return repo.status(files=files, match=match, list_clean=True)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   235
    if ui.configitems('keyword'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   236
        raise util.Abort(_('[keyword] patterns cannot match'))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   237
    raise util.Abort(_('no [keyword] patterns configured'))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   238
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   239
def _overwrite(ui, repo, node=None, expand=True, files=None):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   240
    '''Overwrites selected files expanding/shrinking keywords.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   241
    ctx = repo.changectx(node)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   242
    mf = ctx.manifest()
5823
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   243
    if node is not None:   # commit
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   244
        _kwtemplater.commitnode = node
5915
d0576d065993 Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents: 5885
diff changeset
   245
        files = [f for f in ctx.files() if f in mf]
5823
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   246
        notify = ui.debug
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   247
    else:                  # kwexpand/kwshrink
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   248
        notify = ui.note
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   249
    candidates = [f for f in files if _iskwfile(f, mf.linkf)]
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   250
    if candidates:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   251
        candidates.sort()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   252
        action = expand and 'expanding' or 'shrinking'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   253
        for f in candidates:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   254
            fp = repo.file(f, kwmatch=True)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   255
            data, kwfound = fp.kwctread(mf[f], expand)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   256
            if kwfound:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   257
                notify(_('overwriting %s %s keywords\n') % (f, action))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   258
                repo.wwrite(f, data, mf.flags(f))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   259
                repo.dirstate.normal(f)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   260
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   261
def _kwfwrite(ui, repo, expand, *pats, **opts):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   262
    '''Selects files and passes them to _overwrite.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   263
    status = _status(ui, repo, *pats, **opts)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   264
    modified, added, removed, deleted, unknown, ignored, clean = status
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   265
    if modified or added or removed or deleted:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   266
        raise util.Abort(_('outstanding uncommitted changes in given files'))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   267
    wlock = lock = None
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   268
    try:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   269
        wlock = repo.wlock()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   270
        lock = repo.lock()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   271
        _overwrite(ui, repo, expand=expand, files=clean)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   272
    finally:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   273
        del wlock, lock
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   274
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   275
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   276
def demo(ui, repo, *args, **opts):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   277
    '''print [keywordmaps] configuration and an expansion example
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   278
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   279
    Show current, custom, or default keyword template maps
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   280
    and their expansion.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   281
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   282
    Extend current configuration by specifying maps as arguments
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   283
    and optionally by reading from an additional hgrc file.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   284
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   285
    Override current keyword template maps with "default" option.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   286
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   287
    def demostatus(stat):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   288
        ui.status(_('\n\t%s\n') % stat)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   289
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   290
    def demoitems(section, items):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   291
        ui.write('[%s]\n' % section)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   292
        for k, v in items:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   293
            ui.write('%s = %s\n' % (k, v))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   294
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   295
    msg = 'hg keyword config and expansion example'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   296
    kwstatus = 'current'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   297
    fn = 'demo.txt'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   298
    branchname = 'demobranch'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   299
    tmpdir = tempfile.mkdtemp('', 'kwdemo.')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   300
    ui.note(_('creating temporary repo at %s\n') % tmpdir)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   301
    repo = localrepo.localrepository(ui, path=tmpdir, create=True)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   302
    ui.setconfig('keyword', fn, '')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   303
    if args or opts.get('rcfile'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   304
        kwstatus = 'custom'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   305
    if opts.get('rcfile'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   306
        ui.readconfig(opts.get('rcfile'))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   307
    if opts.get('default'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   308
        kwstatus = 'default'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   309
        kwmaps = kwtemplater.templates
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   310
        if ui.configitems('keywordmaps'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   311
            # override maps from optional rcfile
5946
ee0dc0f3804b keyword: improve use of dicts
Christian Ebert <blacktrash@gmx.net>
parents: 5945
diff changeset
   312
            for k, v in kwmaps.iteritems():
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   313
                ui.setconfig('keywordmaps', k, v)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   314
    elif args:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   315
        # simulate hgrc parsing
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   316
        rcmaps = ['[keywordmaps]\n'] + [a + '\n' for a in args]
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   317
        fp = repo.opener('hgrc', 'w')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   318
        fp.writelines(rcmaps)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   319
        fp.close()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   320
        ui.readconfig(repo.join('hgrc'))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   321
    if not opts.get('default'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   322
        kwmaps = dict(ui.configitems('keywordmaps')) or kwtemplater.templates
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   323
    reposetup(ui, repo)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   324
    for k, v in ui.configitems('extensions'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   325
        if k.endswith('keyword'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   326
            extension = '%s = %s' % (k, v)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   327
            break
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   328
    demostatus('config using %s keyword template maps' % kwstatus)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   329
    ui.write('[extensions]\n%s\n' % extension)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   330
    demoitems('keyword', ui.configitems('keyword'))
5946
ee0dc0f3804b keyword: improve use of dicts
Christian Ebert <blacktrash@gmx.net>
parents: 5945
diff changeset
   331
    demoitems('keywordmaps', kwmaps.iteritems())
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   332
    keywords = '$' + '$\n$'.join(kwmaps.keys()) + '$\n'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   333
    repo.wopener(fn, 'w').write(keywords)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   334
    repo.add([fn])
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   335
    path = repo.wjoin(fn)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   336
    ui.note(_('\n%s keywords written to %s:\n') % (kwstatus, path))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   337
    ui.note(keywords)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   338
    ui.note('\nhg -R "%s" branch "%s"\n' % (tmpdir, branchname))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   339
    # silence branch command if not verbose
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   340
    quiet = ui.quiet
5825
2b67acc404f6 keyword: clean up quiet setting in kwdemo and adding of untracked kwfiles
Christian Ebert <blacktrash@gmx.net>
parents: 5824
diff changeset
   341
    ui.quiet = not ui.verbose
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   342
    commands.branch(ui, repo, branchname)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   343
    ui.quiet = quiet
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   344
    for name, cmd in ui.configitems('hooks'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   345
        if name.split('.', 1)[0].find('commit') > -1:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   346
            repo.ui.setconfig('hooks', name, '')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   347
    ui.note(_('unhooked all commit hooks\n'))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   348
    ui.note('hg -R "%s" ci -m "%s"\n' % (tmpdir, msg))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   349
    repo.commit(text=msg)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   350
    format = ui.verbose and ' in %s' % path or ''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   351
    demostatus('%s keywords expanded%s' % (kwstatus, format))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   352
    ui.write(repo.wread(fn))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   353
    ui.debug(_('\nremoving temporary repo %s\n') % tmpdir)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   354
    shutil.rmtree(tmpdir, ignore_errors=True)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   355
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   356
def expand(ui, repo, *pats, **opts):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   357
    '''expand keywords in working directory
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   358
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   359
    Run after (re)enabling keyword expansion.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   360
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   361
    kwexpand refuses to run if given files contain local changes.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   362
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   363
    # 3rd argument sets expansion to True
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   364
    _kwfwrite(ui, repo, True, *pats, **opts)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   365
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   366
def files(ui, repo, *pats, **opts):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   367
    '''print files currently configured for keyword expansion
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   368
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   369
    Crosscheck which files in working directory are potential targets for
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   370
    keyword expansion.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   371
    That is, files matched by [keyword] config patterns but not symlinks.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   372
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   373
    status = _status(ui, repo, *pats, **opts)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   374
    modified, added, removed, deleted, unknown, ignored, clean = status
5825
2b67acc404f6 keyword: clean up quiet setting in kwdemo and adding of untracked kwfiles
Christian Ebert <blacktrash@gmx.net>
parents: 5824
diff changeset
   375
    files = modified + added + clean
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   376
    if opts.get('untracked'):
5825
2b67acc404f6 keyword: clean up quiet setting in kwdemo and adding of untracked kwfiles
Christian Ebert <blacktrash@gmx.net>
parents: 5824
diff changeset
   377
        files += unknown
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   378
    files.sort()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   379
    kwfiles = [f for f in files if _iskwfile(f, repo._link)]
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   380
    cwd = pats and repo.getcwd() or ''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   381
    kwfstats = not opts.get('ignore') and (('K', kwfiles),) or ()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   382
    if opts.get('all') or opts.get('ignore'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   383
        kwfstats += (('I', [f for f in files if f not in kwfiles]),)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   384
    for char, filenames in kwfstats:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   385
        format = (opts.get('all') or ui.verbose) and '%s %%s\n' % char or '%s\n'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   386
        for f in filenames:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   387
            ui.write(format % repo.pathto(f, cwd))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   388
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   389
def shrink(ui, repo, *pats, **opts):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   390
    '''revert expanded keywords in working directory
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   391
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   392
    Run before changing/disabling active keywords
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   393
    or if you experience problems with "hg import" or "hg merge".
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   394
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   395
    kwshrink refuses to run if given files contain local changes.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   396
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   397
    # 3rd argument sets expansion to False
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   398
    _kwfwrite(ui, repo, False, *pats, **opts)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   399
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   400
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   401
def reposetup(ui, repo):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   402
    '''Sets up repo as kwrepo for keyword substitution.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   403
    Overrides file method to return kwfilelog instead of filelog
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   404
    if file matches user configuration.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   405
    Wraps commit to overwrite configured files with updated
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   406
    keyword substitutions.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   407
    This is done for local repos only, and only if there are
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   408
    files configured at all for keyword substitution.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   409
5884
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   410
    if not repo.local():
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   411
        return
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   412
6021
717881b400b3 keyword: allow keyword expansion on clone
Christian Ebert <blacktrash@gmx.net>
parents: 5976
diff changeset
   413
    nokwcommands = ('add', 'addremove', 'bundle', 'copy', 'export', 'grep',
717881b400b3 keyword: allow keyword expansion on clone
Christian Ebert <blacktrash@gmx.net>
parents: 5976
diff changeset
   414
                    'identify', 'incoming', 'init', 'log', 'outgoing', 'push',
717881b400b3 keyword: allow keyword expansion on clone
Christian Ebert <blacktrash@gmx.net>
parents: 5976
diff changeset
   415
                    'remove', 'rename', 'rollback', 'tip',
5884
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   416
                    'convert')
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   417
    hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:])
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   418
    if hgcmd in nokwcommands:
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   419
        return
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   420
5885
53be157543d4 keyword: avoid extra diffs when not comparing against working dir
Christian Ebert <blacktrash@gmx.net>
parents: 5884
diff changeset
   421
    if hgcmd == 'diff':
53be157543d4 keyword: avoid extra diffs when not comparing against working dir
Christian Ebert <blacktrash@gmx.net>
parents: 5884
diff changeset
   422
        # only expand if comparing against working dir
53be157543d4 keyword: avoid extra diffs when not comparing against working dir
Christian Ebert <blacktrash@gmx.net>
parents: 5884
diff changeset
   423
        node1, node2 = cmdutil.revpair(repo, cmdopts.get('rev'))
53be157543d4 keyword: avoid extra diffs when not comparing against working dir
Christian Ebert <blacktrash@gmx.net>
parents: 5884
diff changeset
   424
        if node2 is not None:
53be157543d4 keyword: avoid extra diffs when not comparing against working dir
Christian Ebert <blacktrash@gmx.net>
parents: 5884
diff changeset
   425
            return
53be157543d4 keyword: avoid extra diffs when not comparing against working dir
Christian Ebert <blacktrash@gmx.net>
parents: 5884
diff changeset
   426
        # shrink if rev is not current node
53be157543d4 keyword: avoid extra diffs when not comparing against working dir
Christian Ebert <blacktrash@gmx.net>
parents: 5884
diff changeset
   427
        if node1 is not None and node1 != repo.changectx().node():
53be157543d4 keyword: avoid extra diffs when not comparing against working dir
Christian Ebert <blacktrash@gmx.net>
parents: 5884
diff changeset
   428
            hgcmd = 'diff1'
53be157543d4 keyword: avoid extra diffs when not comparing against working dir
Christian Ebert <blacktrash@gmx.net>
parents: 5884
diff changeset
   429
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   430
    inc, exc = [], ['.hgtags']
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   431
    for pat, opt in ui.configitems('keyword'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   432
        if opt != 'ignore':
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   433
            inc.append(pat)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   434
        else:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   435
            exc.append(pat)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   436
    if not inc:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   437
        return
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   438
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   439
    global _kwtemplater
5884
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   440
    _kwtemplater = kwtemplater(ui, repo, inc, exc, hgcmd)
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   441
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   442
    class kwrepo(repo.__class__):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   443
        def file(self, f, kwmatch=False):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   444
            if f[0] == '/':
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   445
                f = f[1:]
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   446
            if kwmatch or _kwtemplater.matcher(f):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   447
                return kwfilelog(self.sopener, f)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   448
            return filelog.filelog(self.sopener, f)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   449
5884
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   450
        def wread(self, filename):
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   451
            data = super(kwrepo, self).wread(filename)
5961
ed4d55c2366f keyword: detect restricted commands thru variable
Christian Ebert <blacktrash@gmx.net>
parents: 5946
diff changeset
   452
            if hgcmd in restricted and _kwtemplater.matcher(filename):
5884
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   453
                return _kwtemplater.shrink(data)
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   454
            return data
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   455
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   456
        def commit(self, files=None, text='', user=None, date=None,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   457
                   match=util.always, force=False, force_editor=False,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   458
                   p1=None, p2=None, extra={}):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   459
            wlock = lock = None
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   460
            _p1 = _p2 = None
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   461
            try:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   462
                wlock = self.wlock()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   463
                lock = self.lock()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   464
                # store and postpone commit hooks
5946
ee0dc0f3804b keyword: improve use of dicts
Christian Ebert <blacktrash@gmx.net>
parents: 5945
diff changeset
   465
                commithooks = {}
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   466
                for name, cmd in ui.configitems('hooks'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   467
                    if name.split('.', 1)[0] == 'commit':
5946
ee0dc0f3804b keyword: improve use of dicts
Christian Ebert <blacktrash@gmx.net>
parents: 5945
diff changeset
   468
                        commithooks[name] = cmd
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   469
                        ui.setconfig('hooks', name, None)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   470
                if commithooks:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   471
                    # store parents for commit hook environment
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   472
                    if p1 is None:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   473
                        _p1, _p2 = repo.dirstate.parents()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   474
                    else:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   475
                        _p1, _p2 = p1, p2 or nullid
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   476
                    _p1 = hex(_p1)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   477
                    if _p2 == nullid:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   478
                        _p2 = ''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   479
                    else:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   480
                        _p2 = hex(_p2)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   481
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   482
                node = super(kwrepo,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   483
                             self).commit(files=files, text=text, user=user,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   484
                                          date=date, match=match, force=force,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   485
                                          force_editor=force_editor,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   486
                                          p1=p1, p2=p2, extra=extra)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   487
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   488
                # restore commit hooks
5946
ee0dc0f3804b keyword: improve use of dicts
Christian Ebert <blacktrash@gmx.net>
parents: 5945
diff changeset
   489
                for name, cmd in commithooks.iteritems():
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   490
                    ui.setconfig('hooks', name, cmd)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   491
                if node is not None:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   492
                    _overwrite(ui, self, node=node)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   493
                    repo.hook('commit', node=node, parent1=_p1, parent2=_p2)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   494
                return node
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   495
            finally:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   496
                del wlock, lock
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   497
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   498
    repo.__class__ = kwrepo
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   499
    patch.patchfile.__init__ = _kwpatchfile_init
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   500
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   501
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   502
cmdtable = {
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   503
    'kwdemo':
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   504
        (demo,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   505
         [('d', 'default', None, _('show default keyword template maps')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   506
          ('f', 'rcfile', [], _('read maps from rcfile'))],
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   507
         _('hg kwdemo [-d] [-f RCFILE] [TEMPLATEMAP]...')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   508
    'kwexpand': (expand, commands.walkopts,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   509
                 _('hg kwexpand [OPTION]... [FILE]...')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   510
    'kwfiles':
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   511
        (files,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   512
         [('a', 'all', None, _('show keyword status flags of all files')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   513
          ('i', 'ignore', None, _('show files excluded from expansion')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   514
          ('u', 'untracked', None, _('additionally show untracked files')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   515
         ] + commands.walkopts,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   516
         _('hg kwfiles [OPTION]... [FILE]...')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   517
    'kwshrink': (shrink, commands.walkopts,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   518
                 _('hg kwshrink [OPTION]... [FILE]...')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   519
}