Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 7ae13e6

Browse files
kbleeskasal
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 bb4b8b1 commit 7ae13e6

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
@@ -548,6 +548,9 @@ proc git {args} {
548548
549549
_trace_exec [concat $opt $cmdp $args]
550550
set result [eval exec $opt $cmdp $args]
551+
if {[encoding system] != "utf-8"} {
552+
set result [encoding convertfrom utf-8 [encoding convertto $result]]
553+
}
551554
if {$::_trace} {
552555
puts stderr "< $result"
553556
}
@@ -1104,7 +1107,7 @@ git-version proc _parse_config {arr_name args} {
11041107
[list git_read config] \
11051108
$args \
11061109
[list --null --list]]
1107-
fconfigure $fd_rc -translation binary
1110+
fconfigure $fd_rc -translation binary -encoding utf-8
11081111
set buf [read $fd_rc]
11091112
close $fd_rc
11101113
}
@@ -1678,7 +1681,7 @@ proc read_diff_index {fd after} {
16781681
set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
16791682
set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
16801683
merge_state \
1681-
[encoding convertfrom $p] \
1684+
[encoding convertfrom utf-8 $p] \
16821685
[lindex $i 4]? \
16831686
[list [lindex $i 0] [lindex $i 2]] \
16841687
[list]
@@ -1711,7 +1714,7 @@ proc read_diff_files {fd after} {
17111714
set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
17121715
set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
17131716
merge_state \
1714-
[encoding convertfrom $p] \
1717+
[encoding convertfrom utf-8 $p] \
17151718
?[lindex $i 4] \
17161719
[list] \
17171720
[list [lindex $i 0] [lindex $i 2]]
@@ -1734,7 +1737,7 @@ proc read_ls_others {fd after} {
17341737
set pck [split $buf_rlo "\0"]
17351738
set buf_rlo [lindex $pck end]
17361739
foreach p [lrange $pck 0 end-1] {
1737-
set p [encoding convertfrom $p]
1740+
set p [encoding convertfrom utf-8 $p]
17381741
if {[string index $p end] eq {/}} {
17391742
set p [string range $p 0 end-1]
17401743
}

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
@@ -7525,7 +7525,7 @@ proc gettreeline {gtf id} {
75257525
if {[string index $fname 0] eq "\""} {
75267526
set fname [lindex $fname 0]
75277527
}
7528-
set fname [encoding convertfrom $fname]
7528+
set fname [encoding convertfrom utf-8 $fname]
75297529
lappend treefilelist($id) $fname
75307530
}
75317531
if {![eof $gtf]} {
@@ -7784,7 +7784,7 @@ proc gettreediffline {gdtf ids} {
77847784
if {[string index $file 0] eq "\""} {
77857785
set file [lindex $file 0]
77867786
}
7787-
set file [encoding convertfrom $file]
7787+
set file [encoding convertfrom utf-8 $file]
77887788
if {$file ne [lindex $treediff end]} {
77897789
lappend treediff $file
77907790
lappend sublist $file
@@ -7929,7 +7929,7 @@ proc makediffhdr {fname ids} {
79297929
global ctext curdiffstart treediffs diffencoding
79307930
global ctext_file_names jump_to_here targetline diffline
79317931

7932-
set fname [encoding convertfrom $fname]
7932+
set fname [encoding convertfrom utf-8 $fname]
79337933
set diffencoding [get_path_encoding $fname]
79347934
set i [lsearch -exact $treediffs($ids) $fname]
79357935
if {$i >= 0} {
@@ -7986,7 +7986,7 @@ proc parseblobdiffline {ids line} {
79867986

79877987
if {![string compare -length 5 "diff " $line]} {
79887988
if {![regexp {^diff (--cc|--git) } $line m type]} {
7989-
set line [encoding convertfrom $line]
7989+
set line [encoding convertfrom utf-8 $line]
79907990
$ctext insert end "$line\n" hunksep
79917991
continue
79927992
}
@@ -8033,7 +8033,7 @@ proc parseblobdiffline {ids line} {
80338033
makediffhdr $fname $ids
80348034

80358035
} elseif {![string compare -length 16 "* Unmerged path " $line]} {
8036-
set fname [encoding convertfrom [string range $line 16 end]]
8036+
set fname [encoding convertfrom utf-8 [string range $line 16 end]]
80378037
$ctext insert end "\n"
80388038
set curdiffstart [$ctext index "end - 1c"]
80398039
lappend ctext_file_names $fname
@@ -8088,7 +8088,7 @@ proc parseblobdiffline {ids line} {
80888088
if {[string index $fname 0] eq "\""} {
80898089
set fname [lindex $fname 0]
80908090
}
8091-
set fname [encoding convertfrom $fname]
8091+
set fname [encoding convertfrom utf-8 $fname]
80928092
set i [lsearch -exact $treediffs($ids) $fname]
80938093
if {$i >= 0} {
80948094
setinlist difffilestart $i $curdiffstart
@@ -8107,6 +8107,7 @@ proc parseblobdiffline {ids line} {
81078107
set diffinhdr 0
81088108
return
81098109
}
8110+
set line [encoding convertfrom utf-8 $line]
81108111
$ctext insert end "$line\n" filesep
81118112

81128113
} else {
@@ -11895,7 +11896,7 @@ proc cache_gitattr {attr pathlist} {
1189511896
foreach row [split $rlist "\n"] {
1189611897
if {[regexp "(.*): $attr: (.*)" $row m path value]} {
1189711898
if {[string index $path 0] eq "\""} {
11898-
set path [encoding convertfrom [lindex $path 0]]
11899+
set path [encoding convertfrom utf-8 [lindex $path 0]]
1189911900
}
1190011901
set path_attr_cache($attr,$path) $value
1190111902
}

0 commit comments

Comments
 (0)