@matheusbsbs / matheus-bagliano / commits / 74c4763c76
Fork 0

git-gui: Teach console widget to use git_read

Now that we are pretty strict about setting up own absolute paths to any git helper (saving a marginal runtime cost to resolve the tool) we can do the same in our console widget by making sure all console execs go through git_read if they are a git subcommand, and if not make sure they at least try to use the Tcl 2>@1 IO redirection if possible, as it should be faster than |& cat. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jul 9, 2007 at 03:07 UTC 74c4763c76a111809747652210962ad09896b74f
2 files changed +29 -34
git-gui.sh
+24 -22
@@ -394,6 +394,29 @@ proc git {args} {
394 return [eval $opt $cmdp $args]
395 }
396
397 +proc _open_stdout_stderr {cmd} {
398 + if {[catch {
399 + set fd [open $cmd r]
400 + } err]} {
401 + if { [lindex $cmd end] eq {2>@1}
402 + && $err eq {can not find channel named "1"}
403 + } {
404 + # Older versions of Tcl 8.4 don't have this 2>@1 IO
405 + # redirect operator. Fallback to |& cat for those.
406 + # The command was not actually started, so its safe
407 + # to try to start it a second time.
408 + #
409 + set fd [open [concat \
410 + [lrange $cmd 0 end-1] \
411 + [list |& cat] \
412 + ] r]
413 + } else {
414 + error $err
415 + }
416 + }
417 + return $fd
418 +}
419 +
420 proc git_read {args} {
421 set opt [list |]
422
@@ -422,28 +445,7 @@ proc git_read {args} {
445 set cmdp [_git_cmd [lindex $args 0]]
446 set args [lrange $args 1 end]
447
425 - if {[catch {
426 - set fd [open [concat $opt $cmdp $args] r]
427 - } err]} {
428 - if { [lindex $args end] eq {2>@1}
429 - && $err eq {can not find channel named "1"}
430 - } {
431 - # Older versions of Tcl 8.4 don't have this 2>@1 IO
432 - # redirect operator. Fallback to |& cat for those.
433 - # The command was not actually started, so its safe
434 - # to try to start it a second time.
435 - #
436 - set fd [open [concat \
437 - $opt \
438 - $cmdp \
439 - [lrange $args 0 end-1] \
440 - [list |& cat] \
441 - ] r]
442 - } else {
443 - error $err
444 - }
445 - }
446 - return $fd
448 + return [_open_stdout_stderr [concat $opt $cmdp $args]]
449 }
450
451 proc git_write {args} {
lib/console.tcl
+5 -12
@@ -87,19 +87,12 @@ method _init {} {
87 }
88
89 method exec {cmd {after {}}} {
90 - # -- Cygwin's Tcl tosses the enviroment when we exec our child.
91 - # But most users need that so we have to relogin. :-(
92 - #
93 - if {[is_Cygwin]} {
94 - set cmd [list sh --login -c "cd \"[pwd]\" && [join $cmd { }]"]
90 + if {[lindex $cmd 0] eq {git}} {
91 + set fd_f [eval git_read --stderr [lrange $cmd 1 end]]
92 + } else {
93 + lappend cmd 2>@1
94 + set fd_f [_open_stdout_stderr $cmd]
95 }
96 -
97 - # -- Tcl won't let us redirect both stdout and stderr to
98 - # the same pipe. So pass it through cat...
99 - #
100 - set cmd [concat | $cmd |& cat]
101 -
102 - set fd_f [open $cmd r]
96 fconfigure $fd_f -blocking 0 -translation binary
97 fileevent $fd_f readable [cb _read $fd_f $after]
98 }