templating compatibility between 3.4 and 4.1

Yuya Nishihara yuya at tcha.org
Thu Apr 20 11:50:06 UTC 2017


On Wed, 19 Apr 2017 13:22:29 -0700, Danek Duvall wrote:
> Danek Duvall wrote:
> 
> > We're trying to roll out a cute bit of templating-fu that does some
> > highlighting of keywords in descriptions.  It works pretty well.
> > Unfortunately, the same style file doesn't work on both 3.4 (which is still
> > in reasonably heavy use) and later versions (3.7, 4.1).  I know there were
> > some BC changes in 3.5, so I assume we're running into those, but I'm
> > wondering if there's some way to write the templates so they work across
> > versions.
> > 
> > I'm happy to share the full version of the template, but here's a simple
> > test case.  It has to do with sub() and using backreferences, and the
> > quoting involved.
> > 
> > If I specify the template on the commandline, it works just fine on both
> > versions (this is a recent changeset in the mercurial repo):
> > 
> >     $ hg log -r ed42e00a5c4e -T '{sub("pro(gress)", "con\\1", desc)}\n'
> > 
> > but if I move the template to a style file:
> > 
> >     $ cat /tmp/hgstyle
> >     changeset = '{sub('pro(gress)', 'con\\1', desc)}'
> >     $ hg log -r ed42e00a5c4e --config ui.style=/tmp/hgstyle
> > 
> > then while this work with 4.1, I get a ^A character where I should simply
> > see "gress".  I can get it to work with 3.4 if I use "r'con\\1'", but then
> > that doesn't work with 4.1 -- it gives me a literal "\1".
> > 
> > Is there anything we can do here, or are we going to be limited to using
> > one style file when using 3.4, and another when using something more
> > recent?
> 
> One solution another colleague suggested was to use an alternate form of
> backreference, something I hadn't seriously considered.  Using \g<1> works
> in both versions like a charm.

Mercurial 2.8.1-3.4 had a bug that strings in map file were unescaped twice,
which was fixed in 3.4.1.

https://bz.mercurial-scm.org/show_bug.cgi?id=4290

Another workaround is to load template strings from separate files.

  # hgstyle
  changeset = changeset.tmpl
  # changeset.tmpl
  {sub('pro(gress)', r'con\1', desc)}\n



More information about the Mercurial mailing list