From: Karsten Blees <bl...@dcon.de>
Date: Sat, 4 Feb 2012 21:54:36 +0100

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 <bl...@dcon.de>
Signed-off-by: Stepan Kasal <ka...@ucw.cz>
---
 git-gui/git-gui.sh      | 11 +++++++----
 git-gui/lib/browser.tcl |  2 +-
 git-gui/lib/index.tcl   |  6 +++---
 gitk-git/gitk           | 15 ++++++++-------
 4 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/git-gui/git-gui.sh b/git-gui/git-gui.sh
index b186329..f9c942c 100755
--- a/git-gui/git-gui.sh
+++ b/git-gui/git-gui.sh
@@ -548,6 +548,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"
        }
@@ -1104,7 +1107,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
                }
@@ -1682,7 +1685,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]
@@ -1715,7 +1718,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]]
@@ -1738,7 +1741,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]
                }
diff --git a/git-gui/lib/browser.tcl b/git-gui/lib/browser.tcl
index 0328338..555db89 100644
--- a/git-gui/lib/browser.tcl
+++ b/git-gui/lib/browser.tcl
@@ -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 -encoding binary
+       fconfigure $fd -blocking 0 -translation binary -encoding utf-8
        fileevent $fd readable [cb _read $fd]
 }
 
diff --git a/git-gui/lib/index.tcl b/git-gui/lib/index.tcl
index 74a81a7..d10ffe9 100644
--- a/git-gui/lib/index.tcl
+++ b/git-gui/lib/index.tcl
@@ -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
        }
 
@@ -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
        }
 
@@ -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 ?_
                }
                }
diff --git a/gitk-git/gitk b/gitk-git/gitk
index f6efaa6..0301608 100755
--- a/gitk-git/gitk
+++ b/gitk-git/gitk
@@ -7529,7 +7529,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]} {
@@ -7791,7 +7791,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
@@ -7936,7 +7936,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} {
@@ -7993,7 +7993,7 @@ proc parseblobdiffline {ids line} {
 
     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
        }
@@ -8040,7 +8040,7 @@ proc parseblobdiffline {ids line} {
        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
@@ -8095,7 +8095,7 @@ proc parseblobdiffline {ids line} {
            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
@@ -8114,6 +8114,7 @@ proc parseblobdiffline {ids line} {
            set diffinhdr 0
            return
        }
+       set line [encoding convertfrom utf-8 $line]
        $ctext insert end "$line\n" filesep
 
     } else {
@@ -11902,7 +11903,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
                }
-- 
2.0.0.9635.g0be03cb

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to