gitview: Fix the encoding related bug
Get the encoding information from repository and convert it to utf-8 before passing to gtk.TextBuffer.set_text. gtk.TextBuffer.set_text work only with utf-8 Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com> Signed-off-by: Junio C Hamano <junkio@cox.net>
Aneesh Kumar K.V committed
Feb 27, 2006 at 21:25 UTC
68d55b83a58a68fc1c9cef63f0deccbff3251096
1 file changed
+14
-6
contrib/gitview/gitview
+14
-6
@@ -391,7 +391,7 @@ class DiffWindow:
391
sourceview.show()
392
393
394
- def set_diff(self, commit_sha1, parent_sha1):
394
+ def set_diff(self, commit_sha1, parent_sha1, encoding):
395
"""Set the differences showed by this window.
396
Compares the two trees and populates the window with the
397
differences.
@@ -401,7 +401,7 @@ class DiffWindow:
401
return
402
403
fp = os.popen("git diff-tree -p " + parent_sha1 + " " + commit_sha1)
404
- self.buffer.set_text(fp.read())
404
+ self.buffer.set_text(unicode(fp.read(), encoding).encode('utf-8'))
405
fp.close()
406
self.window.show()
407
@@ -430,6 +430,7 @@ class GitView:
430
self.window.set_border_width(0)
431
self.window.set_title("Git repository browser")
432
433
+ self.get_encoding()
434
self.get_bt_sha1()
435
436
# Use three-quarters of the screen by default
@@ -468,6 +469,13 @@ class GitView:
469
self.bt_sha1[sha1].append(name)
470
fp.close()
471
472
+ def get_encoding(self):
473
+ fp = os.popen("git repo-config --get i18n.commitencoding")
474
+ self.encoding=string.strip(fp.readline())
475
+ fp.close()
476
+ if (self.encoding == ""):
477
+ self.encoding = "utf-8"
478
+
479
480
def construct(self):
481
"""Construct the window contents."""
@@ -683,7 +691,7 @@ class GitView:
691
self.revid_label.set_text(revid_label)
692
self.committer_label.set_text(committer)
693
self.timestamp_label.set_text(timestamp)
686
- self.message_buffer.set_text(message)
694
+ self.message_buffer.set_text(unicode(message, self.encoding).encode('utf-8'))
695
696
for widget in self.parents_widgets:
697
self.table.remove(widget)
@@ -728,7 +736,7 @@ class GitView:
736
button.set_relief(gtk.RELIEF_NONE)
737
button.set_sensitive(True)
738
button.connect("clicked", self._show_clicked_cb,
731
- commit.commit_sha1, parent_id)
739
+ commit.commit_sha1, parent_id, self.encoding)
740
hbox.pack_start(button, expand=False, fill=True)
741
button.show()
742
@@ -967,10 +975,10 @@ class GitView:
975
976
self.treeview.grab_focus()
977
970
- def _show_clicked_cb(self, widget, commit_sha1, parent_sha1):
978
+ def _show_clicked_cb(self, widget, commit_sha1, parent_sha1, encoding):
979
"""Callback for when the show button for a parent is clicked."""
980
window = DiffWindow()
973
- window.set_diff(commit_sha1, parent_sha1)
981
+ window.set_diff(commit_sha1, parent_sha1, encoding)
982
self.treeview.grab_focus()
983
984
if __name__ == "__main__":