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

Commit

Permalink
Unicode file name support (gitk and git-gui)
Browse files Browse the repository at this point in the history
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 <blees@dcon.de>
  • Loading branch information
kblees authored and dscho committed May 3, 2012
1 parent e1897fe commit 6423335
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
11 changes: 7 additions & 4 deletions git-gui/git-gui.sh
Expand Up @@ -533,6 +533,9 @@ proc git {args} {
_trace_exec [concat $opt $cmdp $args]
set result [eval exec $opt $cmdp $args]
if {[encoding system] != "utf-8"} {
set result [encoding convertfrom utf-8 [encoding convertto $result]]
}
if {$::_trace} {
puts stderr "< $result"
}
Expand Down Expand Up @@ -1087,7 +1090,7 @@ git-version proc _parse_config {arr_name args} {
[list git_read config] \
$args \
[list --null --list]]
fconfigure $fd_rc -translation binary
fconfigure $fd_rc -translation binary -encoding utf-8
set buf [read $fd_rc]
close $fd_rc
}
Expand Down Expand Up @@ -1652,7 +1655,7 @@ proc read_diff_index {fd after} {
set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
merge_state \
[encoding convertfrom $p] \
[encoding convertfrom utf-8 $p] \
[lindex $i 4]? \
[list [lindex $i 0] [lindex $i 2]] \
[list]
Expand Down Expand Up @@ -1685,7 +1688,7 @@ proc read_diff_files {fd after} {
set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
merge_state \
[encoding convertfrom $p] \
[encoding convertfrom utf-8 $p] \
?[lindex $i 4] \
[list] \
[list [lindex $i 0] [lindex $i 2]]
Expand All @@ -1708,7 +1711,7 @@ proc read_ls_others {fd after} {
set pck [split $buf_rlo "\0"]
set buf_rlo [lindex $pck end]
foreach p [lrange $pck 0 end-1] {
set p [encoding convertfrom $p]
set p [encoding convertfrom utf-8 $p]
if {[string index $p end] eq {/}} {
set p [string range $p 0 end-1]
}
Expand Down
2 changes: 1 addition & 1 deletion git-gui/lib/browser.tcl
Expand Up @@ -197,7 +197,7 @@ method _ls {tree_id {name {}}} {
$w conf -state disabled

set fd [git_read ls-tree -z $tree_id]
fconfigure $fd -blocking 0 -translation binary
fconfigure $fd -blocking 0 -translation binary -encoding utf-8
fileevent $fd readable [cb _read $fd]
}

Expand Down
6 changes: 3 additions & 3 deletions git-gui/lib/index.tcl
Expand Up @@ -115,7 +115,7 @@ proc write_update_indexinfo {fd pathList totalCnt batch after} {
set info [lindex $s 2]
if {$info eq {}} continue

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

Expand Down Expand Up @@ -186,7 +186,7 @@ proc write_update_index {fd pathList totalCnt batch after} {
?M {set new M_}
?? {continue}
}
puts -nonewline $fd "[encoding convertto $path]\0"
puts -nonewline $fd "[encoding convertto utf-8 $path]\0"
display_file $path $new
}

Expand Down Expand Up @@ -247,7 +247,7 @@ proc write_checkout_index {fd pathList totalCnt batch after} {
?M -
?T -
?D {
puts -nonewline $fd "[encoding convertto $path]\0"
puts -nonewline $fd "[encoding convertto utf-8 $path]\0"
display_file $path ?_
}
}
Expand Down
16 changes: 8 additions & 8 deletions gitk-git/gitk
Expand Up @@ -7329,7 +7329,7 @@ proc gettreeline {gtf id} {
if {[string index $fname 0] eq "\""} {
set fname [lindex $fname 0]
}
set fname [encoding convertfrom $fname]
set fname [encoding convertfrom utf-8 $fname]
lappend treefilelist($id) $fname
}
if {![eof $gtf]} {
Expand Down Expand Up @@ -7551,7 +7551,7 @@ proc gettreediffline {gdtf ids} {
if {[string index $file 0] eq "\""} {
set file [lindex $file 0]
}
set file [encoding convertfrom $file]
set file [encoding convertfrom utf-8 $file]
if {$file ne [lindex $treediff end]} {
lappend treediff $file
lappend sublist $file
Expand Down Expand Up @@ -7700,7 +7700,7 @@ proc makediffhdr {fname ids} {
global ctext curdiffstart treediffs diffencoding
global ctext_file_names jump_to_here targetline diffline

set fname [encoding convertfrom $fname]
set fname [encoding convertfrom utf-8 $fname]
set diffencoding [get_path_encoding $fname]
set i [lsearch -exact $treediffs($ids) $fname]
if {$i >= 0} {
Expand Down Expand Up @@ -7734,7 +7734,7 @@ proc getblobdiffline {bdf ids} {
}
if {![string compare -length 5 "diff " $line]} {
if {![regexp {^diff (--cc|--git) } $line m type]} {
set line [encoding convertfrom $line]
set line [encoding convertfrom utf-8 $line]
$ctext insert end "$line\n" hunksep
continue
}
Expand Down Expand Up @@ -7781,7 +7781,7 @@ proc getblobdiffline {bdf ids} {
makediffhdr $fname $ids

} elseif {![string compare -length 16 "* Unmerged path " $line]} {
set fname [encoding convertfrom [string range $line 16 end]]
set fname [encoding convertfrom utf-8 [string range $line 16 end]]
$ctext insert end "\n"
set curdiffstart [$ctext index "end - 1c"]
lappend ctext_file_names $fname
Expand Down Expand Up @@ -7836,7 +7836,7 @@ proc getblobdiffline {bdf ids} {
if {[string index $fname 0] eq "\""} {
set fname [lindex $fname 0]
}
set fname [encoding convertfrom $fname]
set fname [encoding convertfrom utf-8 $fname]
set i [lsearch -exact $treediffs($ids) $fname]
if {$i >= 0} {
setinlist difffilestart $i $curdiffstart
Expand All @@ -7855,7 +7855,7 @@ proc getblobdiffline {bdf ids} {
set diffinhdr 0
continue
}
set line [encoding convertfrom $line]
set line [encoding convertfrom utf-8 $line]
$ctext insert end "$line\n" filesep

} else {
Expand Down Expand Up @@ -11521,7 +11521,7 @@ proc cache_gitattr {attr pathlist} {
foreach row [split $rlist "\n"] {
if {[regexp "(.*): $attr: (.*)" $row m path value]} {
if {[string index $path 0] eq "\""} {
set path [encoding convertfrom [lindex $path 0]]
set path [encoding convertfrom utf-8 [lindex $path 0]]
}
set path_attr_cache($attr,$path) $value
}
Expand Down

0 comments on commit 6423335

Please sign in to comment.