threads / patch / 60260

patchgit-gui - simplify _open_stdout_stderr

Subject: [PATCH] git-gui - simplify _open_stdout_stderr

## tl;dr

3 messages between Sep 22, 2023 and Apr 1, 2025. Diffs are folded; open one to read it.

replies: 2people: 2as markdown or json

Mark Levedahl· Sep 22, 2023, 16:44 UTC · lore
From: "Mark Levedahl Date: Tue, 19 Sep 2023" <mlevedahl@gmail.com>

Since b792230 ("git-gui: Show a progress meter for checking out files", 2007-07-08), git-gui includes a workaround for Tcl that does not support using 2>@1 to redirect stderr to stdout. Tcl added such support in 8.4.7, released in 2004, while the later 8.4.14 still predated git-gui. But, Cygwin was stuck on an 8.4.1 Tcl variant until 2011, hence the need for this workaround. Commit 7145c65 recently removed much other specific code for that obsolete Cygwin Tcl/Tk, but missed this piece.

Also, Tcl since 8.5 explicitly supports 2>@1 across all platforms, and git-gui requires Tcl >= 8.5, further evidence the workaround is obsolete. (I did test that 2>@1 works as-expected on current Linux, Cygwin, and Git For Windows Tcl packages).

Remove the workaround and exploit concat's documented capability to handle both scalar and list arguments, leaving a much simpler function. This eliminates any question that cmd might be executed twice.

Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
---
 git-gui.sh | 21 ++-------------------
 1 file changed, 2 insertions(+), 19 deletions(-)
Show changes to git-gui.sh +2 −19
diff --git a/git-gui.sh b/git-gui.sh
index 8bc8892..a5d008d 100755
--- a/git-gui.sh
+++ b/git-gui.sh
@@ -583,25 +583,8 @@ proc git {args} {
 
 proc _open_stdout_stderr {cmd} {
 	_trace_exec $cmd
-	if {[catch {
-			set fd [open [concat [list | ] $cmd] r]
-		} err]} {
-		if {   [lindex $cmd end] eq {2>@1}
-		    && $err eq {can not find channel named "1"}
-			} {
-			# Older versions of Tcl 8.4 don't have this 2>@1 IO
-			# redirect operator.  Fallback to |& cat for those.
-			# The command was not actually started, so its safe
-			# to try to start it a second time.
-			#
-			set fd [open [concat \
-				[list | ] \
-				[lrange $cmd 0 end-1] \
-				[list |& cat] \
-				] r]
-		} else {
-			error $err
-		}
+	if {[catch {set fd [open [concat | $cmd] r]} err]} {
+		error $err
 	}
 	fconfigure $fd -eofchar {}
 	return $fd
-- 
2.41.0.99.19
Johannes Schindelin· Apr 1, 2025, 16:04 UTC · re: Mark Levedahl · lore

Re: [PATCH] git-gui - simplify _open_stdout_stderr

Hi Mark,

this patch is still relevant, right? I am Cc:ing Johannes Sixt for awareness.

Ciao, Johannes

On Fri, 22 Sep 2023, Mark Levedahl wrote:
Show 60 quoted lines
> From: "Mark Levedahl Date: Tue, 19 Sep 2023" <mlevedahl@gmail.com>
>
> Since b792230 ("git-gui: Show a progress meter for checking out files",
> 2007-07-08), git-gui includes a workaround for Tcl that does not support
> using 2>@1 to redirect stderr to stdout. Tcl added such support in
> 8.4.7, released in 2004, while the later 8.4.14 still predated git-gui.
> But, Cygwin was stuck on an 8.4.1 Tcl variant until 2011, hence the need
> for this workaround. Commit 7145c65 recently removed much other specific
> code for that obsolete Cygwin Tcl/Tk, but missed this piece.
>
> Also, Tcl since 8.5 explicitly supports 2>@1 across all platforms, and
> git-gui requires Tcl >= 8.5, further evidence the workaround is
> obsolete.  (I did test that 2>@1 works as-expected on current Linux,
> Cygwin, and Git For Windows Tcl packages).
>
> Remove the workaround and exploit concat's documented capability to
> handle both scalar and list arguments, leaving a much simpler function.
> This eliminates any question that cmd might be executed twice.
>
> Signed-off-by: Mark Levedahl <mlevedahl@gmail.com>
> ---
>  git-gui.sh | 21 ++-------------------
>  1 file changed, 2 insertions(+), 19 deletions(-)
>
> diff --git a/git-gui.sh b/git-gui.sh
> index 8bc8892..a5d008d 100755
> --- a/git-gui.sh
> +++ b/git-gui.sh
> @@ -583,25 +583,8 @@ proc git {args} {
>
>  proc _open_stdout_stderr {cmd} {
>  	_trace_exec $cmd
> -	if {[catch {
> -			set fd [open [concat [list | ] $cmd] r]
> -		} err]} {
> -		if {   [lindex $cmd end] eq {2>@1}
> -		    && $err eq {can not find channel named "1"}
> -			} {
> -			# Older versions of Tcl 8.4 don't have this 2>@1 IO
> -			# redirect operator.  Fallback to |& cat for those.
> -			# The command was not actually started, so its safe
> -			# to try to start it a second time.
> -			#
> -			set fd [open [concat \
> -				[list | ] \
> -				[lrange $cmd 0 end-1] \
> -				[list |& cat] \
> -				] r]
> -		} else {
> -			error $err
> -		}
> +	if {[catch {set fd [open [concat | $cmd] r]} err]} {
> +		error $err
>  	}
>  	fconfigure $fd -eofchar {}
>  	return $fd
> --
> 2.41.0.99.19
>
>
Mark Levedahl· Apr 1, 2025, 16:48 UTC · re: Johannes Schindelin · lore

Re: [PATCH] git-gui - simplify _open_stdout_stderr

On 4/1/25 12:04 PM, Johannes Schindelin wrote:
> Hi Mark,
>
> this patch is still relevant, right? I am Cc:ing Johannes Sixt for
> awareness.

Absolutely. I have a number of commits in my tree removing compatibility for unsupportable Tcl/Tk and git versions, I should clean these up now there is a real maintainer.

Mark

← back to recent threads