# HG changeset patch # User Martin Geisler # Date 1252100091 -7200 # Node ID 6cfea6e4c892d762461f6b67d15c3f841756c9e2 # Parent ec26d6986d85f3dd00e4ceb3d9a7d8027f998653# Parent 799373ff2554a96ad61ae987f3c6a39f91c4f0ba Merge with crew-stable diff -r ec26d6986d85 -r 6cfea6e4c892 hgext/highlight/highlight.py --- 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: + # + 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')] colorized = colorized[colorized.find('
')+5:]
-    coloriter = iter(colorized.splitlines())
+    coloriter = (s.encode(encoding.encoding, 'replace')
+                 for s in colorized.splitlines())
 
     tmpl.filters['colorize'] = lambda x: coloriter.next()
 
diff -r ec26d6986d85 -r 6cfea6e4c892 mercurial/error.py
--- 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
 
diff -r ec26d6986d85 -r 6cfea6e4c892 mercurial/hg.py
--- 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)
 
diff -r ec26d6986d85 -r 6cfea6e4c892 mercurial/localrepo.py
--- 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
diff -r ec26d6986d85 -r 6cfea6e4c892 tests/test-highlight
--- 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 '
' | $TESTDIR/printrepr.py + echo % errors encountered + cat errors.log +} + +hgserveget euc-jp eucjp.txt +hgserveget utf-8 eucjp.txt +hgserveget us-ascii eucjp.txt diff -r ec26d6986d85 -r 6cfea6e4c892 tests/test-highlight.out --- 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 +
1 \xb5\xfe
+% errors encountered +% HGENCODING=utf-8 hg serve +% hgweb filerevision, html +
1 \xef\xbf\xbd\xef\xbf\xbd
+% errors encountered +% HGENCODING=us-ascii hg serve +% hgweb filerevision, html +
1 ??
+% errors encountered