{"thread":{"id":"26402","subject":"[PATCH] gitk: Honor encoding conversion in a sole place for all possible cases","startedAt":"2011-02-03T16:42:33Z","lastAt":"2011-02-03T17:20:57Z","messageCount":2,"participants":["Alexey Shumkin"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"160337","messageId":"1296751353-8632-1-git-send-email-zapped@mail.ru","threadId":"26402","inReplyTo":null,"subject":"[PATCH] gitk: Honor encoding conversion in a sole place for all possible cases","fromName":"Alexey Shumkin","fromEmail":"zapped@mail.ru","sentAt":"2011-02-03T16:42:33Z","receivedAt":"2011-02-03T16:42:33Z","isPatch":true,"sender":{"key":"alex.crezoff@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1183752?v=4"},"body":"Previously every bug concerning encoding conversion\nwas fixed with a particular patch in a particular line of code\n(e.g. 1f2cecfd53137b76d39b2dcd7bcf7e918cd745b3)\nregardless other similar situations.\n\nThis patch centralizes reencoding of displayed text\nconsidering all the cases where non-latin encoding may be used:\nfilenames, submodule names, rename/copy files, diffs (hunks),\ncommits comparison\n\nAlso cleaned up global \"diffencoding\" variable\n\nTested on Cygwin 1.5 and Cygwin 1.7\n\nStill buggy on Cygwin 1.7: on a clear working copy shows\nnon-latin named files as removed and not indexed\n\nSigned-off-by: Alexey Shumkin <zapped@mail.ru>\n---\n gitk |   24 ++++++++++--------------\n 1 files changed, 10 insertions(+), 14 deletions(-)\n\ndiff --git a/gitk b/gitk\nindex 9cbc09d..1f9627d 100755\n--- a/gitk\n+++ b/gitk\n@@ -5047,7 +5047,8 @@ proc dodiffindex {} {\n proc readdiffindex {fd serial inst} {\n     global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial\n     global vfilelimit\n-\n+    global gui_encoding\n+\t\n     set isdiff 1\n     if {[gets $fd line] < 0} {\n \tif {![eof $fd]} {\n@@ -5069,6 +5070,9 @@ proc readdiffindex {fd serial inst} {\n     }\n     set fd [open $cmd r]\n     fconfigure $fd -blocking 0\n+    if {$gui_encoding != {}} {\n+\tfconfigure $fd -encoding $gui_encoding\n+    }\n     set i [reg_instance $fd]\n     filerun $fd [list readdifffiles $fd $serial $i]\n \n@@ -7541,7 +7545,7 @@ proc getblobdiffs {ids} {\n     global ignorespace\n     global worddiff\n     global limitdiffs vfilelimit curview\n-    global diffencoding targetline diffnparents\n+    global targetline diffnparents\n     global git_version currdiffsubmod\n \n     set textconv {}\n@@ -7570,7 +7574,7 @@ proc getblobdiffs {ids} {\n     set diffnparents 0\n     set diffinhdr 0\n     set diffencoding [get_path_encoding {}]\n-    fconfigure $bdf -blocking 0 -encoding binary -eofchar {}\n+    fconfigure $bdf -blocking 0 -encoding $diffencoding -eofchar {}\n     set blobdifffd($ids) $bdf\n     set currdiffsubmod \"\"\n     filerun $bdf [list getblobdiffline $bdf $diffids]\n@@ -7618,11 +7622,9 @@ proc setinlist {var i val} {\n }\n \n proc makediffhdr {fname ids} {\n-    global ctext curdiffstart treediffs diffencoding\n+    global ctext curdiffstart treediffs\n     global ctext_file_names jump_to_here targetline diffline\n \n-    set fname [encoding convertfrom $fname]\n-    set diffencoding [get_path_encoding $fname]\n     set i [lsearch -exact $treediffs($ids) $fname]\n     if {$i >= 0} {\n \tsetinlist difffilestart $i $curdiffstart\n@@ -7643,7 +7645,7 @@ proc getblobdiffline {bdf ids} {\n     global diffnexthead diffnextnote difffilestart\n     global ctext_file_names ctext_file_lines\n     global diffinhdr treediffs mergemax diffnparents\n-    global diffencoding jump_to_here targetline diffline currdiffsubmod\n+    global jump_to_here targetline diffline currdiffsubmod\n     global worddiff\n \n     set nr 0\n@@ -7655,7 +7657,6 @@ proc getblobdiffline {bdf ids} {\n \t}\n \tif {![string compare -length 5 \"diff \" $line]} {\n \t    if {![regexp {^diff (--cc|--git) } $line m type]} {\n-\t\tset line [encoding convertfrom $line]\n \t\t$ctext insert end \"$line\\n\" hunksep\n \t\tcontinue\n \t    }\n@@ -7715,7 +7716,6 @@ proc getblobdiffline {bdf ids} {\n \n \t} elseif {![string compare -length 2 \"@@\" $line]} {\n \t    regexp {^@@+} $line ats\n-\t    set line [encoding convertfrom $diffencoding $line]\n \t    $ctext insert end \"$line\\n\" hunksep\n \t    if {[regexp { \\+(\\d+),\\d+ @@} $line m nl]} {\n \t\tset diffline $nl\n@@ -7745,11 +7745,9 @@ proc getblobdiffline {bdf ids} {\n \t    }\n \t} elseif {![string compare -length 3 \"  >\" $line]} {\n \t    set $currdiffsubmod \"\"\n-\t    set line [encoding convertfrom $diffencoding $line]\n \t    $ctext insert end \"$line\\n\" dresult\n \t} elseif {![string compare -length 3 \"  <\" $line]} {\n \t    set $currdiffsubmod \"\"\n-\t    set line [encoding convertfrom $diffencoding $line]\n \t    $ctext insert end \"$line\\n\" d0\n \t} elseif {$diffinhdr} {\n \t    if {![string compare -length 12 \"rename from \" $line]} {\n@@ -7757,7 +7755,6 @@ proc getblobdiffline {bdf ids} {\n \t\tif {[string index $fname 0] eq \"\\\"\"} {\n \t\t    set fname [lindex $fname 0]\n \t\t}\n-\t\tset fname [encoding convertfrom $fname]\n \t\tset i [lsearch -exact $treediffs($ids) $fname]\n \t\tif {$i >= 0} {\n \t\t    setinlist difffilestart $i $curdiffstart\n@@ -7779,8 +7776,7 @@ proc getblobdiffline {bdf ids} {\n \t    $ctext insert end \"$line\\n\" filesep\n \n \t} else {\n-\t    set line [string map {\\x1A ^Z} \\\n-                          [encoding convertfrom $diffencoding $line]]\n+\t\tset line [string map {\\x1A ^Z} $line]\n \t    # parse the prefix - one ' ', '-' or '+' for each parent\n \t    set prefix [string range $line 0 [expr {$diffnparents - 1}]]\n \t    set tag [expr {$diffnparents > 1? \"m\": \"d\"}]\n-- \n1.7.4\n"},{"id":"160338","messageId":"loom.20110203T181237-77@post.gmane.org","threadId":"26402","inReplyTo":"1296751353-8632-1-git-send-email-zapped@mail.ru","subject":"Re: [PATCH] gitk: Honor encoding conversion in a sole place for all possible cases","fromName":"Alexey Shumkin","fromEmail":"zapped@mail.ru","sentAt":"2011-02-03T17:20:57Z","receivedAt":"2011-02-03T17:20:57Z","isPatch":true,"sender":{"key":"alex.crezoff@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1183752?v=4"},"body":"> Still buggy on Cygwin 1.7: on a clear working copy shows\n> non-latin named files as removed and not indexed\n\nOh! Fixed! The matter was in LC_ALL enviroment variable.\nIt is set in my cygwin.bat (or ~/.bashrc).\nFor some reason it is not set with bash when running \"gitk\" command\n(moreover when I ran gitk with \"%CYGPATH%\\bin\\wish84.exe %CYGPATH%\\bin\\gitk\")\nI set it in system environment. That fixes incorrect working copy\nstatus detection.\n"}]}