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 <johannes.schindelin@gmx.de> Thanks-to: Pat Thoyts <patthoyts@users.sourceforge.net> Reported-by: Cloud Chou <515312382@qq.com> Original-test-by: Cloud Chou <515312382@qq.com> Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Cloud Chou <515312382@qq.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>

Karsten Blees committed Feb 26, 2015 at 17:19 UTC ae75e1e432b40a8de8e131888951a831ecef8915
1 file changed +4 -25
git-gui.sh
+4 -25
@@ -534,31 +534,10 @@ proc _lappend_nice {cmd_var} {
534 }
535
536 proc git {args} {
537 - set opt [list]
538 -
539 - while {1} {
540 - switch -- [lindex $args 0] {
541 - --nice {
542 - _lappend_nice opt
543 - }
544 -
545 - default {
546 - break
547 - }
548 -
549 - }
550 -
551 - set args [lrange $args 1 end]
552 - }
553 -
554 - set cmdp [_git_cmd [lindex $args 0]]
555 - set args [lrange $args 1 end]
556 -
557 - _trace_exec [concat $opt $cmdp $args]
558 - set result [eval exec $opt $cmdp $args]
559 - if {[encoding system] != "utf-8"} {
560 - set result [encoding convertfrom utf-8 [encoding convertto $result]]
561 - }
537 + set fd [eval [list git_read] $args]
538 + fconfigure $fd -translation binary -encoding utf-8
539 + set result [string trimright [read $fd] "\n"]
540 + close $fd
541 if {$::_trace} {
542 puts stderr "< $result"
543 }