git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Alexey Shumkin <zapped@mail.ru>
To: git@vger.kernel.org
Cc: Alexey Shumkin <zapped@mail.ru>
Subject: [PATCH] gitk: Honor encoding conversion in a sole place for all possible cases
Date: Thu,  3 Feb 2011 19:42:33 +0300	[thread overview]
Message-ID: <1296751353-8632-1-git-send-email-zapped@mail.ru> (raw)

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

             reply	other threads:[~2011-02-03 16:52 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-03 16:42 Alexey Shumkin [this message]
2011-02-03 17:20 ` [PATCH] gitk: Honor encoding conversion in a sole place for all possible cases Alexey Shumkin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1296751353-8632-1-git-send-email-zapped@mail.ru \
    --to=zapped@mail.ru \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).