@matheusbsbs / matheus-bagliano / commits / 699d5601f5
Fork 0

git-gui: Refactor our ui_status_value update technique

I'm really starting to dislike global variables. The ui_status_value global varible is just one of those that seems to appear in a lot of code and in many cases we didn't even declare it "global" within the proc that updates it so we haven't always been getting all of the updates we expected to see. This change introduces two new global procs: ui_status $msg; # Sets the status bar to show $msg. ui_ready; # Changes the status bar to show "Ready." The second (special) form is used because we often update the area with this message once we are done processing a block of work and want the user to know we have completed it. I'm not fixing the cases that appear in lib/branch.tcl right now as I'm actually in the middle of a huge refactoring of that code to support making a detached HEAD checkout. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Shawn O. Pearce committed Jul 5, 2007 at 23:16 UTC 699d5601f59938d62ec2506f319c25a656a403da
5 files changed +67 -64
git-gui.sh
+21 -15
@@ -527,7 +527,7 @@ proc PARENT {} {
527
528 proc rescan {after {honor_trustmtime 1}} {
529 global HEAD PARENT MERGE_HEAD commit_type
530 - global ui_index ui_workdir ui_status_value ui_comm
530 + global ui_index ui_workdir ui_comm
531 global rescan_active file_states
532 global repo_config
533
@@ -566,7 +566,7 @@ proc rescan {after {honor_trustmtime 1}} {
566 rescan_stage2 {} $after
567 } else {
568 set rescan_active 1
569 - set ui_status_value {Refreshing file status...}
569 + ui_status {Refreshing file status...}
570 set cmd [list git update-index]
571 lappend cmd -q
572 lappend cmd --unmerged
@@ -580,7 +580,6 @@ proc rescan {after {honor_trustmtime 1}} {
580 }
581
582 proc rescan_stage2 {fd after} {
583 - global ui_status_value
583 global rescan_active buf_rdi buf_rdf buf_rlo
584
585 if {$fd ne {}} {
@@ -601,7 +600,7 @@ proc rescan_stage2 {fd after} {
600 set buf_rlo {}
601
602 set rescan_active 3
604 - set ui_status_value {Scanning for modified files ...}
603 + ui_status {Scanning for modified files ...}
604 set fd_di [open "| git diff-index --cached -z [PARENT]" r]
605 set fd_df [open "| git diff-files -z" r]
606 set fd_lo [open $ls_others r]
@@ -761,6 +760,16 @@ proc mapdesc {state path} {
760 return $r
761 }
762
763 +proc ui_status {msg} {
764 + set ::ui_status_value $msg
765 +}
766 +
767 +proc ui_ready {{test {}}} {
768 + if {$test eq {} || $::ui_status_value eq $test} {
769 + ui_status Ready.
770 + }
771 +}
772 +
773 proc escape_path {path} {
774 regsub -all {\\} $path "\\\\" path
775 regsub -all "\n" $path "\\n" path
@@ -1112,7 +1121,7 @@ proc incr_font_size {font {amt 1}} {
1121 set starting_gitk_msg {Starting gitk... please wait...}
1122
1123 proc do_gitk {revs} {
1115 - global env ui_status_value starting_gitk_msg
1124 + global env starting_gitk_msg
1125
1126 # -- Always start gitk through whatever we were loaded with. This
1127 # lets us bypass using shell process on Windows systems.
@@ -1129,11 +1138,9 @@ proc do_gitk {revs} {
1138 error_popup "Unable to start gitk:\n\n$exe does not exist"
1139 } else {
1140 eval exec $cmd &
1132 - set ui_status_value $starting_gitk_msg
1141 + ui_status $starting_gitk_msg
1142 after 10000 {
1134 - if {$ui_status_value eq $starting_gitk_msg} {
1135 - set ui_status_value {Ready.}
1136 - }
1143 + ui_ready $starting_gitk_msg
1144 }
1145 }
1146 }
@@ -1182,7 +1189,7 @@ proc do_quit {} {
1189 }
1190
1191 proc do_rescan {} {
1185 - rescan {set ui_status_value {Ready.}}
1192 + rescan ui_ready
1193 }
1194
1195 proc do_commit {} {
@@ -1217,12 +1224,12 @@ proc toggle_or_diff {w x y} {
1224 update_indexinfo \
1225 "Unstaging [short_path $path] from commit" \
1226 [list $path] \
1220 - [concat $after {set ui_status_value {Ready.}}]
1227 + [concat $after [list ui_ready]]
1228 } elseif {$w eq $ui_workdir} {
1229 update_index \
1230 "Adding [short_path $path]" \
1231 [list $path] \
1225 - [concat $after {set ui_status_value {Ready.}}]
1232 + [concat $after [list ui_ready]]
1233 }
1234 } else {
1235 show_diff $path $w $lno
@@ -1640,20 +1647,19 @@ if {[is_MacOSX]} {
1647 #
1648 if {[is_Cygwin] && [file exists /usr/local/miga/lib/gui-miga]} {
1649 proc do_miga {} {
1643 - global ui_status_value
1650 if {![lock_index update]} return
1651 set cmd [list sh --login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""]
1652 set miga_fd [open "|$cmd" r]
1653 fconfigure $miga_fd -blocking 0
1654 fileevent $miga_fd readable [list miga_done $miga_fd]
1649 - set ui_status_value {Running miga...}
1655 + ui_status {Running miga...}
1656 }
1657 proc miga_done {fd} {
1658 read $fd 512
1659 if {[eof $fd]} {
1660 close $fd
1661 unlock_index
1656 - rescan [list set ui_status_value {Ready.}]
1662 + rescan ui_ready
1663 }
1664 }
1665 .mbar add cascade -label Tools -menu .mbar.tools
lib/commit.tcl
+15 -18
@@ -58,7 +58,7 @@ You are currently in the middle of a merge that has not been fully completed. Y
58 $ui_comm insert end $msg
59 $ui_comm edit reset
60 $ui_comm edit modified false
61 - rescan {set ui_status_value {Ready.}}
61 + rescan ui_ready
62 }
63
64 set GIT_COMMITTER_IDENT {}
@@ -108,12 +108,12 @@ proc create_new_commit {} {
108 $ui_comm delete 0.0 end
109 $ui_comm edit reset
110 $ui_comm edit modified false
111 - rescan {set ui_status_value {Ready.}}
111 + rescan ui_ready
112 }
113
114 proc commit_tree {} {
115 global HEAD commit_type file_states ui_comm repo_config
116 - global ui_status_value pch_error
116 + global pch_error
117
118 if {[committer_ident] eq {}} return
119 if {![lock_index update]} return
@@ -132,7 +132,7 @@ Another Git program has modified this repository since the last scan. A rescan
132 The rescan will be automatically started now.
133 }
134 unlock_index
135 - rescan {set ui_status_value {Ready.}}
135 + rescan ui_ready
136 return
137 }
138
@@ -206,7 +206,7 @@ A good commit message has the following format:
206 return
207 }
208
209 - set ui_status_value {Calling pre-commit hook...}
209 + ui_status {Calling pre-commit hook...}
210 set pch_error {}
211 set fd_ph [open "| $pchook" r]
212 fconfigure $fd_ph -blocking 0 -translation binary
@@ -215,13 +215,13 @@ A good commit message has the following format:
215 }
216
217 proc commit_prehook_wait {fd_ph curHEAD msg} {
218 - global pch_error ui_status_value
218 + global pch_error
219
220 append pch_error [read $fd_ph]
221 fconfigure $fd_ph -blocking 1
222 if {[eof $fd_ph]} {
223 if {[catch {close $fd_ph}]} {
224 - set ui_status_value {Commit declined by pre-commit hook.}
224 + ui_status {Commit declined by pre-commit hook.}
225 hook_failed_popup pre-commit $pch_error
226 unlock_index
227 } else {
@@ -234,9 +234,7 @@ proc commit_prehook_wait {fd_ph curHEAD msg} {
234 }
235
236 proc commit_writetree {curHEAD msg} {
237 - global ui_status_value
238 -
239 - set ui_status_value {Committing changes...}
237 + ui_status {Committing changes...}
238 set fd_wt [open "| git write-tree" r]
239 fileevent $fd_wt readable \
240 [list commit_committree $fd_wt $curHEAD $msg]
@@ -244,15 +242,15 @@ proc commit_writetree {curHEAD msg} {
242
243 proc commit_committree {fd_wt curHEAD msg} {
244 global HEAD PARENT MERGE_HEAD commit_type
247 - global all_heads current_branch
248 - global ui_status_value ui_comm selected_commit_type
245 + global current_branch
246 + global ui_comm selected_commit_type
247 global file_states selected_paths rescan_active
248 global repo_config
249
250 gets $fd_wt tree_id
251 if {$tree_id eq {} || [catch {close $fd_wt} err]} {
252 error_popup "write-tree failed:\n\n$err"
255 - set ui_status_value {Commit failed.}
253 + ui_status {Commit failed.}
254 unlock_index
255 return
256 }
@@ -269,7 +267,7 @@ No files were modified by this commit and it was not a merge commit.
267 A rescan will be automatically started now.
268 }
269 unlock_index
272 - rescan {set ui_status_value {No changes to commit.}}
270 + rescan {ui_status {No changes to commit.}}
271 return
272 }
273 }
@@ -294,7 +292,7 @@ A rescan will be automatically started now.
292 lappend cmd <$msg_p
293 if {[catch {set cmt_id [eval git $cmd]} err]} {
294 error_popup "commit-tree failed:\n\n$err"
297 - set ui_status_value {Commit failed.}
295 + ui_status {Commit failed.}
296 unlock_index
297 return
298 }
@@ -316,7 +314,7 @@ A rescan will be automatically started now.
314 git update-ref -m $reflogm HEAD $cmt_id $curHEAD
315 } err]} {
316 error_popup "update-ref failed:\n\n$err"
319 - set ui_status_value {Commit failed.}
317 + ui_status {Commit failed.}
318 unlock_index
319 return
320 }
@@ -410,6 +408,5 @@ A rescan will be automatically started now.
408 display_all_files
409 unlock_index
410 reshow_diff
413 - set ui_status_value \
414 - "Created commit [string range $cmt_id 0 7]: $subject"
411 + ui_status "Created commit [string range $cmt_id 0 7]: $subject"
412 }
lib/diff.tcl
+9 -9
@@ -17,7 +17,7 @@ proc clear_diff {} {
17 }
18
19 proc reshow_diff {} {
20 - global ui_status_value file_states file_lists
20 + global file_states file_lists
21 global current_diff_path current_diff_side
22
23 set p $current_diff_path
@@ -49,13 +49,13 @@ A rescan will be automatically started to find other files which may have the sa
49
50 clear_diff
51 display_file $path __
52 - rescan {set ui_status_value {Ready.}} 0
52 + rescan ui_ready 0
53 }
54
55 proc show_diff {path w {lno {}}} {
56 global file_states file_lists
57 global is_3way_diff diff_active repo_config
58 - global ui_diff ui_status_value ui_index ui_workdir
58 + global ui_diff ui_index ui_workdir
59 global current_diff_path current_diff_side current_diff_header
60
61 if {$diff_active || ![lock_index read]} return
@@ -78,7 +78,7 @@ proc show_diff {path w {lno {}}} {
78 set current_diff_path $path
79 set current_diff_side $w
80 set current_diff_header {}
81 - set ui_status_value "Loading diff of [escape_path $path]..."
81 + ui_status "Loading diff of [escape_path $path]..."
82
83 # - Git won't give us the diff, there's nothing to compare to!
84 #
@@ -92,7 +92,7 @@ proc show_diff {path w {lno {}}} {
92 } err ]} {
93 set diff_active 0
94 unlock_index
95 - set ui_status_value "Unable to display [escape_path $path]"
95 + ui_status "Unable to display [escape_path $path]"
96 error_popup "Error loading file:\n\n$err"
97 return
98 }
@@ -127,7 +127,7 @@ proc show_diff {path w {lno {}}} {
127 $ui_diff conf -state disabled
128 set diff_active 0
129 unlock_index
130 - set ui_status_value {Ready.}
130 + ui_ready
131 return
132 }
133
@@ -157,7 +157,7 @@ proc show_diff {path w {lno {}}} {
157 if {[catch {set fd [open $cmd r]} err]} {
158 set diff_active 0
159 unlock_index
160 - set ui_status_value "Unable to display [escape_path $path]"
160 + ui_status "Unable to display [escape_path $path]"
161 error_popup "Error loading diff:\n\n$err"
162 return
163 }
@@ -170,7 +170,7 @@ proc show_diff {path w {lno {}}} {
170 }
171
172 proc read_diff {fd} {
173 - global ui_diff ui_status_value diff_active
173 + global ui_diff diff_active
174 global is_3way_diff current_diff_header
175
176 $ui_diff conf -state normal
@@ -256,7 +256,7 @@ proc read_diff {fd} {
256 close $fd
257 set diff_active 0
258 unlock_index
259 - set ui_status_value {Ready.}
259 + ui_ready
260
261 if {[$ui_diff index end] eq {2.0}} {
262 handle_empty_diff
lib/index.tcl
+15 -15
@@ -2,7 +2,7 @@
2 # Copyright (C) 2006, 2007 Shawn Pearce
3
4 proc update_indexinfo {msg pathList after} {
5 - global update_index_cp ui_status_value
5 + global update_index_cp
6
7 if {![lock_index update]} return
8
@@ -12,7 +12,7 @@ proc update_indexinfo {msg pathList after} {
12 set batch [expr {int($totalCnt * .01) + 1}]
13 if {$batch > 25} {set batch 25}
14
15 - set ui_status_value [format \
15 + ui_status [format \
16 "$msg... %i/%i files (%.2f%%)" \
17 $update_index_cp \
18 $totalCnt \
@@ -36,7 +36,7 @@ proc update_indexinfo {msg pathList after} {
36 }
37
38 proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
39 - global update_index_cp ui_status_value
39 + global update_index_cp
40 global file_states current_diff_path
41
42 if {$update_index_cp >= $totalCnt} {
@@ -67,7 +67,7 @@ proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
67 display_file $path $new
68 }
69
70 - set ui_status_value [format \
70 + ui_status [format \
71 "$msg... %i/%i files (%.2f%%)" \
72 $update_index_cp \
73 $totalCnt \
@@ -75,7 +75,7 @@ proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
75 }
76
77 proc update_index {msg pathList after} {
78 - global update_index_cp ui_status_value
78 + global update_index_cp
79
80 if {![lock_index update]} return
81
@@ -85,7 +85,7 @@ proc update_index {msg pathList after} {
85 set batch [expr {int($totalCnt * .01) + 1}]
86 if {$batch > 25} {set batch 25}
87
88 - set ui_status_value [format \
88 + ui_status [format \
89 "$msg... %i/%i files (%.2f%%)" \
90 $update_index_cp \
91 $totalCnt \
@@ -109,7 +109,7 @@ proc update_index {msg pathList after} {
109 }
110
111 proc write_update_index {fd pathList totalCnt batch msg after} {
112 - global update_index_cp ui_status_value
112 + global update_index_cp
113 global file_states current_diff_path
114
115 if {$update_index_cp >= $totalCnt} {
@@ -144,7 +144,7 @@ proc write_update_index {fd pathList totalCnt batch msg after} {
144 display_file $path $new
145 }
146
147 - set ui_status_value [format \
147 + ui_status [format \
148 "$msg... %i/%i files (%.2f%%)" \
149 $update_index_cp \
150 $totalCnt \
@@ -152,7 +152,7 @@ proc write_update_index {fd pathList totalCnt batch msg after} {
152 }
153
154 proc checkout_index {msg pathList after} {
155 - global update_index_cp ui_status_value
155 + global update_index_cp
156
157 if {![lock_index update]} return
158
@@ -162,7 +162,7 @@ proc checkout_index {msg pathList after} {
162 set batch [expr {int($totalCnt * .01) + 1}]
163 if {$batch > 25} {set batch 25}
164
165 - set ui_status_value [format \
165 + ui_status [format \
166 "$msg... %i/%i files (%.2f%%)" \
167 $update_index_cp \
168 $totalCnt \
@@ -192,7 +192,7 @@ proc checkout_index {msg pathList after} {
192 }
193
194 proc write_checkout_index {fd pathList totalCnt batch msg after} {
195 - global update_index_cp ui_status_value
195 + global update_index_cp
196 global file_states current_diff_path
197
198 if {$update_index_cp >= $totalCnt} {
@@ -217,7 +217,7 @@ proc write_checkout_index {fd pathList totalCnt batch msg after} {
217 }
218 }
219
220 - set ui_status_value [format \
220 + ui_status [format \
221 "$msg... %i/%i files (%.2f%%)" \
222 $update_index_cp \
223 $totalCnt \
@@ -249,7 +249,7 @@ proc unstage_helper {txt paths} {
249 update_indexinfo \
250 $txt \
251 $pathList \
252 - [concat $after {set ui_status_value {Ready.}}]
252 + [concat $after [list ui_ready]]
253 }
254 }
255
@@ -293,7 +293,7 @@ proc add_helper {txt paths} {
293 update_index \
294 $txt \
295 $pathList \
296 - [concat $after {set ui_status_value {Ready to commit.}}]
296 + [concat $after {ui_status {Ready to commit.}}]
297 }
298 }
299
@@ -370,7 +370,7 @@ Any unadded changes will be permanently lost by the revert." \
370 checkout_index \
371 $txt \
372 $pathList \
373 - [concat $after {set ui_status_value {Ready.}}]
373 + [concat $after [list ui_ready]]
374 } else {
375 unlock_index
376 }
lib/merge.tcl
+7 -7
@@ -28,7 +28,7 @@ Another Git program has modified this repository since the last scan. A rescan
28 The rescan will be automatically started now.
29 }
30 unlock_index
31 - rescan {set ui_status_value {Ready.}}
31 + rescan ui_ready
32 return 0
33 }
34
@@ -79,7 +79,7 @@ proc _visualize {w list} {
79 }
80
81 proc _start {w list} {
82 - global HEAD ui_status_value current_branch
82 + global HEAD current_branch
83
84 set cmd [list git merge]
85 set names [_refs $w $list]
@@ -121,7 +121,7 @@ Please select fewer branches. To merge more than 15 branches, merge the branche
121 }
122
123 set msg "Merging $current_branch, [join $names {, }]"
124 - set ui_status_value "$msg..."
124 + ui_status "$msg..."
125 set cons [console::new "Merge" $msg]
126 console::exec $cons $cmd \
127 [namespace code [list _finish $revcnt $cons]]
@@ -150,14 +150,14 @@ You can attempt this merge again by merging only one branch at a time." $w
150 fconfigure $fd -blocking 0 -translation binary
151 fileevent $fd readable \
152 [namespace code [list _reset_wait $fd]]
153 - set ui_status_value {Aborting... please wait...}
153 + ui_status {Aborting... please wait...}
154 return
155 }
156
157 set msg {Merge failed. Conflict resolution is required.}
158 }
159 unlock_index
160 - rescan [list set ui_status_value $msg]
160 + rescan [list ui_status $msg]
161 }
162
163 proc dialog {} {
@@ -285,7 +285,7 @@ Continue with aborting the current $op?"] eq {yes}} {
285 set fd [open "| git read-tree --reset -u HEAD" r]
286 fconfigure $fd -blocking 0 -translation binary
287 fileevent $fd readable [namespace code [list _reset_wait $fd]]
288 - set ui_status_value {Aborting... please wait...}
288 + ui_status {Aborting... please wait...}
289 } else {
290 unlock_index
291 }
@@ -308,7 +308,7 @@ proc _reset_wait {fd} {
308 catch {file delete [gitdir MERGE_MSG]}
309 catch {file delete [gitdir GITGUI_MSG]}
310
311 - rescan {set ui_status_value {Abort completed. Ready.}}
311 + rescan {ui_status {Abort completed. Ready.}}
312 }
313 }
314