]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-gui: use -profile tcl8 on encoding conversions
authorMark Levedahl <mlevedahl@gmail.com>
Sat, 31 May 2025 19:18:31 +0000 (15:18 -0400)
committerMark Levedahl <mlevedahl@gmail.com>
Thu, 31 Jul 2025 17:51:03 +0000 (13:51 -0400)
git-gui in the prior commit learned to apply -profile tcl8 when reading
files, avoiding errors on non-binary data streams whose encoding is not
utf-8. But, git-gui also consumes binary data streams (generally blobs
from commits) as the output of commands, and internally decodes this to
support various displays.

With Tcl9, errors occur in this decoding for the same reasons described
in the previous commit: basically, the underlying data may contain
extended ascii characters violating the assumption of utf-8 encoding.

This problem has a similar fix to the prior issue: we must use the tlc8
profile when converting this data to the internal unicode format. Do so,
again only on Tcl9 as Tcl8.6 does not recognize -profile, and only Tcl
9.0 makes strict the default.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
git-gui.sh
lib/blame.tcl
lib/commit.tcl

index 2c83ed506680b420a3ba4176a11706776054910d..1ebf1e288d8ea3c3b0f2ca7389559dd3a33d2319 100755 (executable)
@@ -84,6 +84,13 @@ if {[package vcompare $::tcl_version 9.0] >= 0} {
                chan configure $f -profile tcl8
                return $f
        }
+       proc convertfrom args {
+               return [encoding convertfrom -profile tcl8 {*}$args]
+       }
+} else {
+       proc convertfrom args {
+               return [encoding convertfrom {*}$args]
+       }
 }
 
 ######################################################################
@@ -1543,7 +1550,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 utf-8 $p] \
+                       [convertfrom utf-8 $p] \
                        [lindex $i 4]? \
                        [list [lindex $i 0] [lindex $i 2]] \
                        [list]
@@ -1576,7 +1583,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 utf-8 $p] \
+                       [convertfrom utf-8 $p] \
                        ?[lindex $i 4] \
                        [list] \
                        [list [lindex $i 0] [lindex $i 2]]
@@ -1599,7 +1606,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 utf-8 $p]
+               set p [convertfrom utf-8 $p]
                if {[string index $p end] eq {/}} {
                        set p [string range $p 0 end-1]
                }
index 22c5e7a193ea09b0f5a032478ab7e09bc98e6898..4477b84eaeb7b56295accc2f0d4b7b9ea02d3d55 100644 (file)
@@ -997,7 +997,7 @@ method _showcommit {cur_w lno} {
 
                                set enc [tcl_encoding $enc]
                                if {$enc ne {}} {
-                                       set msg [encoding convertfrom $enc $msg]
+                                       set msg [convertfrom $enc $msg]
                                }
                                set msg [string trim $msg]
                        }
index 5e77fd2f5495ab0c1fcca881c40992b7fee9de16..2c2f73d3af271640c24cbf27cdcba668f615451e 100644 (file)
@@ -43,9 +43,9 @@ You are currently in the middle of a merge that has not been fully completed.  Y
 
                        set enc [tcl_encoding $enc]
                        if {$enc ne {}} {
-                               set msg [encoding convertfrom $enc $msg]
-                               set name [encoding convertfrom $enc $name]
-                               set email [encoding convertfrom $enc $email]
+                               set msg [convertfrom $enc $msg]
+                               set name [convertfrom $enc $name]
+                               set email [convertfrom $enc $email]
                        }
                        if {$name ne {} && $email ne {}} {
                                set commit_author [list name $name email $email date $time]