gitk: Allow safely calling nukefile from a run queue handler
Originally dorunq assumed that the queue entry remained first in the queue after the script eval, and blindly removed it. However, if the handler calls nukefile, it may not be the case anymore, and a random queue entry gets dropped instead. This makes dorunq remove the entry before calling the script, and adds a global variable to allow other functions to determine if they are called from within a dorunq handler. Signed-off-by: Alexander Gavrilov <angavrilov@gmail.com> Signed-off-by: Paul Mackerras <paulus@samba.org>
Alexander Gavrilov committed
Aug 9, 2008 at 14:41 UTC
df75e86d7307c2fd16d8df1bcbe8d7ccfb7305ff
1 file changed
+8
-6
gitk
+8
-6
@@ -22,11 +22,11 @@ proc gitdir {} {
22
# run before X event handlers, so reading from a fast source can
23
# make the GUI completely unresponsive.
24
proc run args {
25
- global isonrunq runq
25
+ global isonrunq runq currunq
26
27
set script $args
28
if {[info exists isonrunq($script)]} return
29
- if {$runq eq {}} {
29
+ if {$runq eq {} && ![info exists currunq]} {
30
after idle dorunq
31
}
32
lappend runq [list {} $script]
@@ -38,10 +38,10 @@ proc filerun {fd script} {
38
}
39
40
proc filereadable {fd script} {
41
- global runq
41
+ global runq currunq
42
43
fileevent $fd readable {}
44
- if {$runq eq {}} {
44
+ if {$runq eq {} && ![info exists currunq]} {
45
after idle dorunq
46
}
47
lappend runq [list $fd $script]
@@ -60,17 +60,19 @@ proc nukefile {fd} {
60
}
61
62
proc dorunq {} {
63
- global isonrunq runq
63
+ global isonrunq runq currunq
64
65
set tstart [clock clicks -milliseconds]
66
set t0 $tstart
67
while {[llength $runq] > 0} {
68
set fd [lindex $runq 0 0]
69
set script [lindex $runq 0 1]
70
+ set currunq [lindex $runq 0]
71
+ set runq [lrange $runq 1 end]
72
set repeat [eval $script]
73
+ unset currunq
74
set t1 [clock clicks -milliseconds]
75
set t [expr {$t1 - $t0}]
73
- set runq [lrange $runq 1 end]
76
if {$repeat ne {} && $repeat} {
77
if {$fd eq {} || $repeat == 2} {
78
# script returns 1 if it wants to be readded