]> git.ipfire.org Git - thirdparty/git.git/commitdiff
git-gui: convert git_read*, git_write to be non-variadic
authorJohannes Sixt <j6t@kdbg.org>
Sat, 3 May 2025 11:24:48 +0000 (13:24 +0200)
committerTaylor Blau <me@ttaylorr.com>
Fri, 23 May 2025 21:04:24 +0000 (17:04 -0400)
We are going to treat command arguments and redirections differently to
avoid passing arguments that look like redirections to the command
accidentally. To do so, it will be necessary to know which arguments
are intentional redirections. As a preparation, convert git_read,
git_read_nice, and git_write to take just a single argument that is
the command in a list. Adjust all call sites accordingly.

In the future, this argument will be the regular command arguments and
a second argument will be the redirection operations.

Signed-off-by: Johannes Sixt <j6t@kdbg.org>
Signed-off-by: Taylor Blau <me@ttaylorr.com>
16 files changed:
git-gui.sh
lib/blame.tcl
lib/branch.tcl
lib/browser.tcl
lib/checkout_op.tcl
lib/choose_repository.tcl
lib/choose_rev.tcl
lib/commit.tcl
lib/console.tcl
lib/database.tcl
lib/diff.tcl
lib/index.tcl
lib/merge.tcl
lib/mergetool.tcl
lib/remote.tcl
lib/remote_branch_delete.tcl

index e10bf2a039295e31d205bf96dd921dfd9293c980..301c7647ecaec6560230248bbba5b89263f9daf3 100755 (executable)
@@ -621,7 +621,7 @@ proc _lappend_nice {cmd_var} {
 }
 
 proc git {args} {
-       set fd [eval [list git_read] $args]
+       set fd [git_read $args]
        fconfigure $fd -translation binary -encoding utf-8
        set result [string trimright [read $fd] "\n"]
        close $fd
@@ -642,34 +642,34 @@ proc _open_stdout_stderr {cmd} {
        return $fd
 }
 
-proc git_read {args} {
-       set cmdp [_git_cmd [lindex $args 0]]
-       set args [lrange $args 1 end]
+proc git_read {cmd} {
+       set cmdp [_git_cmd [lindex $cmd 0]]
+       set cmd [lrange $cmd 1 end]
 
-       return [_open_stdout_stderr [concat $cmdp $args]]
+       return [_open_stdout_stderr [concat $cmdp $cmd]]
 }
 
-proc git_read_nice {args} {
+proc git_read_nice {cmd} {
        set opt [list]
 
        _lappend_nice opt
 
-       set cmdp [_git_cmd [lindex $args 0]]
-       set args [lrange $args 1 end]
+       set cmdp [_git_cmd [lindex $cmd 0]]
+       set cmd [lrange $cmd 1 end]
 
-       return [_open_stdout_stderr [concat $opt $cmdp $args]]
+       return [_open_stdout_stderr [concat $opt $cmdp $cmd]]
 }
 
-proc git_write {args} {
-       set cmdp [_git_cmd [lindex $args 0]]
-       set args [lrange $args 1 end]
+proc git_write {cmd} {
+       set cmdp [_git_cmd [lindex $cmd 0]]
+       set cmd [lrange $cmd 1 end]
 
-       _trace_exec [concat $cmdp $args]
-       return [open [concat [list | ] $cmdp $args] w]
+       _trace_exec [concat $cmdp $cmd]
+       return [open [concat [list | ] $cmdp $cmd] w]
 }
 
 proc githook_read {hook_name args} {
-       git_read hook run --ignore-missing $hook_name -- $args 2>@1
+       git_read [concat [list hook run --ignore-missing $hook_name --] $args 2>@1]
 }
 
 proc kill_file_process {fd} {
@@ -1110,10 +1110,10 @@ proc _parse_config {arr_name args} {
        array unset arr
        set buf {}
        catch {
-               set fd_rc [eval \
-                       [list git_read config] \
+               set fd_rc [git_read \
+                       [concat config \
                        $args \
-                       [list --null --list]]
+                       --null --list]]
                fconfigure $fd_rc -translation binary -encoding utf-8
                set buf [read $fd_rc]
                close $fd_rc
@@ -1482,12 +1482,12 @@ proc rescan {after {honor_trustmtime 1}} {
        } else {
                set rescan_active 1
                ui_status [mc "Refreshing file status..."]
-               set fd_rf [git_read update-index \
+               set fd_rf [git_read [list update-index \
                        -q \
                        --unmerged \
                        --ignore-missing \
                        --refresh \
-                       ]
+                       ]]
                fconfigure $fd_rf -blocking 0 -translation binary
                fileevent $fd_rf readable \
                        [list rescan_stage2 $fd_rf $after]
@@ -1527,11 +1527,11 @@ proc rescan_stage2 {fd after} {
        set rescan_active 2
        ui_status [mc "Scanning for modified files ..."]
        if {[git-version >= "1.7.2"]} {
-               set fd_di [git_read diff-index --cached --ignore-submodules=dirty -z [PARENT]]
+               set fd_di [git_read [list diff-index --cached --ignore-submodules=dirty -z [PARENT]]]
        } else {
-               set fd_di [git_read diff-index --cached -z [PARENT]]
+               set fd_di [git_read [list diff-index --cached -z [PARENT]]]
        }
-       set fd_df [git_read diff-files -z]
+       set fd_df [git_read [list diff-files -z]]
 
        fconfigure $fd_di -blocking 0 -translation binary -encoding binary
        fconfigure $fd_df -blocking 0 -translation binary -encoding binary
@@ -1540,7 +1540,7 @@ proc rescan_stage2 {fd after} {
        fileevent $fd_df readable [list read_diff_files $fd_df $after]
 
        if {[is_config_true gui.displayuntracked]} {
-               set fd_lo [eval git_read ls-files --others -z $ls_others]
+               set fd_lo [git_read [concat ls-files --others -z $ls_others]]
                fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
                fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
                incr rescan_active
index ceb2330266592b2b9a5cb8bab8bf9b0f5f7f6ca4..d6fd8bea91ff531cbec890c13523de575efc46ca 100644 (file)
@@ -486,9 +486,9 @@ method _load {jump} {
                fconfigure $fd -eofchar {}
        } else {
                if {$do_textconv ne 0} {
-                       set fd [git_read cat-file --textconv "$commit:$path"]
+                       set fd [git_read [list cat-file --textconv "$commit:$path"]]
                } else {
-                       set fd [git_read cat-file blob "$commit:$path"]
+                       set fd [git_read [list cat-file blob "$commit:$path"]]
                }
        }
        fconfigure $fd \
@@ -617,7 +617,7 @@ method _exec_blame {cur_w cur_d options cur_s} {
        }
 
        lappend options -- $path
-       set fd [eval git_read_nice blame $options]
+       set fd [git_read_nice [concat blame $options]]
        fconfigure $fd -blocking 0 -translation lf -encoding utf-8
        fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d]
        set current_fd $fd
@@ -986,7 +986,7 @@ method _showcommit {cur_w lno} {
                if {[catch {set msg $header($cmit,message)}]} {
                        set msg {}
                        catch {
-                               set fd [git_read cat-file commit $cmit]
+                               set fd [git_read [list cat-file commit $cmit]]
                                fconfigure $fd -encoding binary -translation lf
                                # By default commits are assumed to be in utf-8
                                set enc utf-8
@@ -1134,7 +1134,7 @@ method _blameparent {} {
                } else {
                        set diffcmd [list diff-tree --unified=0 $cparent $cmit -- $new_path]
                }
-               if {[catch {set fd [eval git_read $diffcmd]} err]} {
+               if {[catch {set fd [git_read $diffcmd]} err]} {
                        $status_operation stop [mc "Unable to display parent"]
                        error_popup [strcat [mc "Error loading diff:"] "\n\n$err"]
                        return
index 8b0c4858890f11cf0e3f31536b584e0596f3aba0..39e0f2dc9864e0d3902840e9c26ab71f8aaf2a81 100644 (file)
@@ -7,7 +7,7 @@ proc load_all_heads {} {
        set rh refs/heads
        set rh_len [expr {[string length $rh] + 1}]
        set all_heads [list]
-       set fd [git_read for-each-ref --format=%(refname) $rh]
+       set fd [git_read [list for-each-ref --format=%(refname) $rh]]
        fconfigure $fd -translation binary -encoding utf-8
        while {[gets $fd line] > 0} {
                if {!$some_heads_tracking || ![is_tracking_branch $line]} {
@@ -21,10 +21,10 @@ proc load_all_heads {} {
 
 proc load_all_tags {} {
        set all_tags [list]
-       set fd [git_read for-each-ref \
+       set fd [git_read [list for-each-ref \
                --sort=-taggerdate \
                --format=%(refname) \
-               refs/tags]
+               refs/tags]]
        fconfigure $fd -translation binary -encoding utf-8
        while {[gets $fd line] > 0} {
                if {![regsub ^refs/tags/ $line {} name]} continue
index a98298366763d841d3f88e4478f0afdc6e9a5653..6fc8d4d6372264468b5333dcd3aa6e35c3e82540 100644 (file)
@@ -196,7 +196,7 @@ method _ls {tree_id {name {}}} {
        lappend browser_stack [list $tree_id $name]
        $w conf -state disabled
 
-       set fd [git_read ls-tree -z $tree_id]
+       set fd [git_read [list ls-tree -z $tree_id]]
        fconfigure $fd -blocking 0 -translation binary -encoding utf-8
        fileevent $fd readable [cb _read $fd]
 }
index 31992f461bc8892f55d937935ed13a0ad51469d9..48fd1a3cacdca717e6c4b7674981288c40a7217b 100644 (file)
@@ -304,12 +304,12 @@ The rescan will be automatically started now.
                _readtree $this
        } else {
                ui_status [mc "Refreshing file status..."]
-               set fd [git_read update-index \
+               set fd [git_read [list update-index \
                        -q \
                        --unmerged \
                        --ignore-missing \
                        --refresh \
-                       ]
+                       ]]
                fconfigure $fd -blocking 0 -translation binary
                fileevent $fd readable [cb _refresh_wait $fd]
        }
@@ -345,7 +345,7 @@ method _readtree {} {
                [mc "Updating working directory to '%s'..." [_name $this]] \
                [mc "files checked out"]]
 
-       set fd [git_read read-tree \
+       set fd [git_read [list read-tree \
                -m \
                -u \
                -v \
@@ -353,7 +353,7 @@ method _readtree {} {
                $HEAD \
                $new_hash \
                2>@1 \
-               ]
+               ]]
        fconfigure $fd -blocking 0 -translation binary
        fileevent $fd readable [cb _readtree_wait $fd $status_bar_operation]
 }
@@ -573,7 +573,7 @@ method _confirm_reset {cur} {
        pack $w.buttons.cancel -side right -padx 5
        pack $w.buttons -side bottom -fill x -pady 10 -padx 10
 
-       set fd [git_read rev-list --pretty=oneline $cur ^$new_hash]
+       set fd [git_read [list rev-list --pretty=oneline $cur ^$new_hash]]
        while {[gets $fd line] > 0} {
                set abbr [string range $line 0 7]
                set subj [string range $line 41 end]
index 7bd738e51e0a9ede23f37b179b84e580cd809808..7b64a112395d68abd5d4401f03e0bc01603acbd8 100644 (file)
@@ -818,9 +818,9 @@ method _clone_refs {} {
                error_popup [mc "Not a Git repository: %s" [file tail $origin_url]]
                return 0
        }
-       set fd_in [git_read for-each-ref \
+       set fd_in [git_read [list for-each-ref \
                --tcl \
-               {--format=list %(refname) %(objectname) %(*objectname)}]
+               {--format=list %(refname) %(objectname) %(*objectname)}]]
        cd $pwd
 
        set fd [safe_open_file [gitdir packed-refs] w]
@@ -953,14 +953,14 @@ method _do_clone_checkout {HEAD} {
                [mc "files"]]
 
        set readtree_err {}
-       set fd [git_read read-tree \
+       set fd [git_read [list read-tree \
                -m \
                -u \
                -v \
                HEAD \
                HEAD \
                2>@1 \
-               ]
+               ]]
        fconfigure $fd -blocking 0 -translation binary
        fileevent $fd readable [cb _readtree_wait $fd]
 }
index 7cf9e160fa3b545f0119e5ed8e863188dab5cf51..8ae7e8a5c4797ee2b1bc92b3ce96db8ae6ed5d88 100644 (file)
@@ -146,14 +146,14 @@ constructor _new {path unmerged_only title} {
        append fmt { %(*subject)}
        append fmt {]}
        set all_refn [list]
-       set fr_fd [git_read for-each-ref \
+       set fr_fd [git_read [list for-each-ref \
                --tcl \
                --sort=-taggerdate \
                --format=$fmt \
                refs/heads \
                refs/remotes \
                refs/tags \
-               ]
+               ]]
        fconfigure $fr_fd -translation lf -encoding utf-8
        while {[gets $fr_fd line] > 0} {
                set line [eval $line]
@@ -176,7 +176,7 @@ constructor _new {path unmerged_only title} {
        close $fr_fd
 
        if {$unmerged_only} {
-               set fr_fd [git_read rev-list --all ^$::HEAD]
+               set fr_fd [git_read [list rev-list --all ^$::HEAD]]
                while {[gets $fr_fd sha1] > 0} {
                        if {[catch {set rlst $cmt_refn($sha1)}]} continue
                        foreach refn $rlst {
index 8d135845a5ec4fdbfcd3d285ed48ab741fae543a..b27e37d38514e0907ca09c8e76da60e6f9bd826f 100644 (file)
@@ -27,7 +27,7 @@ You are currently in the middle of a merge that has not been fully completed.  Y
        if {[catch {
                        set name ""
                        set email ""
-                       set fd [git_read cat-file commit $curHEAD]
+                       set fd [git_read [list cat-file commit $curHEAD]]
                        fconfigure $fd -encoding binary -translation lf
                        # By default commits are assumed to be in utf-8
                        set enc utf-8
@@ -325,7 +325,7 @@ proc commit_commitmsg_wait {fd_ph curHEAD msg_p} {
 
 proc commit_writetree {curHEAD msg_p} {
        ui_status [mc "Committing changes..."]
-       set fd_wt [git_read write-tree]
+       set fd_wt [git_read [list write-tree]]
        fileevent $fd_wt readable \
                [list commit_committree $fd_wt $curHEAD $msg_p]
 }
@@ -350,7 +350,7 @@ proc commit_committree {fd_wt curHEAD msg_p} {
        # -- Verify this wasn't an empty change.
        #
        if {$commit_type eq {normal}} {
-               set fd_ot [git_read cat-file commit $PARENT]
+               set fd_ot [git_read [list cat-file commit $PARENT]]
                fconfigure $fd_ot -encoding binary -translation lf
                set old_tree [gets $fd_ot]
                close $fd_ot
index c7f20b87cbf4bbeef760b66e6f96cbec3e28cebd..44dcdf29be8e8cec6529ad15f1f395a11ca671fc 100644 (file)
@@ -93,7 +93,7 @@ method _init {} {
 method exec {cmd {after {}}} {
        lappend cmd 2>@1
        if {[lindex $cmd 0] eq {git}} {
-               set fd_f [eval git_read [lrange $cmd 1 end]]
+               set fd_f [git_read [lrange $cmd 1 end]]
        } else {
                set fd_f [_open_stdout_stderr $cmd]
        }
index 85783081e0d887a7c7857f07670847ef1bc0629d..1fc0ea00b3ba97fafa28f58e5845e92227029455 100644 (file)
@@ -3,7 +3,7 @@
 
 proc do_stats {} {
        global use_ttk NS
-       set fd [git_read count-objects -v]
+       set fd [git_read [list count-objects -v]]
        while {[gets $fd line] > 0} {
                if {[regexp {^([^:]+): (\d+)$} $line _ name value]} {
                        set stats($name) $value
index ce1bad69007bae01e767eba0b50e6150ac3aac33..8ec740eb50df6ce9494403fe61b9110d311565fb 100644 (file)
@@ -338,7 +338,7 @@ proc start_show_diff {cont_info {add_opts {}}} {
                }
        }
 
-       if {[catch {set fd [eval git_read_nice $cmd]} err]} {
+       if {[catch {set fd [git_read_nice $cmd]} err]} {
                set diff_active 0
                unlock_index
                ui_status [mc "Unable to display %s" [escape_path $path]]
@@ -617,7 +617,7 @@ proc apply_or_revert_hunk {x y revert} {
 
        if {[catch {
                set enc [get_path_encoding $current_diff_path]
-               set p [eval git_write $apply_cmd]
+               set p [git_write $apply_cmd]
                fconfigure $p -translation binary -encoding $enc
                puts -nonewline $p $wholepatch
                close $p} err]} {
@@ -853,7 +853,7 @@ proc apply_or_revert_range_or_line {x y revert} {
 
        if {[catch {
                set enc [get_path_encoding $current_diff_path]
-               set p [eval git_write $apply_cmd]
+               set p [git_write $apply_cmd]
                fconfigure $p -translation binary -encoding $enc
                puts -nonewline $p $current_diff_header
                puts -nonewline $p $wholepatch
@@ -890,7 +890,7 @@ proc undo_last_revert {} {
 
        if {[catch {
                set enc $last_revert_enc
-               set p [eval git_write $apply_cmd]
+               set p [git_write $apply_cmd]
                fconfigure $p -translation binary -encoding $enc
                puts -nonewline $p $last_revert
                close $p} err]} {
index d2ec24bd80e12af37ca0099b8aca0bc471cb180f..857864ff2be2ca618868c44ac3e0f65187c5f247 100644 (file)
@@ -75,7 +75,7 @@ proc update_indexinfo {msg path_list after} {
        if {$batch > 25} {set batch 25}
 
        set status_bar_operation [$::main_status start $msg [mc "files"]]
-       set fd [git_write update-index -z --index-info]
+       set fd [git_write [list update-index -z --index-info]]
        fconfigure $fd \
                -blocking 0 \
                -buffering full \
@@ -144,7 +144,7 @@ proc update_index {msg path_list after} {
        if {$batch > 25} {set batch 25}
 
        set status_bar_operation [$::main_status start $msg [mc "files"]]
-       set fd [git_write update-index --add --remove -z --stdin]
+       set fd [git_write [list update-index --add --remove -z --stdin]]
        fconfigure $fd \
                -blocking 0 \
                -buffering full \
@@ -218,13 +218,13 @@ proc checkout_index {msg path_list after capture_error} {
        if {$batch > 25} {set batch 25}
 
        set status_bar_operation [$::main_status start $msg [mc "files"]]
-       set fd [git_write checkout-index \
+       set fd [git_write [list checkout-index \
                --index \
                --quiet \
                --force \
                -z \
                --stdin \
-               ]
+               ]]
        fconfigure $fd \
                -blocking 0 \
                -buffering full \
index e97c91eab67ae2392a1c6bd4a7cddd78b585c6e5..6317c32127b3991fa9808c79a150e1a61d472d14 100644 (file)
@@ -239,7 +239,7 @@ Continue with resetting the current changes?"]
        }
 
        if {[ask_popup $op_question] eq {yes}} {
-               set fd [git_read read-tree --reset -u -v HEAD 2>@1]
+               set fd [git_read [list read-tree --reset -u -v HEAD 2>@1]]
                fconfigure $fd -blocking 0 -translation binary
                set status_bar_operation [$::main_status \
                        start \
index f2fa4393057d663893280e85fa69e8ad1bff5fea..777d7b323bcd26eb19237f4121bcf1b261760f05 100644 (file)
@@ -88,7 +88,7 @@ proc merge_load_stages {path cont} {
        set merge_stages(3) {}
        set merge_stages_buf {}
 
-       set merge_stages_fd [eval git_read ls-files -u -z -- {$path}]
+       set merge_stages_fd [git_read [list ls-files -u -z -- $path]]
 
        fconfigure $merge_stages_fd -blocking 0 -translation binary -encoding binary
        fileevent $merge_stages_fd readable [list read_merge_stages $merge_stages_fd $cont]
index a733a0f36e6e21270d818cf0df9aaa4f46549e02..cf796d1601437fdef557b133bacc54c0e1f37f73 100644 (file)
@@ -32,7 +32,7 @@ proc all_tracking_branches {} {
        }
 
        if {$pat ne {}} {
-               set fd [eval git_read for-each-ref --format=%(refname) $cmd]
+               set fd [git_read [concat for-each-ref --format=%(refname) $cmd]]
                while {[gets $fd n] > 0} {
                        foreach spec $pat {
                                set dst [string range [lindex $spec 0] 0 end-2]
index 5ba9fcadd17f315a4a47220f91f81ba964d64b08..c8c99b17a8da39f6564855f67aeb6a35d4e610ac 100644 (file)
@@ -308,7 +308,7 @@ method _load {cache uri} {
                set full_list [list]
                set head_cache($cache) [list]
                set full_cache($cache) [list]
-               set active_ls [git_read ls-remote $uri]
+               set active_ls [git_read [list ls-remote $uri]]
                fconfigure $active_ls \
                        -blocking 0 \
                        -translation lf \