git-gui: Supply progress feedback when running update-index.

The git-update-index process can take a while to process a large
number of files; for example my laptop would probably need almost
an hour to chug through 20,000 modified files.  In these incredibly
large cases the user should be given at least some feedback to let
them know the application is still working on their behalf, even if
it won't them do anything else (as the index is locked).

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
This commit is contained in:
Shawn O. Pearce
2006-11-12 06:35:14 -05:00
parent 92148d8091
commit 74e6b12f58

139
git-gui
View File

@ -178,9 +178,7 @@ if {$appname == {git-citool}} {
set single_commit 0 set single_commit 0
set status_active 0 set status_active 0
set diff_active 0 set diff_active 0
set update_active 0
set commit_active 0 set commit_active 0
set update_index_fd {}
set disable_on_lock [list] set disable_on_lock [list]
set index_lock_type none set index_lock_type none
@ -1100,55 +1098,73 @@ proc display_all_files {} {
$ui_other conf -state disabled $ui_other conf -state disabled
} }
proc with_update_index {body} { proc update_index {pathList} {
global update_index_fd global update_index_cp ui_status_value
if {$update_index_fd == {}} { if {![lock_index update]} return
if {![lock_index update]} return
set update_index_fd [open \ set update_index_cp 0
"| git update-index --add --remove -z --stdin" \ set totalCnt [llength $pathList]
w] set batch [expr {int($totalCnt * .01) + 1}]
fconfigure $update_index_fd -translation binary if {$batch > 25} {set batch 25}
uplevel 1 $body
close $update_index_fd set ui_status_value "Including files ... 0/$totalCnt 0%"
set update_index_fd {} set ui_status_value [format \
unlock_index "Including files ... %i/%i files (%.2f%%)" \
} else { $update_index_cp \
uplevel 1 $body $totalCnt \
} 0.0]
set fd [open "| git update-index --add --remove -z --stdin" w]
fconfigure $fd -blocking 0 -translation binary
fileevent $fd writable [list \
write_update_index \
$fd \
$pathList \
$totalCnt \
$batch \
]
} }
proc update_index {path} { proc write_update_index {fd pathList totalCnt batch} {
global update_index_fd global update_index_cp ui_status_value
if {$update_index_fd == {}} {
error {not in with_update_index}
} else {
puts -nonewline $update_index_fd "$path\0"
}
}
proc toggle_mode {path} {
global file_states ui_fname_value global file_states ui_fname_value
set s $file_states($path) if {$update_index_cp >= $totalCnt} {
set m [lindex $s 0] close $fd
unlock_index
switch -- $m { set ui_status_value {Ready.}
AM - return
_O {set new A*}
_M -
MM {set new M*}
AD -
_D {set new D*}
default {return}
} }
with_update_index {update_index $path} for {set i $batch} \
display_file $path $new {$update_index_cp < $totalCnt && $i > 0} \
if {$ui_fname_value == $path} { {incr i -1} {
show_diff $path set path [lindex $pathList $update_index_cp]
incr update_index_cp
switch -- [lindex $file_states($path) 0] {
AM -
_O {set new A*}
_M -
MM {set new M*}
AD -
_D {set new D*}
default {continue}
}
puts -nonewline $fd $path
puts -nonewline $fd "\0"
display_file $path $new
if {$ui_fname_value == $path} {
show_diff $path
}
} }
set ui_status_value [format \
"Including files ... %i/%i files (%.2f%%)" \
$update_index_cp \
$totalCnt \
[expr {100.0 * $update_index_cp / $totalCnt}]]
} }
###################################################################### ######################################################################
@ -1627,27 +1643,25 @@ proc do_rescan {} {
} }
proc do_include_all {} { proc do_include_all {} {
global update_active ui_status_value global file_states
if {$update_active || ![lock_index begin-update]} return if {![lock_index begin-update]} return
set update_active 1 set pathList [list]
set ui_status_value {Including all modified files...} foreach path [array names file_states] {
after 1 { set s $file_states($path)
with_update_index { set m [lindex $s 0]
foreach path [array names file_states] { switch -- $m {
set s $file_states($path) AM -
set m [lindex $s 0] MM -
switch -- $m { _M -
AM - _D {lappend pathList $path}
MM -
_M -
_D {toggle_mode $path}
}
}
} }
set update_active 0 }
set ui_status_value {Ready.} if {$pathList == {}} {
unlock_index
} else {
update_index $pathList
} }
} }
@ -1844,7 +1858,7 @@ proc unclick {w x y} {
if {$path == {}} return if {$path == {}} return
if {$col == 0} { if {$col == 0} {
toggle_mode $path update_index [list $path]
} }
} }
@ -2318,4 +2332,5 @@ load_all_remotes
populate_remote_menu .mbar.fetch From fetch_from populate_remote_menu .mbar.fetch From fetch_from
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
tkwait visibility .
update_status update_status