Kiln » TortoiseHg » TortoiseHg
Clone URL:  
Pushed to one repository · View In Graph Contained in 0.4rc2, 0.4rc3, and 0.4rc4

hggtk: generic fix on encoding issues

respect env variable HGENCODING, but not HGENCODINGMODE.

Changeset 8a56ab916e0a

Parent 275dac79437c

by TK Soh

Changes to 9 files · Browse files at 8a56ab916e0a Showing diff from parent 275dac79437c Diff from another changeset...

 
22
23
24
 
25
26
27
 
106
107
108
109
 
110
111
112
 
125
126
127
128
129
130
131
 
132
133
134
 
139
140
141
142
143
144
145
 
146
147
148
 
155
156
157
158
 
159
160
161
 
183
184
185
186
187
188
189
190
 
191
192
193
194
195
 
196
197
198
 
206
207
208
209
 
210
211
212
 
22
23
24
25
26
27
28
 
107
108
109
 
110
111
112
113
 
126
127
128
 
 
 
 
129
130
131
132
 
137
138
139
 
 
 
 
140
141
142
143
 
150
151
152
 
153
154
155
156
 
178
179
180
 
 
 
 
 
181
182
183
184
185
 
186
187
188
189
 
197
198
199
 
200
201
202
203
@@ -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
Change 1 of 3 Show Entire File hggtk/​hgcmd.py Stacked
 
13
14
15
16
 
17
18
19
 
104
105
106
107
 
108
109
110
 
120
121
122
123
124
 
125
126
127
 
13
14
15
 
16
17
18
19
 
104
105
106
 
107
108
109
110
 
120
121
122
 
 
123
124
125
126
@@ -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
Change 1 of 1 Show Entire File hggtk/​hglib.py Stacked
 
33
34
35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
37
38
 
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@@ -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 """
Change 1 of 1 Show Entire File hggtk/​history.py Stacked
 
22
23
24
 
25
26
27
 
22
23
24
25
26
27
28
@@ -22,6 +22,7 @@
 from merge import MergeDialog  from vis import treemodel  from vis.treeview import TreeView +from hglib import toutf  import gtklib    
Change 1 of 2 Show Entire File hggtk/​recovery.py Stacked
 
21
22
23
24
 
25
26
27
 
173
174
175
176
 
177
178
179
 
21
22
23
 
24
25
26
27
 
173
174
175
 
176
177
178
179
@@ -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)
Change 1 of 1 Show Entire File hggtk/​serve.py Stacked
 
250
251
252
253
 
254
255
256
 
250
251
252
 
253
254
255
256
@@ -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)
Change 1 of 2 Show Entire File hggtk/​synch.py Stacked
 
20
21
22
23
 
24
25
26
 
470
471
472
473
 
474
475
476
 
20
21
22
 
23
24
25
26
 
470
471
472
 
473
474
475
476
@@ -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)
Change 1 of 2 Show Entire File hggtk/​tracelog.py Stacked
 
13
14
15
 
 
16
17
18
 
111
112
113
114
 
115
116
117
 
13
14
15
16
17
18
19
20
 
113
114
115
 
116
117
118
119
@@ -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
30
31
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
32
33
34
 
86
87
88
89
90
91
92
93
 
94
95
96
97
98
99
 
100
101
 
102
103
104
 
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
 
104
105
106
 
 
 
 
 
107
108
109
110
111
 
 
112
113
 
114
115
116
117
@@ -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]))