Skip to content

Commit

Permalink
gitk: Allow safely calling nukefile from a run queue handler
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Alexander Gavrilov authored and Paul Mackerras committed Aug 11, 2008
1 parent 8eacbc1 commit df75e86
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions gitk
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ proc gitdir {} {
# run before X event handlers, so reading from a fast source can
# make the GUI completely unresponsive.
proc run args {
global isonrunq runq
global isonrunq runq currunq

set script $args
if {[info exists isonrunq($script)]} return
if {$runq eq {}} {
if {$runq eq {} && ![info exists currunq]} {
after idle dorunq
}
lappend runq [list {} $script]
Expand All @@ -38,10 +38,10 @@ proc filerun {fd script} {
}

proc filereadable {fd script} {
global runq
global runq currunq

fileevent $fd readable {}
if {$runq eq {}} {
if {$runq eq {} && ![info exists currunq]} {
after idle dorunq
}
lappend runq [list $fd $script]
Expand All @@ -60,17 +60,19 @@ proc nukefile {fd} {
}

proc dorunq {} {
global isonrunq runq
global isonrunq runq currunq

set tstart [clock clicks -milliseconds]
set t0 $tstart
while {[llength $runq] > 0} {
set fd [lindex $runq 0 0]
set script [lindex $runq 0 1]
set currunq [lindex $runq 0]
set runq [lrange $runq 1 end]
set repeat [eval $script]
unset currunq
set t1 [clock clicks -milliseconds]
set t [expr {$t1 - $t0}]
set runq [lrange $runq 1 end]
if {$repeat ne {} && $repeat} {
if {$fd eq {} || $repeat == 2} {
# script returns 1 if it wants to be readded
Expand Down

0 comments on commit df75e86

Please sign in to comment.