Skip to content

Commit 68d55b8

Browse files
kvaneeshJunio C Hamano
authored andcommitted
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>
1 parent f891cb3 commit 68d55b8

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

contrib/gitview/gitview

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ class DiffWindow:
391391
sourceview.show()
392392

393393

394-
def set_diff(self, commit_sha1, parent_sha1):
394+
def set_diff(self, commit_sha1, parent_sha1, encoding):
395395
"""Set the differences showed by this window.
396396
Compares the two trees and populates the window with the
397397
differences.
@@ -401,7 +401,7 @@ class DiffWindow:
401401
return
402402

403403
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'))
405405
fp.close()
406406
self.window.show()
407407

@@ -430,6 +430,7 @@ class GitView:
430430
self.window.set_border_width(0)
431431
self.window.set_title("Git repository browser")
432432

433+
self.get_encoding()
433434
self.get_bt_sha1()
434435

435436
# Use three-quarters of the screen by default
@@ -468,6 +469,13 @@ class GitView:
468469
self.bt_sha1[sha1].append(name)
469470
fp.close()
470471

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+
471479

472480
def construct(self):
473481
"""Construct the window contents."""
@@ -683,7 +691,7 @@ class GitView:
683691
self.revid_label.set_text(revid_label)
684692
self.committer_label.set_text(committer)
685693
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'))
687695

688696
for widget in self.parents_widgets:
689697
self.table.remove(widget)
@@ -728,7 +736,7 @@ class GitView:
728736
button.set_relief(gtk.RELIEF_NONE)
729737
button.set_sensitive(True)
730738
button.connect("clicked", self._show_clicked_cb,
731-
commit.commit_sha1, parent_id)
739+
commit.commit_sha1, parent_id, self.encoding)
732740
hbox.pack_start(button, expand=False, fill=True)
733741
button.show()
734742

@@ -967,10 +975,10 @@ class GitView:
967975

968976
self.treeview.grab_focus()
969977

970-
def _show_clicked_cb(self, widget, commit_sha1, parent_sha1):
978+
def _show_clicked_cb(self, widget, commit_sha1, parent_sha1, encoding):
971979
"""Callback for when the show button for a parent is clicked."""
972980
window = DiffWindow()
973-
window.set_diff(commit_sha1, parent_sha1)
981+
window.set_diff(commit_sha1, parent_sha1, encoding)
974982
self.treeview.grab_focus()
975983

976984
if __name__ == "__main__":

0 commit comments

Comments
 (0)