@@ -30,7 +30,7 @@ along with this program; if not, see <https://www.gnu.org/licenses/>.}]
3030# #
3131# # Tcl/Tk sanity check
3232
33- if {[catch {package require Tcl 8.6-8.8 } err]} {
33+ if {[catch {package require Tcl 8.6-} err]} {
3434 catch {wm withdraw .}
3535 tk_messageBox \
3636 -icon error \
@@ -73,6 +73,26 @@ 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+ proc convertfrom args {
88+ return [encoding convertfrom -profile tcl8 {*}$args ]
89+ }
90+ } else {
91+ proc convertfrom args {
92+ return [encoding convertfrom {*}$args ]
93+ }
94+ }
95+
7696# #####################################################################
7797# #
7898# # PATH lookup. Sanitize $PATH, assure exec/open use only that
@@ -177,7 +197,9 @@ if {[is_Windows]} {
177197 set command_line [string trim [string range $arg0 1 end]]
178198 lset args 0 " | [ sanitize_command_line $command_line 0] "
179199 }
180- uplevel 1 real_open $args
200+ set fd [real_open {*}$args ]
201+ fconfigure $fd -eofchar {}
202+ return $fd
181203 }
182204
183205} else {
@@ -582,7 +604,7 @@ proc git {args} {
582604
583605proc git_redir {cmd redir} {
584606 set fd [git_read $cmd $redir ]
585- fconfigure $fd -translation binary - encoding utf-8
607+ fconfigure $fd -encoding utf-8
586608 set result [string trimright [read $fd ] " \n " ]
587609 close $fd
588610 if {$::_trace } {
@@ -599,7 +621,6 @@ proc safe_open_command {cmd {redir {}}} {
599621 } err]} {
600622 error $err
601623 }
602- fconfigure $fd -eofchar {}
603624 return $fd
604625}
605626
@@ -995,7 +1016,7 @@ proc _parse_config {arr_name args} {
9951016 [concat config \
9961017 $args \
9971018 --null --list]]
998- fconfigure $fd_rc -translation binary - encoding utf-8
1019+ fconfigure $fd_rc -encoding utf-8
9991020 set buf [read $fd_rc ]
10001021 close $fd_rc
10011022 }
@@ -1397,15 +1418,15 @@ proc rescan_stage2 {fd after} {
13971418 set fd_di [git_read [list diff-index --cached --ignore-submodules=dirty -z [PARENT]]]
13981419 set fd_df [git_read [list diff-files -z]]
13991420
1400- fconfigure $fd_di -blocking 0 -translation binary -encoding binary
1401- fconfigure $fd_df -blocking 0 -translation binary -encoding binary
1421+ fconfigure $fd_di -blocking 0 -translation binary
1422+ fconfigure $fd_df -blocking 0 -translation binary
14021423
14031424 fileevent $fd_di readable [list read_diff_index $fd_di $after ]
14041425 fileevent $fd_df readable [list read_diff_files $fd_df $after ]
14051426
14061427 if {[is_config_true gui.displayuntracked]} {
14071428 set fd_lo [git_read [concat ls-files --others -z $ls_others ]]
1408- fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
1429+ fconfigure $fd_lo -blocking 0 -translation binary
14091430 fileevent $fd_lo readable [list read_ls_others $fd_lo $after ]
14101431 incr rescan_active
14111432 }
@@ -1419,7 +1440,6 @@ proc load_message {file {encoding {}}} {
14191440 if {[catch {set fd [safe_open_file $f r]}]} {
14201441 return 0
14211442 }
1422- fconfigure $fd -eofchar {}
14231443 if {$encoding ne {}} {
14241444 fconfigure $fd -encoding $encoding
14251445 }
@@ -1476,7 +1496,7 @@ proc run_prepare_commit_msg_hook {} {
14761496 ui_status [mc " Calling prepare-commit-msg hook..." ]
14771497 set pch_error {}
14781498
1479- fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1499+ fconfigure $fd_ph -blocking 0 -translation binary
14801500 fileevent $fd_ph readable \
14811501 [list prepare_commit_msg_hook_wait $fd_ph ]
14821502
@@ -1522,7 +1542,7 @@ proc read_diff_index {fd after} {
15221542 set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
15231543 set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
15241544 merge_state \
1525- [encoding convertfrom utf-8 $p ] \
1545+ [convertfrom utf-8 $p ] \
15261546 [lindex $i 4]? \
15271547 [list [lindex $i 0] [lindex $i 2]] \
15281548 [list ]
@@ -1555,7 +1575,7 @@ proc read_diff_files {fd after} {
15551575 set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
15561576 set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
15571577 merge_state \
1558- [encoding convertfrom utf-8 $p ] \
1578+ [convertfrom utf-8 $p ] \
15591579 ?[lindex $i 4] \
15601580 [list ] \
15611581 [list [lindex $i 0] [lindex $i 2]]
@@ -1578,7 +1598,7 @@ proc read_ls_others {fd after} {
15781598 set pck [split $buf_rlo " \0 " ]
15791599 set buf_rlo [lindex $pck end]
15801600 foreach p [lrange $pck 0 end-1] {
1581- set p [encoding convertfrom utf-8 $p ]
1601+ set p [convertfrom utf-8 $p ]
15821602 if {[string index $p end] eq {/}} {
15831603 set p [string range $p 0 end-1]
15841604 }
0 commit comments