Skip to content

Commit dc9ecb1

Browse files
j6tttaylorr
authored andcommitted
git-gui: convert git_read*, git_write to be non-variadic
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 <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent 074c2b9 commit dc9ecb1

16 files changed

+62
-62
lines changed

git-gui.sh

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ proc _lappend_nice {cmd_var} {
621621
}
622622

623623
proc git {args} {
624-
set fd [eval [list git_read] $args]
624+
set fd [git_read $args]
625625
fconfigure $fd -translation binary -encoding utf-8
626626
set result [string trimright [read $fd] "\n"]
627627
close $fd
@@ -642,34 +642,34 @@ proc _open_stdout_stderr {cmd} {
642642
return $fd
643643
}
644644

645-
proc git_read {args} {
646-
set cmdp [_git_cmd [lindex $args 0]]
647-
set args [lrange $args 1 end]
645+
proc git_read {cmd} {
646+
set cmdp [_git_cmd [lindex $cmd 0]]
647+
set cmd [lrange $cmd 1 end]
648648

649-
return [_open_stdout_stderr [concat $cmdp $args]]
649+
return [_open_stdout_stderr [concat $cmdp $cmd]]
650650
}
651651

652-
proc git_read_nice {args} {
652+
proc git_read_nice {cmd} {
653653
set opt [list]
654654

655655
_lappend_nice opt
656656

657-
set cmdp [_git_cmd [lindex $args 0]]
658-
set args [lrange $args 1 end]
657+
set cmdp [_git_cmd [lindex $cmd 0]]
658+
set cmd [lrange $cmd 1 end]
659659

660-
return [_open_stdout_stderr [concat $opt $cmdp $args]]
660+
return [_open_stdout_stderr [concat $opt $cmdp $cmd]]
661661
}
662662

663-
proc git_write {args} {
664-
set cmdp [_git_cmd [lindex $args 0]]
665-
set args [lrange $args 1 end]
663+
proc git_write {cmd} {
664+
set cmdp [_git_cmd [lindex $cmd 0]]
665+
set cmd [lrange $cmd 1 end]
666666

667-
_trace_exec [concat $cmdp $args]
668-
return [open [concat [list | ] $cmdp $args] w]
667+
_trace_exec [concat $cmdp $cmd]
668+
return [open [concat [list | ] $cmdp $cmd] w]
669669
}
670670

671671
proc githook_read {hook_name args} {
672-
git_read hook run --ignore-missing $hook_name -- $args 2>@1
672+
git_read [concat [list hook run --ignore-missing $hook_name --] $args 2>@1]
673673
}
674674

675675
proc kill_file_process {fd} {
@@ -1110,10 +1110,10 @@ proc _parse_config {arr_name args} {
11101110
array unset arr
11111111
set buf {}
11121112
catch {
1113-
set fd_rc [eval \
1114-
[list git_read config] \
1113+
set fd_rc [git_read \
1114+
[concat config \
11151115
$args \
1116-
[list --null --list]]
1116+
--null --list]]
11171117
fconfigure $fd_rc -translation binary -encoding utf-8
11181118
set buf [read $fd_rc]
11191119
close $fd_rc
@@ -1482,12 +1482,12 @@ proc rescan {after {honor_trustmtime 1}} {
14821482
} else {
14831483
set rescan_active 1
14841484
ui_status [mc "Refreshing file status..."]
1485-
set fd_rf [git_read update-index \
1485+
set fd_rf [git_read [list update-index \
14861486
-q \
14871487
--unmerged \
14881488
--ignore-missing \
14891489
--refresh \
1490-
]
1490+
]]
14911491
fconfigure $fd_rf -blocking 0 -translation binary
14921492
fileevent $fd_rf readable \
14931493
[list rescan_stage2 $fd_rf $after]
@@ -1527,11 +1527,11 @@ proc rescan_stage2 {fd after} {
15271527
set rescan_active 2
15281528
ui_status [mc "Scanning for modified files ..."]
15291529
if {[git-version >= "1.7.2"]} {
1530-
set fd_di [git_read diff-index --cached --ignore-submodules=dirty -z [PARENT]]
1530+
set fd_di [git_read [list diff-index --cached --ignore-submodules=dirty -z [PARENT]]]
15311531
} else {
1532-
set fd_di [git_read diff-index --cached -z [PARENT]]
1532+
set fd_di [git_read [list diff-index --cached -z [PARENT]]]
15331533
}
1534-
set fd_df [git_read diff-files -z]
1534+
set fd_df [git_read [list diff-files -z]]
15351535

15361536
fconfigure $fd_di -blocking 0 -translation binary -encoding binary
15371537
fconfigure $fd_df -blocking 0 -translation binary -encoding binary
@@ -1540,7 +1540,7 @@ proc rescan_stage2 {fd after} {
15401540
fileevent $fd_df readable [list read_diff_files $fd_df $after]
15411541

15421542
if {[is_config_true gui.displayuntracked]} {
1543-
set fd_lo [eval git_read ls-files --others -z $ls_others]
1543+
set fd_lo [git_read [concat ls-files --others -z $ls_others]]
15441544
fconfigure $fd_lo -blocking 0 -translation binary -encoding binary
15451545
fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
15461546
incr rescan_active

lib/blame.tcl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,9 @@ method _load {jump} {
486486
fconfigure $fd -eofchar {}
487487
} else {
488488
if {$do_textconv ne 0} {
489-
set fd [git_read cat-file --textconv "$commit:$path"]
489+
set fd [git_read [list cat-file --textconv "$commit:$path"]]
490490
} else {
491-
set fd [git_read cat-file blob "$commit:$path"]
491+
set fd [git_read [list cat-file blob "$commit:$path"]]
492492
}
493493
}
494494
fconfigure $fd \
@@ -617,7 +617,7 @@ method _exec_blame {cur_w cur_d options cur_s} {
617617
}
618618

619619
lappend options -- $path
620-
set fd [eval git_read_nice blame $options]
620+
set fd [git_read_nice [concat blame $options]]
621621
fconfigure $fd -blocking 0 -translation lf -encoding utf-8
622622
fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d]
623623
set current_fd $fd
@@ -986,7 +986,7 @@ method _showcommit {cur_w lno} {
986986
if {[catch {set msg $header($cmit,message)}]} {
987987
set msg {}
988988
catch {
989-
set fd [git_read cat-file commit $cmit]
989+
set fd [git_read [list cat-file commit $cmit]]
990990
fconfigure $fd -encoding binary -translation lf
991991
# By default commits are assumed to be in utf-8
992992
set enc utf-8
@@ -1134,7 +1134,7 @@ method _blameparent {} {
11341134
} else {
11351135
set diffcmd [list diff-tree --unified=0 $cparent $cmit -- $new_path]
11361136
}
1137-
if {[catch {set fd [eval git_read $diffcmd]} err]} {
1137+
if {[catch {set fd [git_read $diffcmd]} err]} {
11381138
$status_operation stop [mc "Unable to display parent"]
11391139
error_popup [strcat [mc "Error loading diff:"] "\n\n$err"]
11401140
return

lib/branch.tcl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ proc load_all_heads {} {
77
set rh refs/heads
88
set rh_len [expr {[string length $rh] + 1}]
99
set all_heads [list]
10-
set fd [git_read for-each-ref --format=%(refname) $rh]
10+
set fd [git_read [list for-each-ref --format=%(refname) $rh]]
1111
fconfigure $fd -translation binary -encoding utf-8
1212
while {[gets $fd line] > 0} {
1313
if {!$some_heads_tracking || ![is_tracking_branch $line]} {
@@ -21,10 +21,10 @@ proc load_all_heads {} {
2121

2222
proc load_all_tags {} {
2323
set all_tags [list]
24-
set fd [git_read for-each-ref \
24+
set fd [git_read [list for-each-ref \
2525
--sort=-taggerdate \
2626
--format=%(refname) \
27-
refs/tags]
27+
refs/tags]]
2828
fconfigure $fd -translation binary -encoding utf-8
2929
while {[gets $fd line] > 0} {
3030
if {![regsub ^refs/tags/ $line {} name]} continue

lib/browser.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ method _ls {tree_id {name {}}} {
196196
lappend browser_stack [list $tree_id $name]
197197
$w conf -state disabled
198198

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

lib/checkout_op.tcl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -304,12 +304,12 @@ The rescan will be automatically started now.
304304
_readtree $this
305305
} else {
306306
ui_status [mc "Refreshing file status..."]
307-
set fd [git_read update-index \
307+
set fd [git_read [list update-index \
308308
-q \
309309
--unmerged \
310310
--ignore-missing \
311311
--refresh \
312-
]
312+
]]
313313
fconfigure $fd -blocking 0 -translation binary
314314
fileevent $fd readable [cb _refresh_wait $fd]
315315
}
@@ -345,15 +345,15 @@ method _readtree {} {
345345
[mc "Updating working directory to '%s'..." [_name $this]] \
346346
[mc "files checked out"]]
347347

348-
set fd [git_read read-tree \
348+
set fd [git_read [list read-tree \
349349
-m \
350350
-u \
351351
-v \
352352
--exclude-per-directory=.gitignore \
353353
$HEAD \
354354
$new_hash \
355355
2>@1 \
356-
]
356+
]]
357357
fconfigure $fd -blocking 0 -translation binary
358358
fileevent $fd readable [cb _readtree_wait $fd $status_bar_operation]
359359
}
@@ -573,7 +573,7 @@ method _confirm_reset {cur} {
573573
pack $w.buttons.cancel -side right -padx 5
574574
pack $w.buttons -side bottom -fill x -pady 10 -padx 10
575575

576-
set fd [git_read rev-list --pretty=oneline $cur ^$new_hash]
576+
set fd [git_read [list rev-list --pretty=oneline $cur ^$new_hash]]
577577
while {[gets $fd line] > 0} {
578578
set abbr [string range $line 0 7]
579579
set subj [string range $line 41 end]

lib/choose_repository.tcl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -818,9 +818,9 @@ method _clone_refs {} {
818818
error_popup [mc "Not a Git repository: %s" [file tail $origin_url]]
819819
return 0
820820
}
821-
set fd_in [git_read for-each-ref \
821+
set fd_in [git_read [list for-each-ref \
822822
--tcl \
823-
{--format=list %(refname) %(objectname) %(*objectname)}]
823+
{--format=list %(refname) %(objectname) %(*objectname)}]]
824824
cd $pwd
825825

826826
set fd [safe_open_file [gitdir packed-refs] w]
@@ -953,14 +953,14 @@ method _do_clone_checkout {HEAD} {
953953
[mc "files"]]
954954

955955
set readtree_err {}
956-
set fd [git_read read-tree \
956+
set fd [git_read [list read-tree \
957957
-m \
958958
-u \
959959
-v \
960960
HEAD \
961961
HEAD \
962962
2>@1 \
963-
]
963+
]]
964964
fconfigure $fd -blocking 0 -translation binary
965965
fileevent $fd readable [cb _readtree_wait $fd]
966966
}

lib/choose_rev.tcl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,14 @@ constructor _new {path unmerged_only title} {
146146
append fmt { %(*subject)}
147147
append fmt {]}
148148
set all_refn [list]
149-
set fr_fd [git_read for-each-ref \
149+
set fr_fd [git_read [list for-each-ref \
150150
--tcl \
151151
--sort=-taggerdate \
152152
--format=$fmt \
153153
refs/heads \
154154
refs/remotes \
155155
refs/tags \
156-
]
156+
]]
157157
fconfigure $fr_fd -translation lf -encoding utf-8
158158
while {[gets $fr_fd line] > 0} {
159159
set line [eval $line]
@@ -176,7 +176,7 @@ constructor _new {path unmerged_only title} {
176176
close $fr_fd
177177

178178
if {$unmerged_only} {
179-
set fr_fd [git_read rev-list --all ^$::HEAD]
179+
set fr_fd [git_read [list rev-list --all ^$::HEAD]]
180180
while {[gets $fr_fd sha1] > 0} {
181181
if {[catch {set rlst $cmt_refn($sha1)}]} continue
182182
foreach refn $rlst {

lib/commit.tcl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ You are currently in the middle of a merge that has not been fully completed. Y
2727
if {[catch {
2828
set name ""
2929
set email ""
30-
set fd [git_read cat-file commit $curHEAD]
30+
set fd [git_read [list cat-file commit $curHEAD]]
3131
fconfigure $fd -encoding binary -translation lf
3232
# By default commits are assumed to be in utf-8
3333
set enc utf-8
@@ -325,7 +325,7 @@ proc commit_commitmsg_wait {fd_ph curHEAD msg_p} {
325325

326326
proc commit_writetree {curHEAD msg_p} {
327327
ui_status [mc "Committing changes..."]
328-
set fd_wt [git_read write-tree]
328+
set fd_wt [git_read [list write-tree]]
329329
fileevent $fd_wt readable \
330330
[list commit_committree $fd_wt $curHEAD $msg_p]
331331
}
@@ -350,7 +350,7 @@ proc commit_committree {fd_wt curHEAD msg_p} {
350350
# -- Verify this wasn't an empty change.
351351
#
352352
if {$commit_type eq {normal}} {
353-
set fd_ot [git_read cat-file commit $PARENT]
353+
set fd_ot [git_read [list cat-file commit $PARENT]]
354354
fconfigure $fd_ot -encoding binary -translation lf
355355
set old_tree [gets $fd_ot]
356356
close $fd_ot

lib/console.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ method _init {} {
9393
method exec {cmd {after {}}} {
9494
lappend cmd 2>@1
9595
if {[lindex $cmd 0] eq {git}} {
96-
set fd_f [eval git_read [lrange $cmd 1 end]]
96+
set fd_f [git_read [lrange $cmd 1 end]]
9797
} else {
9898
set fd_f [_open_stdout_stderr $cmd]
9999
}

lib/database.tcl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
proc do_stats {} {
55
global use_ttk NS
6-
set fd [git_read count-objects -v]
6+
set fd [git_read [list count-objects -v]]
77
while {[gets $fd line] > 0} {
88
if {[regexp {^([^:]+): (\d+)$} $line _ name value]} {
99
set stats($name) $value

0 commit comments

Comments
 (0)