Preparsing templates and cache breaks hgext.highlight

Matt Mackall mpm at selenic.com
Sun Apr 18 17:52:05 CDT 2010


On Sun, 2010-04-18 at 14:33 +0200, Isaac Jurado wrote:
> Replying Christian Ebert:
> > * Christian Ebert on Saturday, April 17, 2010 at 23:54:18 +0200
> > > * Mercurial Commits on Monday, April 05, 2010 at 23:15:34 +0200
> > >> http://selenic.com/repo/hg//rev/9d8194c2fcbd
> > >> changeset:   10845:9d8194c2fcbd
> > >> user:        Matt Mackall <mpm at selenic.com>
> > >> date:        Mon Apr 05 15:25:08 2010 -0500
> > >> summary:     templater: preparse templates and cache
> > > 
> > > This breaks makes hgext.hightlight a noop. At least here on
> > > localhost. Will investigate further.
> > 
> > $ ./run-tests.py test-highlight
> > 
> > ERROR: /Users/chris/HGworkspace/hg-crew-mq/tests/test-highlight output changed
> > --- /Users/chris/HGworkspace/hg-crew-mq/tests/test-highlight.out
> > +++ /Users/chris/HGworkspace/hg-crew-mq/tests/test-highlight.err
> > @@ -10,7 +10,6 @@
> >  <meta name="robots" content="index, nofollow" />
> >  <link rel="stylesheet" href="/static/style-paper.css" type="text/css" />
> > 
> > -<link rel="stylesheet" href="/highlightcss" type="text/css" />
> >  <title>test: 853dcd4de2a6 primes.py</title>
> >  </head>
> >  <body>
> > @@ -129,7 +128,6 @@
> >  <meta name="robots" content="index, nofollow" />
> >  <link rel="stylesheet" href="/static/style-paper.css" type="text/css" />
> > 
> > -<link rel="stylesheet" href="/highlightcss" type="text/css" />
> >  <title>test: primes.py annotate</title>
> >  </head>
> >  <body>
> > !
> > Failed test-highlight: output changed
> > # Ran 1 tests, 0 skipped, 1 failed.
> 
> It is funny because everything seems to work, but the stylesheet
> reference is not inserted: hgext.highlight.highlight.pygmentize is
> called correctly, the CSS link line is added to tmpl.cache['header']
> normally, the rest of the text is highlighted.  However, the modified
> header is ignored.

Here's my fix:

diff -r 5eaedcd29642 hgext/highlight/highlight.py
--- a/hgext/highlight/highlight.py	Sun Apr 18 18:18:19 2010 -0400
+++ b/hgext/highlight/highlight.py	Sun Apr 18 15:47:54 2010 -0700
@@ -23,7 +23,7 @@
 def pygmentize(field, fctx, style, tmpl):
 
     # append a <link ...> to the syntax highlighting css
-    old_header = ''.join(tmpl('header'))
+    old_header = tmpl.load('header')
     if SYNTAX_CSS not in old_header:
         new_header =  old_header + SYNTAX_CSS
         tmpl.cache['header'] = new_header

The original code was wrong in the sense that it was not only loading
the template, it was actually instantiating it as well, then putting the
instantiated template back into the cache as a raw template.
Instantiation was causing the template to get parsed and cached by the
templating engine.

This patch simply loads the raw template and modifies it without showing
it to the engine.

-- 
http://selenic.com : development and support for Mercurial and Linux




More information about the Mercurial-devel mailing list