--- a/hgext/highlight/highlight.py Fri Sep 04 22:26:57 2009 +0200
+++ b/hgext/highlight/highlight.py Fri Sep 04 23:34:51 2009 +0200
@@ -32,26 +32,27 @@
if util.binary(text):
return
- # avoid UnicodeDecodeError in pygments
- text = encoding.tolocal(text)
+ # Pygments is best used with Unicode strings:
+ # <http://pygments.org/docs/unicode/>
+ text = text.decode(encoding.encoding, 'replace')
# To get multi-line strings right, we can't format line-by-line
try:
- lexer = guess_lexer_for_filename(fctx.path(), text[:1024],
- encoding=encoding.encoding)
+ lexer = guess_lexer_for_filename(fctx.path(), text[:1024])
except (ClassNotFound, ValueError):
try:
- lexer = guess_lexer(text[:1024], encoding=encoding.encoding)
+ lexer = guess_lexer(text[:1024])
except (ClassNotFound, ValueError):
- lexer = TextLexer(encoding=encoding.encoding)
+ lexer = TextLexer()
- formatter = HtmlFormatter(style=style, encoding=encoding.encoding)
+ formatter = HtmlFormatter(style=style)
colorized = highlight(text, lexer, formatter)
# strip wrapping div
colorized = colorized[:colorized.find('\n</pre>')]
colorized = colorized[colorized.find('<pre>')+5:]
- coloriter = iter(colorized.splitlines())
+ coloriter = (s.encode(encoding.encoding, 'replace')
+ for s in colorized.splitlines())
tmpl.filters['colorize'] = lambda x: coloriter.next()
--- a/mercurial/error.py Fri Sep 04 22:26:57 2009 +0200
+++ b/mercurial/error.py Fri Sep 04 23:34:51 2009 +0200
@@ -36,6 +36,9 @@
class RepoError(Exception):
pass
+class RepoLookupError(RepoError):
+ pass
+
class CapabilityError(RepoError):
pass
--- a/mercurial/hg.py Fri Sep 04 22:26:57 2009 +0200
+++ b/mercurial/hg.py Fri Sep 04 23:34:51 2009 +0200
@@ -137,10 +137,12 @@
if update is not True:
checkout = update
for test in (checkout, 'default', 'tip'):
+ if test is None:
+ continue
try:
uprev = r.lookup(test)
break
- except LookupError:
+ except error.RepoLookupError:
continue
_update(r, uprev)
@@ -309,10 +311,12 @@
if update is not True:
checkout = update
for test in (checkout, 'default', 'tip'):
+ if test is None:
+ continue
try:
uprev = dest_repo.lookup(test)
break
- except:
+ except error.RepoLookupError:
continue
_update(dest_repo, uprev)
--- a/mercurial/localrepo.py Fri Sep 04 22:26:57 2009 +0200
+++ b/mercurial/localrepo.py Fri Sep 04 23:34:51 2009 +0200
@@ -459,7 +459,7 @@
key = hex(key)
except:
pass
- raise error.RepoError(_("unknown revision '%s'") % key)
+ raise error.RepoLookupError(_("unknown revision '%s'") % key)
def local(self):
return True
--- a/tests/test-highlight Fri Sep 04 22:26:57 2009 +0200
+++ b/tests/test-highlight Fri Sep 04 23:34:51 2009 +0200
@@ -121,3 +121,28 @@
echo % errors encountered
cat errors.log
+
+cd ..
+hg init eucjp
+cd eucjp
+
+printf '\265\376\n' >> eucjp.txt # Japanese kanji "Kyo"
+
+hg ci -Ama
+
+hgserveget () {
+ "$TESTDIR/killdaemons.py"
+ echo % HGENCODING="$1" hg serve
+ HGENCODING="$1" hg serve -p $HGPORT -d -n test --pid-file=hg.pid -E errors.log
+ cat hg.pid >> $DAEMON_PIDS
+
+ echo % hgweb filerevision, html
+ "$TESTDIR/get-with-headers.py" localhost:$HGPORT "/file/tip/$2" \
+ | grep '<div class="parity0 source">' | $TESTDIR/printrepr.py
+ echo % errors encountered
+ cat errors.log
+}
+
+hgserveget euc-jp eucjp.txt
+hgserveget utf-8 eucjp.txt
+hgserveget us-ascii eucjp.txt
--- a/tests/test-highlight.out Fri Sep 04 22:26:57 2009 +0200
+++ b/tests/test-highlight.out Fri Sep 04 23:34:51 2009 +0200
@@ -538,3 +538,16 @@
/* pygments_style = fruity */
% errors encountered
+adding eucjp.txt
+% HGENCODING=euc-jp hg serve
+% hgweb filerevision, html
+<div class="parity0 source"><a href="#l1" id="l1"> 1</a> \xb5\xfe</div>
+% errors encountered
+% HGENCODING=utf-8 hg serve
+% hgweb filerevision, html
+<div class="parity0 source"><a href="#l1" id="l1"> 1</a> \xef\xbf\xbd\xef\xbf\xbd</div>
+% errors encountered
+% HGENCODING=us-ascii hg serve
+% hgweb filerevision, html
+<div class="parity0 source"><a href="#l1" id="l1"> 1</a> ??</div>
+% errors encountered