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>
Shawn O. Pearce committed
Nov 12, 2006 at 06:35 UTC
74e6b12f5831a8c93a5d3c90118a73e908d0680a
1 file changed
+79
-64
git-gui
+79
-64
@@ -178,9 +178,7 @@ if {$appname == {git-citool}} {
178
set single_commit 0
179
set status_active 0
180
set diff_active 0
181
-set update_active 0
181
set commit_active 0
183
-set update_index_fd {}
182
183
set disable_on_lock [list]
184
set index_lock_type none
@@ -1100,55 +1098,73 @@ proc display_all_files {} {
1098
$ui_other conf -state disabled
1099
}
1100
1103
-proc with_update_index {body} {
1104
- global update_index_fd
1101
+proc update_index {pathList} {
1102
+ global update_index_cp ui_status_value
1103
1106
- if {$update_index_fd == {}} {
1107
- if {![lock_index update]} return
1108
- set update_index_fd [open \
1109
- "| git update-index --add --remove -z --stdin" \
1110
- w]
1111
- fconfigure $update_index_fd -translation binary
1112
- uplevel 1 $body
1113
- close $update_index_fd
1114
- set update_index_fd {}
1115
- unlock_index
1116
- } else {
1117
- uplevel 1 $body
1118
- }
1119
-}
1104
+ if {![lock_index update]} return
1105
1121
-proc update_index {path} {
1122
- global update_index_fd
1106
+ set update_index_cp 0
1107
+ set totalCnt [llength $pathList]
1108
+ set batch [expr {int($totalCnt * .01) + 1}]
1109
+ if {$batch > 25} {set batch 25}
1110
+
1111
+ set ui_status_value "Including files ... 0/$totalCnt 0%"
1112
+ set ui_status_value [format \
1113
+ "Including files ... %i/%i files (%.2f%%)" \
1114
+ $update_index_cp \
1115
+ $totalCnt \
1116
+ 0.0]
1117
+ set fd [open "| git update-index --add --remove -z --stdin" w]
1118
+ fconfigure $fd -blocking 0 -translation binary
1119
+ fileevent $fd writable [list \
1120
+ write_update_index \
1121
+ $fd \
1122
+ $pathList \
1123
+ $totalCnt \
1124
+ $batch \
1125
+ ]
1126
+}
1127
+
1128
+proc write_update_index {fd pathList totalCnt batch} {
1129
+ global update_index_cp ui_status_value
1130
+ global file_states ui_fname_value
1131
1124
- if {$update_index_fd == {}} {
1125
- error {not in with_update_index}
1126
- } else {
1127
- puts -nonewline $update_index_fd "$path\0"
1132
+ if {$update_index_cp >= $totalCnt} {
1133
+ close $fd
1134
+ unlock_index
1135
+ set ui_status_value {Ready.}
1136
+ return
1137
}
1129
-}
1138
1131
-proc toggle_mode {path} {
1132
- global file_states ui_fname_value
1133
-
1134
- set s $file_states($path)
1135
- set m [lindex $s 0]
1139
+ for {set i $batch} \
1140
+ {$update_index_cp < $totalCnt && $i > 0} \
1141
+ {incr i -1} {
1142
+ set path [lindex $pathList $update_index_cp]
1143
+ incr update_index_cp
1144
+
1145
+ switch -- [lindex $file_states($path) 0] {
1146
+ AM -
1147
+ _O {set new A*}
1148
+ _M -
1149
+ MM {set new M*}
1150
+ AD -
1151
+ _D {set new D*}
1152
+ default {continue}
1153
+ }
1154
1137
- switch -- $m {
1138
- AM -
1139
- _O {set new A*}
1140
- _M -
1141
- MM {set new M*}
1142
- AD -
1143
- _D {set new D*}
1144
- default {return}
1155
+ puts -nonewline $fd $path
1156
+ puts -nonewline $fd "\0"
1157
+ display_file $path $new
1158
+ if {$ui_fname_value == $path} {
1159
+ show_diff $path
1160
+ }
1161
}
1162
1147
- with_update_index {update_index $path}
1148
- display_file $path $new
1149
- if {$ui_fname_value == $path} {
1150
- show_diff $path
1151
- }
1163
+ set ui_status_value [format \
1164
+ "Including files ... %i/%i files (%.2f%%)" \
1165
+ $update_index_cp \
1166
+ $totalCnt \
1167
+ [expr {100.0 * $update_index_cp / $totalCnt}]]
1168
}
1169
1170
######################################################################
@@ -1627,27 +1643,25 @@ proc do_rescan {} {
1643
}
1644
1645
proc do_include_all {} {
1630
- global update_active ui_status_value
1631
-
1632
- if {$update_active || ![lock_index begin-update]} return
1633
-
1634
- set update_active 1
1635
- set ui_status_value {Including all modified files...}
1636
- after 1 {
1637
- with_update_index {
1638
- foreach path [array names file_states] {
1639
- set s $file_states($path)
1640
- set m [lindex $s 0]
1641
- switch -- $m {
1642
- AM -
1643
- MM -
1644
- _M -
1645
- _D {toggle_mode $path}
1646
- }
1647
- }
1646
+ global file_states
1647
+
1648
+ if {![lock_index begin-update]} return
1649
+
1650
+ set pathList [list]
1651
+ foreach path [array names file_states] {
1652
+ set s $file_states($path)
1653
+ set m [lindex $s 0]
1654
+ switch -- $m {
1655
+ AM -
1656
+ MM -
1657
+ _M -
1658
+ _D {lappend pathList $path}
1659
}
1649
- set update_active 0
1650
- set ui_status_value {Ready.}
1660
+ }
1661
+ if {$pathList == {}} {
1662
+ unlock_index
1663
+ } else {
1664
+ update_index $pathList
1665
}
1666
}
1667
@@ -1844,7 +1858,7 @@ proc unclick {w x y} {
1858
if {$path == {}} return
1859
1860
if {$col == 0} {
1847
- toggle_mode $path
1861
+ update_index [list $path]
1862
}
1863
}
1864
@@ -2318,4 +2332,5 @@ load_all_remotes
2332
populate_remote_menu .mbar.fetch From fetch_from
2333
populate_remote_menu .mbar.push To push_to
2334
populate_pull_menu .mbar.pull
2335
+tkwait visibility .
2336
update_status