Skip to content

Commit c6a6233

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 840c875 commit c6a6233

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
@@ -7629,7 +7629,7 @@ proc gettreeline {gtf id} {
76297629
if {[string index $fname 0] eq "\""} {
76307630
set fname [lindex $fname 0]
76317631
}
7632-
set fname [encoding convertfrom $fname]
7632+
set fname [encoding convertfrom utf-8 $fname]
76337633
lappend treefilelist($id) $fname
76347634
}
76357635
if {![eof $gtf]} {
@@ -7891,7 +7891,7 @@ proc gettreediffline {gdtf ids} {
78917891
if {[string index $file 0] eq "\""} {
78927892
set file [lindex $file 0]
78937893
}
7894-
set file [encoding convertfrom $file]
7894+
set file [encoding convertfrom utf-8 $file]
78957895
if {$file ne [lindex $treediff end]} {
78967896
lappend treediff $file
78977897
lappend sublist $file
@@ -8036,7 +8036,7 @@ proc makediffhdr {fname ids} {
80368036
global ctext curdiffstart treediffs diffencoding
80378037
global ctext_file_names jump_to_here targetline diffline
80388038

8039-
set fname [encoding convertfrom $fname]
8039+
set fname [encoding convertfrom utf-8 $fname]
80408040
set diffencoding [get_path_encoding $fname]
80418041
set i [lsearch -exact $treediffs($ids) $fname]
80428042
if {$i >= 0} {
@@ -8093,7 +8093,7 @@ proc parseblobdiffline {ids line} {
80938093

80948094
if {![string compare -length 5 "diff " $line]} {
80958095
if {![regexp {^diff (--cc|--git) } $line m type]} {
8096-
set line [encoding convertfrom $line]
8096+
set line [encoding convertfrom utf-8 $line]
80978097
$ctext insert end "$line\n" hunksep
80988098
continue
80998099
}
@@ -8140,7 +8140,7 @@ proc parseblobdiffline {ids line} {
81408140
makediffhdr $fname $ids
81418141

81428142
} elseif {![string compare -length 16 "* Unmerged path " $line]} {
8143-
set fname [encoding convertfrom [string range $line 16 end]]
8143+
set fname [encoding convertfrom utf-8 [string range $line 16 end]]
81448144
$ctext insert end "\n"
81458145
set curdiffstart [$ctext index "end - 1c"]
81468146
lappend ctext_file_names $fname
@@ -8195,7 +8195,7 @@ proc parseblobdiffline {ids line} {
81958195
if {[string index $fname 0] eq "\""} {
81968196
set fname [lindex $fname 0]
81978197
}
8198-
set fname [encoding convertfrom $fname]
8198+
set fname [encoding convertfrom utf-8 $fname]
81998199
set i [lsearch -exact $treediffs($ids) $fname]
82008200
if {$i >= 0} {
82018201
setinlist difffilestart $i $curdiffstart
@@ -8214,6 +8214,7 @@ proc parseblobdiffline {ids line} {
82148214
set diffinhdr 0
82158215
return
82168216
}
8217+
set line [encoding convertfrom utf-8 $line]
82178218
$ctext insert end "$line\n" filesep
82188219

82198220
} else {
@@ -12047,7 +12048,7 @@ proc cache_gitattr {attr pathlist} {
1204712048
foreach row [split $rlist "\n"] {
1204812049
if {[regexp "(.*): $attr: (.*)" $row m path value]} {
1204912050
if {[string index $path 0] eq "\""} {
12050-
set path [encoding convertfrom [lindex $path 0]]
12051+
set path [encoding convertfrom utf-8 [lindex $path 0]]
1205112052
}
1205212053
set path_attr_cache($attr,$path) $value
1205312054
}

0 commit comments

Comments
 (0)