Skip to content

Commit a7ba593

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 recognize -profile, and only Tcl 9.0 makes strict the default. Signed-off-by: Mark Levedahl <[email protected]>
1 parent 688f409 commit a7ba593

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
######################################################################
@@ -7859,7 +7866,7 @@ proc gettreeline {gtf id} {
78597866
if {[string index $fname 0] eq "\""} {
78607867
set fname [lindex $fname 0]
78617868
}
7862-
set fname [encoding convertfrom utf-8 $fname]
7869+
set fname [convertfrom utf-8 $fname]
78637870
lappend treefilelist($id) $fname
78647871
}
78657872
if {![eof $gtf]} {
@@ -8121,7 +8128,7 @@ proc gettreediffline {gdtf ids} {
81218128
if {[string index $file 0] eq "\""} {
81228129
set file [lindex $file 0]
81238130
}
8124-
set file [encoding convertfrom utf-8 $file]
8131+
set file [convertfrom utf-8 $file]
81258132
if {$file ne [lindex $treediff end]} {
81268133
lappend treediff $file
81278134
lappend sublist $file
@@ -8266,7 +8273,7 @@ proc makediffhdr {fname ids} {
82668273
global ctext curdiffstart treediffs diffencoding
82678274
global ctext_file_names jump_to_here targetline diffline
82688275
8269-
set fname [encoding convertfrom utf-8 $fname]
8276+
set fname [convertfrom utf-8 $fname]
82708277
set diffencoding [get_path_encoding $fname]
82718278
set i [lsearch -exact $treediffs($ids) $fname]
82728279
if {$i >= 0} {
@@ -8328,7 +8335,7 @@ proc parseblobdiffline {ids line} {
83288335
83298336
if {![string compare -length 5 "diff " $line]} {
83308337
if {![regexp {^diff (--cc|--git) } $line m type]} {
8331-
set line [encoding convertfrom utf-8 $line]
8338+
set line [convertfrom utf-8 $line]
83328339
$ctext insert end "$line\n" hunksep
83338340
continue
83348341
}
@@ -8377,7 +8384,7 @@ proc parseblobdiffline {ids line} {
83778384
makediffhdr $fname $ids
83788385
83798386
} elseif {![string compare -length 16 "* Unmerged path " $line]} {
8380-
set fname [encoding convertfrom utf-8 [string range $line 16 end]]
8387+
set fname [convertfrom utf-8 [string range $line 16 end]]
83818388
$ctext insert end "\n"
83828389
set curdiffstart [$ctext index "end - 1c"]
83838390
lappend ctext_file_names $fname
@@ -8390,7 +8397,7 @@ proc parseblobdiffline {ids line} {
83908397
83918398
} elseif {![string compare -length 2 "@@" $line]} {
83928399
regexp {^@@+} $line ats
8393-
set line [encoding convertfrom $diffencoding $line]
8400+
set line [convertfrom $diffencoding $line]
83948401
$ctext insert end "$line\n" hunksep
83958402
if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
83968403
set diffline $nl
@@ -8419,18 +8426,18 @@ proc parseblobdiffline {ids line} {
84198426
$ctext insert end "$line\n" filesep
84208427
}
84218428
} elseif {$currdiffsubmod != "" && ![string compare -length 3 " >" $line]} {
8422-
set line [encoding convertfrom $diffencoding $line]
8429+
set line [convertfrom $diffencoding $line]
84238430
$ctext insert end "$line\n" dresult
84248431
} elseif {$currdiffsubmod != "" && ![string compare -length 3 " <" $line]} {
8425-
set line [encoding convertfrom $diffencoding $line]
8432+
set line [convertfrom $diffencoding $line]
84268433
$ctext insert end "$line\n" d0
84278434
} elseif {$diffinhdr} {
84288435
if {![string compare -length 12 "rename from " $line]} {
84298436
set fname [string range $line [expr 6 + [string first " from " $line] ] end]
84308437
if {[string index $fname 0] eq "\""} {
84318438
set fname [lindex $fname 0]
84328439
}
8433-
set fname [encoding convertfrom utf-8 $fname]
8440+
set fname [convertfrom utf-8 $fname]
84348441
set i [lsearch -exact $treediffs($ids) $fname]
84358442
if {$i >= 0} {
84368443
setinlist difffilestart $i $curdiffstart
@@ -8449,12 +8456,12 @@ proc parseblobdiffline {ids line} {
84498456
set diffinhdr 0
84508457
return
84518458
}
8452-
set line [encoding convertfrom utf-8 $line]
8459+
set line [convertfrom utf-8 $line]
84538460
$ctext insert end "$line\n" filesep
84548461
84558462
} else {
84568463
set line [string map {\x1A ^Z} \
8457-
[encoding convertfrom $diffencoding $line]]
8464+
[convertfrom $diffencoding $line]]
84588465
# parse the prefix - one ' ', '-' or '+' for each parent
84598466
set prefix [string range $line 0 [expr {$diffnparents - 1}]]
84608467
set tag [expr {$diffnparents > 1? "m": "d"}]
@@ -12448,7 +12455,7 @@ proc cache_gitattr {attr pathlist} {
1244812455
foreach row [split $rlist "\n"] {
1244912456
if {[regexp "(.*): $attr: (.*)" $row m path value]} {
1245012457
if {[string index $path 0] eq "\""} {
12451-
set path [encoding convertfrom utf-8 [lindex $path 0]]
12458+
set path [convertfrom utf-8 [lindex $path 0]]
1245212459
}
1245312460
set path_attr_cache($attr,$path) $value
1245412461
}

0 commit comments

Comments
 (0)