Skip to content

Commit df75e86

Browse files
angavrilovpaulusmack
authored andcommitted
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 <[email protected]> Signed-off-by: Paul Mackerras <[email protected]>
1 parent 8eacbc1 commit df75e86

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

gitk

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ proc gitdir {} {
2222
# run before X event handlers, so reading from a fast source can
2323
# make the GUI completely unresponsive.
2424
proc run args {
25-
global isonrunq runq
25+
global isonrunq runq currunq
2626

2727
set script $args
2828
if {[info exists isonrunq($script)]} return
29-
if {$runq eq {}} {
29+
if {$runq eq {} && ![info exists currunq]} {
3030
after idle dorunq
3131
}
3232
lappend runq [list {} $script]
@@ -38,10 +38,10 @@ proc filerun {fd script} {
3838
}
3939

4040
proc filereadable {fd script} {
41-
global runq
41+
global runq currunq
4242

4343
fileevent $fd readable {}
44-
if {$runq eq {}} {
44+
if {$runq eq {} && ![info exists currunq]} {
4545
after idle dorunq
4646
}
4747
lappend runq [list $fd $script]
@@ -60,17 +60,19 @@ proc nukefile {fd} {
6060
}
6161

6262
proc dorunq {} {
63-
global isonrunq runq
63+
global isonrunq runq currunq
6464

6565
set tstart [clock clicks -milliseconds]
6666
set t0 $tstart
6767
while {[llength $runq] > 0} {
6868
set fd [lindex $runq 0 0]
6969
set script [lindex $runq 0 1]
70+
set currunq [lindex $runq 0]
71+
set runq [lrange $runq 1 end]
7072
set repeat [eval $script]
73+
unset currunq
7174
set t1 [clock clicks -milliseconds]
7275
set t [expr {$t1 - $t0}]
73-
set runq [lrange $runq 1 end]
7476
if {$repeat ne {} && $repeat} {
7577
if {$fd eq {} || $repeat == 2} {
7678
# script returns 1 if it wants to be readded

0 commit comments

Comments
 (0)