Mercurial > hg-stable
changeset 6024:3121f0feefb4
keyword: nokwcommands, restricted string variables at top level
- prettier syntax conforming eg. to commands.norepo
- possibly easier to hook from outside
author | Christian Ebert <blacktrash@gmx.net> |
---|---|
date | Mon, 04 Feb 2008 21:08:45 +0100 |
parents | ee7df90d1daa |
children | f2335246e5c7 |
files | hgext/keyword.py |
diffstat | 1 files changed, 12 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/hgext/keyword.py Mon Feb 04 18:27:36 2008 +0100 +++ b/hgext/keyword.py Mon Feb 04 21:08:45 2008 +0100 @@ -86,10 +86,13 @@ commands.optionalrepo += ' kwdemo' +# hg commands that do not act on keywords +nokwcommands = ('add addremove bundle copy export grep identify incoming init' + 'log outgoing push remove rename rollback tip convert') + # hg commands that trigger expansion only when writing to working dir, # not when reading filelog, and unexpand when reading from working dir -restricted = ('diff1', 'record', - 'qfold', 'qimport', 'qnew', 'qpush', 'qrefresh', 'qrecord') +restricted = 'diff1 record qfold qimport qnew qpush qrefresh qrecord' def utcdate(date): '''Returns hgdate in cvs-like UTC format.''' @@ -113,11 +116,11 @@ 'Header': '{root}/{file},v {node|short} {date|utcdate} {author|user}', } - def __init__(self, ui, repo, inc, exc, hgcmd): + def __init__(self, ui, repo, inc, exc, restricted): self.ui = ui self.repo = repo self.matcher = util.matcher(repo.root, inc=inc, exc=exc)[1] - self.hgcmd = hgcmd + self.restricted = restricted self.commitnode = None self.path = '' @@ -156,7 +159,7 @@ def expand(self, node, data): '''Returns data with keywords expanded.''' - if util.binary(data) or self.hgcmd in restricted: + if self.restricted or util.binary(data): return data return self.substitute(node, data, self.re_kw.sub) @@ -410,12 +413,8 @@ if not repo.local(): return - nokwcommands = ('add', 'addremove', 'bundle', 'copy', 'export', 'grep', - 'identify', 'incoming', 'init', 'log', 'outgoing', 'push', - 'remove', 'rename', 'rollback', 'tip', - 'convert') hgcmd, func, args, opts, cmdopts = dispatch._parse(ui, sys.argv[1:]) - if hgcmd in nokwcommands: + if hgcmd in nokwcommands.split(): return if hgcmd == 'diff': @@ -437,7 +436,8 @@ return global _kwtemplater - _kwtemplater = kwtemplater(ui, repo, inc, exc, hgcmd) + _restricted = hgcmd in restricted.split() + _kwtemplater = kwtemplater(ui, repo, inc, exc, _restricted) class kwrepo(repo.__class__): def file(self, f, kwmatch=False): @@ -449,7 +449,7 @@ def wread(self, filename): data = super(kwrepo, self).wread(filename) - if hgcmd in restricted and _kwtemplater.matcher(filename): + if _restricted and _kwtemplater.matcher(filename): return _kwtemplater.shrink(data) return data