git-gui: Provide an after-rescan script to rescan.

There are some situations where we need to run rescan and have it do
more than just updating the status in the UI when its complete.  To
help with that this changes the rescan procedure to take a script which
it will run at the global level as soon as the rescan is done and the
UI has finished updating with the results.  This is useful for example
if we performed a rescan as part of a commit operation; we can go back
to the commit where we left off when the rescan got initiated.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
Shawn O. Pearce 2006-11-14 01:29:32 -05:00
parent 99058720df
commit 8f52548a9e

68
git-gui
View File

@ -181,7 +181,7 @@ if {$appname eq {git-citool}} {
## ##
## task management ## task management
set status_active 0 set rescan_active 0
set diff_active 0 set diff_active 0
set last_clicked {} set last_clicked {}
@ -234,13 +234,13 @@ proc repository_state {hdvar ctvar} {
} }
} }
proc rescan {{final Ready.}} { proc rescan {after} {
global HEAD PARENT commit_type global HEAD PARENT commit_type
global ui_index ui_other ui_status_value ui_comm global ui_index ui_other ui_status_value ui_comm
global status_active file_states global rescan_active file_states
global repo_config global repo_config
if {$status_active || ![lock_index read]} return if {$rescan_active > 0 || ![lock_index read]} return
repository_state new_HEAD new_type repository_state new_HEAD new_type
if {$commit_type eq {amend} if {$commit_type eq {amend}
@ -265,9 +265,9 @@ proc rescan {{final Ready.}} {
} }
if {$repo_config(gui.trustmtime) eq {true}} { if {$repo_config(gui.trustmtime) eq {true}} {
rescan_stage2 {} $final rescan_stage2 {} $after
} else { } else {
set status_active 1 set rescan_active 1
set ui_status_value {Refreshing file status...} set ui_status_value {Refreshing file status...}
set cmd [list git update-index] set cmd [list git update-index]
lappend cmd -q lappend cmd -q
@ -277,14 +277,14 @@ proc rescan {{final Ready.}} {
set fd_rf [open "| $cmd" r] set fd_rf [open "| $cmd" r]
fconfigure $fd_rf -blocking 0 -translation binary fconfigure $fd_rf -blocking 0 -translation binary
fileevent $fd_rf readable \ fileevent $fd_rf readable \
[list rescan_stage2 $fd_rf $final] [list rescan_stage2 $fd_rf $after]
} }
} }
proc rescan_stage2 {fd final} { proc rescan_stage2 {fd after} {
global gitdir PARENT commit_type global gitdir PARENT commit_type
global ui_index ui_other ui_status_value ui_comm global ui_index ui_other ui_status_value ui_comm
global status_active global rescan_active
global buf_rdi buf_rdf buf_rlo global buf_rdi buf_rdf buf_rlo
if {$fd ne {}} { if {$fd ne {}} {
@ -304,7 +304,7 @@ proc rescan_stage2 {fd final} {
set buf_rdf {} set buf_rdf {}
set buf_rlo {} set buf_rlo {}
set status_active 3 set rescan_active 3
set ui_status_value {Scanning for modified files ...} set ui_status_value {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]
@ -313,9 +313,9 @@ proc rescan_stage2 {fd final} {
fconfigure $fd_di -blocking 0 -translation binary fconfigure $fd_di -blocking 0 -translation binary
fconfigure $fd_df -blocking 0 -translation binary fconfigure $fd_df -blocking 0 -translation binary
fconfigure $fd_lo -blocking 0 -translation binary fconfigure $fd_lo -blocking 0 -translation binary
fileevent $fd_di readable [list read_diff_index $fd_di $final] fileevent $fd_di readable [list read_diff_index $fd_di $after]
fileevent $fd_df readable [list read_diff_files $fd_df $final] fileevent $fd_df readable [list read_diff_files $fd_df $after]
fileevent $fd_lo readable [list read_ls_others $fd_lo $final] fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
} }
proc load_message {file} { proc load_message {file} {
@ -335,7 +335,7 @@ proc load_message {file} {
return 0 return 0
} }
proc read_diff_index {fd final} { proc read_diff_index {fd after} {
global buf_rdi global buf_rdi
append buf_rdi [read $fd] append buf_rdi [read $fd]
@ -361,10 +361,10 @@ proc read_diff_index {fd final} {
set buf_rdi {} set buf_rdi {}
} }
status_eof $fd buf_rdi $final rescan_done $fd buf_rdi $after
} }
proc read_diff_files {fd final} { proc read_diff_files {fd after} {
global buf_rdf global buf_rdf
append buf_rdf [read $fd] append buf_rdf [read $fd]
@ -390,10 +390,10 @@ proc read_diff_files {fd final} {
set buf_rdf {} set buf_rdf {}
} }
status_eof $fd buf_rdf $final rescan_done $fd buf_rdf $after
} }
proc read_ls_others {fd final} { proc read_ls_others {fd after} {
global buf_rlo global buf_rlo
append buf_rlo [read $fd] append buf_rlo [read $fd]
@ -402,18 +402,18 @@ proc read_ls_others {fd final} {
foreach p [lrange $pck 0 end-1] { foreach p [lrange $pck 0 end-1] {
display_file $p _O display_file $p _O
} }
status_eof $fd buf_rlo $final rescan_done $fd buf_rlo $after
} }
proc status_eof {fd buf final} { proc rescan_done {fd buf after} {
global status_active ui_status_value global rescan_active
global file_states repo_config global file_states repo_config
upvar $buf to_clear upvar $buf to_clear
if {![eof $fd]} return if {![eof $fd]} return
set to_clear {} set to_clear {}
close $fd close $fd
if {[incr status_active -1] > 0} return if {[incr rescan_active -1] > 0} return
prune_selection prune_selection
unlock_index unlock_index
@ -434,7 +434,7 @@ proc status_eof {fd buf final} {
} }
reshow_diff reshow_diff
set ui_status_value $final uplevel #0 $after
} }
proc prune_selection {} { proc prune_selection {} {
@ -684,7 +684,7 @@ proc load_last_commit {} {
set commit_type amend set commit_type amend
set HEAD {} set HEAD {}
set PARENT {} set PARENT {}
rescan rescan {set ui_status_value {Ready.}}
} elseif {$parent_count == 1} { } elseif {$parent_count == 1} {
set commit_type amend set commit_type amend
set PARENT $parent set PARENT $parent
@ -692,7 +692,7 @@ proc load_last_commit {} {
$ui_comm insert end $msg $ui_comm insert end $msg
$ui_comm edit modified false $ui_comm edit modified false
$ui_comm edit reset $ui_comm edit reset
rescan rescan {set ui_status_value {Ready.}}
} else { } else {
error_popup {You can't amend a merge commit.} error_popup {You can't amend a merge commit.}
return return
@ -720,7 +720,7 @@ repository since our last scan. A rescan is required
before committing. before committing.
} }
unlock_index unlock_index
rescan rescan {set ui_status_value {Ready.}}
return return
} }
@ -987,7 +987,7 @@ repository since our last scan. A rescan is required
before a pull can be started. before a pull can be started.
} }
unlock_index unlock_index
rescan rescan {set ui_status_value {Ready.}}
return return
} }
@ -1024,10 +1024,10 @@ proc post_pull_remote {remote branch success} {
if {$success} { if {$success} {
repository_state HEAD commit_type repository_state HEAD commit_type
set PARENT $HEAD set PARENT $HEAD
set $ui_status_value {Ready.} set $ui_status_value "Pulling $branch from $remote complete."
} else { } else {
rescan \ set m "Conflicts detected while pulling $branch from $remote."
"Conflicts detected while pulling $branch from $remote." rescan "set ui_status_value {$m}"
} }
} }
@ -1115,10 +1115,10 @@ proc merge_state {path new_state} {
} }
proc display_file {path state} { proc display_file {path state} {
global file_states file_lists selected_paths status_active global file_states file_lists selected_paths rescan_active
set old_m [merge_state $path $state] set old_m [merge_state $path $state]
if {$status_active} return if {$rescan_active > 0} return
set s $file_states($path) set s $file_states($path)
set new_m [lindex $s 0] set new_m [lindex $s 0]
@ -1744,7 +1744,7 @@ proc do_quit {} {
} }
proc do_rescan {} { proc do_rescan {} {
rescan rescan {set ui_status_value {Ready.}}
} }
proc do_include_all {} { proc do_include_all {} {
@ -2559,4 +2559,4 @@ if {!$single_commit} {
populate_remote_menu .mbar.push To push_to populate_remote_menu .mbar.push To push_to
populate_pull_menu .mbar.pull populate_pull_menu .mbar.pull
} }
after 1 rescan after 1 do_rescan