gitk: have callers of diffcmd supply pipe symbol when necessary

Function 'diffcmd' derives which of git diff-files, git diff-index, or git diff-tree must be invoked depending on the ids provided. It puts the pipe symbol as the first element of the returned command list. Note though that of the four callers only two use the command with Tcl 'open' and need the pipe symbol. The other two callers pass the command to Tcl 'exec' and must remove the pipe symbol. Do not include the pipe symbol in the constructed command list, but let the call sites decide whether to add it or not. Note that Tcl 'open' inspects only the first character of the command list, which is also the first character of the first element in the list. For this reason, it is valid to just tack on the pipe symbol with |$cmd and it is not necessary to use [concat | $cmd]. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Johannes Sixt committed Mar 17, 2025 at 21:39 UTC 6eb797f5d1d8885c0f08e42cc5291c11be6f11a4
1 file changed +6 -10
gitk
+6 -10
@@ -7892,7 +7892,7 @@ proc diffcmd {ids flags} {
7892 if {$i >= 0} {
7893 if {[llength $ids] > 1 && $j < 0} {
7894 # comparing working directory with some specific revision
7895 - set cmd [concat | git diff-index $flags]
7895 + set cmd [concat git diff-index $flags]
7896 if {$i == 0} {
7897 lappend cmd -R [lindex $ids 1]
7898 } else {
@@ -7900,7 +7900,7 @@ proc diffcmd {ids flags} {
7900 }
7901 } else {
7902 # comparing working directory with index
7903 - set cmd [concat | git diff-files $flags]
7903 + set cmd [concat git diff-files $flags]
7904 if {$j == 1} {
7905 lappend cmd -R
7906 }
@@ -7909,7 +7909,7 @@ proc diffcmd {ids flags} {
7909 if {[package vcompare $git_version "1.7.2"] >= 0} {
7910 set flags "$flags --ignore-submodules=dirty"
7911 }
7912 - set cmd [concat | git diff-index --cached $flags]
7912 + set cmd [concat git diff-index --cached $flags]
7913 if {[llength $ids] > 1} {
7914 # comparing index with specific revision
7915 if {$j == 0} {
@@ -7925,7 +7925,7 @@ proc diffcmd {ids flags} {
7925 if {$log_showroot} {
7926 lappend flags --root
7927 }
7928 - set cmd [concat | git diff-tree -r $flags $ids]
7928 + set cmd [concat git diff-tree -r $flags $ids]
7929 }
7930 return $cmd
7931 }
@@ -7937,7 +7937,7 @@ proc gettreediffs {ids} {
7937 if {$limitdiffs && $vfilelimit($curview) ne {}} {
7938 set cmd [concat $cmd -- $vfilelimit($curview)]
7939 }
7940 - if {[catch {set gdtf [open $cmd r]}]} return
7940 + if {[catch {set gdtf [open |$cmd r]}]} return
7941
7942 set treepending $ids
7943 set treediff {}
@@ -8057,7 +8057,7 @@ proc getblobdiffs {ids} {
8057 if {$limitdiffs && $vfilelimit($curview) ne {}} {
8058 set cmd [concat $cmd -- $vfilelimit($curview)]
8059 }
8060 - if {[catch {set bdf [open $cmd r]} err]} {
8060 + if {[catch {set bdf [open |$cmd r]} err]} {
8061 error_popup [mc "Error getting diffs: %s" $err]
8062 return
8063 }
@@ -9080,8 +9080,6 @@ proc getpatchid {id} {
9080
9081 if {![info exists patchids($id)]} {
9082 set cmd [diffcmd [list $id] {-p --root}]
9083 - # trim off the initial "|"
9084 - set cmd [lrange $cmd 1 end]
9083 if {[catch {
9084 set x [eval exec $cmd | git patch-id]
9085 set patchids($id) [lindex $x 0]
@@ -9326,8 +9324,6 @@ proc mkpatchgo {} {
9324 set newid [$patchtop.tosha1 get]
9325 set fname [$patchtop.fname get]
9326 set cmd [diffcmd [list $oldid $newid] -p]
9329 - # trim off the initial "|"
9330 - set cmd [lrange $cmd 1 end]
9327 lappend cmd >$fname &
9328 if {[catch {eval exec $cmd} err]} {
9329 error_popup "[mc "Error creating patch:"] $err" $patchtop