Show More
@@ -86,10 +86,13 b' import re, shutil, sys, tempfile, time' | |||||
86 |
|
86 | |||
87 | commands.optionalrepo += ' kwdemo' |
|
87 | commands.optionalrepo += ' kwdemo' | |
88 |
|
88 | |||
|
89 | # hg commands that do not act on keywords | |||
|
90 | nokwcommands = ('add addremove bundle copy export grep identify incoming init' | |||
|
91 | 'log outgoing push remove rename rollback tip convert') | |||
|
92 | ||||
89 | # hg commands that trigger expansion only when writing to working dir, |
|
93 | # hg commands that trigger expansion only when writing to working dir, | |
90 | # not when reading filelog, and unexpand when reading from working dir |
|
94 | # not when reading filelog, and unexpand when reading from working dir | |
91 | restricted = ('diff1', 'record', |
|
95 | restricted = 'diff1 record qfold qimport qnew qpush qrefresh qrecord' | |
92 | 'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord') |
|
|||
93 |
|
96 | |||
94 | def utcdate(date): |
|
97 | def utcdate(date): | |
95 | '''Returns hgdate in cvs-like UTC format.''' |
|
98 | '''Returns hgdate in cvs-like UTC format.''' | |
@@ -113,11 +116,11 b' class kwtemplater(object):' | |||||
113 | 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', |
|
116 | 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', | |
114 | } |
|
117 | } | |
115 |
|
118 | |||
116 |
def __init__(self, ui, repo, inc, exc, |
|
119 | def __init__(self, ui, repo, inc, exc, restricted): | |
117 | self.ui = ui |
|
120 | self.ui = ui | |
118 | self.repo = repo |
|
121 | self.repo = repo | |
119 | self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1] |
|
122 | self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1] | |
120 |
self. |
|
123 | self.restricted = restricted | |
121 | self.commitnode = None |
|
124 | self.commitnode = None | |
122 | self.path = '' |
|
125 | self.path = '' | |
123 |
|
126 | |||
@@ -156,7 +159,7 b' class kwtemplater(object):' | |||||
156 |
|
159 | |||
157 | def expand(self, node, data): |
|
160 | def expand(self, node, data): | |
158 | '''Returns data with keywords expanded.''' |
|
161 | '''Returns data with keywords expanded.''' | |
159 | if util.binary(data) or self.hgcmd in restricted: |
|
162 | if self.restricted or util.binary(data): | |
160 | return data |
|
163 | return data | |
161 | return self.substitute(node, data, self.re_kw.sub) |
|
164 | return self.substitute(node, data, self.re_kw.sub) | |
162 |
|
165 | |||
@@ -410,12 +413,8 b' def reposetup(ui, repo):' | |||||
410 | if not repo.local(): |
|
413 | if not repo.local(): | |
411 | return |
|
414 | return | |
412 |
|
415 | |||
413 | nokwcommands = ('add', 'addremove', 'bundle', 'copy', 'export', 'grep', |
|
|||
414 | 'identify', 'incoming', 'init', 'log', 'outgoing', 'push', |
|
|||
415 | 'remove', 'rename', 'rollback', 'tip', |
|
|||
416 | 'convert') |
|
|||
417 | hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:]) |
|
416 | hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:]) | |
418 | if hgcmd in nokwcommands: |
|
417 | if hgcmd in nokwcommands.split(): | |
419 | return |
|
418 | return | |
420 |
|
419 | |||
421 | if hgcmd == 'diff': |
|
420 | if hgcmd == 'diff': | |
@@ -437,7 +436,8 b' def reposetup(ui, repo):' | |||||
437 | return |
|
436 | return | |
438 |
|
437 | |||
439 | global _kwtemplater |
|
438 | global _kwtemplater | |
440 | _kwtemplater = kwtemplater(ui, repo, inc, exc, hgcmd) |
|
439 | _restricted = hgcmd in restricted.split() | |
|
440 | _kwtemplater = kwtemplater(ui, repo, inc, exc, _restricted) | |||
441 |
|
441 | |||
442 | class kwrepo(repo.__class__): |
|
442 | class kwrepo(repo.__class__): | |
443 | def file(self, f, kwmatch=False): |
|
443 | def file(self, f, kwmatch=False): | |
@@ -449,7 +449,7 b' def reposetup(ui, repo):' | |||||
449 |
|
449 | |||
450 | def wread(self, filename): |
|
450 | def wread(self, filename): | |
451 | data = super(kwrepo, self).wread(filename) |
|
451 | data = super(kwrepo, self).wread(filename) | |
452 |
if |
|
452 | if _restricted and _kwtemplater.matcher(filename): | |
453 | return _kwtemplater.shrink(data) |
|
453 | return _kwtemplater.shrink(data) | |
454 | return data |
|
454 | return data | |
455 |
|
455 |
General Comments 0
You need to be logged in to leave comments.
Login now