Skip to content

Commit 67c599f

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 0715914 commit 67c599f

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
######################################################################
@@ -7869,7 +7876,7 @@ proc gettreeline {gtf id} {
78697876
if {[string index $fname 0] eq "\""} {
78707877
set fname [lindex $fname 0]
78717878
}
7872-
set fname [encoding convertfrom utf-8 $fname]
7879+
set fname [convertfrom utf-8 $fname]
78737880
lappend treefilelist($id) $fname
78747881
}
78757882
if {![eof $gtf]} {
@@ -8131,7 +8138,7 @@ proc gettreediffline {gdtf ids} {
81318138
if {[string index $file 0] eq "\""} {
81328139
set file [lindex $file 0]
81338140
}
8134-
set file [encoding convertfrom utf-8 $file]
8141+
set file [convertfrom utf-8 $file]
81358142
if {$file ne [lindex $treediff end]} {
81368143
lappend treediff $file
81378144
lappend sublist $file
@@ -8276,7 +8283,7 @@ proc makediffhdr {fname ids} {
82768283
global ctext curdiffstart treediffs diffencoding
82778284
global ctext_file_names jump_to_here targetline diffline
82788285
8279-
set fname [encoding convertfrom utf-8 $fname]
8286+
set fname [convertfrom utf-8 $fname]
82808287
set diffencoding [get_path_encoding $fname]
82818288
set i [lsearch -exact $treediffs($ids) $fname]
82828289
if {$i >= 0} {
@@ -8338,7 +8345,7 @@ proc parseblobdiffline {ids line} {
83388345
83398346
if {![string compare -length 5 "diff " $line]} {
83408347
if {![regexp {^diff (--cc|--git) } $line m type]} {
8341-
set line [encoding convertfrom utf-8 $line]
8348+
set line [convertfrom utf-8 $line]
83428349
$ctext insert end "$line\n" hunksep
83438350
continue
83448351
}
@@ -8387,7 +8394,7 @@ proc parseblobdiffline {ids line} {
83878394
makediffhdr $fname $ids
83888395
83898396
} elseif {![string compare -length 16 "* Unmerged path " $line]} {
8390-
set fname [encoding convertfrom utf-8 [string range $line 16 end]]
8397+
set fname [convertfrom utf-8 [string range $line 16 end]]
83918398
$ctext insert end "\n"
83928399
set curdiffstart [$ctext index "end - 1c"]
83938400
lappend ctext_file_names $fname
@@ -8400,7 +8407,7 @@ proc parseblobdiffline {ids line} {
84008407
84018408
} elseif {![string compare -length 2 "@@" $line]} {
84028409
regexp {^@@+} $line ats
8403-
set line [encoding convertfrom $diffencoding $line]
8410+
set line [convertfrom $diffencoding $line]
84048411
$ctext insert end "$line\n" hunksep
84058412
if {[regexp { \+(\d+),\d+ @@} $line m nl]} {
84068413
set diffline $nl
@@ -8429,18 +8436,18 @@ proc parseblobdiffline {ids line} {
84298436
$ctext insert end "$line\n" filesep
84308437
}
84318438
} elseif {$currdiffsubmod != "" && ![string compare -length 3 " >" $line]} {
8432-
set line [encoding convertfrom $diffencoding $line]
8439+
set line [convertfrom $diffencoding $line]
84338440
$ctext insert end "$line\n" dresult
84348441
} elseif {$currdiffsubmod != "" && ![string compare -length 3 " <" $line]} {
8435-
set line [encoding convertfrom $diffencoding $line]
8442+
set line [convertfrom $diffencoding $line]
84368443
$ctext insert end "$line\n" d0
84378444
} elseif {$diffinhdr} {
84388445
if {![string compare -length 12 "rename from " $line]} {
84398446
set fname [string range $line [expr 6 + [string first " from " $line] ] end]
84408447
if {[string index $fname 0] eq "\""} {
84418448
set fname [lindex $fname 0]
84428449
}
8443-
set fname [encoding convertfrom utf-8 $fname]
8450+
set fname [convertfrom utf-8 $fname]
84448451
set i [lsearch -exact $treediffs($ids) $fname]
84458452
if {$i >= 0} {
84468453
setinlist difffilestart $i $curdiffstart
@@ -8459,12 +8466,12 @@ proc parseblobdiffline {ids line} {
84598466
set diffinhdr 0
84608467
return
84618468
}
8462-
set line [encoding convertfrom utf-8 $line]
8469+
set line [convertfrom utf-8 $line]
84638470
$ctext insert end "$line\n" filesep
84648471
84658472
} else {
84668473
set line [string map {\x1A ^Z} \
8467-
[encoding convertfrom $diffencoding $line]]
8474+
[convertfrom $diffencoding $line]]
84688475
# parse the prefix - one ' ', '-' or '+' for each parent
84698476
set prefix [string range $line 0 [expr {$diffnparents - 1}]]
84708477
set tag [expr {$diffnparents > 1? "m": "d"}]
@@ -12453,7 +12460,7 @@ proc cache_gitattr {attr pathlist} {
1245312460
foreach row [split $rlist "\n"] {
1245412461
if {[regexp "(.*): $attr: (.*)" $row m path value]} {
1245512462
if {[string index $path 0] eq "\""} {
12456-
set path [encoding convertfrom utf-8 [lindex $path 0]]
12463+
set path [convertfrom utf-8 [lindex $path 0]]
1245712464
}
1245812465
set path_attr_cache($attr,$path) $value
1245912466
}

0 commit comments

Comments
 (0)