From e2039e946e6efa6c220b3cf186671f93e7aec9b9 Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Sat, 4 Feb 2012 21:54:36 +0100 Subject: [PATCH 1/2] git-gui: unicode file name support on windows Assumes file names in git tree objects are UTF-8 encoded. On most unix systems, the system encoding (and thus the TCL system encoding) will be UTF-8, so file names will be displayed correctly. On Windows, it is impossible to set the system encoding to UTF-8. Changing the TCL system encoding (via 'encoding system ...', e.g. in the startup code) is explicitly discouraged by the TCL docs. Change git-gui functions dealing with file names to always convert from and to UTF-8. Signed-off-by: Karsten Blees Signed-off-by: Pat Thoyts --- git-gui.sh | 11 +++++++---- lib/browser.tcl | 2 +- lib/index.tcl | 6 +++--- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index f9b323abff..1f5acc3c75 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -556,6 +556,9 @@ proc git {args} { _trace_exec [concat $opt $cmdp $args] set result [eval exec $opt $cmdp $args] + if {[encoding system] != "utf-8"} { + set result [encoding convertfrom utf-8 [encoding convertto $result]] + } if {$::_trace} { puts stderr "< $result" } @@ -1111,7 +1114,7 @@ git-version proc _parse_config {arr_name args} { [list git_read config] \ $args \ [list --null --list]] - fconfigure $fd_rc -translation binary + fconfigure $fd_rc -translation binary -encoding utf-8 set buf [read $fd_rc] close $fd_rc } @@ -1691,7 +1694,7 @@ proc read_diff_index {fd after} { set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }] set p [string range $buf_rdi $z1 [expr {$z2 - 1}]] merge_state \ - [encoding convertfrom $p] \ + [encoding convertfrom utf-8 $p] \ [lindex $i 4]? \ [list [lindex $i 0] [lindex $i 2]] \ [list] @@ -1724,7 +1727,7 @@ proc read_diff_files {fd after} { set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }] set p [string range $buf_rdf $z1 [expr {$z2 - 1}]] merge_state \ - [encoding convertfrom $p] \ + [encoding convertfrom utf-8 $p] \ ?[lindex $i 4] \ [list] \ [list [lindex $i 0] [lindex $i 2]] @@ -1747,7 +1750,7 @@ proc read_ls_others {fd after} { set pck [split $buf_rlo "\0"] set buf_rlo [lindex $pck end] foreach p [lrange $pck 0 end-1] { - set p [encoding convertfrom $p] + set p [encoding convertfrom utf-8 $p] if {[string index $p end] eq {/}} { set p [string range $p 0 end-1] } diff --git a/lib/browser.tcl b/lib/browser.tcl index 158049353f..a982983667 100644 --- a/lib/browser.tcl +++ b/lib/browser.tcl @@ -197,7 +197,7 @@ method _ls {tree_id {name {}}} { $w conf -state disabled set fd [git_read ls-tree -z $tree_id] - fconfigure $fd -blocking 0 -translation binary -encoding binary + fconfigure $fd -blocking 0 -translation binary -encoding utf-8 fileevent $fd readable [cb _read $fd] } diff --git a/lib/index.tcl b/lib/index.tcl index 3a3e534aef..b588db11d9 100644 --- a/lib/index.tcl +++ b/lib/index.tcl @@ -115,7 +115,7 @@ proc write_update_indexinfo {fd pathList totalCnt batch after} { set info [lindex $s 2] if {$info eq {}} continue - puts -nonewline $fd "$info\t[encoding convertto $path]\0" + puts -nonewline $fd "$info\t[encoding convertto utf-8 $path]\0" display_file $path $new } @@ -186,7 +186,7 @@ proc write_update_index {fd pathList totalCnt batch after} { ?M {set new M_} ?? {continue} } - puts -nonewline $fd "[encoding convertto $path]\0" + puts -nonewline $fd "[encoding convertto utf-8 $path]\0" display_file $path $new } @@ -247,7 +247,7 @@ proc write_checkout_index {fd pathList totalCnt batch after} { ?M - ?T - ?D { - puts -nonewline $fd "[encoding convertto $path]\0" + puts -nonewline $fd "[encoding convertto utf-8 $path]\0" display_file $path ?_ } } From ae75e1e432b40a8de8e131888951a831ecef8915 Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Thu, 26 Feb 2015 17:19:45 +0800 Subject: [PATCH 2/2] git-gui: handle the encoding of Git's output correctly If we use 'eval exec $opt $cmdp $args' to execute git command, tcl engine will convert the output of the git comand with the rule system default code page to unicode. But cp936 -> unicode conversion implicitly done by exec is not reversible. So we have to use git_read instead. Bug report and an original reproducer by Cloud Chou: https://github.com/msysgit/git/issues/302 Cloud Chou find the reason of the bug. Thanks-to: Johannes Schindelin Thanks-to: Pat Thoyts Reported-by: Cloud Chou <515312382@qq.com> Original-test-by: Cloud Chou <515312382@qq.com> Signed-off-by: Karsten Blees Signed-off-by: Cloud Chou <515312382@qq.com> Signed-off-by: Johannes Schindelin Signed-off-by: Pat Thoyts --- git-gui.sh | 29 ++++------------------------- 1 file changed, 4 insertions(+), 25 deletions(-) diff --git a/git-gui.sh b/git-gui.sh index 1f5acc3c75..5bc21b878d 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -534,31 +534,10 @@ proc _lappend_nice {cmd_var} { } proc git {args} { - set opt [list] - - while {1} { - switch -- [lindex $args 0] { - --nice { - _lappend_nice opt - } - - default { - break - } - - } - - set args [lrange $args 1 end] - } - - set cmdp [_git_cmd [lindex $args 0]] - set args [lrange $args 1 end] - - _trace_exec [concat $opt $cmdp $args] - set result [eval exec $opt $cmdp $args] - if {[encoding system] != "utf-8"} { - set result [encoding convertfrom utf-8 [encoding convertto $result]] - } + set fd [eval [list git_read] $args] + fconfigure $fd -translation binary -encoding utf-8 + set result [string trimright [read $fd] "\n"] + close $fd if {$::_trace} { puts stderr "< $result" }