{"thread":{"id":"21223","subject":"[PATCH] gitk: Prevent garbage text at the end of the tag description","startedAt":"2009-10-13T07:34:28Z","lastAt":"2009-10-13T07:34:28Z","messageCount":1,"participants":["Björn Gustavsson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"124821","messageId":"4AD42D84.2030406@gmail.com","threadId":"21223","inReplyTo":null,"subject":"[PATCH] gitk: Prevent garbage text at the end of the tag description","fromName":"Björn Gustavsson","fromEmail":"bgustavsson@gmail.com","sentAt":"2009-10-13T07:34:28Z","receivedAt":"2009-10-13T07:34:28Z","isPatch":true,"sender":{"key":"bgustavsson@gmail.com","avatar":"https://avatars.githubusercontent.com/u/74840?v=4"},"body":"When first clicking on a commit with a huge diff (in 1000 files\nor more), and then clicking on a tag, garbage text could appear\nafter the tag description.\n\nThe problem is that commits are shown incrementally using a\nrun queue (implemented by the runq() and filerun() procedures).\nWhen the user requests a tag to be shown, there may still be\njobs in the run queue updating the previous commit.\n\nSolve this problem by implementing a new procedure\nempty_run_queue() that will empty the run queue and cancel all\noutstanding file events. Call it from showtag().\n\nSigned-off-by: Björn Gustavsson <bgustavsson@gmail.com>\n---\n\nThis is more an annoyance than a real bug, but I was quite\nsurprised the first time I saw it happen and at first searched\nfor a bug in my own scripts that had created the tags.\n\nThis patch is a suggested correction.\n\nHere is an example of a repository where the problem can be\nreproduced quite easily:\n\ngit://github.com/mfoemmel/erlang-otp.git\n\n gitk-git/gitk |   34 ++++++++++++++++++++++++++++++++--\n 1 files changed, 32 insertions(+), 2 deletions(-)\n\ndiff --git a/gitk-git/gitk b/gitk-git/gitk\nindex a0214b7..ee0d0c3 100644\n--- a/gitk-git/gitk\n+++ b/gitk-git/gitk\n@@ -34,12 +34,16 @@ proc run args {\n }\n \n proc filerun {fd script} {\n+    global pending_file_events\n+\n+    set pending_file_events($fd) $fd\n     fileevent $fd readable [list filereadable $fd $script]\n }\n \n proc filereadable {fd script} {\n-    global runq currunq\n+    global runq currunq pending_file_events\n \n+    unset pending_file_events($fd)\n     fileevent $fd readable {}\n     if {$runq eq {} && ![info exists currunq]} {\n \tafter idle dorunq\n@@ -60,7 +64,7 @@ proc nukefile {fd} {\n }\n \n proc dorunq {} {\n-    global isonrunq runq currunq\n+    global isonrunq runq currunq pending_file_events\n \n     set tstart [clock clicks -milliseconds]\n     set t0 $tstart\n@@ -79,6 +83,7 @@ proc dorunq {} {\n \t\t# file readers return 2 if they could do more straight away\n \t\tlappend runq [list $fd $script]\n \t    } else {\n+\t\tset pending_file_events($fd) $fd\n \t\tfileevent $fd readable [list filereadable $fd $script]\n \t    }\n \t} elseif {$fd eq {}} {\n@@ -92,6 +97,29 @@ proc dorunq {} {\n     }\n }\n \n+# Empty the run queue, cancel all outstanding file events,\n+# and close all files associated with file events.\n+proc empty_run_queue {} {\n+    global isonrunq runq pending_file_events\n+\n+    foreach entry $runq {\n+\tset fd [lindex $entry 0]\n+\tset script [lindex $entry 1]\n+\tif {$fd eq {}} {\n+\t    unset isonrunq($script)\n+\t} else {\n+\t    catch {close $fd}\n+\t}\n+    }\n+    set runq {}\n+\n+    foreach fd [array names pending_file_events] {\n+\tfileevent $fd readable {}\n+\tunset pending_file_events($fd)\n+\tcatch {close $fd}\n+    }\n+}\n+\n proc reg_instance {fd} {\n     global commfd leftover loginstance\n \n@@ -10261,6 +10289,8 @@ proc listrefs {id} {\n proc showtag {tag isnew} {\n     global ctext tagcontents tagids linknum tagobjid\n \n+    empty_run_queue\n+\n     if {$isnew} {\n \taddtohistory [list showtag $tag 0]\n     }\n-- \n1.6.5.2.gd6127\n"}]}