git-gui: unicode file name support on windows

Assumes file names in git tree objects are UTF-8 encoded. On most unix systems, the system encoding (and thus the TCL system encoding) will be UTF-8, so file names will be displayed correctly. On Windows, it is impossible to set the system encoding to UTF-8. Changing the TCL system encoding (via 'encoding system ...', e.g. in the startup code) is explicitly discouraged by the TCL docs. Change git-gui functions dealing with file names to always convert from and to UTF-8. Signed-off-by: Karsten Blees <blees@dcon.de> Signed-off-by: Pat Thoyts <patthoyts@users.sourceforge.net>

Karsten Blees committed Feb 4, 2012 at 21:54 UTC e2039e946e6efa6c220b3cf186671f93e7aec9b9
3 files changed +11 -8
git-gui.sh
+7 -4
@@ -556,6 +556,9 @@ proc git {args} {
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 + }
562 if {$::_trace} {
563 puts stderr "< $result"
564 }
@@ -1111,7 +1114,7 @@ git-version proc _parse_config {arr_name args} {
1114 [list git_read config] \
1115 $args \
1116 [list --null --list]]
1114 - fconfigure $fd_rc -translation binary
1117 + fconfigure $fd_rc -translation binary -encoding utf-8
1118 set buf [read $fd_rc]
1119 close $fd_rc
1120 }
@@ -1691,7 +1694,7 @@ proc read_diff_index {fd after} {
1694 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
1695 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
1696 merge_state \
1694 - [encoding convertfrom $p] \
1697 + [encoding convertfrom utf-8 $p] \
1698 [lindex $i 4]? \
1699 [list [lindex $i 0] [lindex $i 2]] \
1700 [list]
@@ -1724,7 +1727,7 @@ proc read_diff_files {fd after} {
1727 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1728 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1729 merge_state \
1727 - [encoding convertfrom $p] \
1730 + [encoding convertfrom utf-8 $p] \
1731 ?[lindex $i 4] \
1732 [list] \
1733 [list [lindex $i 0] [lindex $i 2]]
@@ -1747,7 +1750,7 @@ proc read_ls_others {fd after} {
1750 set pck [split $buf_rlo "\0"]
1751 set buf_rlo [lindex $pck end]
1752 foreach p [lrange $pck 0 end-1] {
1750 - set p [encoding convertfrom $p]
1753 + set p [encoding convertfrom utf-8 $p]
1754 if {[string index $p end] eq {/}} {
1755 set p [string range $p 0 end-1]
1756 }
lib/browser.tcl
+1 -1
@@ -197,7 +197,7 @@ method _ls {tree_id {name {}}} {
197 $w conf -state disabled
198
199 set fd [git_read ls-tree -z $tree_id]
200 - fconfigure $fd -blocking 0 -translation binary -encoding binary
200 + fconfigure $fd -blocking 0 -translation binary -encoding utf-8
201 fileevent $fd readable [cb _read $fd]
202 }
203
lib/index.tcl
+3 -3
@@ -115,7 +115,7 @@ proc write_update_indexinfo {fd pathList totalCnt batch after} {
115 set info [lindex $s 2]
116 if {$info eq {}} continue
117
118 - puts -nonewline $fd "$info\t[encoding convertto $path]\0"
118 + puts -nonewline $fd "$info\t[encoding convertto utf-8 $path]\0"
119 display_file $path $new
120 }
121
@@ -186,7 +186,7 @@ proc write_update_index {fd pathList totalCnt batch after} {
186 ?M {set new M_}
187 ?? {continue}
188 }
189 - puts -nonewline $fd "[encoding convertto $path]\0"
189 + puts -nonewline $fd "[encoding convertto utf-8 $path]\0"
190 display_file $path $new
191 }
192
@@ -247,7 +247,7 @@ proc write_checkout_index {fd pathList totalCnt batch after} {
247 ?M -
248 ?T -
249 ?D {
250 - puts -nonewline $fd "[encoding convertto $path]\0"
250 + puts -nonewline $fd "[encoding convertto utf-8 $path]\0"
251 display_file $path ?_
252 }
253 }