Skip to content

Commit e2039e9

Browse files
kbleespatthoyts
authored andcommitted
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 <[email protected]> Signed-off-by: Pat Thoyts <[email protected]>
1 parent 12d29c3 commit e2039e9

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

git-gui.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,9 @@ proc git {args} {
556556
557557
_trace_exec [concat $opt $cmdp $args]
558558
set result [eval exec $opt $cmdp $args]
559+
if {[encoding system] != "utf-8"} {
560+
set result [encoding convertfrom utf-8 [encoding convertto $result]]
561+
}
559562
if {$::_trace} {
560563
puts stderr "< $result"
561564
}
@@ -1111,7 +1114,7 @@ git-version proc _parse_config {arr_name args} {
11111114
[list git_read config] \
11121115
$args \
11131116
[list --null --list]]
1114-
fconfigure $fd_rc -translation binary
1117+
fconfigure $fd_rc -translation binary -encoding utf-8
11151118
set buf [read $fd_rc]
11161119
close $fd_rc
11171120
}
@@ -1691,7 +1694,7 @@ proc read_diff_index {fd after} {
16911694
set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
16921695
set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
16931696
merge_state \
1694-
[encoding convertfrom $p] \
1697+
[encoding convertfrom utf-8 $p] \
16951698
[lindex $i 4]? \
16961699
[list [lindex $i 0] [lindex $i 2]] \
16971700
[list]
@@ -1724,7 +1727,7 @@ proc read_diff_files {fd after} {
17241727
set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
17251728
set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
17261729
merge_state \
1727-
[encoding convertfrom $p] \
1730+
[encoding convertfrom utf-8 $p] \
17281731
?[lindex $i 4] \
17291732
[list] \
17301733
[list [lindex $i 0] [lindex $i 2]]
@@ -1747,7 +1750,7 @@ proc read_ls_others {fd after} {
17471750
set pck [split $buf_rlo "\0"]
17481751
set buf_rlo [lindex $pck end]
17491752
foreach p [lrange $pck 0 end-1] {
1750-
set p [encoding convertfrom $p]
1753+
set p [encoding convertfrom utf-8 $p]
17511754
if {[string index $p end] eq {/}} {
17521755
set p [string range $p 0 end-1]
17531756
}

lib/browser.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ method _ls {tree_id {name {}}} {
197197
$w conf -state disabled
198198

199199
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
201201
fileevent $fd readable [cb _read $fd]
202202
}
203203

lib/index.tcl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ proc write_update_indexinfo {fd pathList totalCnt batch after} {
115115
set info [lindex $s 2]
116116
if {$info eq {}} continue
117117

118-
puts -nonewline $fd "$info\t[encoding convertto $path]\0"
118+
puts -nonewline $fd "$info\t[encoding convertto utf-8 $path]\0"
119119
display_file $path $new
120120
}
121121

@@ -186,7 +186,7 @@ proc write_update_index {fd pathList totalCnt batch after} {
186186
?M {set new M_}
187187
?? {continue}
188188
}
189-
puts -nonewline $fd "[encoding convertto $path]\0"
189+
puts -nonewline $fd "[encoding convertto utf-8 $path]\0"
190190
display_file $path $new
191191
}
192192

@@ -247,7 +247,7 @@ proc write_checkout_index {fd pathList totalCnt batch after} {
247247
?M -
248248
?T -
249249
?D {
250-
puts -nonewline $fd "[encoding convertto $path]\0"
250+
puts -nonewline $fd "[encoding convertto utf-8 $path]\0"
251251
display_file $path ?_
252252
}
253253
}

0 commit comments

Comments
 (0)