git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Alexey Shumkin <zapped@mail.ru>
Date
Feb 3, 2011, 16:42 UTC
Message-ID
<1296751353-8632-1-git-send-email-zapped@mail.ru>

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@mail.ru>
---
 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
Next: Alexey Shumkin
Message 1 of 2 in “gitk: Honor encoding conversion in a sole place for all possible cases”
  1. gitk: Honor encoding conversion in a sole place for all possible casesAlexey Shumkin, Feb 3, 2011
  2. Alexey ShumkinFeb 3, 2011

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.