Skip to content

Commit f8ed135

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 66c844d commit f8ed135

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
######################################################################
@@ -7849,7 +7856,7 @@ proc gettreeline {gtf id} {
78497856
if {[string index $fname 0] eq "\""} {
78507857
set fname [lindex $fname 0]
78517858
}
7852-
set fname [encoding convertfrom utf-8 $fname]
7859+
set fname [convertfrom utf-8 $fname]
78537860
lappend treefilelist($id) $fname
78547861
}
78557862
if {![eof $gtf]} {
@@ -8111,7 +8118,7 @@ proc gettreediffline {gdtf ids} {
81118118
if {[string index $file 0] eq "\""} {
81128119
set file [lindex $file 0]
81138120
}
8114-
set file [encoding convertfrom utf-8 $file]
8121+
set file [convertfrom utf-8 $file]
81158122
if {$file ne [lindex $treediff end]} {
81168123
lappend treediff $file
81178124
lappend sublist $file
@@ -8256,7 +8263,7 @@ proc makediffhdr {fname ids} {
82568263
global ctext curdiffstart treediffs diffencoding
82578264
global ctext_file_names jump_to_here targetline diffline
82588265
8259-
set fname [encoding convertfrom utf-8 $fname]
8266+
set fname [convertfrom utf-8 $fname]
82608267
set diffencoding [get_path_encoding $fname]
82618268
set i [lsearch -exact $treediffs($ids) $fname]
82628269
if {$i >= 0} {
@@ -8318,7 +8325,7 @@ proc parseblobdiffline {ids line} {
83188325
83198326
if {![string compare -length 5 "diff " $line]} {
83208327
if {![regexp {^diff (--cc|--git) } $line m type]} {
8321-
set line [encoding convertfrom utf-8 $line]
8328+
set line [convertfrom utf-8 $line]
83228329
$ctext insert end "$line\n" hunksep
83238330
continue
83248331
}
@@ -8367,7 +8374,7 @@ proc parseblobdiffline {ids line} {
83678374
makediffhdr $fname $ids
83688375
83698376
} elseif {![string compare -length 16 "* Unmerged path " $line]} {
8370-
set fname [encoding convertfrom utf-8 [string range $line 16 end]]
8377+
set fname [convertfrom utf-8 [string range $line 16 end]]
83718378
$ctext insert end "\n"
83728379
set curdiffstart [$ctext index "end - 1c"]
83738380
lappend ctext_file_names $fname
@@ -8380,7 +8387,7 @@ proc parseblobdiffline {ids line} {
83808387
83818388
} elseif {![string compare -length 2 "@@" $line]} {
83828389
regexp {^@@+} $line ats
8383-
set line [encoding convertfrom $diffencoding $line]
8390+
set line [convertfrom $diffencoding $line]
83848391
$ctext insert end "$line\n" hunksep
83858392
if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
83868393
set diffline $nl
@@ -8409,18 +8416,18 @@ proc parseblobdiffline {ids line} {
84098416
$ctext insert end "$line\n" filesep
84108417
}
84118418
} elseif {$currdiffsubmod != "" && ![string compare -length 3 " >" $line]} {
8412-
set line [encoding convertfrom $diffencoding $line]
8419+
set line [convertfrom $diffencoding $line]
84138420
$ctext insert end "$line\n" dresult
84148421
} elseif {$currdiffsubmod != "" && ![string compare -length 3 " <" $line]} {
8415-
set line [encoding convertfrom $diffencoding $line]
8422+
set line [convertfrom $diffencoding $line]
84168423
$ctext insert end "$line\n" d0
84178424
} elseif {$diffinhdr} {
84188425
if {![string compare -length 12 "rename from " $line]} {
84198426
set fname [string range $line [expr 6 + [string first " from " $line] ] end]
84208427
if {[string index $fname 0] eq "\""} {
84218428
set fname [lindex $fname 0]
84228429
}
8423-
set fname [encoding convertfrom utf-8 $fname]
8430+
set fname [convertfrom utf-8 $fname]
84248431
set i [lsearch -exact $treediffs($ids) $fname]
84258432
if {$i >= 0} {
84268433
setinlist difffilestart $i $curdiffstart
@@ -8439,12 +8446,12 @@ proc parseblobdiffline {ids line} {
84398446
set diffinhdr 0
84408447
return
84418448
}
8442-
set line [encoding convertfrom utf-8 $line]
8449+
set line [convertfrom utf-8 $line]
84438450
$ctext insert end "$line\n" filesep
84448451
84458452
} else {
84468453
set line [string map {\x1A ^Z} \
8447-
[encoding convertfrom $diffencoding $line]]
8454+
[convertfrom $diffencoding $line]]
84488455
# parse the prefix - one ' ', '-' or '+' for each parent
84498456
set prefix [string range $line 0 [expr {$diffnparents - 1}]]
84508457
set tag [expr {$diffnparents > 1? "m": "d"}]
@@ -12433,7 +12440,7 @@ proc cache_gitattr {attr pathlist} {
1243312440
foreach row [split $rlist "\n"] {
1243412441
if {[regexp "(.*): $attr: (.*)" $row m path value]} {
1243512442
if {[string index $path 0] eq "\""} {
12436-
set path [encoding convertfrom utf-8 [lindex $path 0]]
12443+
set path [convertfrom utf-8 [lindex $path 0]]
1243712444
}
1243812445
set path_attr_cache($attr,$path) $value
1243912446
}

0 commit comments

Comments
 (0)