]> asedeno.scripts.mit.edu Git - git.git/commitdiff
git-gui: Provide an after-rescan script to rescan.
authorShawn O. Pearce <spearce@spearce.org>
Tue, 14 Nov 2006 06:29:32 +0000 (01:29 -0500)
committerShawn O. Pearce <spearce@spearce.org>
Tue, 14 Nov 2006 06:29:32 +0000 (01:29 -0500)
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>
git-gui

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