[PATCH] gitk: Honor encoding conversion in a sole place for all possible cases

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Previously every bug concerning encoding conversion
was fixed with a particular patch in a particular line of code
(e.g. 1f2cecfd53137b76d39b2dcd7bcf7e918cd745b3)
regardless other similar situations.

This patch centralizes reencoding of displayed text
considering all the cases where non-latin encoding may be used:
filenames, submodule names, rename/copy files, diffs (hunks),
commits comparison

Also cleaned up global "diffencoding" variable

Tested on Cygwin 1.5 and Cygwin 1.7

Still buggy on Cygwin 1.7: on a clear working copy shows
non-latin named files as removed and not indexed

Signed-off-by: Alexey Shumkin <zapped@xxxxxxx>
---
 gitk |   24 ++++++++++--------------
 1 files changed, 10 insertions(+), 14 deletions(-)

diff --git a/gitk b/gitk
index 9cbc09d..1f9627d 100755
--- a/gitk
+++ b/gitk
@@ -5047,7 +5047,8 @@ proc dodiffindex {} {
 proc readdiffindex {fd serial inst} {
     global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial
     global vfilelimit
-
+    global gui_encoding
+	
     set isdiff 1
     if {[gets $fd line] < 0} {
 	if {![eof $fd]} {
@@ -5069,6 +5070,9 @@ proc readdiffindex {fd serial inst} {
     }
     set fd [open $cmd r]
     fconfigure $fd -blocking 0
+    if {$gui_encoding != {}} {
+	fconfigure $fd -encoding $gui_encoding
+    }
     set i [reg_instance $fd]
     filerun $fd [list readdifffiles $fd $serial $i]
 
@@ -7541,7 +7545,7 @@ proc getblobdiffs {ids} {
     global ignorespace
     global worddiff
     global limitdiffs vfilelimit curview
-    global diffencoding targetline diffnparents
+    global targetline diffnparents
     global git_version currdiffsubmod
 
     set textconv {}
@@ -7570,7 +7574,7 @@ proc getblobdiffs {ids} {
     set diffnparents 0
     set diffinhdr 0
     set diffencoding [get_path_encoding {}]
-    fconfigure $bdf -blocking 0 -encoding binary -eofchar {}
+    fconfigure $bdf -blocking 0 -encoding $diffencoding -eofchar {}
     set blobdifffd($ids) $bdf
     set currdiffsubmod ""
     filerun $bdf [list getblobdiffline $bdf $diffids]
@@ -7618,11 +7622,9 @@ proc setinlist {var i val} {
 }
 
 proc makediffhdr {fname ids} {
-    global ctext curdiffstart treediffs diffencoding
+    global ctext curdiffstart treediffs
     global ctext_file_names jump_to_here targetline diffline
 
-    set fname [encoding convertfrom $fname]
-    set diffencoding [get_path_encoding $fname]
     set i [lsearch -exact $treediffs($ids) $fname]
     if {$i >= 0} {
 	setinlist difffilestart $i $curdiffstart
@@ -7643,7 +7645,7 @@ proc getblobdiffline {bdf ids} {
     global diffnexthead diffnextnote difffilestart
     global ctext_file_names ctext_file_lines
     global diffinhdr treediffs mergemax diffnparents
-    global diffencoding jump_to_here targetline diffline currdiffsubmod
+    global jump_to_here targetline diffline currdiffsubmod
     global worddiff
 
     set nr 0
@@ -7655,7 +7657,6 @@ proc getblobdiffline {bdf ids} {
 	}
 	if {![string compare -length 5 "diff " $line]} {
 	    if {![regexp {^diff (--cc|--git) } $line m type]} {
-		set line [encoding convertfrom $line]
 		$ctext insert end "$line\n" hunksep
 		continue
 	    }
@@ -7715,7 +7716,6 @@ proc getblobdiffline {bdf ids} {
 
 	} elseif {![string compare -length 2 "@@" $line]} {
 	    regexp {^@@+} $line ats
-	    set line [encoding convertfrom $diffencoding $line]
 	    $ctext insert end "$line\n" hunksep
 	    if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
 		set diffline $nl
@@ -7745,11 +7745,9 @@ proc getblobdiffline {bdf ids} {
 	    }
 	} elseif {![string compare -length 3 "  >" $line]} {
 	    set $currdiffsubmod ""
-	    set line [encoding convertfrom $diffencoding $line]
 	    $ctext insert end "$line\n" dresult
 	} elseif {![string compare -length 3 "  <" $line]} {
 	    set $currdiffsubmod ""
-	    set line [encoding convertfrom $diffencoding $line]
 	    $ctext insert end "$line\n" d0
 	} elseif {$diffinhdr} {
 	    if {![string compare -length 12 "rename from " $line]} {
@@ -7757,7 +7755,6 @@ proc getblobdiffline {bdf ids} {
 		if {[string index $fname 0] eq "\""} {
 		    set fname [lindex $fname 0]
 		}
-		set fname [encoding convertfrom $fname]
 		set i [lsearch -exact $treediffs($ids) $fname]
 		if {$i >= 0} {
 		    setinlist difffilestart $i $curdiffstart
@@ -7779,8 +7776,7 @@ proc getblobdiffline {bdf ids} {
 	    $ctext insert end "$line\n" filesep
 
 	} else {
-	    set line [string map {\x1A ^Z} \
-                          [encoding convertfrom $diffencoding $line]]
+		set line [string map {\x1A ^Z} $line]
 	    # parse the prefix - one ' ', '-' or '+' for each parent
 	    set prefix [string range $line 0 [expr {$diffnparents - 1}]]
 	    set tag [expr {$diffnparents > 1? "m": "d"}]
-- 
1.7.4


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


[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]