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:

Cloud Chou find the reason of the bug.

Thanks-to: Johannes Schindelin <>
Thanks-to: Pat Thoyts <>
Reported-by: Cloud Chou <>
Original-test-by: Cloud Chou <>
Signed-off-by: Karsten Blees <>
Signed-off-by: Cloud Chou <>
Signed-off-by: Johannes Schindelin <>
Signed-off-by: Pat Thoyts <>
This commit is contained in:
Karsten Blees 2015-02-26 17:19:45 +08:00 committed by Pat Thoyts
parent e2039e946e
commit ae75e1e432
1 changed files with 4 additions and 25 deletions

View File

@ -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 {
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"