Skip to content

Commit e7fd4cc

Browse files
kbleesdscho
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 Karsten Blees writes this code patch. Cloud Chou find the reason of the bug. Thanks-to: dscho Thanks-to: patthoyts Signed-off-by: Karsten Blees <[email protected]> Original-test-by: Cloud Chou <[email protected]> Signed-off-by: Cloud Chou <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent c6a6233 commit e7fd4cc

File tree

1 file changed

+4
-25
lines changed

1 file changed

+4
-25
lines changed

git-gui/git-gui.sh

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -530,31 +530,10 @@ proc _lappend_nice {cmd_var} {
530530
}
531531
532532
proc git {args} {
533-
set opt [list]
534-
535-
while {1} {
536-
switch -- [lindex $args 0] {
537-
--nice {
538-
_lappend_nice opt
539-
}
540-
541-
default {
542-
break
543-
}
544-
545-
}
546-
547-
set args [lrange $args 1 end]
548-
}
549-
550-
set cmdp [_git_cmd [lindex $args 0]]
551-
set args [lrange $args 1 end]
552-
553-
_trace_exec [concat $opt $cmdp $args]
554-
set result [eval exec $opt $cmdp $args]
555-
if {[encoding system] != "utf-8"} {
556-
set result [encoding convertfrom utf-8 [encoding convertto $result]]
557-
}
533+
set fd [eval [list git_read] $args]
534+
fconfigure $fd -translation binary -encoding utf-8
535+
set result [string trimright [read $fd] "\n"]
536+
close $fd
558537
if {$::_trace} {
559538
puts stderr "< $result"
560539
}

0 commit comments

Comments
 (0)