Skip to content

Commit 5d5d337

Browse files
committed
gitk: use -profile tcl8 for file input with Tcl 9
gitk invokes many git commands expecting output in utf-8 encoding, but git accepts extended ascii (code page unknown) as utf-8 without validating, so cannot guarantee valid utf-8 on output. In particular, using any extended ascii code page, of which there are many, has long been acceptable given that everyone on a project is aware of and uses that same code page to view all data. utf-8 accepts only 7-bit ascii characters in single bytes, and any characters outside of that base set require at least two bytes. Tcl is a string based language, and transcodes all input data to an internal unicode format, and to whatever format is requested on output: "pure" binary is recoded using iso8859-1. Tcl8.x silently recodes invalid utf-8 as binary data, so extended ascii characters maintain their binary value on output but may not display correctly. Tcl 8.7 added three profiles to control this behviour: strict (raises execptions), replace (replaces each invalid byte with ?), and the default tcl8 maintaining the old behavior. Tcl 9 changes the default profile to strict, meaning any invalid utf-8 raises an exception that gitk does not handle. An example of this in the git repository is commit 7eb93c8965 ("[PATCH] Simplify git script", 2005-09-07). This includes extended ascii characters in the author name and commit message. As a result, gitk + Tcl 9 cannot view the git repository at any point beyond that commit. Note: Tcl 9.0 has a bug, to be fixed in 9.1, where this particular condition results in a memory error causing Tcl to crash [1]. The tcl8 profile used so far has acceptable behavior given gitk's acceptance: this allows gitk to accept extended ascii though it may display incorrectly. Let's continue that behavior by overriding open to use the tcl8 profile on Tcl9 and later: Tcl 8.6 does not understand fconfigure -profile, and Tcl 8.7 maintains the tcl8 profile. [1] Per https://core.tcl-lang.org/tcl/tktview/73bb42fb3f35cd613af6fcea465e35bbfd352216 Signed-off-by: Mark Levedahl <[email protected]>
1 parent 1d01592 commit 5d5d337

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

gitk

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,19 @@ if {[catch {package require Tcl 8.6-} err]} {
1717
exit 1
1818
}
1919

20+
######################################################################
21+
## Enable Tcl8 profile in Tcl9, allowing consumption of data that has
22+
## bytes not conforming to the assumed encoding profile.
23+
24+
if {[package vcompare $::tcl_version 9.0] >= 0} {
25+
rename open _strict_open
26+
proc open args {
27+
set f [_strict_open {*}$args]
28+
chan configure $f -profile tcl8
29+
return $f
30+
}
31+
}
32+
2033
######################################################################
2134
##
2235
## Enabling platform-specific code paths

0 commit comments

Comments
 (0)