Skip to content

Commit ae75e1e

Browse files
kbleespatthoyts
authored andcommitted
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: msysgit#302 Cloud Chou find the reason of the bug. Thanks-to: Johannes Schindelin <[email protected]> Thanks-to: Pat Thoyts <[email protected]> Reported-by: Cloud Chou <[email protected]> Original-test-by: Cloud Chou <[email protected]> Signed-off-by: Karsten Blees <[email protected]> Signed-off-by: Cloud Chou <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Pat Thoyts <[email protected]>
1 parent e2039e9 commit ae75e1e

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

git-gui.sh

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -534,31 +534,10 @@ proc _lappend_nice {cmd_var} {
534534
}
535535
536536
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
562541
if {$::_trace} {
563542
puts stderr "< $result"
564543
}

0 commit comments

Comments
 (0)