Skip to content

Commit

Permalink
gitview: Fix the encoding related bug
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Junio C Hamano <[email protected]>
  • Loading branch information
kvaneesh authored and Junio C Hamano committed Feb 27, 2006
1 parent f891cb3 commit 68d55b8
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions contrib/gitview/gitview
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ class DiffWindow:
sourceview.show()


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

fp = os.popen("git diff-tree -p " + parent_sha1 + " " + commit_sha1)
self.buffer.set_text(fp.read())
self.buffer.set_text(unicode(fp.read(), encoding).encode('utf-8'))
fp.close()
self.window.show()

Expand Down Expand Up @@ -430,6 +430,7 @@ class GitView:
self.window.set_border_width(0)
self.window.set_title("Git repository browser")

self.get_encoding()
self.get_bt_sha1()

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

def get_encoding(self):
fp = os.popen("git repo-config --get i18n.commitencoding")
self.encoding=string.strip(fp.readline())
fp.close()
if (self.encoding == ""):
self.encoding = "utf-8"


def construct(self):
"""Construct the window contents."""
Expand Down Expand Up @@ -683,7 +691,7 @@ class GitView:
self.revid_label.set_text(revid_label)
self.committer_label.set_text(committer)
self.timestamp_label.set_text(timestamp)
self.message_buffer.set_text(message)
self.message_buffer.set_text(unicode(message, self.encoding).encode('utf-8'))

for widget in self.parents_widgets:
self.table.remove(widget)
Expand Down Expand Up @@ -728,7 +736,7 @@ class GitView:
button.set_relief(gtk.RELIEF_NONE)
button.set_sensitive(True)
button.connect("clicked", self._show_clicked_cb,
commit.commit_sha1, parent_id)
commit.commit_sha1, parent_id, self.encoding)
hbox.pack_start(button, expand=False, fill=True)
button.show()

Expand Down Expand Up @@ -967,10 +975,10 @@ class GitView:

self.treeview.grab_focus()

def _show_clicked_cb(self, widget, commit_sha1, parent_sha1):
def _show_clicked_cb(self, widget, commit_sha1, parent_sha1, encoding):
"""Callback for when the show button for a parent is clicked."""
window = DiffWindow()
window.set_diff(commit_sha1, parent_sha1)
window.set_diff(commit_sha1, parent_sha1, encoding)
self.treeview.grab_focus()

if __name__ == "__main__":
Expand Down

0 comments on commit 68d55b8

Please sign in to comment.