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>
This commit is contained in:
Shawn O. Pearce
2007-07-05 23:16:13 -04:00
parent 311e02a4a5
commit 699d5601f5
5 changed files with 67 additions and 64 deletions

View File

@ -527,7 +527,7 @@ proc PARENT {} {
proc rescan {after {honor_trustmtime 1}} { proc rescan {after {honor_trustmtime 1}} {
global HEAD PARENT MERGE_HEAD commit_type global HEAD PARENT MERGE_HEAD commit_type
global ui_index ui_workdir ui_status_value ui_comm global ui_index ui_workdir ui_comm
global rescan_active file_states global rescan_active file_states
global repo_config global repo_config
@ -566,7 +566,7 @@ proc rescan {after {honor_trustmtime 1}} {
rescan_stage2 {} $after rescan_stage2 {} $after
} else { } else {
set rescan_active 1 set rescan_active 1
set ui_status_value {Refreshing file status...} ui_status {Refreshing file status...}
set cmd [list git update-index] set cmd [list git update-index]
lappend cmd -q lappend cmd -q
lappend cmd --unmerged lappend cmd --unmerged
@ -580,7 +580,6 @@ proc rescan {after {honor_trustmtime 1}} {
} }
proc rescan_stage2 {fd after} { proc rescan_stage2 {fd after} {
global ui_status_value
global rescan_active buf_rdi buf_rdf buf_rlo global rescan_active buf_rdi buf_rdf buf_rlo
if {$fd ne {}} { if {$fd ne {}} {
@ -601,7 +600,7 @@ proc rescan_stage2 {fd after} {
set buf_rlo {} set buf_rlo {}
set rescan_active 3 set rescan_active 3
set ui_status_value {Scanning for modified files ...} ui_status {Scanning for modified files ...}
set fd_di [open "| git diff-index --cached -z [PARENT]" r] set fd_di [open "| git diff-index --cached -z [PARENT]" r]
set fd_df [open "| git diff-files -z" r] set fd_df [open "| git diff-files -z" r]
set fd_lo [open $ls_others r] set fd_lo [open $ls_others r]
@ -761,6 +760,16 @@ proc mapdesc {state path} {
return $r return $r
} }
proc ui_status {msg} {
set ::ui_status_value $msg
}
proc ui_ready {{test {}}} {
if {$test eq {} || $::ui_status_value eq $test} {
ui_status Ready.
}
}
proc escape_path {path} { proc escape_path {path} {
regsub -all {\\} $path "\\\\" path regsub -all {\\} $path "\\\\" path
regsub -all "\n" $path "\\n" path regsub -all "\n" $path "\\n" path
@ -1112,7 +1121,7 @@ proc incr_font_size {font {amt 1}} {
set starting_gitk_msg {Starting gitk... please wait...} set starting_gitk_msg {Starting gitk... please wait...}
proc do_gitk {revs} { proc do_gitk {revs} {
global env ui_status_value starting_gitk_msg global env starting_gitk_msg
# -- Always start gitk through whatever we were loaded with. This # -- Always start gitk through whatever we were loaded with. This
# lets us bypass using shell process on Windows systems. # lets us bypass using shell process on Windows systems.
@ -1129,11 +1138,9 @@ proc do_gitk {revs} {
error_popup "Unable to start gitk:\n\n$exe does not exist" error_popup "Unable to start gitk:\n\n$exe does not exist"
} else { } else {
eval exec $cmd & eval exec $cmd &
set ui_status_value $starting_gitk_msg ui_status $starting_gitk_msg
after 10000 { after 10000 {
if {$ui_status_value eq $starting_gitk_msg} { ui_ready $starting_gitk_msg
set ui_status_value {Ready.}
}
} }
} }
} }
@ -1182,7 +1189,7 @@ proc do_quit {} {
} }
proc do_rescan {} { proc do_rescan {} {
rescan {set ui_status_value {Ready.}} rescan ui_ready
} }
proc do_commit {} { proc do_commit {} {
@ -1217,12 +1224,12 @@ proc toggle_or_diff {w x y} {
update_indexinfo \ update_indexinfo \
"Unstaging [short_path $path] from commit" \ "Unstaging [short_path $path] from commit" \
[list $path] \ [list $path] \
[concat $after {set ui_status_value {Ready.}}] [concat $after [list ui_ready]]
} elseif {$w eq $ui_workdir} { } elseif {$w eq $ui_workdir} {
update_index \ update_index \
"Adding [short_path $path]" \ "Adding [short_path $path]" \
[list $path] \ [list $path] \
[concat $after {set ui_status_value {Ready.}}] [concat $after [list ui_ready]]
} }
} else { } else {
show_diff $path $w $lno show_diff $path $w $lno
@ -1640,20 +1647,19 @@ if {[is_MacOSX]} {
# #
if {[is_Cygwin] && [file exists /usr/local/miga/lib/gui-miga]} { if {[is_Cygwin] && [file exists /usr/local/miga/lib/gui-miga]} {
proc do_miga {} { proc do_miga {} {
global ui_status_value
if {![lock_index update]} return if {![lock_index update]} return
set cmd [list sh --login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""] set cmd [list sh --login -c "/usr/local/miga/lib/gui-miga \"[pwd]\""]
set miga_fd [open "|$cmd" r] set miga_fd [open "|$cmd" r]
fconfigure $miga_fd -blocking 0 fconfigure $miga_fd -blocking 0
fileevent $miga_fd readable [list miga_done $miga_fd] fileevent $miga_fd readable [list miga_done $miga_fd]
set ui_status_value {Running miga...} ui_status {Running miga...}
} }
proc miga_done {fd} { proc miga_done {fd} {
read $fd 512 read $fd 512
if {[eof $fd]} { if {[eof $fd]} {
close $fd close $fd
unlock_index unlock_index
rescan [list set ui_status_value {Ready.}] rescan ui_ready
} }
} }
.mbar add cascade -label Tools -menu .mbar.tools .mbar add cascade -label Tools -menu .mbar.tools

View File

@ -58,7 +58,7 @@ You are currently in the middle of a merge that has not been fully completed. Y
$ui_comm insert end $msg $ui_comm insert end $msg
$ui_comm edit reset $ui_comm edit reset
$ui_comm edit modified false $ui_comm edit modified false
rescan {set ui_status_value {Ready.}} rescan ui_ready
} }
set GIT_COMMITTER_IDENT {} set GIT_COMMITTER_IDENT {}
@ -108,12 +108,12 @@ proc create_new_commit {} {
$ui_comm delete 0.0 end $ui_comm delete 0.0 end
$ui_comm edit reset $ui_comm edit reset
$ui_comm edit modified false $ui_comm edit modified false
rescan {set ui_status_value {Ready.}} rescan ui_ready
} }
proc commit_tree {} { proc commit_tree {} {
global HEAD commit_type file_states ui_comm repo_config global HEAD commit_type file_states ui_comm repo_config
global ui_status_value pch_error global pch_error
if {[committer_ident] eq {}} return if {[committer_ident] eq {}} return
if {![lock_index update]} return if {![lock_index update]} return
@ -132,7 +132,7 @@ Another Git program has modified this repository since the last scan. A rescan
The rescan will be automatically started now. The rescan will be automatically started now.
} }
unlock_index unlock_index
rescan {set ui_status_value {Ready.}} rescan ui_ready
return return
} }
@ -206,7 +206,7 @@ A good commit message has the following format:
return return
} }
set ui_status_value {Calling pre-commit hook...} ui_status {Calling pre-commit hook...}
set pch_error {} set pch_error {}
set fd_ph [open "| $pchook" r] set fd_ph [open "| $pchook" r]
fconfigure $fd_ph -blocking 0 -translation binary fconfigure $fd_ph -blocking 0 -translation binary
@ -215,13 +215,13 @@ A good commit message has the following format:
} }
proc commit_prehook_wait {fd_ph curHEAD msg} { proc commit_prehook_wait {fd_ph curHEAD msg} {
global pch_error ui_status_value global pch_error
append pch_error [read $fd_ph] append pch_error [read $fd_ph]
fconfigure $fd_ph -blocking 1 fconfigure $fd_ph -blocking 1
if {[eof $fd_ph]} { if {[eof $fd_ph]} {
if {[catch {close $fd_ph}]} { if {[catch {close $fd_ph}]} {
set ui_status_value {Commit declined by pre-commit hook.} ui_status {Commit declined by pre-commit hook.}
hook_failed_popup pre-commit $pch_error hook_failed_popup pre-commit $pch_error
unlock_index unlock_index
} else { } else {
@ -234,9 +234,7 @@ proc commit_prehook_wait {fd_ph curHEAD msg} {
} }
proc commit_writetree {curHEAD msg} { proc commit_writetree {curHEAD msg} {
global ui_status_value ui_status {Committing changes...}
set ui_status_value {Committing changes...}
set fd_wt [open "| git write-tree" r] set fd_wt [open "| git write-tree" r]
fileevent $fd_wt readable \ fileevent $fd_wt readable \
[list commit_committree $fd_wt $curHEAD $msg] [list commit_committree $fd_wt $curHEAD $msg]
@ -244,15 +242,15 @@ proc commit_writetree {curHEAD msg} {
proc commit_committree {fd_wt curHEAD msg} { proc commit_committree {fd_wt curHEAD msg} {
global HEAD PARENT MERGE_HEAD commit_type global HEAD PARENT MERGE_HEAD commit_type
global all_heads current_branch global current_branch
global ui_status_value ui_comm selected_commit_type global ui_comm selected_commit_type
global file_states selected_paths rescan_active global file_states selected_paths rescan_active
global repo_config global repo_config
gets $fd_wt tree_id gets $fd_wt tree_id
if {$tree_id eq {} || [catch {close $fd_wt} err]} { if {$tree_id eq {} || [catch {close $fd_wt} err]} {
error_popup "write-tree failed:\n\n$err" error_popup "write-tree failed:\n\n$err"
set ui_status_value {Commit failed.} ui_status {Commit failed.}
unlock_index unlock_index
return return
} }
@ -269,7 +267,7 @@ No files were modified by this commit and it was not a merge commit.
A rescan will be automatically started now. A rescan will be automatically started now.
} }
unlock_index unlock_index
rescan {set ui_status_value {No changes to commit.}} rescan {ui_status {No changes to commit.}}
return return
} }
} }
@ -294,7 +292,7 @@ A rescan will be automatically started now.
lappend cmd <$msg_p lappend cmd <$msg_p
if {[catch {set cmt_id [eval git $cmd]} err]} { if {[catch {set cmt_id [eval git $cmd]} err]} {
error_popup "commit-tree failed:\n\n$err" error_popup "commit-tree failed:\n\n$err"
set ui_status_value {Commit failed.} ui_status {Commit failed.}
unlock_index unlock_index
return return
} }
@ -316,7 +314,7 @@ A rescan will be automatically started now.
git update-ref -m $reflogm HEAD $cmt_id $curHEAD git update-ref -m $reflogm HEAD $cmt_id $curHEAD
} err]} { } err]} {
error_popup "update-ref failed:\n\n$err" error_popup "update-ref failed:\n\n$err"
set ui_status_value {Commit failed.} ui_status {Commit failed.}
unlock_index unlock_index
return return
} }
@ -410,6 +408,5 @@ A rescan will be automatically started now.
display_all_files display_all_files
unlock_index unlock_index
reshow_diff reshow_diff
set ui_status_value \ ui_status "Created commit [string range $cmt_id 0 7]: $subject"
"Created commit [string range $cmt_id 0 7]: $subject"
} }

View File

@ -17,7 +17,7 @@ proc clear_diff {} {
} }
proc reshow_diff {} { proc reshow_diff {} {
global ui_status_value file_states file_lists global file_states file_lists
global current_diff_path current_diff_side global current_diff_path current_diff_side
set p $current_diff_path set p $current_diff_path
@ -49,13 +49,13 @@ A rescan will be automatically started to find other files which may have the sa
clear_diff clear_diff
display_file $path __ display_file $path __
rescan {set ui_status_value {Ready.}} 0 rescan ui_ready 0
} }
proc show_diff {path w {lno {}}} { proc show_diff {path w {lno {}}} {
global file_states file_lists global file_states file_lists
global is_3way_diff diff_active repo_config global is_3way_diff diff_active repo_config
global ui_diff ui_status_value ui_index ui_workdir global ui_diff ui_index ui_workdir
global current_diff_path current_diff_side current_diff_header global current_diff_path current_diff_side current_diff_header
if {$diff_active || ![lock_index read]} return if {$diff_active || ![lock_index read]} return
@ -78,7 +78,7 @@ proc show_diff {path w {lno {}}} {
set current_diff_path $path set current_diff_path $path
set current_diff_side $w set current_diff_side $w
set current_diff_header {} set current_diff_header {}
set ui_status_value "Loading diff of [escape_path $path]..." ui_status "Loading diff of [escape_path $path]..."
# - Git won't give us the diff, there's nothing to compare to! # - Git won't give us the diff, there's nothing to compare to!
# #
@ -92,7 +92,7 @@ proc show_diff {path w {lno {}}} {
} err ]} { } err ]} {
set diff_active 0 set diff_active 0
unlock_index unlock_index
set ui_status_value "Unable to display [escape_path $path]" ui_status "Unable to display [escape_path $path]"
error_popup "Error loading file:\n\n$err" error_popup "Error loading file:\n\n$err"
return return
} }
@ -127,7 +127,7 @@ proc show_diff {path w {lno {}}} {
$ui_diff conf -state disabled $ui_diff conf -state disabled
set diff_active 0 set diff_active 0
unlock_index unlock_index
set ui_status_value {Ready.} ui_ready
return return
} }
@ -157,7 +157,7 @@ proc show_diff {path w {lno {}}} {
if {[catch {set fd [open $cmd r]} err]} { if {[catch {set fd [open $cmd r]} err]} {
set diff_active 0 set diff_active 0
unlock_index unlock_index
set ui_status_value "Unable to display [escape_path $path]" ui_status "Unable to display [escape_path $path]"
error_popup "Error loading diff:\n\n$err" error_popup "Error loading diff:\n\n$err"
return return
} }
@ -170,7 +170,7 @@ proc show_diff {path w {lno {}}} {
} }
proc read_diff {fd} { proc read_diff {fd} {
global ui_diff ui_status_value diff_active global ui_diff diff_active
global is_3way_diff current_diff_header global is_3way_diff current_diff_header
$ui_diff conf -state normal $ui_diff conf -state normal
@ -256,7 +256,7 @@ proc read_diff {fd} {
close $fd close $fd
set diff_active 0 set diff_active 0
unlock_index unlock_index
set ui_status_value {Ready.} ui_ready
if {[$ui_diff index end] eq {2.0}} { if {[$ui_diff index end] eq {2.0}} {
handle_empty_diff handle_empty_diff

View File

@ -2,7 +2,7 @@
# Copyright (C) 2006, 2007 Shawn Pearce # Copyright (C) 2006, 2007 Shawn Pearce
proc update_indexinfo {msg pathList after} { proc update_indexinfo {msg pathList after} {
global update_index_cp ui_status_value global update_index_cp
if {![lock_index update]} return if {![lock_index update]} return
@ -12,7 +12,7 @@ proc update_indexinfo {msg pathList after} {
set batch [expr {int($totalCnt * .01) + 1}] set batch [expr {int($totalCnt * .01) + 1}]
if {$batch > 25} {set batch 25} if {$batch > 25} {set batch 25}
set ui_status_value [format \ ui_status [format \
"$msg... %i/%i files (%.2f%%)" \ "$msg... %i/%i files (%.2f%%)" \
$update_index_cp \ $update_index_cp \
$totalCnt \ $totalCnt \
@ -36,7 +36,7 @@ proc update_indexinfo {msg pathList after} {
} }
proc write_update_indexinfo {fd pathList totalCnt batch msg after} { proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
global update_index_cp ui_status_value global update_index_cp
global file_states current_diff_path global file_states current_diff_path
if {$update_index_cp >= $totalCnt} { if {$update_index_cp >= $totalCnt} {
@ -67,7 +67,7 @@ proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
display_file $path $new display_file $path $new
} }
set ui_status_value [format \ ui_status [format \
"$msg... %i/%i files (%.2f%%)" \ "$msg... %i/%i files (%.2f%%)" \
$update_index_cp \ $update_index_cp \
$totalCnt \ $totalCnt \
@ -75,7 +75,7 @@ proc write_update_indexinfo {fd pathList totalCnt batch msg after} {
} }
proc update_index {msg pathList after} { proc update_index {msg pathList after} {
global update_index_cp ui_status_value global update_index_cp
if {![lock_index update]} return if {![lock_index update]} return
@ -85,7 +85,7 @@ proc update_index {msg pathList after} {
set batch [expr {int($totalCnt * .01) + 1}] set batch [expr {int($totalCnt * .01) + 1}]
if {$batch > 25} {set batch 25} if {$batch > 25} {set batch 25}
set ui_status_value [format \ ui_status [format \
"$msg... %i/%i files (%.2f%%)" \ "$msg... %i/%i files (%.2f%%)" \
$update_index_cp \ $update_index_cp \
$totalCnt \ $totalCnt \
@ -109,7 +109,7 @@ proc update_index {msg pathList after} {
} }
proc write_update_index {fd pathList totalCnt batch msg after} { proc write_update_index {fd pathList totalCnt batch msg after} {
global update_index_cp ui_status_value global update_index_cp
global file_states current_diff_path global file_states current_diff_path
if {$update_index_cp >= $totalCnt} { if {$update_index_cp >= $totalCnt} {
@ -144,7 +144,7 @@ proc write_update_index {fd pathList totalCnt batch msg after} {
display_file $path $new display_file $path $new
} }
set ui_status_value [format \ ui_status [format \
"$msg... %i/%i files (%.2f%%)" \ "$msg... %i/%i files (%.2f%%)" \
$update_index_cp \ $update_index_cp \
$totalCnt \ $totalCnt \
@ -152,7 +152,7 @@ proc write_update_index {fd pathList totalCnt batch msg after} {
} }
proc checkout_index {msg pathList after} { proc checkout_index {msg pathList after} {
global update_index_cp ui_status_value global update_index_cp
if {![lock_index update]} return if {![lock_index update]} return
@ -162,7 +162,7 @@ proc checkout_index {msg pathList after} {
set batch [expr {int($totalCnt * .01) + 1}] set batch [expr {int($totalCnt * .01) + 1}]
if {$batch > 25} {set batch 25} if {$batch > 25} {set batch 25}
set ui_status_value [format \ ui_status [format \
"$msg... %i/%i files (%.2f%%)" \ "$msg... %i/%i files (%.2f%%)" \
$update_index_cp \ $update_index_cp \
$totalCnt \ $totalCnt \
@ -192,7 +192,7 @@ proc checkout_index {msg pathList after} {
} }
proc write_checkout_index {fd pathList totalCnt batch msg after} { proc write_checkout_index {fd pathList totalCnt batch msg after} {
global update_index_cp ui_status_value global update_index_cp
global file_states current_diff_path global file_states current_diff_path
if {$update_index_cp >= $totalCnt} { if {$update_index_cp >= $totalCnt} {
@ -217,7 +217,7 @@ proc write_checkout_index {fd pathList totalCnt batch msg after} {
} }
} }
set ui_status_value [format \ ui_status [format \
"$msg... %i/%i files (%.2f%%)" \ "$msg... %i/%i files (%.2f%%)" \
$update_index_cp \ $update_index_cp \
$totalCnt \ $totalCnt \
@ -249,7 +249,7 @@ proc unstage_helper {txt paths} {
update_indexinfo \ update_indexinfo \
$txt \ $txt \
$pathList \ $pathList \
[concat $after {set ui_status_value {Ready.}}] [concat $after [list ui_ready]]
} }
} }
@ -293,7 +293,7 @@ proc add_helper {txt paths} {
update_index \ update_index \
$txt \ $txt \
$pathList \ $pathList \
[concat $after {set ui_status_value {Ready to commit.}}] [concat $after {ui_status {Ready to commit.}}]
} }
} }
@ -370,7 +370,7 @@ Any unadded changes will be permanently lost by the revert." \
checkout_index \ checkout_index \
$txt \ $txt \
$pathList \ $pathList \
[concat $after {set ui_status_value {Ready.}}] [concat $after [list ui_ready]]
} else { } else {
unlock_index unlock_index
} }

View File

@ -28,7 +28,7 @@ Another Git program has modified this repository since the last scan. A rescan
The rescan will be automatically started now. The rescan will be automatically started now.
} }
unlock_index unlock_index
rescan {set ui_status_value {Ready.}} rescan ui_ready
return 0 return 0
} }
@ -79,7 +79,7 @@ proc _visualize {w list} {
} }
proc _start {w list} { proc _start {w list} {
global HEAD ui_status_value current_branch global HEAD current_branch
set cmd [list git merge] set cmd [list git merge]
set names [_refs $w $list] set names [_refs $w $list]
@ -121,7 +121,7 @@ Please select fewer branches. To merge more than 15 branches, merge the branche
} }
set msg "Merging $current_branch, [join $names {, }]" set msg "Merging $current_branch, [join $names {, }]"
set ui_status_value "$msg..." ui_status "$msg..."
set cons [console::new "Merge" $msg] set cons [console::new "Merge" $msg]
console::exec $cons $cmd \ console::exec $cons $cmd \
[namespace code [list _finish $revcnt $cons]] [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
fconfigure $fd -blocking 0 -translation binary fconfigure $fd -blocking 0 -translation binary
fileevent $fd readable \ fileevent $fd readable \
[namespace code [list _reset_wait $fd]] [namespace code [list _reset_wait $fd]]
set ui_status_value {Aborting... please wait...} ui_status {Aborting... please wait...}
return return
} }
set msg {Merge failed. Conflict resolution is required.} set msg {Merge failed. Conflict resolution is required.}
} }
unlock_index unlock_index
rescan [list set ui_status_value $msg] rescan [list ui_status $msg]
} }
proc dialog {} { proc dialog {} {
@ -285,7 +285,7 @@ Continue with aborting the current $op?"] eq {yes}} {
set fd [open "| git read-tree --reset -u HEAD" r] set fd [open "| git read-tree --reset -u HEAD" r]
fconfigure $fd -blocking 0 -translation binary fconfigure $fd -blocking 0 -translation binary
fileevent $fd readable [namespace code [list _reset_wait $fd]] fileevent $fd readable [namespace code [list _reset_wait $fd]]
set ui_status_value {Aborting... please wait...} ui_status {Aborting... please wait...}
} else { } else {
unlock_index unlock_index
} }
@ -308,7 +308,7 @@ proc _reset_wait {fd} {
catch {file delete [gitdir MERGE_MSG]} catch {file delete [gitdir MERGE_MSG]}
catch {file delete [gitdir GITGUI_MSG]} catch {file delete [gitdir GITGUI_MSG]}
rescan {set ui_status_value {Abort completed. Ready.}} rescan {ui_status {Abort completed. Ready.}}
} }
} }