{"thread":{"id":"3478","subject":"gitview: Fix the encoding related bug","startedAt":"2006-02-27T15:55:13Z","lastAt":"2006-02-27T15:55:13Z","messageCount":1,"participants":["Aneesh Kumar K.V"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"16823","messageId":"440320E1.4080301@gmail.com","threadId":"3478","inReplyTo":null,"subject":"gitview: Fix the encoding related bug","fromName":"Aneesh Kumar K.V","fromEmail":"aneesh.kumar@gmail.com","sentAt":"2006-02-27T15:55:13Z","receivedAt":"2006-02-27T15:55:13Z","isPatch":false,"sender":{"key":"aneesh.kumar@gmail.com","avatar":"https://gravatar.com/avatar/0621fc0b2f14ead1e9024382f16053a808c148596da30c1b92572fa075621f68?d=mp&s=160"},"body":"\n\nSubject: gitview: Fix the encoding related bug\n\nGet the encoding information from repository and convert it to utf-8 before\npassing to gtk.TextBuffer.set_text. gtk.TextBuffer.set_text work only with utf-8\n\nSigned-off-by: Aneesh Kumar K.V <aneesh.kumar@gmail.com>\n\n---\n\n contrib/gitview/gitview |   20 ++++++++++++++------\n 1 files changed, 14 insertions(+), 6 deletions(-)\n\n0900cf4b80aa18e314aa487d84189b8237d088e7\ndiff --git a/contrib/gitview/gitview b/contrib/gitview/gitview\nindex 4e3847d..1d042e3 100755\n--- a/contrib/gitview/gitview\n+++ b/contrib/gitview/gitview\n@@ -391,7 +391,7 @@ class DiffWindow:\n \t\tsourceview.show()\n \n \n-\tdef set_diff(self, commit_sha1, parent_sha1):\n+\tdef set_diff(self, commit_sha1, parent_sha1, encoding):\n \t\t\"\"\"Set the differences showed by this window.\n \t\tCompares the two trees and populates the window with the\n \t\tdifferences.\n@@ -401,7 +401,7 @@ class DiffWindow:\n \t\t\treturn\n \n \t\tfp = os.popen(\"git diff-tree -p \" + parent_sha1 + \" \" + commit_sha1)\n-\t\tself.buffer.set_text(fp.read())\n+\t\tself.buffer.set_text(unicode(fp.read(), encoding).encode('utf-8'))\n \t\tfp.close()\n \t\tself.window.show()\n \n@@ -430,6 +430,7 @@ class GitView:\n \t\tself.window.set_border_width(0)\n \t\tself.window.set_title(\"Git repository browser\")\n \n+\t\tself.get_encoding()\n \t\tself.get_bt_sha1()\n \n \t\t# Use three-quarters of the screen by default\n@@ -468,6 +469,13 @@ class GitView:\n \t\t\tself.bt_sha1[sha1].append(name)\n \t\tfp.close()\n \n+\tdef get_encoding(self):\n+\t\tfp = os.popen(\"git repo-config --get i18n.commitencoding\")\n+\t\tself.encoding=string.strip(fp.readline())\n+\t\tfp.close()\n+\t\tif (self.encoding == \"\"):\n+\t\t\tself.encoding = \"utf-8\"\n+\n \n \tdef construct(self):\n \t\t\"\"\"Construct the window contents.\"\"\"\n@@ -683,7 +691,7 @@ class GitView:\n \t\tself.revid_label.set_text(revid_label)\n \t\tself.committer_label.set_text(committer)\n \t\tself.timestamp_label.set_text(timestamp)\n-\t\tself.message_buffer.set_text(message)\n+\t\tself.message_buffer.set_text(unicode(message, self.encoding).encode('utf-8'))\n \n \t\tfor widget in self.parents_widgets:\n \t\t\tself.table.remove(widget)\n@@ -728,7 +736,7 @@ class GitView:\n \t\t\tbutton.set_relief(gtk.RELIEF_NONE)\n \t\t\tbutton.set_sensitive(True)\n \t\t\tbutton.connect(\"clicked\", self._show_clicked_cb,\n-\t\t\t\t\tcommit.commit_sha1, parent_id)\n+\t\t\t\t\tcommit.commit_sha1, parent_id, self.encoding)\n \t\t\thbox.pack_start(button, expand=False, fill=True)\n \t\t\tbutton.show()\n \n@@ -967,10 +975,10 @@ class GitView:\n \n \t\tself.treeview.grab_focus()\n \n-\tdef _show_clicked_cb(self, widget,  commit_sha1, parent_sha1):\n+\tdef _show_clicked_cb(self, widget,  commit_sha1, parent_sha1, encoding):\n \t\t\"\"\"Callback for when the show button for a parent is clicked.\"\"\"\n \t\twindow = DiffWindow()\n-\t\twindow.set_diff(commit_sha1, parent_sha1)\n+\t\twindow.set_diff(commit_sha1, parent_sha1, encoding)\n \t\tself.treeview.grab_focus()\n \n if __name__ == \"__main__\":\n-- \n1.2.3.g2cf3-dirty\n\n"}]}