Skip to content

Commit 83fd8a0

Browse files
committed
Merge branch 'ml/tcl90'
* ml/tcl90: git-gui: Allow Tcl 9.0 git-gui: use -profile tcl8 on encoding conversions git-gui: use -profile tcl8 for file input with Tcl 9 git-gui: themed.tcl: use full namespace for color git-gui: remove EOL translation for gets git-gui: do not mix -translation binary and -encoding git-gui: replace encoding binary with iso8859-1 git-gui: translation binary defines iso8859-1 git-gui: assure -eofchar {} on all channels Signed-off-by: Johannes Sixt <[email protected]>
2 parents 0919339 + c20408c commit 83fd8a0

13 files changed

+58
-45
lines changed

git-gui.sh

Lines changed: 33 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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

583605
proc 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
}

lib/blame.tcl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,6 @@ method _load {jump} {
483483
} else {
484484
set fd [safe_open_file $path r]
485485
}
486-
fconfigure $fd -eofchar {}
487486
} else {
488487
if {$do_textconv ne 0} {
489488
set fd [git_read [list cat-file --textconv "$commit:$path"]]
@@ -493,7 +492,6 @@ method _load {jump} {
493492
}
494493
fconfigure $fd \
495494
-blocking 0 \
496-
-translation lf \
497495
-encoding [get_path_encoding $path]
498496
fileevent $fd readable [cb _read_file $fd $jump]
499497
set current_fd $fd
@@ -620,7 +618,7 @@ method _exec_blame {cur_w cur_d options cur_s} {
620618

621619
lappend options -- $path
622620
set fd [git_read_nice [concat blame $options]]
623-
fconfigure $fd -blocking 0 -translation lf -encoding utf-8
621+
fconfigure $fd -blocking 0 -encoding utf-8
624622
fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d]
625623
set current_fd $fd
626624
set blame_lines 0
@@ -986,7 +984,7 @@ method _showcommit {cur_w lno} {
986984
set msg {}
987985
catch {
988986
set fd [git_read [list cat-file commit $cmit]]
989-
fconfigure $fd -encoding binary -translation lf
987+
fconfigure $fd -encoding iso8859-1
990988
# By default commits are assumed to be in utf-8
991989
set enc utf-8
992990
while {[gets $fd line] > 0} {
@@ -999,7 +997,7 @@ method _showcommit {cur_w lno} {
999997

1000998
set enc [tcl_encoding $enc]
1001999
if {$enc ne {}} {
1002-
set msg [encoding convertfrom $enc $msg]
1000+
set msg [convertfrom $enc $msg]
10031001
}
10041002
set msg [string trim $msg]
10051003
}
@@ -1143,7 +1141,6 @@ method _blameparent {} {
11431141

11441142
fconfigure $fd \
11451143
-blocking 0 \
1146-
-encoding binary \
11471144
-translation binary
11481145
fileevent $fd readable [cb _read_diff_load_commit \
11491146
$fd $cparent $new_path $r_orig_line]

lib/branch.tcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ proc load_all_heads {} {
88
set rh_len [expr {[string length $rh] + 1}]
99
set all_heads [list]
1010
set fd [git_read [list for-each-ref --format=%(refname) $rh]]
11-
fconfigure $fd -translation binary -encoding utf-8
11+
fconfigure $fd -encoding utf-8
1212
while {[gets $fd line] > 0} {
1313
if {!$some_heads_tracking || ![is_tracking_branch $line]} {
1414
lappend all_heads [string range $line $rh_len end]
@@ -25,7 +25,7 @@ proc load_all_tags {} {
2525
--sort=-taggerdate \
2626
--format=%(refname) \
2727
refs/tags]]
28-
fconfigure $fd -translation binary -encoding utf-8
28+
fconfigure $fd -encoding utf-8
2929
while {[gets $fd line] > 0} {
3030
if {![regsub ^refs/tags/ $line {} name]} continue
3131
lappend all_tags $name

lib/browser.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ method _ls {tree_id {name {}}} {
195195
$w conf -state disabled
196196

197197
set fd [git_read [list ls-tree -z $tree_id]]
198-
fconfigure $fd -blocking 0 -translation binary -encoding utf-8
198+
fconfigure $fd -blocking 0 -encoding utf-8
199199
fileevent $fd readable [cb _read $fd]
200200
}
201201

lib/checkout_op.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,7 @@ If you wanted to be on a branch, create one now starting from 'This Detached Che
462462
if {$fd_ph ne {}} {
463463
global pch_error
464464
set pch_error {}
465-
fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
465+
fconfigure $fd_ph -blocking 0 -translation binary
466466
fileevent $fd_ph readable [cb _postcheckout_wait $fd_ph]
467467
} else {
468468
_update_repo_state $this

lib/choose_rev.tcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ constructor _new {path unmerged_only title} {
147147
refs/remotes \
148148
refs/tags \
149149
]]
150-
fconfigure $fr_fd -translation lf -encoding utf-8
150+
fconfigure $fr_fd -encoding utf-8
151151
while {[gets $fr_fd line] > 0} {
152152
set line [eval $line]
153153
if {[lindex $line 1 0] eq {tag}} {
@@ -570,7 +570,7 @@ method _reflog_last {name} {
570570
set last {}
571571
if {[catch {set last [file mtime [gitdir $name]]}]
572572
&& ![catch {set g [safe_open_file [gitdir logs $name] r]}]} {
573-
fconfigure $g -translation binary
573+
fconfigure $g -encoding iso8859-1
574574
while {[gets $g line] >= 0} {
575575
if {[regexp {> ([1-9][0-9]*) } $line line when]} {
576576
set last $when

lib/commit.tcl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ You are currently in the middle of a merge that has not been fully completed. Y
2828
set name ""
2929
set email ""
3030
set fd [git_read [list cat-file commit $curHEAD]]
31-
fconfigure $fd -encoding binary -translation lf
31+
fconfigure $fd -encoding iso8859-1
3232
# By default commits are assumed to be in utf-8
3333
set enc utf-8
3434
while {[gets $fd line] > 0} {
@@ -43,9 +43,9 @@ You are currently in the middle of a merge that has not been fully completed. Y
4343

4444
set enc [tcl_encoding $enc]
4545
if {$enc ne {}} {
46-
set msg [encoding convertfrom $enc $msg]
47-
set name [encoding convertfrom $enc $name]
48-
set email [encoding convertfrom $enc $email]
46+
set msg [convertfrom $enc $msg]
47+
set name [convertfrom $enc $name]
48+
set email [convertfrom $enc $email]
4949
}
5050
if {$name ne {} && $email ne {}} {
5151
set commit_author [list name $name email $email date $time]
@@ -252,7 +252,7 @@ A good commit message has the following format:
252252

253253
ui_status [mc "Calling pre-commit hook..."]
254254
set pch_error {}
255-
fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
255+
fconfigure $fd_ph -blocking 0 -translation binary
256256
fileevent $fd_ph readable \
257257
[list commit_prehook_wait $fd_ph $curHEAD $msg_p]
258258
}
@@ -307,7 +307,7 @@ Do you really want to proceed with your Commit?"]
307307

308308
ui_status [mc "Calling commit-msg hook..."]
309309
set pch_error {}
310-
fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
310+
fconfigure $fd_ph -blocking 0 -translation binary
311311
fileevent $fd_ph readable \
312312
[list commit_commitmsg_wait $fd_ph $curHEAD $msg_p]
313313
}
@@ -361,7 +361,7 @@ proc commit_committree {fd_wt curHEAD msg_p} {
361361
#
362362
if {$commit_type eq {normal}} {
363363
set fd_ot [git_read [list cat-file commit $PARENT]]
364-
fconfigure $fd_ot -encoding binary -translation lf
364+
fconfigure $fd_ot -encoding iso8859-1
365365
set old_tree [gets $fd_ot]
366366
close $fd_ot
367367

@@ -460,7 +460,7 @@ A rescan will be automatically started now.
460460
if {$fd_ph ne {}} {
461461
global pch_error
462462
set pch_error {}
463-
fconfigure $fd_ph -blocking 0 -translation binary -eofchar {}
463+
fconfigure $fd_ph -blocking 0 -translation binary
464464
fileevent $fd_ph readable \
465465
[list commit_postcommit_wait $fd_ph $cmt_id]
466466
}

lib/diff.tcl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ proc show_other_diff {path w m cont_info} {
191191
file {
192192
set fd [safe_open_file $path r]
193193
fconfigure $fd \
194-
-eofchar {} \
195194
-encoding [get_path_encoding $path]
196195
set content [read $fd $max_sz]
197196
close $fd
@@ -325,6 +324,8 @@ proc start_show_diff {cont_info {add_opts {}}} {
325324
# '++' lines which is not bijective. Thus, we need to maintain a state
326325
# across lines.
327326
set ::conflict_in_pre_image 0
327+
328+
# git-diff has eol==\n, \r if present is part of the text
328329
fconfigure $fd \
329330
-blocking 0 \
330331
-encoding [get_path_encoding $path] \

lib/index.tcl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ proc update_indexinfo {msg path_list after} {
7878
-blocking 0 \
7979
-buffering full \
8080
-buffersize 512 \
81-
-encoding binary \
8281
-translation binary
8382
fileevent $fd writable [list \
8483
write_update_indexinfo \
@@ -147,7 +146,6 @@ proc update_index {msg path_list after} {
147146
-blocking 0 \
148147
-buffering full \
149148
-buffersize 512 \
150-
-encoding binary \
151149
-translation binary
152150
fileevent $fd writable [list \
153151
write_update_index \
@@ -227,7 +225,6 @@ proc checkout_index {msg path_list after capture_error} {
227225
-blocking 0 \
228226
-buffering full \
229227
-buffersize 512 \
230-
-encoding binary \
231228
-translation binary
232229
fileevent $fd writable [list \
233230
write_checkout_index \

lib/mergetool.tcl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ proc merge_load_stages {path cont} {
9090

9191
set merge_stages_fd [git_read [list ls-files -u -z -- $path]]
9292

93-
fconfigure $merge_stages_fd -blocking 0 -translation binary -encoding binary
93+
fconfigure $merge_stages_fd -blocking 0 -translation binary
9494
fileevent $merge_stages_fd readable [list read_merge_stages $merge_stages_fd $cont]
9595
}
9696

@@ -370,7 +370,7 @@ proc merge_tool_start {cmdline target backup stages} {
370370

371371
ui_status [mc "Running merge tool..."]
372372

373-
fconfigure $mtool_fd -blocking 0 -translation binary -encoding binary
373+
fconfigure $mtool_fd -blocking 0 -translation binary
374374
fileevent $mtool_fd readable [list read_mtool_output $mtool_fd]
375375
}
376376

0 commit comments

Comments
 (0)