@matheusbsbs / matheus-bagliano / commits / 6c3d1481ba
Fork 0

git-gui: Refactor console success/failure handling.

Because I want to be able to run multiple output-producing commands in a single 'console' window within git-gui I'm refactoring the console handling routines to require the "after" argument of console_exec. This should specify a procedure to execute which will receive two args, the first is the console window handle and the second is the status of the last command (0 on failure, 1 on success). A new procedure console_done can be passed to the last console_exec command to forward perform all cleanup and enable the Close button. Its status argument is used to update the final status bar on the bottom of the console window. This isn't any real logic changing, and no new functionality is in this patch. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jan 26, 2007 at 01:29 UTC 6c3d1481bab96659a80771194d935cb6db02300e
1 file changed +29 -18
git-gui.sh
+29 -18
@@ -1277,7 +1277,7 @@ proc fetch_from {remote} {
1277 "Fetching new changes from $remote"]
1278 set cmd [list git fetch]
1279 lappend cmd $remote
1280 - console_exec $w $cmd
1280 + console_exec $w $cmd console_done
1281 }
1282
1283 proc push_to {remote} {
@@ -1287,7 +1287,7 @@ proc push_to {remote} {
1287 set cmd [list git push]
1288 lappend cmd -v
1289 lappend cmd $remote
1290 - console_exec $w $cmd
1290 + console_exec $w $cmd console_done
1291 }
1292
1293 ######################################################################
@@ -2476,7 +2476,7 @@ proc start_push_anywhere_action {w} {
2476 }
2477
2478 set cons [new_console "push $r_url" "Pushing $cnt $unit to $r_url"]
2479 - console_exec $cons $cmd
2479 + console_exec $cons $cmd console_done
2480 destroy $w
2481 }
2482
@@ -2854,7 +2854,7 @@ proc console_init {w} {
2854 return $w
2855 }
2856
2857 -proc console_exec {w cmd {after {}}} {
2857 +proc console_exec {w cmd after} {
2858 # -- Windows tosses the enviroment when we exec our child.
2859 # But most users need that so we have to relogin. :-(
2860 #
@@ -2873,7 +2873,7 @@ proc console_exec {w cmd {after {}}} {
2873 }
2874
2875 proc console_read {w fd after} {
2876 - global console_cr console_data
2876 + global console_cr
2877
2878 set buf [read $fd]
2879 if {$buf ne {}} {
@@ -2907,25 +2907,36 @@ proc console_read {w fd after} {
2907 fconfigure $fd -blocking 1
2908 if {[eof $fd]} {
2909 if {[catch {close $fd}]} {
2910 - if {![winfo exists $w]} {console_init $w}
2911 - $w.m.s conf -background red -text {Error: Command Failed}
2912 - $w.ok conf -state normal
2910 set ok 0
2914 - } elseif {[winfo exists $w]} {
2915 - $w.m.s conf -background green -text {Success}
2916 - $w.ok conf -state normal
2911 + } else {
2912 set ok 1
2913 }
2919 - array unset console_cr $w
2920 - array unset console_data $w
2921 - if {$after ne {}} {
2922 - uplevel #0 $after $ok
2923 - }
2914 + uplevel #0 $after $w $ok
2915 return
2916 }
2917 fconfigure $fd -blocking 0
2918 }
2919
2920 +proc console_done {w ok} {
2921 + global console_cr console_data
2922 +
2923 + if {$ok} {
2924 + if {[winfo exists $w]} {
2925 + $w.m.s conf -background green -text {Success}
2926 + $w.ok conf -state normal
2927 + }
2928 + } else {
2929 + if {![winfo exists $w]} {
2930 + console_init $w
2931 + }
2932 + $w.m.s conf -background red -text {Error: Command Failed}
2933 + $w.ok conf -state normal
2934 + }
2935 +
2936 + array unset console_cr $w
2937 + array unset console_data $w
2938 +}
2939 +
2940 ######################################################################
2941 ##
2942 ## ui commands
@@ -3027,7 +3038,7 @@ proc do_stats {} {
3038
3039 proc do_gc {} {
3040 set w [new_console {gc} {Compressing the object database}]
3030 - console_exec $w {git gc}
3041 + console_exec $w {git gc} console_done
3042 }
3043
3044 proc do_fsck_objects {} {
@@ -3037,7 +3048,7 @@ proc do_fsck_objects {} {
3048 lappend cmd --full
3049 lappend cmd --cache
3050 lappend cmd --strict
3040 - console_exec $w $cmd
3051 + console_exec $w $cmd console_done
3052 }
3053
3054 set is_quitting 0