From ae75e1e432b40a8de8e131888951a831ecef8915 Mon Sep 17 00:00:00 2001 From: Karsten Blees Date: Thu, 26 Feb 2015 17:19:45 +0800 Subject: [PATCH] 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 1f5acc3..5bc21b8 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" } -- 2.11.4.GIT