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>
Shawn O. Pearce committed
Nov 14, 2006 at 01:29 UTC
8f52548a9ed078d581379ad526a4259920f80a88
1 file changed
+34
-34
git-gui
+34
-34
@@ -181,7 +181,7 @@ if {$appname eq {git-citool}} {
181
##
182
## task management
183
184
-set status_active 0
184
+set rescan_active 0
185
set diff_active 0
186
set last_clicked {}
187
@@ -234,13 +234,13 @@ proc repository_state {hdvar ctvar} {
234
}
235
}
236
237
-proc rescan {{final Ready.}} {
237
+proc rescan {after} {
238
global HEAD PARENT commit_type
239
global ui_index ui_other ui_status_value ui_comm
240
- global status_active file_states
240
+ global rescan_active file_states
241
global repo_config
242
243
- if {$status_active || ![lock_index read]} return
243
+ if {$rescan_active > 0 || ![lock_index read]} return
244
245
repository_state new_HEAD new_type
246
if {$commit_type eq {amend}
@@ -265,9 +265,9 @@ proc rescan {{final Ready.}} {
265
}
266
267
if {$repo_config(gui.trustmtime) eq {true}} {
268
- rescan_stage2 {} $final
268
+ rescan_stage2 {} $after
269
} else {
270
- set status_active 1
270
+ set rescan_active 1
271
set ui_status_value {Refreshing file status...}
272
set cmd [list git update-index]
273
lappend cmd -q
@@ -277,14 +277,14 @@ proc rescan {{final Ready.}} {
277
set fd_rf [open "| $cmd" r]
278
fconfigure $fd_rf -blocking 0 -translation binary
279
fileevent $fd_rf readable \
280
- [list rescan_stage2 $fd_rf $final]
280
+ [list rescan_stage2 $fd_rf $after]
281
}
282
}
283
284
-proc rescan_stage2 {fd final} {
284
+proc rescan_stage2 {fd after} {
285
global gitdir PARENT commit_type
286
global ui_index ui_other ui_status_value ui_comm
287
- global status_active
287
+ global rescan_active
288
global buf_rdi buf_rdf buf_rlo
289
290
if {$fd ne {}} {
@@ -304,7 +304,7 @@ proc rescan_stage2 {fd final} {
304
set buf_rdf {}
305
set buf_rlo {}
306
307
- set status_active 3
307
+ set rescan_active 3
308
set ui_status_value {Scanning for modified files ...}
309
set fd_di [open "| git diff-index --cached -z $PARENT" r]
310
set fd_df [open "| git diff-files -z" r]
@@ -313,9 +313,9 @@ proc rescan_stage2 {fd final} {
313
fconfigure $fd_di -blocking 0 -translation binary
314
fconfigure $fd_df -blocking 0 -translation binary
315
fconfigure $fd_lo -blocking 0 -translation binary
316
- fileevent $fd_di readable [list read_diff_index $fd_di $final]
317
- fileevent $fd_df readable [list read_diff_files $fd_df $final]
318
- fileevent $fd_lo readable [list read_ls_others $fd_lo $final]
316
+ fileevent $fd_di readable [list read_diff_index $fd_di $after]
317
+ fileevent $fd_df readable [list read_diff_files $fd_df $after]
318
+ fileevent $fd_lo readable [list read_ls_others $fd_lo $after]
319
}
320
321
proc load_message {file} {
@@ -335,7 +335,7 @@ proc load_message {file} {
335
return 0
336
}
337
338
-proc read_diff_index {fd final} {
338
+proc read_diff_index {fd after} {
339
global buf_rdi
340
341
append buf_rdi [read $fd]
@@ -361,10 +361,10 @@ proc read_diff_index {fd final} {
361
set buf_rdi {}
362
}
363
364
- status_eof $fd buf_rdi $final
364
+ rescan_done $fd buf_rdi $after
365
}
366
367
-proc read_diff_files {fd final} {
367
+proc read_diff_files {fd after} {
368
global buf_rdf
369
370
append buf_rdf [read $fd]
@@ -390,10 +390,10 @@ proc read_diff_files {fd final} {
390
set buf_rdf {}
391
}
392
393
- status_eof $fd buf_rdf $final
393
+ rescan_done $fd buf_rdf $after
394
}
395
396
-proc read_ls_others {fd final} {
396
+proc read_ls_others {fd after} {
397
global buf_rlo
398
399
append buf_rlo [read $fd]
@@ -402,18 +402,18 @@ proc read_ls_others {fd final} {
402
foreach p [lrange $pck 0 end-1] {
403
display_file $p _O
404
}
405
- status_eof $fd buf_rlo $final
405
+ rescan_done $fd buf_rlo $after
406
}
407
408
-proc status_eof {fd buf final} {
409
- global status_active ui_status_value
408
+proc rescan_done {fd buf after} {
409
+ global rescan_active
410
global file_states repo_config
411
upvar $buf to_clear
412
413
if {![eof $fd]} return
414
set to_clear {}
415
close $fd
416
- if {[incr status_active -1] > 0} return
416
+ if {[incr rescan_active -1] > 0} return
417
418
prune_selection
419
unlock_index
@@ -434,7 +434,7 @@ proc status_eof {fd buf final} {
434
}
435
436
reshow_diff
437
- set ui_status_value $final
437
+ uplevel #0 $after
438
}
439
440
proc prune_selection {} {
@@ -684,7 +684,7 @@ proc load_last_commit {} {
684
set commit_type amend
685
set HEAD {}
686
set PARENT {}
687
- rescan
687
+ rescan {set ui_status_value {Ready.}}
688
} elseif {$parent_count == 1} {
689
set commit_type amend
690
set PARENT $parent
@@ -692,7 +692,7 @@ proc load_last_commit {} {
692
$ui_comm insert end $msg
693
$ui_comm edit modified false
694
$ui_comm edit reset
695
- rescan
695
+ rescan {set ui_status_value {Ready.}}
696
} else {
697
error_popup {You can't amend a merge commit.}
698
return
@@ -720,7 +720,7 @@ repository since our last scan. A rescan is required
720
before committing.
721
}
722
unlock_index
723
- rescan
723
+ rescan {set ui_status_value {Ready.}}
724
return
725
}
726
@@ -987,7 +987,7 @@ repository since our last scan. A rescan is required
987
before a pull can be started.
988
}
989
unlock_index
990
- rescan
990
+ rescan {set ui_status_value {Ready.}}
991
return
992
}
993
@@ -1024,10 +1024,10 @@ proc post_pull_remote {remote branch success} {
1024
if {$success} {
1025
repository_state HEAD commit_type
1026
set PARENT $HEAD
1027
- set $ui_status_value {Ready.}
1027
+ set $ui_status_value "Pulling $branch from $remote complete."
1028
} else {
1029
- rescan \
1030
- "Conflicts detected while pulling $branch from $remote."
1029
+ set m "Conflicts detected while pulling $branch from $remote."
1030
+ rescan "set ui_status_value {$m}"
1031
}
1032
}
1033
@@ -1115,10 +1115,10 @@ proc merge_state {path new_state} {
1115
}
1116
1117
proc display_file {path state} {
1118
- global file_states file_lists selected_paths status_active
1118
+ global file_states file_lists selected_paths rescan_active
1119
1120
set old_m [merge_state $path $state]
1121
- if {$status_active} return
1121
+ if {$rescan_active > 0} return
1122
1123
set s $file_states($path)
1124
set new_m [lindex $s 0]
@@ -1744,7 +1744,7 @@ proc do_quit {} {
1744
}
1745
1746
proc do_rescan {} {
1747
- rescan
1747
+ rescan {set ui_status_value {Ready.}}
1748
}
1749
1750
proc do_include_all {} {
@@ -2559,4 +2559,4 @@ if {!$single_commit} {
2559
populate_remote_menu .mbar.push To push_to
2560
populate_pull_menu .mbar.pull
2561
}
2562
-after 1 rescan
2562
+after 1 do_rescan