Skip to content

Commit ac222bc

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 aa1b8d3 commit ac222bc

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
@@ -44,6 +44,13 @@ if {[package vcompare $::tcl_version 9.0] >= 0} {
4444
chan configure $f -profile tcl8
4545
return $f
4646
}
47+
proc convertfrom args {
48+
return [encoding convertfrom -profile tcl8 {*}$args]
49+
}
50+
} else {
51+
proc convertfrom args {
52+
return [encoding convertfrom {*}$args]
53+
}
4754
}
4855

4956
######################################################################
@@ -7823,7 +7830,7 @@ proc gettreeline {gtf id} {
78237830
if {[string index $fname 0] eq "\""} {
78247831
set fname [lindex $fname 0]
78257832
}
7826-
set fname [encoding convertfrom utf-8 $fname]
7833+
set fname [convertfrom utf-8 $fname]
78277834
lappend treefilelist($id) $fname
78287835
}
78297836
if {![eof $gtf]} {
@@ -8083,7 +8090,7 @@ proc gettreediffline {gdtf ids} {
80838090
if {[string index $file 0] eq "\""} {
80848091
set file [lindex $file 0]
80858092
}
8086-
set file [encoding convertfrom utf-8 $file]
8093+
set file [convertfrom utf-8 $file]
80878094
if {$file ne [lindex $treediff end]} {
80888095
lappend treediff $file
80898096
lappend sublist $file
@@ -8219,7 +8226,7 @@ proc makediffhdr {fname ids} {
82198226
global ctext curdiffstart treediffs diffencoding
82208227
global ctext_file_names jump_to_here targetline diffline
82218228
8222-
set fname [encoding convertfrom utf-8 $fname]
8229+
set fname [convertfrom utf-8 $fname]
82238230
set diffencoding [get_path_encoding $fname]
82248231
set i [lsearch -exact $treediffs($ids) $fname]
82258232
if {$i >= 0} {
@@ -8281,7 +8288,7 @@ proc parseblobdiffline {ids line} {
82818288
82828289
if {![string compare -length 5 "diff " $line]} {
82838290
if {![regexp {^diff (--cc|--git) } $line m type]} {
8284-
set line [encoding convertfrom utf-8 $line]
8291+
set line [convertfrom utf-8 $line]
82858292
$ctext insert end "$line\n" hunksep
82868293
continue
82878294
}
@@ -8330,7 +8337,7 @@ proc parseblobdiffline {ids line} {
83308337
makediffhdr $fname $ids
83318338
83328339
} elseif {![string compare -length 16 "* Unmerged path " $line]} {
8333-
set fname [encoding convertfrom utf-8 [string range $line 16 end]]
8340+
set fname [convertfrom utf-8 [string range $line 16 end]]
83348341
$ctext insert end "\n"
83358342
set curdiffstart [$ctext index "end - 1c"]
83368343
lappend ctext_file_names $fname
@@ -8343,7 +8350,7 @@ proc parseblobdiffline {ids line} {
83438350
83448351
} elseif {![string compare -length 2 "@@" $line]} {
83458352
regexp {^@@+} $line ats
8346-
set line [encoding convertfrom $diffencoding $line]
8353+
set line [convertfrom $diffencoding $line]
83478354
$ctext insert end "$line\n" hunksep
83488355
if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
83498356
set diffline $nl
@@ -8372,18 +8379,18 @@ proc parseblobdiffline {ids line} {
83728379
$ctext insert end "$line\n" filesep
83738380
}
83748381
} elseif {$currdiffsubmod != "" && ![string compare -length 3 " >" $line]} {
8375-
set line [encoding convertfrom $diffencoding $line]
8382+
set line [convertfrom $diffencoding $line]
83768383
$ctext insert end "$line\n" dresult
83778384
} elseif {$currdiffsubmod != "" && ![string compare -length 3 " <" $line]} {
8378-
set line [encoding convertfrom $diffencoding $line]
8385+
set line [convertfrom $diffencoding $line]
83798386
$ctext insert end "$line\n" d0
83808387
} elseif {$diffinhdr} {
83818388
if {![string compare -length 12 "rename from " $line]} {
83828389
set fname [string range $line [expr 6 + [string first " from " $line] ] end]
83838390
if {[string index $fname 0] eq "\""} {
83848391
set fname [lindex $fname 0]
83858392
}
8386-
set fname [encoding convertfrom utf-8 $fname]
8393+
set fname [convertfrom utf-8 $fname]
83878394
set i [lsearch -exact $treediffs($ids) $fname]
83888395
if {$i >= 0} {
83898396
setinlist difffilestart $i $curdiffstart
@@ -8402,12 +8409,12 @@ proc parseblobdiffline {ids line} {
84028409
set diffinhdr 0
84038410
return
84048411
}
8405-
set line [encoding convertfrom utf-8 $line]
8412+
set line [convertfrom utf-8 $line]
84068413
$ctext insert end "$line\n" filesep
84078414
84088415
} else {
84098416
set line [string map {\x1A ^Z} \
8410-
[encoding convertfrom $diffencoding $line]]
8417+
[convertfrom $diffencoding $line]]
84118418
# parse the prefix - one ' ', '-' or '+' for each parent
84128419
set prefix [string range $line 0 [expr {$diffnparents - 1}]]
84138420
set tag [expr {$diffnparents > 1? "m": "d"}]
@@ -12279,7 +12286,7 @@ proc cache_gitattr {attr pathlist} {
1227912286
foreach row [split $rlist "\n"] {
1228012287
if {[regexp "(.*): $attr: (.*)" $row m path value]} {
1228112288
if {[string index $path 0] eq "\""} {
12282-
set path [encoding convertfrom utf-8 [lindex $path 0]]
12289+
set path [convertfrom utf-8 [lindex $path 0]]
1228312290
}
1228412291
set path_attr_cache($attr,$path) $value
1228512292
}

0 commit comments

Comments
 (0)