diff -r 56573f49772c -r 03fc5e667518 hgkw/keyword.py --- a/hgkw/keyword.py Tue Feb 05 18:38:00 2008 +0100 +++ b/hgkw/keyword.py Tue Feb 05 18:40:32 2008 +0100 @@ -88,10 +88,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.''' @@ -115,11 +118,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 = '' @@ -158,7 +161,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) @@ -412,12 +415,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': @@ -439,7 +438,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): @@ -451,7 +451,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