git-gui: break out a separate function git_read_nice

There are two callers of git_read that request special treatment using option --nice. Rewrite them to call a new function git_read_nice that does the special treatment. Now we can remove all option treatment from git_read. git_write has the same capability, but there are no callers that request --nice. Remove the feature without substitution. This is a preparation for a later change where we want to make git_read and friends non-variadic. Then it cannot have optional arguments. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Johannes Sixt committed May 3, 2025 at 13:11 UTC aa42e87ef4ee9d84bd2fdb5e56de2ac2b61575d9
3 files changed +11 -34
git-gui.sh
+9 -32
@@ -643,22 +643,16 @@ proc _open_stdout_stderr {cmd} {
643 }
644
645 proc git_read {args} {
646 - set opt [list]
647 -
648 - while {1} {
649 - switch -- [lindex $args 0] {
650 - --nice {
651 - _lappend_nice opt
652 - }
646 + set cmdp [_git_cmd [lindex $args 0]]
647 + set args [lrange $args 1 end]
648
654 - default {
655 - break
656 - }
649 + return [_open_stdout_stderr [concat $cmdp $args]]
650 +}
651
658 - }
652 +proc git_read_nice {args} {
653 + set opt [list]
654
660 - set args [lrange $args 1 end]
661 - }
655 + _lappend_nice opt
656
657 set cmdp [_git_cmd [lindex $args 0]]
658 set args [lrange $args 1 end]
@@ -667,28 +661,11 @@ proc git_read {args} {
661 }
662
663 proc git_write {args} {
670 - set opt [list]
671 -
672 - while {1} {
673 - switch -- [lindex $args 0] {
674 - --nice {
675 - _lappend_nice opt
676 - }
677 -
678 - default {
679 - break
680 - }
681 -
682 - }
683 -
684 - set args [lrange $args 1 end]
685 - }
686 -
664 set cmdp [_git_cmd [lindex $args 0]]
665 set args [lrange $args 1 end]
666
690 - _trace_exec [concat $opt $cmdp $args]
691 - return [open [concat [list | ] $opt $cmdp $args] w]
667 + _trace_exec [concat $cmdp $args]
668 + return [open [concat [list | ] $cmdp $args] w]
669 }
670
671 proc githook_read {hook_name args} {
lib/blame.tcl
+1 -1
@@ -617,7 +617,7 @@ method _exec_blame {cur_w cur_d options cur_s} {
617 }
618
619 lappend options -- $path
620 - set fd [eval git_read --nice blame $options]
620 + set fd [eval git_read_nice blame $options]
621 fconfigure $fd -blocking 0 -translation lf -encoding utf-8
622 fileevent $fd readable [cb _read_blame $fd $cur_w $cur_d]
623 set current_fd $fd
lib/diff.tcl
+1 -1
@@ -338,7 +338,7 @@ proc start_show_diff {cont_info {add_opts {}}} {
338 }
339 }
340
341 - if {[catch {set fd [eval git_read --nice $cmd]} err]} {
341 + if {[catch {set fd [eval git_read_nice $cmd]} err]} {
342 set diff_active 0
343 unlock_index
344 ui_status [mc "Unable to display %s" [escape_path $path]]