annotate hgext/keyword.py @ 6082:875b745996e8

keyword: add glog to nokwcommands
author Christian Ebert <blacktrash@gmx.net>
date Tue, 12 Feb 2008 21:44:56 +0100
parents beb775df5630
children 911f5be5d159
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
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
6024
3121f0feefb4 keyword: nokwcommands, restricted string variables at top level
Christian Ebert <blacktrash@gmx.net>
parents: 6023
diff changeset
97 restricted = 'diff1 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__
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
108 _dispatch_parse = dispatch._parse
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
109
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
110 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
111 '''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
112 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
113 _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
114 if _kwtemplater.matcher(self.fname):
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
115 # shrink keywords read from working dir
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
116 kwshrunk = _kwtemplater.shrink(''.join(self.lines))
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
117 self.lines = kwshrunk.splitlines(True)
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
118
6081
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
119 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
120 '''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
121 _kwtemplater.matcher = util.never
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
122 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
123
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
124 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
125 '''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
126 _kwtemplater.matcher = util.never
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
127 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
128
6052
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
129 def _kwdispatch_parse(ui, args):
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
130 '''Monkeypatch dispatch._parse to obtain
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
131 current command and command options (global _cmd, _cmdoptions).'''
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
132 global _cmd, _cmdoptions
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
133 _cmd, func, args, options, _cmdoptions = _dispatch_parse(ui, args)
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
134 return _cmd, func, args, options, _cmdoptions
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
135
6081
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
136 # 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
137 dispatch._parse = _kwdispatch_parse
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
138
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
139
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
140 class kwtemplater(object):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
141 '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
142 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
143 provides keyword substitution functions.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
144 '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
145 templates = {
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
146 'Revision': '{node|short}',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
147 'Author': '{author|user}',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
148 'Date': '{date|utcdate}',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
149 'RCSFile': '{file|basename},v',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
150 'Source': '{root}/{file},v',
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
151 '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
152 '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
153 }
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
154
6071
127c973e4499 keyword: make restrict entirely a kwtemplater attribute
Christian Ebert <blacktrash@gmx.net>
parents: 6070
diff changeset
155 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
156 self.ui = ui
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
157 self.repo = repo
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
158 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
159 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
160 self.commitnode = None
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
161 self.path = ''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
162
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
163 kwmaps = self.ui.configitems('keywordmaps')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
164 if kwmaps: # override default templates
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
165 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
166 for (k, v) in kwmaps]
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
167 self.templates = dict(kwmaps)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
168 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
169 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
170 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
171
5976
9f1e6ab76069 templates: move filters to their own module
Matt Mackall <mpm@selenic.com>
parents: 5961
diff changeset
172 templatefilters.filters['utcdate'] = utcdate
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
173 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
174 False, '', False)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
175
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
176 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
177 '''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
178 and calls given substitution function.'''
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
179 if self.commitnode:
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
180 fnode = self.commitnode
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
181 else:
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
182 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
183 fnode = c.node()
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
184
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
185 def kwsub(mobj):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
186 '''Substitutes keyword using corresponding template.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
187 kw = mobj.group(1)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
188 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
189 self.ui.pushbuffer()
5823
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
190 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
191 ekw = templatefilters.firstline(self.ui.popbuffer())
ee7df90d1daa keyword: split line continuation in 2 steps (style)
Christian Ebert <blacktrash@gmx.net>
parents: 6022
diff changeset
192 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
193
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
194 return subfunc(kwsub, data)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
195
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
196 def expand(self, node, data):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
197 '''Returns data with keywords expanded.'''
6050
adf73753eb7d keyword: fix pychecker warning about shadowed variable
Christian Ebert <blacktrash@gmx.net>
parents: 6026
diff changeset
198 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
199 return data
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
200 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
201
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
202 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
203 '''Returns a tuple: data, count.
5831
4a40b7066525 keyword: fix some doc strings; update copyright
Christian Ebert <blacktrash@gmx.net>
parents: 5825
diff changeset
204 Count is number of keywords/keyword substitutions,
4a40b7066525 keyword: fix some doc strings; update copyright
Christian Ebert <blacktrash@gmx.net>
parents: 5825
diff changeset
205 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
206 if util.binary(data):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
207 return data, None
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
208 if expand:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
209 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
210 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
211
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
212 def shrink(self, text):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
213 '''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
214 if util.binary(text):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
215 return text
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
216 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
217
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
218 class kwfilelog(filelog.filelog):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
219 '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
220 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
221 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
222 '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
223 def __init__(self, opener, path):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
224 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
225 _kwtemplater.path = path
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
226
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
227 def kwctread(self, node, expand):
5831
4a40b7066525 keyword: fix some doc strings; update copyright
Christian Ebert <blacktrash@gmx.net>
parents: 5825
diff changeset
228 '''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
229 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
230 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
231
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
232 def read(self, node):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
233 '''Expands keywords when reading filelog.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
234 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
235 return _kwtemplater.expand(node, data)
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 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
238 '''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
239 text = _kwtemplater.shrink(text)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
240 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
241
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
242 def cmp(self, node, text):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
243 '''Removes keyword substitutions for comparison.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
244 text = _kwtemplater.shrink(text)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
245 if self.renamed(node):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
246 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
247 return t2 != text
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
248 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
249
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
250 def _iskwfile(f, link):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
251 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
252
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
253 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
254 '''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
255 Returns status of working directory.'''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
256 if _kwtemplater:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
257 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
258 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
259 if ui.configitems('keyword'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
260 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
261 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
262
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
263 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
264 '''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
265 ctx = repo.changectx(node)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
266 mf = ctx.manifest()
5823
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
267 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
268 _kwtemplater.commitnode = node
5915
d0576d065993 Prefer i in d over d.has_key(i)
Christian Ebert <blacktrash@gmx.net>
parents: 5885
diff changeset
269 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
270 notify = ui.debug
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
271 else: # kwexpand/kwshrink
2a66138c5e7e keyword: (bugfix) only set changenode for kwtemplater when committing
Christian Ebert <blacktrash@gmx.net>
parents: 5815
diff changeset
272 notify = ui.note
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
273 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
274 if candidates:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
275 candidates.sort()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
276 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
277 for f in candidates:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
278 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
279 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
280 if kwfound:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
281 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
282 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
283 repo.dirstate.normal(f)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
284
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
285 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
286 '''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
287 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
288 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
289 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
290 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
291 wlock = lock = None
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
292 try:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
293 wlock = repo.wlock()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
294 lock = repo.lock()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
295 _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
296 finally:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
297 del wlock, lock
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
298
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
299
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
300 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
301 '''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
302
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
303 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
304 and their expansion.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
305
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
306 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
307 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
308
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
309 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
310 '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
311 def demostatus(stat):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
312 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
313
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
314 def demoitems(section, items):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
315 ui.write('[%s]\n' % section)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
316 for k, v in items:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
317 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
318
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
319 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
320 kwstatus = 'current'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
321 fn = 'demo.txt'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
322 branchname = 'demobranch'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
323 tmpdir = tempfile.mkdtemp('', 'kwdemo.')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
324 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
325 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
326 ui.setconfig('keyword', fn, '')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
327 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
328 kwstatus = 'custom'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
329 if opts.get('rcfile'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
330 ui.readconfig(opts.get('rcfile'))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
331 if opts.get('default'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
332 kwstatus = 'default'
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
333 kwmaps = kwtemplater.templates
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
334 if ui.configitems('keywordmaps'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
335 # override maps from optional rcfile
5946
ee0dc0f3804b keyword: improve use of dicts
Christian Ebert <blacktrash@gmx.net>
parents: 5945
diff changeset
336 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
337 ui.setconfig('keywordmaps', k, v)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
338 elif args:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
339 # simulate hgrc parsing
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
340 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
341 fp = repo.opener('hgrc', 'w')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
342 fp.writelines(rcmaps)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
343 fp.close()
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
344 ui.readconfig(repo.join('hgrc'))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
345 if not opts.get('default'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
346 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
347 reposetup(ui, repo)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
348 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
349 if k.endswith('keyword'):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
350 extension = '%s = %s' % (k, v)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
351 break
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
352 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
353 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
354 demoitems('keyword', ui.configitems('keyword'))
5946
ee0dc0f3804b keyword: improve use of dicts
Christian Ebert <blacktrash@gmx.net>
parents: 5945
diff changeset
355 demoitems('keywordmaps', kwmaps.iteritems())
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
356 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
357 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
358 repo.add([fn])
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
359 path = repo.wjoin(fn)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
360 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
361 ui.note(keywords)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
362 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
363 # 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
364 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
365 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
366 commands.branch(ui, repo, branchname)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
367 ui.quiet = quiet
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
368 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
369 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
370 repo.ui.setconfig('hooks', name, '')
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
371 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
372 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
373 repo.commit(text=msg)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
374 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
375 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
376 ui.write(repo.wread(fn))
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
377 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
378 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
379
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
380 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
381 '''expand keywords in working directory
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
382
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
383 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
384
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
385 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
386 '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
387 # 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
388 _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
389
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
390 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
391 '''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
392
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
393 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
394 keyword expansion.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
395 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
396 '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
397 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
398 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
399 files = modified + added + clean
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
400 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
401 files += unknown
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
402 files.sort()
6060
e4d74100d41b keyword: fix symlink detection under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 6059
diff changeset
403 wctx = repo.workingctx()
e4d74100d41b keyword: fix symlink detection under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 6059
diff changeset
404 islink = lambda p: 'l' in wctx.fileflags(p)
e4d74100d41b keyword: fix symlink detection under Windows
Patrick Mezard <pmezard@gmail.com>
parents: 6059
diff changeset
405 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
406 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
407 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
408 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
409 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
410 for char, filenames in kwfstats:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
411 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
412 for f in filenames:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
413 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
414
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
415 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
416 '''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
417
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
418 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
419 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
420
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
421 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
422 '''
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
423 # 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
424 _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
425
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
426
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
427 def reposetup(ui, repo):
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
428 '''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
429 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
430 if file matches user configuration.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
431 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
432 keyword substitutions.
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
433 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
434 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
435
6052
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
436 global _kwtemplater
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
437 hgcmd, hgcmdopts = _cmd, _cmdoptions
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
438
6051
1038b1458d7a keyword: safeguards against erroneous behaviour or aborts
Christian Ebert <blacktrash@gmx.net>
parents: 6050
diff changeset
439 try:
6052
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
440 if (not repo.local() or hgcmd in nokwcommands.split()
6069
212bfb5c50e1 keyword: avoid os import by using util.splitpath
Christian Ebert <blacktrash@gmx.net>
parents: 6060
diff changeset
441 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
442 or repo._url.startswith('bundle:')):
1038b1458d7a keyword: safeguards against erroneous behaviour or aborts
Christian Ebert <blacktrash@gmx.net>
parents: 6050
diff changeset
443 return
1038b1458d7a keyword: safeguards against erroneous behaviour or aborts
Christian Ebert <blacktrash@gmx.net>
parents: 6050
diff changeset
444 except AttributeError:
1038b1458d7a keyword: safeguards against erroneous behaviour or aborts
Christian Ebert <blacktrash@gmx.net>
parents: 6050
diff changeset
445 pass
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
446
6051
1038b1458d7a keyword: safeguards against erroneous behaviour or aborts
Christian Ebert <blacktrash@gmx.net>
parents: 6050
diff changeset
447 inc, exc = [], ['.hg*']
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
448 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
449 if opt != 'ignore':
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
450 inc.append(pat)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
451 else:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
452 exc.append(pat)
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
453 if not inc:
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
454 return
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
455
6052
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
456 if hgcmd == 'diff':
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
457 # only expand if comparing against working dir
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
458 node1, node2 = cmdutil.revpair(repo, hgcmdopts.get('rev'))
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
459 if node2 is not None:
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
460 return
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
461 # shrink if rev is not current node
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
462 if node1 is not None and node1 != repo.changectx().node():
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
463 hgcmd = 'diff1'
75425961e955 keyword: monkeypatch dispatch._parse to avoid redundant run
Christian Ebert <blacktrash@gmx.net>
parents: 6051
diff changeset
464
6071
127c973e4499 keyword: make restrict entirely a kwtemplater attribute
Christian Ebert <blacktrash@gmx.net>
parents: 6070
diff changeset
465 _kwtemplater = kwtemplater(ui, repo, inc, exc, hgcmd)
5815
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
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
6081
beb775df5630 keyword: enable all monkey patches using _kwtemplater at reposetup
Christian Ebert <blacktrash@gmx.net>
parents: 6072
diff changeset
526 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
527 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
528
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 cmdtable = {
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
531 'kwdemo':
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
532 (demo,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
533 [('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
534 ('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
535 _('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
536 'kwexpand': (expand, commands.walkopts,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
537 _('hg kwexpand [OPTION]... [FILE]...')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
538 'kwfiles':
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
539 (files,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
540 [('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
541 ('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
542 ('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
543 ] + commands.walkopts,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
544 _('hg kwfiles [OPTION]... [FILE]...')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
545 'kwshrink': (shrink, commands.walkopts,
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
546 _('hg kwshrink [OPTION]... [FILE]...')),
0637d97a8cb4 Add extension for filewise RCS-keyword expansion in working dir
Christian Ebert <blacktrash@gmx.net>
parents:
diff changeset
547 }