Changeset 8a56ab916e0a…
Parent 275dac79437c…
by
Changes to 9 files · Browse files at 8a56ab916e0a Showing diff from parent 275dac79437c Diff from another changeset...
@@ -22,6 +22,7 @@ from mercurial import context, patch, revlog
from gdialog import *
from hgcmd import CmdDialog
+from hglib import toutf
class ChangeSet(GDialog):
@@ -106,7 +107,7 @@ def _fill_buffer(self, buf, rev, ctx, filelist):
def title_line(title, text, tag):
pad = ' ' * (12 - len(title))
- utext = util.fromlocal(title + pad + text)
+ utext = toutf(title + pad + text)
buf.insert_with_tags_by_name(eob, utext, tag)
buf.insert(eob, "\n")
@@ -125,10 +126,7 @@ for p in parents:
pctx = self.repo.changectx(p)
summary = pctx.description().splitlines()[0]
- try:
- summary = unicode(summary)
- except UnicodeDecodeError:
- summary = unicode(summary, util._fallbackencoding, 'replace')
+ summary = toutf(summary)
change = str(p) + ':' + short(self.repo.changelog.node(p))
title = 'parent:'
title += ' ' * (12 - len(title))
@@ -139,10 +137,7 @@ for n in self.repo.changelog.children(ctx.node()):
cctx = self.repo.changectx(n)
summary = cctx.description().splitlines()[0]
- try:
- summary = unicode(summary)
- except UnicodeDecodeError:
- summary = unicode(summary, util._fallbackencoding, 'replace')
+ summary = toutf(summary)
childrev = self.repo.changelog.rev(n)
change = str(childrev) + ':' + short(n)
title = 'child:'
@@ -155,7 +150,7 @@ childrev = self.repo.changelog.rev(n)
if tags: title_line('tags:', tags, 'tag')
- log = util.fromlocal(ctx.description())
+ log = toutf(ctx.description())
buf.insert(eob, '\n' + log + '\n\n')
if self.parent_toggle.get_active():
@@ -183,16 +178,12 @@ except StopIteration:
return False
- try:
- utxt = unicode(txt, util._encoding, 'strict')
- except UnicodeDecodeError:
- utxt = unicode(txt, util._fallbackencoding, 'replace')
- lines = utxt.splitlines()
+ lines = txt.splitlines()
eob = buf.get_end_iter()
offset = eob.get_offset()
fileoffs, tags, lines, statmax = self.prepare_diff(lines, offset, file)
for l in lines:
- buf.insert(eob, l)
+ buf.insert(eob, toutf(l))
# inserts the tags
for name, p0, p1 in tags:
@@ -206,7 +197,7 @@ pos = buf.get_iter_at_offset(offset)
mark = 'mark_%d' % offset
buf.create_mark(mark, pos)
- filelist.append((status, file, mark, True, stats))
+ filelist.append((status, toutf(file), mark, True, stats))
sob, eob = buf.get_bounds()
buf.apply_tag_by_name("mono", pos, eob)
return True
|
@@ -13,7 +13,7 @@ import os
import threading
import Queue
-from hglib import HgThread, hgcmd_toq
+from hglib import HgThread, hgcmd_toq, toutf
from shlib import set_tortoise_icon, get_system_times
class CmdDialog(gtk.Dialog):
@@ -104,7 +104,7 @@ gobject.timeout_add(10, self.process_queue)
def write(self, msg, append=True):
- msg = unicode(msg, 'iso-8859-1')
+ msg = toutf(msg, 'iso-8859-1')
if append:
enditer = self.textbuffer.get_end_iter()
self.textbuffer.insert(enditer, msg)
@@ -120,8 +120,7 @@ while self.hgthread.getqueue().qsize():
try:
msg = self.hgthread.getqueue().get(0)
- msg = unicode(msg, 'iso-8859-1')
- self.textbuffer.insert(enditer, msg)
+ self.textbuffer.insert(enditer, toutf(msg))
self.textview.scroll_to_mark(self.textbuffer.get_insert(), 0)
except Queue.Empty:
pass
|
@@ -33,6 +33,32 @@ finally:
demandimport.enable()
+def toutf(s):
+ """
+ Convert a string to UTF-8 encoding
+
+ Based on mercurial.util.tolocal()
+ """
+ for e in ('utf-8', util._encoding):
+ try:
+ return s.decode(e, 'strict').encode('utf-8')
+ except UnicodeDecodeError:
+ pass
+ return s.decode(util._fallbackencoding, 'replace').encode('utf-8')
+
+def fromutf(s):
+ """
+ Convert UTF-8 encoded string to local.
+
+ It's primarily used on strings converted to UTF-8 by toutf().
+ """
+ try:
+ return s.decode('utf-8').encode(util._encoding)
+ except UnicodeDecodeError:
+ pass
+ except UnicodeEncodeError:
+ pass
+ return s.decode('utf-8').encode(util._fallbackencoding)
def rootpath(path=None):
""" find Mercurial's repo root of path """
|
@@ -22,6 +22,7 @@ from merge import MergeDialog
from vis import treemodel
from vis.treeview import TreeView
+from hglib import toutf
import gtklib
|
@@ -21,7 +21,7 @@ from mercurial.repo import RepoError
from mercurial.node import *
from dialog import error_dialog, question_dialog
-from hglib import HgThread
+from hglib import HgThread, toutf
from shlib import set_tortoise_icon, shell_notify
import gtklib
@@ -173,7 +173,7 @@ self.stbar.set_status_text('hg ' + ' '.join(cmdline))
def write(self, msg, append=True):
- msg = unicode(msg, 'iso-8859-1')
+ msg = toutf(msg)
if append:
enditer = self.textbuffer.get_end_iter()
self.textbuffer.insert(enditer, msg)
|
@@ -250,7 +250,7 @@ self._queue.put(msg)
def _write(self, msg, append=True):
- msg = unicode(msg, 'iso-8859-1')
+ msg = hglib.toutf(msg)
if append:
enditer = self.textbuffer.get_end_iter()
self.textbuffer.insert(enditer, msg)
|
@@ -20,7 +20,7 @@ from mercurial import hg, ui, util, extensions
from mercurial.repo import RepoError
from dialog import error_dialog, question_dialog, info_dialog
-from hglib import HgThread
+from hglib import HgThread, toutf
import shlib
import gtklib
@@ -470,7 +470,7 @@ self.pathlist.append([p])
def write(self, msg, append=True):
- msg = unicode(msg, 'iso-8859-1')
+ msg = toutf(msg)
if append:
enditer = self.textbuffer.get_end_iter()
self.textbuffer.insert(enditer, msg)
|
@@ -13,6 +13,8 @@ import Queue
import win32trace
+from hglib import toutf
+
class TraceLog():
def __init__(self):
self.window = gtk.Window(gtk.WINDOW_TOPLEVEL)
@@ -111,7 +113,7 @@ self.queue.put(msg)
def write(self, msg, append=True):
- msg = unicode(msg, 'iso-8859-1')
+ msg = toutf(msg)
if append:
enditer = self.textbuffer.get_end_iter()
self.textbuffer.insert(enditer, msg)
|
@@ -29,6 +29,24 @@ MARKED = 12
FGCOLOR = 13
+# FIXME:
+# this function is a copy of hglib.touft(), but I've
+# trouble importing hglib (resides one dir level above )
+# into this module.
+#
+# Note: Python 2.5's new import syntax causes problem
+# when importing this module from command line.
+def toutf(s):
+ """
+ Convert a string to UTF-8 encoding
+ """
+ for e in ('utf-8', util._encoding):
+ try:
+ return s.decode(e, 'strict').encode('utf-8')
+ except UnicodeDecodeError:
+ pass
+ return s.decode(util._fallbackencoding, 'replace').encode('utf-8')
+
class TreeModel(gtk.GenericTreeModel):
def __init__ (self, repo, graphdata, color_func):
@@ -86,19 +104,14 @@
summary = ctx.description().replace('\0', '')
summary = summary.split('\n')[0]
- try:
- summary = unicode(summary)
- except UnicodeDecodeError:
- summary = unicode(summary, util._fallbackencoding, 'replace')
- summary = gobject.markup_escape_text(summary)
+ summary = gobject.markup_escape_text(toutf(summary))
node = self.repo.lookup(revid)
tags = ', '.join(self.repo.nodetags(node))
if '<' in ctx.user():
- author = util.fromlocal((self.author_re.sub('',
- ctx.user()).strip(' ')))
+ author = toutf(self.author_re.sub('', ctx.user()).strip(' '))
else:
- author = util.fromlocal(util.shortuser(ctx.user()))
+ author = toutf(util.shortuser(ctx.user()))
date = strftime("%Y-%m-%d %H:%M:%S", gmtime(ctx.date()[0]))
|
Loading...