[PATCH] highlight: convert text to local before passing to pygmentize

Christian Ebert blacktrash at gmx.net
Thu Oct 9 06:29:46 CDT 2008


# HG changeset patch
# User Christian Ebert <blacktrash at gmx.net>
# Date 1223551751 -7200
# Node ID f3904b16d70a62a4f427d1460e369e3e44b2232b
# Parent  643c751e60b248e4672f53633e040929f8041dc0
highlight: convert text to local before passing to pygmentize

Example case:
Display file written in iso-8859-1 with currten HGENCODING utf-8.
At the moment only an Error page appears because pygmentize
chokes on the replacement chars.

Alternatives:
1) Turn off highlighting and avoid UnicodeDecodeError
   for files that are not in HGENCODING.
2) [this patch] use util.tolocal to display these files.

Alternative 2) seems ok, as this only concerns display and
readability.

See also: fe38b0a3a928, apparently put aside during refactor of
highlight.

diff --git a/hgext/highlight/highlight.py b/hgext/highlight/highlight.py
--- a/hgext/highlight/highlight.py
+++ b/hgext/highlight/highlight.py
@@ -28,6 +28,7 @@
     text = fctx.data()
     if util.binary(text):
         return
+    text = util.tolocal(text)
 
     # To get multi-line strings right, we can't format line-by-line
     try:


More information about the Mercurial-devel mailing list