diff -r 7bc6c0e12464 -r 82e2b3807073 hgkw/keyword.py --- a/hgkw/keyword.py Tue Feb 05 12:22:48 2008 +0100 +++ b/hgkw/keyword.py Tue Feb 05 16:13:15 2008 +0100 @@ -80,7 +80,7 @@ "Log = {desc}" expands to the first line of the changeset description. ''' -from mercurial import commands, cmdutil, context, filelog, localrepo +from mercurial import commands, cmdutil, context, localrepo from mercurial import patch, revlog, templater, templatefilters, util from mercurial.node import * from mercurial.hgweb import webcommands @@ -142,10 +142,6 @@ except revlog.LookupError: # eg: convert return subfunc == self.re_kw.sub and data or (data, None) - elif subfunc == self.re_kw.sub: - # hg kwcat using kwfilelog.read - c = context.filectx(self.repo, path, fileid=node) - node = c.node() def kwsub(mobj): '''Substitutes keyword using corresponding template.''' @@ -181,20 +177,6 @@ return data return self.re_kw.sub(r'$\1$', data) -class kwfilelog(filelog.filelog): - ''' - Subclass of filelog to hook into its read method for kwcat. - ''' - def __init__(self, opener, path, kwt): - super(kwfilelog, self).__init__(opener, path) - self._kwt = kwt - self._path = path - - def read(self, node): - '''Expands keywords when reading filelog.''' - data = super(kwfilelog, self).read(node) - return self._kwt.expand(self._path, data, node) - # store original patch.patchfile.__init__ _patchfile_init = patch.patchfile.__init__ @@ -263,11 +245,22 @@ %d dirname of file being printed, or '.' if in repo root %p root-relative path name of file being printed ''' + ctx = repo.changectx(opts['rev']) try: - repo.file = repo._kwfile + repo._kwt.ctx = ctx + kw = True except AttributeError: - pass - commands.cat(ui, repo, file1, *pats, **opts) + kw = False + err = 1 + for src, abs, rel, exact in cmdutil.walk(repo, (file1,) + pats, opts, + ctx.node()): + fp = cmdutil.make_file(repo, opts['output'], ctx.node(), pathname=abs) + data = ctx.filectx(abs).data() + if kw and repo._kwt.matcher(abs): + data = repo._kwt.expand(abs, data, None) + fp.write(data) + err = 0 + return err def demo(ui, repo, *args, **opts): '''print [keywordmaps] configuration and an expansion example @@ -408,14 +401,6 @@ return class kwrepo(repo.__class__): - def _kwfile(self, f): - '''Returns filelog expanding keywords on read (for kwcat).''' - if f[0] == '/': - f = f[1:] - if self._kwt.matcher(f): - return kwfilelog(self.sopener, f, self._kwt) - return filelog.filelog(self.sopener, f) - def _wreadkwct(self, filename, expand, ctx, node): '''Reads filename and returns tuple of data with keywords expanded/shrunk and count of keywords (for _overwrite).''' @@ -509,7 +494,7 @@ path = fctx.path() text = fctx.data() if kwt.matcher(path): - text = kwt.expand(path, text, None) + text = kwt.expand(path, text, fctx.node()) mt = mimetypes.guess_type(path)[0] if mt is None or util.binary(text): mt = mt or 'application/octet-stream'