# HG changeset patch # User Christian Ebert # Date 1198055492 -3600 # Node ID 5957c7b5894a6833f30855af0a3a0b5e81179b77 # Parent f75ca1b0c81eb8be892923b9a34aee228a98c461 highlight: fix more tracebacks by forcing util._encoding to hgweb.encoding This is needed in case util._encoding and hgweb.encoding conflict. Extreme example: HGENCODING=UTF-8 [web] encoding = ascii Note: display of files whose encoding differs from HGENCODING or hgweb.encoding behaves not exactly the same way as with highlight turned off as replacement chars are either converted or replaced. diff -r f75ca1b0c81e -r 5957c7b5894a hgext/highlight.py --- a/hgext/highlight.py Tue Dec 18 12:45:30 2007 -0800 +++ b/hgext/highlight.py Wed Dec 19 10:11:32 2007 +0100 @@ -66,12 +66,10 @@ yield 0, "" -def pygments_format(filename, rawtext, forcetext, encoding, - stripecount, style): - etext = util.tolocal(rawtext) +def pygments_format(filename, text, forcetext, stripecount, style): if not forcetext: try: - lexer = guess_lexer_for_filename(filename, etext, + lexer = guess_lexer_for_filename(filename, text, encoding=util._encoding) except ClassNotFound: lexer = TextLexer(encoding=util._encoding) @@ -79,9 +77,9 @@ lexer = TextLexer(encoding=util._encoding) formatter = StripedHtmlFormatter(stripecount, style=style, - linenos='inline', encoding=encoding) + linenos='inline', encoding=util._encoding) - return highlight(etext, lexer, formatter) + return highlight(text, lexer, formatter) def filerevision_pygments(self, tmpl, fctx): @@ -96,6 +94,9 @@ mt = mimetypes.guess_type(f)[0] + # we always want hgweb.encoding + util._encoding = self.encoding + if util.binary(text): mt = mt or 'application/octet-stream' text = "(binary:%s)" % mt @@ -104,6 +105,9 @@ forcetext = True else: mt = mt or 'text/plain' + + # encode to hgweb.encoding for lexers and formatter + text = util.tolocal(text) forcetext = False def lines(text): @@ -112,7 +116,7 @@ style = self.config("web", "pygments_style", "colorful") - text_formatted = lines(pygments_format(f, text, forcetext, self.encoding, + text_formatted = lines(pygments_format(f, text, forcetext, self.stripecount, style)) # override per-line template