From 847c8a2ec4e9504fd112be263c261f2ea2690444 Mon Sep 17 00:00:00 2001 From: Mark Levedahl Date: Wed, 21 May 2025 17:38:10 -0400 Subject: git-gui: assure -eofchar {} on all channels Per 6eb420ef61 ("git-gui: Always disable the Tcl EOF character when reading", 2007-07-17), git-gui should disable Tcl's EOF character detection on all files when on Windows: the default is disabled on all other platforms (and with Tcl 9.0, is disabled on Windows too). This EOF character is for compatibility with files / applications written for file systems that know only the disc sectors allocated, and not the number of bytes used. This has nothing to do with git. But, git-gui does not set -eofchar {} on all channels. To avoid any further leakage, let's just add this to the Windows specific override of open. This override is needed only as long as Tcl 8.x is in use (Tcl 9.0 makes -eofchar {} default on all platforms). Signed-off-by: Mark Levedahl --- lib/commit.tcl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/commit.tcl') diff --git a/lib/commit.tcl b/lib/commit.tcl index 2fd57a51fb..d6313e568b 100644 --- a/lib/commit.tcl +++ b/lib/commit.tcl @@ -252,7 +252,7 @@ A good commit message has the following format: ui_status [mc "Calling pre-commit hook..."] set pch_error {} - fconfigure $fd_ph -blocking 0 -translation binary -eofchar {} + fconfigure $fd_ph -blocking 0 -translation binary fileevent $fd_ph readable \ [list commit_prehook_wait $fd_ph $curHEAD $msg_p] } @@ -307,7 +307,7 @@ Do you really want to proceed with your Commit?"] ui_status [mc "Calling commit-msg hook..."] set pch_error {} - fconfigure $fd_ph -blocking 0 -translation binary -eofchar {} + fconfigure $fd_ph -blocking 0 -translation binary fileevent $fd_ph readable \ [list commit_commitmsg_wait $fd_ph $curHEAD $msg_p] } @@ -460,7 +460,7 @@ A rescan will be automatically started now. if {$fd_ph ne {}} { global pch_error set pch_error {} - fconfigure $fd_ph -blocking 0 -translation binary -eofchar {} + fconfigure $fd_ph -blocking 0 -translation binary fileevent $fd_ph readable \ [list commit_postcommit_wait $fd_ph $cmt_id] } -- cgit v1.2.3 From 40f54f670a01b6ae4f13e0888796948ddce9104c Mon Sep 17 00:00:00 2001 From: Mark Levedahl Date: Thu, 22 May 2025 13:33:00 -0400 Subject: git-gui: replace encoding binary with iso8859-1 git-gui currently configures some channels as '-encoding binary' when the channel is not really binary (e.g, the channel is consumed as lines of text). In 8.6, '-encoding binary' is an alias for '-encoding iso8859), but TIP 699 removes this alias for Tcl 9.0. Let's switch to '-encoding iso8859-1' to be compatible across Tcl versions. Signed-off-by: Mark Levedahl --- lib/blame.tcl | 2 +- lib/commit.tcl | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/commit.tcl') diff --git a/lib/blame.tcl b/lib/blame.tcl index e51a820b12..bb67b047eb 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -985,7 +985,7 @@ method _showcommit {cur_w lno} { set msg {} catch { set fd [git_read [list cat-file commit $cmit]] - fconfigure $fd -encoding binary -translation lf + fconfigure $fd -encoding iso8859-1 -translation lf # By default commits are assumed to be in utf-8 set enc utf-8 while {[gets $fd line] > 0} { diff --git a/lib/commit.tcl b/lib/commit.tcl index d6313e568b..adde708084 100644 --- a/lib/commit.tcl +++ b/lib/commit.tcl @@ -28,7 +28,7 @@ You are currently in the middle of a merge that has not been fully completed. Y set name "" set email "" set fd [git_read [list cat-file commit $curHEAD]] - fconfigure $fd -encoding binary -translation lf + fconfigure $fd -encoding iso8859-1 -translation lf # By default commits are assumed to be in utf-8 set enc utf-8 while {[gets $fd line] > 0} { @@ -361,7 +361,7 @@ proc commit_committree {fd_wt curHEAD msg_p} { # if {$commit_type eq {normal}} { set fd_ot [git_read [list cat-file commit $PARENT]] - fconfigure $fd_ot -encoding binary -translation lf + fconfigure $fd_ot -encoding iso8859-1 -translation lf set old_tree [gets $fd_ot] close $fd_ot -- cgit v1.2.3 From beab415e429067108953966d3d2d4420d75515cd Mon Sep 17 00:00:00 2001 From: Mark Levedahl Date: Wed, 21 May 2025 21:13:27 -0400 Subject: git-gui: remove EOL translation for gets git-gui configures '-translation lf' on a number of channels. The default configuration is 'auto', which on input changes any occurrence of \n, \r, or \r\n to \n, and on output changes any such EOL sequence to a platform dependent value (\n on Unix, \r\n on Windows). Such translation can be necessary, but much of what is configured now is redundant. In particular, many of the channels configured this way are then consumed by gets, which already recognizes any of \n, \r, or \r\n as terminators. Configuring a channel to first change these line endings, then give the result to gets, is redundant. The valid uses of -translation lf are for output where we do not want \r\n on Windows, and for consuming entire files without going through gets, assuring that \n will be used internally. Let's remove all the others that only serve to confuse. lib/diff.tcl must have -translation lf because \r\n might be stored in the repository (e.g., on Windows, with no crlf translation enabled), and git will treat \n as the line ending, while the preceding \r is just whitespace, and these may be split by ANSI color coding. git-gui's read_diff handles this correctly as-is. Signed-off-by: Mark Levedahl --- lib/blame.tcl | 5 ++--- lib/choose_rev.tcl | 2 +- lib/commit.tcl | 4 ++-- lib/diff.tcl | 2 ++ lib/remote_branch_delete.tcl | 1 - 5 files changed, 7 insertions(+), 7 deletions(-) (limited to 'lib/commit.tcl') diff --git a/lib/blame.tcl b/lib/blame.tcl index bb67b047eb..22c5e7a193 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -492,7 +492,6 @@ method _load {jump} { } fconfigure $fd \ -blocking 0 \ - -translation lf \ -encoding [get_path_encoding $path] fileevent $fd readable [cb _read_file $fd $jump] set current_fd $fd @@ -619,7 +618,7 @@ method _exec_blame {cur_w cur_d options cur_s} { lappend options -- $path set fd [git_read_nice [concat blame $options]] - fconfigure $fd -blocking 0 -translation lf -encoding utf-8 + fconfigure $fd -blocking 0 -encoding utf-8 fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d] set current_fd $fd set blame_lines 0 @@ -985,7 +984,7 @@ method _showcommit {cur_w lno} { set msg {} catch { set fd [git_read [list cat-file commit $cmit]] - fconfigure $fd -encoding iso8859-1 -translation lf + fconfigure $fd -encoding iso8859-1 # By default commits are assumed to be in utf-8 set enc utf-8 while {[gets $fd line] > 0} { diff --git a/lib/choose_rev.tcl b/lib/choose_rev.tcl index 4cf6cebac4..cd355cc92a 100644 --- a/lib/choose_rev.tcl +++ b/lib/choose_rev.tcl @@ -147,7 +147,7 @@ constructor _new {path unmerged_only title} { refs/remotes \ refs/tags \ ]] - fconfigure $fr_fd -translation lf -encoding utf-8 + fconfigure $fr_fd -encoding utf-8 while {[gets $fr_fd line] > 0} { set line [eval $line] if {[lindex $line 1 0] eq {tag}} { diff --git a/lib/commit.tcl b/lib/commit.tcl index adde708084..5e77fd2f54 100644 --- a/lib/commit.tcl +++ b/lib/commit.tcl @@ -28,7 +28,7 @@ You are currently in the middle of a merge that has not been fully completed. Y set name "" set email "" set fd [git_read [list cat-file commit $curHEAD]] - fconfigure $fd -encoding iso8859-1 -translation lf + fconfigure $fd -encoding iso8859-1 # By default commits are assumed to be in utf-8 set enc utf-8 while {[gets $fd line] > 0} { @@ -361,7 +361,7 @@ proc commit_committree {fd_wt curHEAD msg_p} { # if {$commit_type eq {normal}} { set fd_ot [git_read [list cat-file commit $PARENT]] - fconfigure $fd_ot -encoding iso8859-1 -translation lf + fconfigure $fd_ot -encoding iso8859-1 set old_tree [gets $fd_ot] close $fd_ot diff --git a/lib/diff.tcl b/lib/diff.tcl index 65d0997b79..442737ba4f 100644 --- a/lib/diff.tcl +++ b/lib/diff.tcl @@ -324,6 +324,8 @@ proc start_show_diff {cont_info {add_opts {}}} { # '++' lines which is not bijective. Thus, we need to maintain a state # across lines. set ::conflict_in_pre_image 0 + + # git-diff has eol==\n, \r if present is part of the text fconfigure $fd \ -blocking 0 \ -encoding [get_path_encoding $path] \ diff --git a/lib/remote_branch_delete.tcl b/lib/remote_branch_delete.tcl index 349d31edf3..f0814efdd7 100644 --- a/lib/remote_branch_delete.tcl +++ b/lib/remote_branch_delete.tcl @@ -307,7 +307,6 @@ method _load {cache uri} { set active_ls [git_read [list ls-remote $uri]] fconfigure $active_ls \ -blocking 0 \ - -translation lf \ -encoding utf-8 fileevent $active_ls readable [cb _read $cache $active_ls] } else { -- cgit v1.2.3 From cc41d374fa9e130cf9b89da5cbcf7694257b7df1 Mon Sep 17 00:00:00 2001 From: Mark Levedahl Date: Sat, 31 May 2025 15:18:31 -0400 Subject: git-gui: use -profile tcl8 on encoding conversions git-gui in the prior commit learned to apply -profile tcl8 when reading files, avoiding errors on non-binary data streams whose encoding is not utf-8. But, git-gui also consumes binary data streams (generally blobs from commits) as the output of commands, and internally decodes this to support various displays. With Tcl9, errors occur in this decoding for the same reasons described in the previous commit: basically, the underlying data may contain extended ascii characters violating the assumption of utf-8 encoding. This problem has a similar fix to the prior issue: we must use the tlc8 profile when converting this data to the internal unicode format. Do so, again only on Tcl9 as Tcl8.6 does not recognize -profile, and only Tcl 9.0 makes strict the default. Signed-off-by: Mark Levedahl --- git-gui.sh | 13 ++++++++++--- lib/blame.tcl | 2 +- lib/commit.tcl | 6 +++--- 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'lib/commit.tcl') diff --git a/git-gui.sh b/git-gui.sh index 2c83ed5066..1ebf1e288d 100755 --- a/git-gui.sh +++ b/git-gui.sh @@ -84,6 +84,13 @@ if {[package vcompare $::tcl_version 9.0] >= 0} { chan configure $f -profile tcl8 return $f } + proc convertfrom args { + return [encoding convertfrom -profile tcl8 {*}$args] + } +} else { + proc convertfrom args { + return [encoding convertfrom {*}$args] + } } ###################################################################### @@ -1543,7 +1550,7 @@ proc read_diff_index {fd after} { set i [split [string range $buf_rdi $c [expr {$z1 - 2}]] { }] set p [string range $buf_rdi $z1 [expr {$z2 - 1}]] merge_state \ - [encoding convertfrom utf-8 $p] \ + [convertfrom utf-8 $p] \ [lindex $i 4]? \ [list [lindex $i 0] [lindex $i 2]] \ [list] @@ -1576,7 +1583,7 @@ proc read_diff_files {fd after} { set i [split [string range $buf_rdf $c [expr {$z1 - 2}]] { }] set p [string range $buf_rdf $z1 [expr {$z2 - 1}]] merge_state \ - [encoding convertfrom utf-8 $p] \ + [convertfrom utf-8 $p] \ ?[lindex $i 4] \ [list] \ [list [lindex $i 0] [lindex $i 2]] @@ -1599,7 +1606,7 @@ proc read_ls_others {fd after} { set pck [split $buf_rlo "\0"] set buf_rlo [lindex $pck end] foreach p [lrange $pck 0 end-1] { - set p [encoding convertfrom utf-8 $p] + set p [convertfrom utf-8 $p] if {[string index $p end] eq {/}} { set p [string range $p 0 end-1] } diff --git a/lib/blame.tcl b/lib/blame.tcl index 22c5e7a193..4477b84eae 100644 --- a/lib/blame.tcl +++ b/lib/blame.tcl @@ -997,7 +997,7 @@ method _showcommit {cur_w lno} { set enc [tcl_encoding $enc] if {$enc ne {}} { - set msg [encoding convertfrom $enc $msg] + set msg [convertfrom $enc $msg] } set msg [string trim $msg] } diff --git a/lib/commit.tcl b/lib/commit.tcl index 5e77fd2f54..2c2f73d3af 100644 --- a/lib/commit.tcl +++ b/lib/commit.tcl @@ -43,9 +43,9 @@ You are currently in the middle of a merge that has not been fully completed. Y set enc [tcl_encoding $enc] if {$enc ne {}} { - set msg [encoding convertfrom $enc $msg] - set name [encoding convertfrom $enc $name] - set email [encoding convertfrom $enc $email] + set msg [convertfrom $enc $msg] + set name [convertfrom $enc $name] + set email [convertfrom $enc $email] } if {$name ne {} && $email ne {}} { set commit_author [list name $name email $email date $time] -- cgit v1.2.3