Skip to content

Commit 036fc90

Browse files
committed
gitk: use -profile tcl8 on encoding conversions
gitk in the prior commit learned to apply -profile tcl8 to all input data streams, avoiding errors on non-binary data streams whose encoding is not utf-8. But, gitk also consumes binary data streams (generally blobs from commits), 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 was not validated to conform to the given encoding, and this source encoding may not be utf-8. gitk performs this decoding using Tcl's '[encoding convert from' operator. For example, the 7th commit in gitk's history has the extended ascii value 0xA9, so gitk 9a40c50 in gitk's repository raises an exception. The error log has: unexpected byte sequence starting at index 11: '\xA9' while executing "encoding convertfrom $diffencoding $line" (procedure "parseblobdiffline" line 135) invoked from within "parseblobdiffline $ids $line" (procedure "getblobdiffline" line 16) invoked from within "getblobdiffline file6 9a40c50" ("eval" body line 1) invoked from within "eval $script" (procedure "dorunq" line 11) invoked from within "dorunq" ("after" script) This problem has a similar fix to the prior issue: we must use the tlc8 profile when converting this data. Do so, again only on Tcl9 as Tcl8.6 does not recoginize -profile, and only Tcl 9.0 makes strict the default. Signed-off-by: Mark Levedahl <[email protected]>
1 parent 5d5d337 commit 036fc90

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

gitk

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ if {[package vcompare $::tcl_version 9.0] >= 0} {
2828
chan configure $f -profile tcl8
2929
return $f
3030
}
31+
proc convertfrom args {
32+
return [encoding convertfrom -profile tcl8 {*}$args]
33+
}
34+
} else {
35+
proc convertfrom args {
36+
return [encoding convertfrom {*}$args]
37+
}
3138
}
3239

3340
######################################################################
@@ -7851,7 +7858,7 @@ proc gettreeline {gtf id} {
78517858
if {[string index $fname 0] eq "\""} {
78527859
set fname [lindex $fname 0]
78537860
}
7854-
set fname [encoding convertfrom utf-8 $fname]
7861+
set fname [convertfrom utf-8 $fname]
78557862
lappend treefilelist($id) $fname
78567863
}
78577864
if {![eof $gtf]} {
@@ -8113,7 +8120,7 @@ proc gettreediffline {gdtf ids} {
81138120
if {[string index $file 0] eq "\""} {
81148121
set file [lindex $file 0]
81158122
}
8116-
set file [encoding convertfrom utf-8 $file]
8123+
set file [convertfrom utf-8 $file]
81178124
if {$file ne [lindex $treediff end]} {
81188125
lappend treediff $file
81198126
lappend sublist $file
@@ -8258,7 +8265,7 @@ proc makediffhdr {fname ids} {
82588265
global ctext curdiffstart treediffs diffencoding
82598266
global ctext_file_names jump_to_here targetline diffline
82608267
8261-
set fname [encoding convertfrom utf-8 $fname]
8268+
set fname [convertfrom utf-8 $fname]
82628269
set diffencoding [get_path_encoding $fname]
82638270
set i [lsearch -exact $treediffs($ids) $fname]
82648271
if {$i >= 0} {
@@ -8320,7 +8327,7 @@ proc parseblobdiffline {ids line} {
83208327
83218328
if {![string compare -length 5 "diff " $line]} {
83228329
if {![regexp {^diff (--cc|--git) } $line m type]} {
8323-
set line [encoding convertfrom utf-8 $line]
8330+
set line [convertfrom utf-8 $line]
83248331
$ctext insert end "$line\n" hunksep
83258332
continue
83268333
}
@@ -8369,7 +8376,7 @@ proc parseblobdiffline {ids line} {
83698376
makediffhdr $fname $ids
83708377
83718378
} elseif {![string compare -length 16 "* Unmerged path " $line]} {
8372-
set fname [encoding convertfrom utf-8 [string range $line 16 end]]
8379+
set fname [convertfrom utf-8 [string range $line 16 end]]
83738380
$ctext insert end "\n"
83748381
set curdiffstart [$ctext index "end - 1c"]
83758382
lappend ctext_file_names $fname
@@ -8382,7 +8389,7 @@ proc parseblobdiffline {ids line} {
83828389
83838390
} elseif {![string compare -length 2 "@@" $line]} {
83848391
regexp {^@@+} $line ats
8385-
set line [encoding convertfrom $diffencoding $line]
8392+
set line [convertfrom $diffencoding $line]
83868393
$ctext insert end "$line\n" hunksep
83878394
if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
83888395
set diffline $nl
@@ -8411,18 +8418,18 @@ proc parseblobdiffline {ids line} {
84118418
$ctext insert end "$line\n" filesep
84128419
}
84138420
} elseif {$currdiffsubmod != "" && ![string compare -length 3 " >" $line]} {
8414-
set line [encoding convertfrom $diffencoding $line]
8421+
set line [convertfrom $diffencoding $line]
84158422
$ctext insert end "$line\n" dresult
84168423
} elseif {$currdiffsubmod != "" && ![string compare -length 3 " <" $line]} {
8417-
set line [encoding convertfrom $diffencoding $line]
8424+
set line [convertfrom $diffencoding $line]
84188425
$ctext insert end "$line\n" d0
84198426
} elseif {$diffinhdr} {
84208427
if {![string compare -length 12 "rename from " $line]} {
84218428
set fname [string range $line [expr 6 + [string first " from " $line] ] end]
84228429
if {[string index $fname 0] eq "\""} {
84238430
set fname [lindex $fname 0]
84248431
}
8425-
set fname [encoding convertfrom utf-8 $fname]
8432+
set fname [convertfrom utf-8 $fname]
84268433
set i [lsearch -exact $treediffs($ids) $fname]
84278434
if {$i >= 0} {
84288435
setinlist difffilestart $i $curdiffstart
@@ -8441,12 +8448,12 @@ proc parseblobdiffline {ids line} {
84418448
set diffinhdr 0
84428449
return
84438450
}
8444-
set line [encoding convertfrom utf-8 $line]
8451+
set line [convertfrom utf-8 $line]
84458452
$ctext insert end "$line\n" filesep
84468453
84478454
} else {
84488455
set line [string map {\x1A ^Z} \
8449-
[encoding convertfrom $diffencoding $line]]
8456+
[convertfrom $diffencoding $line]]
84508457
# parse the prefix - one ' ', '-' or '+' for each parent
84518458
set prefix [string range $line 0 [expr {$diffnparents - 1}]]
84528459
set tag [expr {$diffnparents > 1? "m": "d"}]
@@ -12435,7 +12442,7 @@ proc cache_gitattr {attr pathlist} {
1243512442
foreach row [split $rlist "\n"] {
1243612443
if {[regexp "(.*): $attr: (.*)" $row m path value]} {
1243712444
if {[string index $path 0] eq "\""} {
12438-
set path [encoding convertfrom utf-8 [lindex $path 0]]
12445+
set path [convertfrom utf-8 [lindex $path 0]]
1243912446
}
1244012447
set path_attr_cache($attr,$path) $value
1244112448
}

0 commit comments

Comments
 (0)