hgext/keyword.py
author Matt Mackall <mpm@selenic.com>
Thu, 14 Feb 2008 10:28:27 -0600
changeset 6096 d8477881ee0f
parent 6092 911f5be5d159
child 6114 ee83510fe567
permissions -rw-r--r--
hgweb: add new logos
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
6072
e521ec1ad985 keyword: no expansion in web diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6071
diff changeset
    83
from mercurial.hgweb import webcommands
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    84
from mercurial.node import *
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    85
from mercurial.i18n import _
6069
212bfb5c50e1 keyword: avoid os import by using util.splitpath
Christian Ebert <blacktrash@gmx.net>
parents: 6060
diff changeset
    86
import re, shutil, tempfile, time
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    87
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    88
commands.optionalrepo += ' kwdemo'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    89
6024
3121f0feefb4 keyword: nokwcommands, restricted string variables at top level
Christian Ebert <blacktrash@gmx.net>
parents: 6023
diff changeset
    90
# hg commands that do not act on keywords
3121f0feefb4 keyword: nokwcommands, restricted string variables at top level
Christian Ebert <blacktrash@gmx.net>
parents: 6023
diff changeset
    91
nokwcommands = ('add addremove bundle copy export grep identify incoming init'
6082
875b745996e8 keyword: add glog to nokwcommands
Christian Ebert <blacktrash@gmx.net>
parents: 6081
diff changeset
    92
                ' log outgoing push remove rename rollback tip'
875b745996e8 keyword: add glog to nokwcommands
Christian Ebert <blacktrash@gmx.net>
parents: 6081
diff changeset
    93
                ' convert email glog')
6024
3121f0feefb4 keyword: nokwcommands, restricted string variables at top level
Christian Ebert <blacktrash@gmx.net>
parents: 6023
diff changeset
    94
5961
ed4d55c2366f keyword: detect restricted commands thru variable
Christian Ebert <blacktrash@gmx.net>
parents: 5946
diff changeset
    95
# 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
    96
# not when reading filelog, and unexpand when reading from working dir
6092
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
    97
restricted = 'record qfold qimport qnew qpush qrefresh qrecord'
5961
ed4d55c2366f keyword: detect restricted commands thru variable
Christian Ebert <blacktrash@gmx.net>
parents: 5946
diff changeset
    98
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
    99
def utcdate(date):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   100
    '''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
   101
    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
   102
5884
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   103
6070
5fd126d1adf8 keyword: declare globals in a more compact way
Christian Ebert <blacktrash@gmx.net>
parents: 6069
diff changeset
   104
_kwtemplater = _cmd = _cmdoptions = None
6052
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   105
 
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   106
# store originals of monkeypatches
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   107
_patchfile_init = patch.patchfile.__init__
6092
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   108
_patch_diff = patch.diff
6052
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   109
_dispatch_parse = dispatch._parse
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   110
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   111
def _kwpatchfile_init(self, ui, fname, missing=False):
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   112
    '''Monkeypatch/wrap patch.patchfile.__init__ to avoid
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   113
    rejects or conflicts due to expanded keywords in working dir.'''
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   114
    _patchfile_init(self, ui, fname, missing=missing)
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   115
    if _kwtemplater.matcher(self.fname):
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   116
        # shrink keywords read from working dir
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   117
        kwshrunk = _kwtemplater.shrink(''.join(self.lines))
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   118
        self.lines = kwshrunk.splitlines(True)
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   119
6092
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   120
def _kw_diff(repo, node1=None, node2=None, files=None, match=util.always,
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   121
             fp=None, changes=None, opts=None):
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   122
    # only expand if comparing against working dir
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   123
    if node2 is not None:
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   124
        _kwtemplater.matcher = util.never
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   125
    if node1 is not None and node1 != repo.changectx().node():
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   126
        _kwtemplater.restrict = True
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   127
    _patch_diff(repo, node1=node1, node2=node2, files=files, match=match,
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   128
                fp=fp, changes=changes, opts=opts)
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   129
6081
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   130
def _kwweb_changeset(web, req, tmpl):
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   131
    '''Wraps webcommands.changeset turning off keyword expansion.'''
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   132
    _kwtemplater.matcher = util.never
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   133
    return web.changeset(tmpl, web.changectx(req))
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   134
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   135
def _kwweb_filediff(web, req, tmpl):
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   136
    '''Wraps webcommands.filediff turning off keyword expansion.'''
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   137
    _kwtemplater.matcher = util.never
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   138
    return web.filediff(tmpl, web.filectx(req))
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   139
6052
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   140
def _kwdispatch_parse(ui, args):
6092
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   141
    '''Monkeypatch dispatch._parse to obtain running hg command.'''
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   142
    global _cmd
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   143
    _cmd, func, args, options, cmdoptions = _dispatch_parse(ui, args)
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   144
    return _cmd, func, args, options, cmdoptions
6052
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   145
6081
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   146
# dispatch._parse is run before reposetup, so wrap it here
6052
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   147
dispatch._parse = _kwdispatch_parse
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   148
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   149
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   150
class kwtemplater(object):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   151
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   152
    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
   153
    provides keyword substitution functions.
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
    templates = {
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   156
        'Revision': '{node|short}',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   157
        'Author': '{author|user}',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   158
        'Date': '{date|utcdate}',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   159
        'RCSFile': '{file|basename},v',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   160
        'Source': '{root}/{file},v',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   161
        '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
   162
        '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
   163
    }
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   164
6071
127c973e4499 keyword: make restrict entirely a kwtemplater attribute
Christian Ebert <blacktrash@gmx.net>
parents: 6070
diff changeset
   165
    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
   166
        self.ui = ui
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   167
        self.repo = repo
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   168
        self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1]
6071
127c973e4499 keyword: make restrict entirely a kwtemplater attribute
Christian Ebert <blacktrash@gmx.net>
parents: 6070
diff changeset
   169
        self.restrict = hgcmd in restricted.split()
5823
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   170
        self.commitnode = None
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   171
        self.path = ''
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
        kwmaps = self.ui.configitems('keywordmaps')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   174
        if kwmaps: # override default templates
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   175
            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
   176
                      for (k, v) in kwmaps]
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   177
            self.templates = dict(kwmaps)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   178
        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
   179
        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
   180
        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
   181
5976
9f1e6ab76069 templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents: 5961
diff changeset
   182
        templatefilters.filters['utcdate'] = utcdate
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   183
        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
   184
                                              False, '', False)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   185
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   186
    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
   187
        '''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
   188
        and calls given substitution function.'''
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   189
        if self.commitnode:
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   190
            fnode = self.commitnode
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   191
        else:
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   192
            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
   193
            fnode = c.node()
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   194
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   195
        def kwsub(mobj):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   196
            '''Substitutes keyword using corresponding template.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   197
            kw = mobj.group(1)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   198
            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
   199
            self.ui.pushbuffer()
5823
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   200
            self.ct.show(changenode=fnode, root=self.repo.root, file=self.path)
6023
ee7df90d1daa keyword: split line continuation in 2 steps (style)
Christian Ebert <blacktrash@gmx.net>
parents: 6022
diff changeset
   201
            ekw = templatefilters.firstline(self.ui.popbuffer())
ee7df90d1daa keyword: split line continuation in 2 steps (style)
Christian Ebert <blacktrash@gmx.net>
parents: 6022
diff changeset
   202
            return '$%s: %s $' % (kw, ekw)
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   203
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   204
        return subfunc(kwsub, data)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   205
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   206
    def expand(self, node, data):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   207
        '''Returns data with keywords expanded.'''
6050
adf73753eb7d keyword: fix pychecker warning about shadowed variable
Christian Ebert <blacktrash@gmx.net>
parents: 6026
diff changeset
   208
        if self.restrict or util.binary(data):
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   209
            return data
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   210
        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
   211
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   212
    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
   213
        '''Returns a tuple: data, count.
5831
4a40b7066525 keyword: fix some doc strings; update copyright
Christian Ebert <blacktrash@gmx.net>
parents: 5825
diff changeset
   214
        Count is number of keywords/keyword substitutions,
4a40b7066525 keyword: fix some doc strings; update copyright
Christian Ebert <blacktrash@gmx.net>
parents: 5825
diff changeset
   215
        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
   216
        if util.binary(data):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   217
            return data, None
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   218
        if expand:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   219
            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
   220
        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
   221
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   222
    def shrink(self, text):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   223
        '''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
   224
        if util.binary(text):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   225
            return text
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   226
        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
   227
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   228
class kwfilelog(filelog.filelog):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   229
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   230
    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
   231
    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
   232
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   233
    def __init__(self, opener, path):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   234
        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
   235
        _kwtemplater.path = path
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   236
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   237
    def kwctread(self, node, expand):
5831
4a40b7066525 keyword: fix some doc strings; update copyright
Christian Ebert <blacktrash@gmx.net>
parents: 5825
diff changeset
   238
        '''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
   239
        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
   240
        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
   241
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   242
    def read(self, node):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   243
        '''Expands keywords when reading filelog.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   244
        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
   245
        return _kwtemplater.expand(node, data)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   246
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   247
    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
   248
        '''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
   249
        text = _kwtemplater.shrink(text)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   250
        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
   251
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   252
    def cmp(self, node, text):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   253
        '''Removes keyword substitutions for comparison.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   254
        text = _kwtemplater.shrink(text)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   255
        if self.renamed(node):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   256
            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
   257
            return t2 != text
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   258
        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
   259
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   260
def _iskwfile(f, link):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   261
    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
   262
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   263
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
   264
    '''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
   265
    Returns status of working directory.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   266
    if _kwtemplater:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   267
        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
   268
        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
   269
    if ui.configitems('keyword'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   270
        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
   271
    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
   272
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   273
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
   274
    '''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
   275
    ctx = repo.changectx(node)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   276
    mf = ctx.manifest()
5823
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   277
    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
   278
        _kwtemplater.commitnode = node
5915
d0576d065993 Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents: 5885
diff changeset
   279
        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
   280
        notify = ui.debug
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   281
    else:                  # kwexpand/kwshrink
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
   282
        notify = ui.note
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   283
    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
   284
    if candidates:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   285
        candidates.sort()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   286
        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
   287
        for f in candidates:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   288
            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
   289
            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
   290
            if kwfound:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   291
                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
   292
                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
   293
                repo.dirstate.normal(f)
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
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
   296
    '''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
   297
    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
   298
    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
   299
    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
   300
        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
   301
    wlock = lock = None
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   302
    try:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   303
        wlock = repo.wlock()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   304
        lock = repo.lock()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   305
        _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
   306
    finally:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   307
        del wlock, lock
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   308
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   309
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   310
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
   311
    '''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
   312
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   313
    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
   314
    and their expansion.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   315
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   316
    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
   317
    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
   318
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   319
    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
   320
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   321
    def demostatus(stat):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   322
        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
   323
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   324
    def demoitems(section, items):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   325
        ui.write('[%s]\n' % section)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   326
        for k, v in items:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   327
            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
   328
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   329
    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
   330
    kwstatus = 'current'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   331
    fn = 'demo.txt'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   332
    branchname = 'demobranch'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   333
    tmpdir = tempfile.mkdtemp('', 'kwdemo.')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   334
    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
   335
    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
   336
    ui.setconfig('keyword', fn, '')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   337
    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
   338
        kwstatus = 'custom'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   339
    if opts.get('rcfile'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   340
        ui.readconfig(opts.get('rcfile'))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   341
    if opts.get('default'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   342
        kwstatus = 'default'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   343
        kwmaps = kwtemplater.templates
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   344
        if ui.configitems('keywordmaps'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   345
            # override maps from optional rcfile
5946
ee0dc0f3804b keyword: improve use of dicts
Christian Ebert <blacktrash@gmx.net>
parents: 5945
diff changeset
   346
            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
   347
                ui.setconfig('keywordmaps', k, v)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   348
    elif args:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   349
        # simulate hgrc parsing
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   350
        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
   351
        fp = repo.opener('hgrc', 'w')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   352
        fp.writelines(rcmaps)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   353
        fp.close()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   354
        ui.readconfig(repo.join('hgrc'))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   355
    if not opts.get('default'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   356
        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
   357
    reposetup(ui, repo)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   358
    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
   359
        if k.endswith('keyword'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   360
            extension = '%s = %s' % (k, v)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   361
            break
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   362
    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
   363
    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
   364
    demoitems('keyword', ui.configitems('keyword'))
5946
ee0dc0f3804b keyword: improve use of dicts
Christian Ebert <blacktrash@gmx.net>
parents: 5945
diff changeset
   365
    demoitems('keywordmaps', kwmaps.iteritems())
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   366
    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
   367
    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
   368
    repo.add([fn])
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   369
    path = repo.wjoin(fn)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   370
    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
   371
    ui.note(keywords)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   372
    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
   373
    # 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
   374
    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
   375
    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
   376
    commands.branch(ui, repo, branchname)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   377
    ui.quiet = quiet
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   378
    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
   379
        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
   380
            repo.ui.setconfig('hooks', name, '')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   381
    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
   382
    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
   383
    repo.commit(text=msg)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   384
    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
   385
    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
   386
    ui.write(repo.wread(fn))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   387
    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
   388
    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
   389
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   390
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
   391
    '''expand keywords in working directory
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   392
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   393
    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
   394
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   395
    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
   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 True
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   398
    _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
   399
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   400
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
   401
    '''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
   402
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   403
    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
   404
    keyword expansion.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   405
    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
   406
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   407
    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
   408
    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
   409
    files = modified + added + clean
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   410
    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
   411
        files += unknown
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   412
    files.sort()
6060
e4d74100d41b keyword: fix symlink detection under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 6059
diff changeset
   413
    wctx = repo.workingctx()
e4d74100d41b keyword: fix symlink detection under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 6059
diff changeset
   414
    islink = lambda p: 'l' in wctx.fileflags(p)
e4d74100d41b keyword: fix symlink detection under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 6059
diff changeset
   415
    kwfiles = [f for f in files if _iskwfile(f, islink)]
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   416
    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
   417
    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
   418
    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
   419
        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
   420
    for char, filenames in kwfstats:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   421
        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
   422
        for f in filenames:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   423
            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
   424
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   425
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
   426
    '''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
   427
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   428
    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
   429
    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
   430
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   431
    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
   432
    '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   433
    # 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
   434
    _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
   435
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   436
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   437
def reposetup(ui, repo):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   438
    '''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
   439
    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
   440
    if file matches user configuration.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   441
    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
   442
    keyword substitutions.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   443
    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
   444
    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
   445
6052
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   446
    global _kwtemplater
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
   447
6051
1038b1458d7a keyword: safeguards against erroneous behaviour or aborts
Christian Ebert <blacktrash@gmx.net>
parents: 6050
diff changeset
   448
    try:
6092
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   449
        if (not repo.local() or _cmd in nokwcommands.split() 
6069
212bfb5c50e1 keyword: avoid os import by using util.splitpath
Christian Ebert <blacktrash@gmx.net>
parents: 6060
diff changeset
   450
            or '.hg' in util.splitpath(repo.root)
6051
1038b1458d7a keyword: safeguards against erroneous behaviour or aborts
Christian Ebert <blacktrash@gmx.net>
parents: 6050
diff changeset
   451
            or repo._url.startswith('bundle:')):
1038b1458d7a keyword: safeguards against erroneous behaviour or aborts
Christian Ebert <blacktrash@gmx.net>
parents: 6050
diff changeset
   452
            return
1038b1458d7a keyword: safeguards against erroneous behaviour or aborts
Christian Ebert <blacktrash@gmx.net>
parents: 6050
diff changeset
   453
    except AttributeError:
1038b1458d7a keyword: safeguards against erroneous behaviour or aborts
Christian Ebert <blacktrash@gmx.net>
parents: 6050
diff changeset
   454
        pass
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   455
6051
1038b1458d7a keyword: safeguards against erroneous behaviour or aborts
Christian Ebert <blacktrash@gmx.net>
parents: 6050
diff changeset
   456
    inc, exc = [], ['.hg*']
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   457
    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
   458
        if opt != 'ignore':
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   459
            inc.append(pat)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   460
        else:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   461
            exc.append(pat)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   462
    if not inc:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   463
        return
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   464
6092
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   465
    _kwtemplater = kwtemplater(ui, repo, inc, exc, _cmd)
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   466
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   467
    class kwrepo(repo.__class__):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   468
        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
   469
            if f[0] == '/':
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   470
                f = f[1:]
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   471
            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
   472
                return kwfilelog(self.sopener, f)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   473
            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
   474
5884
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   475
        def wread(self, filename):
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   476
            data = super(kwrepo, self).wread(filename)
6071
127c973e4499 keyword: make restrict entirely a kwtemplater attribute
Christian Ebert <blacktrash@gmx.net>
parents: 6070
diff changeset
   477
            if _kwtemplater.restrict and _kwtemplater.matcher(filename):
5884
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   478
                return _kwtemplater.shrink(data)
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   479
            return data
a139f141dcae keyword: support mq; handle (q)record more gracefully
Christian Ebert <blacktrash@gmx.net>
parents: 5831
diff changeset
   480
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   481
        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
   482
                   match=util.always, force=False, force_editor=False,
6022
e5b5010ff7da keyword: add empty_ok argument to kwrepo.commit
Christian Ebert <blacktrash@gmx.net>
parents: 6021
diff changeset
   483
                   p1=None, p2=None, extra={}, empty_ok=False):
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   484
            wlock = lock = None
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   485
            _p1 = _p2 = None
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   486
            try:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   487
                wlock = self.wlock()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   488
                lock = self.lock()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   489
                # store and postpone commit hooks
5946
ee0dc0f3804b keyword: improve use of dicts
Christian Ebert <blacktrash@gmx.net>
parents: 5945
diff changeset
   490
                commithooks = {}
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   491
                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
   492
                    if name.split('.', 1)[0] == 'commit':
5946
ee0dc0f3804b keyword: improve use of dicts
Christian Ebert <blacktrash@gmx.net>
parents: 5945
diff changeset
   493
                        commithooks[name] = cmd
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   494
                        ui.setconfig('hooks', name, None)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   495
                if commithooks:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   496
                    # 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
   497
                    if p1 is None:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   498
                        _p1, _p2 = repo.dirstate.parents()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   499
                    else:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   500
                        _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
   501
                    _p1 = hex(_p1)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   502
                    if _p2 == nullid:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   503
                        _p2 = ''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   504
                    else:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   505
                        _p2 = hex(_p2)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   506
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   507
                node = super(kwrepo,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   508
                             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
   509
                                          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
   510
                                          force_editor=force_editor,
6022
e5b5010ff7da keyword: add empty_ok argument to kwrepo.commit
Christian Ebert <blacktrash@gmx.net>
parents: 6021
diff changeset
   511
                                          p1=p1, p2=p2, extra=extra,
e5b5010ff7da keyword: add empty_ok argument to kwrepo.commit
Christian Ebert <blacktrash@gmx.net>
parents: 6021
diff changeset
   512
                                          empty_ok=empty_ok)
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   513
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   514
                # restore commit hooks
5946
ee0dc0f3804b keyword: improve use of dicts
Christian Ebert <blacktrash@gmx.net>
parents: 5945
diff changeset
   515
                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
   516
                    ui.setconfig('hooks', name, cmd)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   517
                if node is not None:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   518
                    _overwrite(ui, self, node=node)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   519
                    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
   520
                return node
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   521
            finally:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   522
                del wlock, lock
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   523
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   524
    repo.__class__ = kwrepo
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   525
    patch.patchfile.__init__ = _kwpatchfile_init
6092
911f5be5d159 keyword: monkeypatch patch.diff for non-interactive diffs
Christian Ebert <blacktrash@gmx.net>
parents: 6082
diff changeset
   526
    patch.diff = _kw_diff
6081
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   527
    webcommands.changeset = webcommands.rev = _kwweb_changeset
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
   528
    webcommands.filediff = webcommands.diff = _kwweb_filediff
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   529
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   530
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   531
cmdtable = {
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   532
    'kwdemo':
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   533
        (demo,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   534
         [('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
   535
          ('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
   536
         _('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
   537
    'kwexpand': (expand, commands.walkopts,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   538
                 _('hg kwexpand [OPTION]... [FILE]...')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   539
    'kwfiles':
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   540
        (files,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   541
         [('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
   542
          ('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
   543
          ('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
   544
         ] + commands.walkopts,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   545
         _('hg kwfiles [OPTION]... [FILE]...')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   546
    'kwshrink': (shrink, commands.walkopts,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   547
                 _('hg kwshrink [OPTION]... [FILE]...')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
   548
}