Skip to content

Commit 928a4cd

Browse files
kbleesdscho
authored andcommitted
Unicode file name support (gitk and git-gui)
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 gitk and git-gui functions dealing with file names to always convert from and to UTF-8. Signed-off-by: Karsten Blees <[email protected]>
1 parent b3b8b31 commit 928a4cd

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

git-gui/git-gui.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,9 @@ proc git {args} {
552552
553553
_trace_exec [concat $opt $cmdp $args]
554554
set result [eval exec $opt $cmdp $args]
555+
if {[encoding system] != "utf-8"} {
556+
set result [encoding convertfrom utf-8 [encoding convertto $result]]
557+
}
555558
if {$::_trace} {
556559
puts stderr "< $result"
557560
}
@@ -1107,7 +1110,7 @@ git-version proc _parse_config {arr_name args} {
11071110
[list git_read config] \
11081111
$args \
11091112
[list --null --list]]
1110-
fconfigure $fd_rc -translation binary
1113+
fconfigure $fd_rc -translation binary -encoding utf-8
11111114
set buf [read $fd_rc]
11121115
close $fd_rc
11131116
}
@@ -1685,7 +1688,7 @@ proc read_diff_index {fd after} {
16851688
set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
16861689
set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
16871690
merge_state \
1688-
[encoding convertfrom $p] \
1691+
[encoding convertfrom utf-8 $p] \
16891692
[lindex $i 4]? \
16901693
[list [lindex $i 0] [lindex $i 2]] \
16911694
[list]
@@ -1718,7 +1721,7 @@ proc read_diff_files {fd after} {
17181721
set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
17191722
set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
17201723
merge_state \
1721-
[encoding convertfrom $p] \
1724+
[encoding convertfrom utf-8 $p] \
17221725
?[lindex $i 4] \
17231726
[list] \
17241727
[list [lindex $i 0] [lindex $i 2]]
@@ -1741,7 +1744,7 @@ proc read_ls_others {fd after} {
17411744
set pck [split $buf_rlo "\0"]
17421745
set buf_rlo [lindex $pck end]
17431746
foreach p [lrange $pck 0 end-1] {
1744-
set p [encoding convertfrom $p]
1747+
set p [encoding convertfrom utf-8 $p]
17451748
if {[string index $p end] eq {/}} {
17461749
set p [string range $p 0 end-1]
17471750
}

git-gui/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

git-gui/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
}

gitk-git/gitk

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7611,7 +7611,7 @@ proc gettreeline {gtf id} {
76117611
if {[string index $fname 0] eq "\""} {
76127612
set fname [lindex $fname 0]
76137613
}
7614-
set fname [encoding convertfrom $fname]
7614+
set fname [encoding convertfrom utf-8 $fname]
76157615
lappend treefilelist($id) $fname
76167616
}
76177617
if {![eof $gtf]} {
@@ -7873,7 +7873,7 @@ proc gettreediffline {gdtf ids} {
78737873
if {[string index $file 0] eq "\""} {
78747874
set file [lindex $file 0]
78757875
}
7876-
set file [encoding convertfrom $file]
7876+
set file [encoding convertfrom utf-8 $file]
78777877
if {$file ne [lindex $treediff end]} {
78787878
lappend treediff $file
78797879
lappend sublist $file
@@ -8018,7 +8018,7 @@ proc makediffhdr {fname ids} {
80188018
global ctext curdiffstart treediffs diffencoding
80198019
global ctext_file_names jump_to_here targetline diffline
80208020

8021-
set fname [encoding convertfrom $fname]
8021+
set fname [encoding convertfrom utf-8 $fname]
80228022
set diffencoding [get_path_encoding $fname]
80238023
set i [lsearch -exact $treediffs($ids) $fname]
80248024
if {$i >= 0} {
@@ -8075,7 +8075,7 @@ proc parseblobdiffline {ids line} {
80758075

80768076
if {![string compare -length 5 "diff " $line]} {
80778077
if {![regexp {^diff (--cc|--git) } $line m type]} {
8078-
set line [encoding convertfrom $line]
8078+
set line [encoding convertfrom utf-8 $line]
80798079
$ctext insert end "$line\n" hunksep
80808080
continue
80818081
}
@@ -8122,7 +8122,7 @@ proc parseblobdiffline {ids line} {
81228122
makediffhdr $fname $ids
81238123

81248124
} elseif {![string compare -length 16 "* Unmerged path " $line]} {
8125-
set fname [encoding convertfrom [string range $line 16 end]]
8125+
set fname [encoding convertfrom utf-8 [string range $line 16 end]]
81268126
$ctext insert end "\n"
81278127
set curdiffstart [$ctext index "end - 1c"]
81288128
lappend ctext_file_names $fname
@@ -8177,7 +8177,7 @@ proc parseblobdiffline {ids line} {
81778177
if {[string index $fname 0] eq "\""} {
81788178
set fname [lindex $fname 0]
81798179
}
8180-
set fname [encoding convertfrom $fname]
8180+
set fname [encoding convertfrom utf-8 $fname]
81818181
set i [lsearch -exact $treediffs($ids) $fname]
81828182
if {$i >= 0} {
81838183
setinlist difffilestart $i $curdiffstart
@@ -8196,6 +8196,7 @@ proc parseblobdiffline {ids line} {
81968196
set diffinhdr 0
81978197
return
81988198
}
8199+
set line [encoding convertfrom utf-8 $line]
81998200
$ctext insert end "$line\n" filesep
82008201

82018202
} else {
@@ -12029,7 +12030,7 @@ proc cache_gitattr {attr pathlist} {
1202912030
foreach row [split $rlist "\n"] {
1203012031
if {[regexp "(.*): $attr: (.*)" $row m path value]} {
1203112032
if {[string index $path 0] eq "\""} {
12032-
set path [encoding convertfrom [lindex $path 0]]
12033+
set path [encoding convertfrom utf-8 [lindex $path 0]]
1203312034
}
1203412035
set path_attr_cache($attr,$path) $value
1203512036
}

0 commit comments

Comments
 (0)