Skip to content

Commit 24b1078

Browse files
committed
git-gui: use -profile tcl8 for file input with Tcl 9
git-gui 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 has long been acceptable on git 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 for representation in unicode. 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 byte by byte 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 behaviour: strict (raises exceptions), 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 git-gui does not handle. An example of this in the git repository is commit 7eb93c8 ("[PATCH] Simplify git script", 2005-09-07). This includes extended ascii characters in the author name and commit message. The tcl8 profile used so far has acceptable behavior given git-gui's acceptance: this allows git-gui 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. Signed-off-by: Mark Levedahl <[email protected]>
1 parent 0832752 commit 24b1078

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

git-gui.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,19 @@ proc is_Cygwin {} {
7373
return $_iscygwin
7474
}
7575

76+
######################################################################
77+
## Enable Tcl8 profile in Tcl9, allowing consumption of data that has
78+
## bytes not conforming to the assumed encoding profile.
79+
80+
if {[package vcompare $::tcl_version 9.0] >= 0} {
81+
rename open _strict_open
82+
proc open args {
83+
set f [_strict_open {*}$args]
84+
chan configure $f -profile tcl8
85+
return $f
86+
}
87+
}
88+
7689
######################################################################
7790
##
7891
## PATH lookup. Sanitize $PATH, assure exec/open use only that

0 commit comments

Comments
 (0)