[PATCH] templates: add built-in fileset() function
Yuya Nishihara
yuya at tcha.org
Wed Sep 21 10:08:48 EDT 2016
On Wed, 21 Sep 2016 19:59:45 +0900, FUJIWARA Katsunori wrote:
> At Tue, 20 Sep 2016 15:57:41 +0000,
> Hannes Oldenburg wrote:
> > # HG changeset patch
> > # User Hannes Oldenburg <hannes.christian.oldenburg at gmail.com>
> > # Date 1474379333 0
> > # Tue Sep 20 13:48:53 2016 +0000
> > # Node ID cf2156395bff0e3fc4a6604b8aa45b5b7829ba98
> > # Parent 285a8c3e53f2183438f0cdbc238e4ab851d0d110
> > templates: add built-in fileset() function
> > + at templatefunc('fileset(query)')
> > +def fileset(context, mapping, args):
> > + """Execute a fileset set query with the current changeset. See
> > + :hg:`help fileset`."""
> > + if not len(args) == 1:
> > + # i18n: "revset" is a keyword
>
> nitpicking: "fileset" is a keyword
>
> > + raise error.ParseError(_("fileset expects no arguments"))
> > +
> > + raw = evalstring(context, mapping, args[0])
> > + ctx = mapping['ctx']
> > + filesetcache = mapping['cache'].setdefault("filesetcache", {})
> > + if raw in filesetcache:
> > + files = filesetcache[raw]
> > + else:
> > + files = ctx.getfileset(raw)
Unlike revset, fileset is a low-level function behind matcher and enabled
by 'set:' prefix. I think this function should use ctx.match() (i.e. glob
pattern by default), and be named as 'files(pattern)'.
> > + filesetcache[raw] = files
>
> fileset query should be evaluated for each templated changesets, but
> mapping['cache'] is shared between those changesets.
>
> Therefore, fileset() template function returns unexpected result for
> the second or later changesets in templating.
>
> IMHO, 'revcache' instead of 'cache' seems appropriate for this
> purpose.
or simply go without cache. I don't think the cached data would be reused in
most cases.
More information about the Mercurial-devel
mailing list