@@ -30,7 +30,7 @@ along with this program; if not, see <https://www.gnu.org/licenses/>.}]
30
30
# #
31
31
# # Tcl/Tk sanity check
32
32
33
- if {[catch {package require Tcl 8.6-8.8 } err]} {
33
+ if {[catch {package require Tcl 8.6-} err]} {
34
34
catch {wm withdraw .}
35
35
tk_messageBox \
36
36
-icon error \
@@ -73,6 +73,26 @@ proc is_Cygwin {} {
73
73
return $_iscygwin
74
74
}
75
75
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
+
76
96
# #####################################################################
77
97
# #
78
98
# # PATH lookup. Sanitize $PATH, assure exec/open use only that
@@ -177,7 +197,9 @@ if {[is_Windows]} {
177
197
set command_line [string trim [string range $arg0 1 end]]
178
198
lset args 0 " | [ sanitize_command_line $command_line 0] "
179
199
}
180
- uplevel 1 real_open $args
200
+ set fd [real_open {*}$args ]
201
+ fconfigure $fd -eofchar {}
202
+ return $fd
181
203
}
182
204
183
205
} else {
@@ -582,7 +604,7 @@ proc git {args} {
582
604
583
605
proc git_redir {cmd redir} {
584
606
set fd [git_read $cmd $redir ]
585
- fconfigure $fd -translation binary - encoding utf-8
607
+ fconfigure $fd -encoding utf-8
586
608
set result [string trimright [read $fd ] " \n " ]
587
609
close $fd
588
610
if {$::_trace } {
@@ -599,7 +621,6 @@ proc safe_open_command {cmd {redir {}}} {
599
621
} err]} {
600
622
error $err
601
623
}
602
- fconfigure $fd -eofchar {}
603
624
return $fd
604
625
}
605
626
@@ -995,7 +1016,7 @@ proc _parse_config {arr_name args} {
995
1016
[concat config \
996
1017
$args \
997
1018
--null --list]]
998
- fconfigure $fd_rc -translation binary - encoding utf-8
1019
+ fconfigure $fd_rc -encoding utf-8
999
1020
set buf [read $fd_rc ]
1000
1021
close $fd_rc
1001
1022
}
@@ -1397,15 +1418,15 @@ proc rescan_stage2 {fd after} {
1397
1418
set fd_di [git_read [list diff-index --cached --ignore-submodules=dirty -z [PARENT]]]
1398
1419
set fd_df [git_read [list diff-files -z]]
1399
1420
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
1402
1423
1403
1424
fileevent $fd_di readable [list read_diff_index $fd_di $after ]
1404
1425
fileevent $fd_df readable [list read_diff_files $fd_df $after ]
1405
1426
1406
1427
if {[is_config_true gui.displayuntracked]} {
1407
1428
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
1409
1430
fileevent $fd_lo readable [list read_ls_others $fd_lo $after ]
1410
1431
incr rescan_active
1411
1432
}
@@ -1419,7 +1440,6 @@ proc load_message {file {encoding {}}} {
1419
1440
if {[catch {set fd [safe_open_file $f r]}]} {
1420
1441
return 0
1421
1442
}
1422
- fconfigure $fd -eofchar {}
1423
1443
if {$encoding ne {}} {
1424
1444
fconfigure $fd -encoding $encoding
1425
1445
}
@@ -1476,7 +1496,7 @@ proc run_prepare_commit_msg_hook {} {
1476
1496
ui_status [mc " Calling prepare-commit-msg hook..." ]
1477
1497
set pch_error {}
1478
1498
1479
- fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
1499
+ fconfigure $fd_ph -blocking 0 -translation binary
1480
1500
fileevent $fd_ph readable \
1481
1501
[list prepare_commit_msg_hook_wait $fd_ph ]
1482
1502
@@ -1522,7 +1542,7 @@ proc read_diff_index {fd after} {
1522
1542
set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }]
1523
1543
set p [string range $buf_rdi $z1 [expr {$z2 - 1}]]
1524
1544
merge_state \
1525
- [encoding convertfrom utf-8 $p ] \
1545
+ [convertfrom utf-8 $p ] \
1526
1546
[lindex $i 4]? \
1527
1547
[list [lindex $i 0] [lindex $i 2]] \
1528
1548
[list ]
@@ -1555,7 +1575,7 @@ proc read_diff_files {fd after} {
1555
1575
set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }]
1556
1576
set p [string range $buf_rdf $z1 [expr {$z2 - 1}]]
1557
1577
merge_state \
1558
- [encoding convertfrom utf-8 $p ] \
1578
+ [convertfrom utf-8 $p ] \
1559
1579
?[lindex $i 4] \
1560
1580
[list ] \
1561
1581
[list [lindex $i 0] [lindex $i 2]]
@@ -1578,7 +1598,7 @@ proc read_ls_others {fd after} {
1578
1598
set pck [split $buf_rlo " \0 " ]
1579
1599
set buf_rlo [lindex $pck end]
1580
1600
foreach p [lrange $pck 0 end-1] {
1581
- set p [encoding convertfrom utf-8 $p ]
1601
+ set p [convertfrom utf-8 $p ]
1582
1602
if {[string index $p end] eq {/}} {
1583
1603
set p [string range $p 0 end-1]
1584
1604
}
0 commit comments