@matheusbsbs / matheus-bagliano / commits / 7eb3cb9c68
Fork 0

gitk: Implement a simple scheduler for the compute-intensive stuff

This allows us to do compute-intensive processing, such as laying out the graph, relatively efficiently while also having the GUI be reasonably responsive. The problem previously was that file events were serviced before X events, so reading from another process which supplies data quickly (hi git rev-list :) could mean that X events didn't get processed for a long time. With this, gitk finishes laying out the graph slightly sooner and still responds to the GUI while doing so. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Jun 17, 2007 at 14:45 UTC 7eb3cb9c683624681541972910328054e9431b43
1 file changed +310 -253
gitk
+310 -253
@@ -16,13 +16,75 @@ proc gitdir {} {
16 }
17 }
18
19 +# A simple scheduler for compute-intensive stuff.
20 +# The aim is to make sure that event handlers for GUI actions can
21 +# run at least every 50-100 ms. Unfortunately fileevent handlers are
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
26 +
27 + set script $args
28 + if {[info exists isonrunq($script)]} return
29 + if {$runq eq {}} {
30 + after idle dorunq
31 + }
32 + lappend runq [list {} $script]
33 + set isonrunq($script) 1
34 +}
35 +
36 +proc filerun {fd script} {
37 + fileevent $fd readable [list filereadable $fd $script]
38 +}
39 +
40 +proc filereadable {fd script} {
41 + global runq
42 +
43 + fileevent $fd readable {}
44 + if {$runq eq {}} {
45 + after idle dorunq
46 + }
47 + lappend runq [list $fd $script]
48 +}
49 +
50 +proc dorunq {} {
51 + global isonrunq runq
52 +
53 + set tstart [clock clicks -milliseconds]
54 + set t0 $tstart
55 + while {$runq ne {}} {
56 + set fd [lindex $runq 0 0]
57 + set script [lindex $runq 0 1]
58 + set repeat [eval $script]
59 + set t1 [clock clicks -milliseconds]
60 + set t [expr {$t1 - $t0}]
61 + set runq [lrange $runq 1 end]
62 + if {$repeat ne {} && $repeat} {
63 + if {$fd eq {} || $repeat == 2} {
64 + # script returns 1 if it wants to be readded
65 + # file readers return 2 if they could do more straight away
66 + lappend runq [list $fd $script]
67 + } else {
68 + fileevent $fd readable [list filereadable $fd $script]
69 + }
70 + } elseif {$fd eq {}} {
71 + unset isonrunq($script)
72 + }
73 + set t0 $t1
74 + if {$t1 - $tstart >= 80} break
75 + }
76 + if {$runq ne {}} {
77 + after idle dorunq
78 + }
79 +}
80 +
81 +# Start off a git rev-list process and arrange to read its output
82 proc start_rev_list {view} {
20 - global startmsecs nextupdate
83 + global startmsecs
84 global commfd leftover tclencoding datemode
85 global viewargs viewfiles commitidx
86
87 set startmsecs [clock clicks -milliseconds]
25 - set nextupdate [expr {$startmsecs + 100}]
88 set commitidx($view) 0
89 set args $viewargs($view)
90 if {$viewfiles($view) ne {}} {
@@ -45,7 +107,7 @@ proc start_rev_list {view} {
107 if {$tclencoding != {}} {
108 fconfigure $fd -encoding $tclencoding
109 }
48 - fileevent $fd readable [list getcommitlines $fd $view]
110 + filerun $fd [list getcommitlines $fd $view]
111 nowbusy $view
112 }
113
@@ -72,7 +134,7 @@ proc getcommits {} {
134 }
135
136 proc getcommitlines {fd view} {
75 - global commitlisted nextupdate
137 + global commitlisted
138 global leftover commfd
139 global displayorder commitidx commitrow commitdata
140 global parentlist childlist children curview hlview
@@ -80,7 +142,9 @@ proc getcommitlines {fd view} {
142
143 set stuff [read $fd 500000]
144 if {$stuff == {}} {
83 - if {![eof $fd]} return
145 + if {![eof $fd]} {
146 + return 1
147 + }
148 global viewname
149 unset commfd($view)
150 notbusy $view
@@ -105,9 +169,9 @@ proc getcommitlines {fd view} {
169 error_popup $err
170 }
171 if {$view == $curview} {
108 - after idle finishcommits
172 + run chewcommits $view
173 }
110 - return
174 + return 0
175 }
176 set start 0
177 set gotsome 0
@@ -183,29 +247,42 @@ proc getcommitlines {fd view} {
247 set gotsome 1
248 }
249 if {$gotsome} {
186 - if {$view == $curview} {
187 - while {[layoutmore $nextupdate]} doupdate
188 - } elseif {[info exists hlview] && $view == $hlview} {
189 - vhighlightmore
190 - }
191 - }
192 - if {[clock clicks -milliseconds] >= $nextupdate} {
193 - doupdate
250 + run chewcommits $view
251 }
252 + return 2
253 }
254
197 -proc doupdate {} {
198 - global commfd nextupdate numcommits
255 +proc chewcommits {view} {
256 + global curview hlview commfd
257 + global selectedline pending_select
258 +
259 + set more 0
260 + if {$view == $curview} {
261 + set allread [expr {![info exists commfd($view)]}]
262 + set tlimit [expr {[clock clicks -milliseconds] + 50}]
263 + set more [layoutmore $tlimit $allread]
264 + if {$allread && !$more} {
265 + global displayorder commitidx phase
266 + global numcommits startmsecs
267
200 - foreach v [array names commfd] {
201 - fileevent $commfd($v) readable {}
268 + if {[info exists pending_select]} {
269 + set row [expr {[lindex $displayorder 0] eq $nullid}]
270 + selectline $row 1
271 + }
272 + if {$commitidx($curview) > 0} {
273 + #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
274 + #puts "overall $ms ms for $numcommits commits"
275 + } else {
276 + show_status "No commits selected"
277 + }
278 + notbusy layout
279 + set phase {}
280 + }
281 }
203 - update
204 - set nextupdate [expr {[clock clicks -milliseconds] + 100}]
205 - foreach v [array names commfd] {
206 - set fd $commfd($v)
207 - fileevent $fd readable [list getcommitlines $fd $v]
282 + if {[info exists hlview] && $view == $hlview} {
283 + vhighlightmore
284 }
285 + return $more
286 }
287
288 proc readcommit {id} {
@@ -1594,9 +1671,9 @@ proc newviewok {top n} {
1671 set viewargs($n) $newargs
1672 addviewmenu $n
1673 if {!$newishighlight} {
1597 - after idle showview $n
1674 + run showview $n
1675 } else {
1599 - after idle addvhighlight $n
1676 + run addvhighlight $n
1677 }
1678 } else {
1679 # editing an existing view
@@ -1612,7 +1689,7 @@ proc newviewok {top n} {
1689 set viewfiles($n) $files
1690 set viewargs($n) $newargs
1691 if {$curview == $n} {
1615 - after idle updatecommits
1692 + run updatecommits
1693 }
1694 }
1695 }
@@ -1670,7 +1747,7 @@ proc showview {n} {
1747 global matchinglines treediffs
1748 global pending_select phase
1749 global commitidx rowlaidout rowoptim linesegends
1673 - global commfd nextupdate
1750 + global commfd
1751 global selectedview selectfirst
1752 global vparentlist vchildlist vdisporder vcmitlisted
1753 global hlview selectedhlview
@@ -1791,11 +1868,7 @@ proc showview {n} {
1868 if {$phase eq "getcommits"} {
1869 show_status "Reading commits..."
1870 }
1794 - if {[info exists commfd($n)]} {
1795 - layoutmore {}
1796 - } else {
1797 - finishcommits
1798 - }
1871 + run chewcommits $n
1872 } elseif {$numcommits == 0} {
1873 show_status "No commits selected"
1874 }
@@ -1983,7 +2056,7 @@ proc do_file_hl {serial} {
2056 set cmd [concat | git diff-tree -r -s --stdin $gdtargs]
2057 set filehighlight [open $cmd r+]
2058 fconfigure $filehighlight -blocking 0
1986 - fileevent $filehighlight readable readfhighlight
2059 + filerun $filehighlight readfhighlight
2060 set fhl_list {}
2061 drawvisible
2062 flushhighlights
@@ -2011,7 +2084,11 @@ proc readfhighlight {} {
2084 global filehighlight fhighlights commitrow curview mainfont iddrawn
2085 global fhl_list
2086
2014 - while {[gets $filehighlight line] >= 0} {
2087 + if {![info exists filehighlight]} {
2088 + return 0
2089 + }
2090 + set nr 0
2091 + while {[incr nr] <= 100 && [gets $filehighlight line] >= 0} {
2092 set line [string trim $line]
2093 set i [lsearch -exact $fhl_list $line]
2094 if {$i < 0} continue
@@ -2035,8 +2112,10 @@ proc readfhighlight {} {
2112 puts "oops, git diff-tree died"
2113 catch {close $filehighlight}
2114 unset filehighlight
2115 + return 0
2116 }
2117 next_hlcont
2118 + return 1
2119 }
2120
2121 proc find_change {name ix op} {
@@ -2103,7 +2182,7 @@ proc vrel_change {name ix op} {
2182
2183 rhighlight_none
2184 if {$highlight_related ne "None"} {
2106 - after idle drawvisible
2185 + run drawvisible
2186 }
2187 }
2188
@@ -2118,7 +2197,7 @@ proc rhighlight_sel {a} {
2197 set anc_todo [list $a]
2198 if {$highlight_related ne "None"} {
2199 rhighlight_none
2121 - after idle drawvisible
2200 + run drawvisible
2201 }
2202 }
2203
@@ -2474,15 +2553,17 @@ proc visiblerows {} {
2553 return [list $r0 $r1]
2554 }
2555
2477 -proc layoutmore {tmax} {
2556 +proc layoutmore {tmax allread} {
2557 global rowlaidout rowoptim commitidx numcommits optim_delay
2479 - global uparrowlen curview
2558 + global uparrowlen curview rowidlist idinlist
2559
2560 + set showdelay $optim_delay
2561 + set optdelay [expr {$uparrowlen + 1}]
2562 while {1} {
2482 - if {$rowoptim - $optim_delay > $numcommits} {
2483 - showstuff [expr {$rowoptim - $optim_delay}]
2484 - } elseif {$rowlaidout - $uparrowlen - 1 > $rowoptim} {
2485 - set nr [expr {$rowlaidout - $uparrowlen - 1 - $rowoptim}]
2563 + if {$rowoptim - $showdelay > $numcommits} {
2564 + showstuff [expr {$rowoptim - $showdelay}]
2565 + } elseif {$rowlaidout - $optdelay > $rowoptim} {
2566 + set nr [expr {$rowlaidout - $optdelay - $rowoptim}]
2567 if {$nr > 100} {
2568 set nr 100
2569 }
@@ -2496,10 +2577,23 @@ proc layoutmore {tmax} {
2577 set nr 150
2578 }
2579 set row $rowlaidout
2499 - set rowlaidout [layoutrows $row [expr {$row + $nr}] 0]
2580 + set rowlaidout [layoutrows $row [expr {$row + $nr}] $allread]
2581 if {$rowlaidout == $row} {
2582 return 0
2583 }
2584 + } elseif {$allread} {
2585 + set optdelay 0
2586 + set nrows $commitidx($curview)
2587 + if {[lindex $rowidlist $nrows] ne {} ||
2588 + [array names idinlist] ne {}} {
2589 + layouttail
2590 + set rowlaidout $commitidx($curview)
2591 + } elseif {$rowoptim == $nrows} {
2592 + set showdelay 0
2593 + if {$numcommits == $nrows} {
2594 + return 0
2595 + }
2596 + }
2597 } else {
2598 return 0
2599 }
@@ -2715,6 +2809,7 @@ proc layouttail {} {
2809 }
2810
2811 foreach id [array names idinlist] {
2812 + unset idinlist($id)
2813 addextraid $id $row
2814 lset rowidlist $row [list $id]
2815 lset rowoffsets $row 0
@@ -3423,19 +3518,6 @@ proc show_status {msg} {
3518 -tags text -fill $fgcolor
3519 }
3520
3426 -proc finishcommits {} {
3427 - global commitidx phase curview
3428 - global pending_select
3429 -
3430 - if {$commitidx($curview) > 0} {
3431 - drawrest
3432 - } else {
3433 - show_status "No commits selected"
3434 - }
3435 - set phase {}
3436 - catch {unset pending_select}
3437 -}
3438 -
3521 # Insert a new commit as the child of the commit on row $row.
3522 # The new commit will be displayed on row $row and the commits
3523 # on that row and below will move down one row.
@@ -3569,24 +3651,6 @@ proc notbusy {what} {
3651 }
3652 }
3653
3572 -proc drawrest {} {
3573 - global startmsecs
3574 - global rowlaidout commitidx curview
3575 - global pending_select
3576 -
3577 - layoutrows $rowlaidout $commitidx($curview) 1
3578 - layouttail
3579 - optimize_rows $row 0 $commitidx($curview)
3580 - showstuff $commitidx($curview)
3581 - if {[info exists pending_select]} {
3582 - selectline 0 1
3583 - }
3584 -
3585 - set drawmsecs [expr {[clock clicks -milliseconds] - $startmsecs}]
3586 - #global numcommits
3587 - #puts "overall $drawmsecs ms for $numcommits commits"
3588 -}
3589 -
3654 proc findmatches {f} {
3655 global findtype foundstring foundstrlen
3656 if {$findtype == "Regexp"} {
@@ -4243,7 +4307,7 @@ proc gettree {id} {
4307 set treefilelist($id) {}
4308 set treeidlist($id) {}
4309 fconfigure $gtf -blocking 0
4246 - fileevent $gtf readable [list gettreeline $gtf $id]
4310 + filerun $gtf [list gettreeline $gtf $id]
4311 }
4312 } else {
4313 setfilelist $id
@@ -4253,14 +4317,21 @@ proc gettree {id} {
4317 proc gettreeline {gtf id} {
4318 global treefilelist treeidlist treepending cmitmode diffids
4319
4256 - while {[gets $gtf line] >= 0} {
4257 - if {[lindex $line 1] ne "blob"} continue
4258 - set sha1 [lindex $line 2]
4259 - set fname [lindex $line 3]
4260 - lappend treefilelist($id) $fname
4320 + set nl 0
4321 + while {[incr nl] <= 1000 && [gets $gtf line] >= 0} {
4322 + set tl [split $line "\t"]
4323 + if {[lindex $tl 0 1] ne "blob"} continue
4324 + set sha1 [lindex $tl 0 2]
4325 + set fname [lindex $tl 1]
4326 + if {[string index $fname 0] eq "\""} {
4327 + set fname [lindex $fname 0]
4328 + }
4329 lappend treeidlist($id) $sha1
4330 + lappend treefilelist($id) $fname
4331 + }
4332 + if {![eof $gtf]} {
4333 + return [expr {$nl >= 1000? 2: 1}]
4334 }
4263 - if {![eof $gtf]} return
4335 close $gtf
4336 unset treepending
4337 if {$cmitmode ne "tree"} {
@@ -4272,6 +4343,7 @@ proc gettreeline {gtf id} {
4343 } else {
4344 setfilelist $id
4345 }
4346 + return 0
4347 }
4348
4349 proc showfile {f} {
@@ -4289,7 +4361,7 @@ proc showfile {f} {
4361 return
4362 }
4363 fconfigure $bf -blocking 0
4292 - fileevent $bf readable [list getblobline $bf $diffids]
4364 + filerun $bf [list getblobline $bf $diffids]
4365 $ctext config -state normal
4366 clear_ctext $commentend
4367 $ctext insert end "\n"
@@ -4303,18 +4375,21 @@ proc getblobline {bf id} {
4375
4376 if {$id ne $diffids || $cmitmode ne "tree"} {
4377 catch {close $bf}
4306 - return
4378 + return 0
4379 }
4380 $ctext config -state normal
4309 - while {[gets $bf line] >= 0} {
4381 + set nl 0
4382 + while {[incr nl] <= 1000 && [gets $bf line] >= 0} {
4383 $ctext insert end "$line\n"
4384 }
4385 if {[eof $bf]} {
4386 # delete last newline
4387 $ctext delete "end - 2c" "end - 1c"
4388 close $bf
4389 + return 0
4390 }
4391 $ctext config -state disabled
4392 + return [expr {$nl >= 1000? 2: 1}]
4393 }
4394
4395 proc mergediff {id l} {
@@ -4334,83 +4409,78 @@ proc mergediff {id l} {
4409 fconfigure $mdf -blocking 0
4410 set mdifffd($id) $mdf
4411 set np [llength [lindex $parentlist $l]]
4337 - fileevent $mdf readable [list getmergediffline $mdf $id $np]
4338 - set nextupdate [expr {[clock clicks -milliseconds] + 100}]
4412 + filerun $mdf [list getmergediffline $mdf $id $np]
4413 }
4414
4415 proc getmergediffline {mdf id np} {
4342 - global diffmergeid ctext cflist nextupdate mergemax
4416 + global diffmergeid ctext cflist mergemax
4417 global difffilestart mdifffd
4418
4345 - set n [gets $mdf line]
4346 - if {$n < 0} {
4347 - if {[eof $mdf]} {
4419 + $ctext conf -state normal
4420 + set nr 0
4421 + while {[incr nr] <= 1000 && [gets $mdf line] >= 0} {
4422 + if {![info exists diffmergeid] || $id != $diffmergeid
4423 + || $mdf != $mdifffd($id)} {
4424 close $mdf
4425 + return 0
4426 }
4350 - return
4351 - }
4352 - if {![info exists diffmergeid] || $id != $diffmergeid
4353 - || $mdf != $mdifffd($id)} {
4354 - return
4355 - }
4356 - $ctext conf -state normal
4357 - if {[regexp {^diff --cc (.*)} $line match fname]} {
4358 - # start of a new file
4359 - $ctext insert end "\n"
4360 - set here [$ctext index "end - 1c"]
4361 - lappend difffilestart $here
4362 - add_flist [list $fname]
4363 - set l [expr {(78 - [string length $fname]) / 2}]
4364 - set pad [string range "----------------------------------------" 1 $l]
4365 - $ctext insert end "$pad $fname $pad\n" filesep
4366 - } elseif {[regexp {^@@} $line]} {
4367 - $ctext insert end "$line\n" hunksep
4368 - } elseif {[regexp {^[0-9a-f]{40}$} $line] || [regexp {^index} $line]} {
4369 - # do nothing
4370 - } else {
4371 - # parse the prefix - one ' ', '-' or '+' for each parent
4372 - set spaces {}
4373 - set minuses {}
4374 - set pluses {}
4375 - set isbad 0
4376 - for {set j 0} {$j < $np} {incr j} {
4377 - set c [string range $line $j $j]
4378 - if {$c == " "} {
4379 - lappend spaces $j
4380 - } elseif {$c == "-"} {
4381 - lappend minuses $j
4382 - } elseif {$c == "+"} {
4383 - lappend pluses $j
4384 - } else {
4385 - set isbad 1
4386 - break
4427 + if {[regexp {^diff --cc (.*)} $line match fname]} {
4428 + # start of a new file
4429 + $ctext insert end "\n"
4430 + set here [$ctext index "end - 1c"]
4431 + lappend difffilestart $here
4432 + add_flist [list $fname]
4433 + set l [expr {(78 - [string length $fname]) / 2}]
4434 + set pad [string range "----------------------------------------" 1 $l]
4435 + $ctext insert end "$pad $fname $pad\n" filesep
4436 + } elseif {[regexp {^@@} $line]} {
4437 + $ctext insert end "$line\n" hunksep
4438 + } elseif {[regexp {^[0-9a-f]{40}$} $line] || [regexp {^index} $line]} {
4439 + # do nothing
4440 + } else {
4441 + # parse the prefix - one ' ', '-' or '+' for each parent
4442 + set spaces {}
4443 + set minuses {}
4444 + set pluses {}
4445 + set isbad 0
4446 + for {set j 0} {$j < $np} {incr j} {
4447 + set c [string range $line $j $j]
4448 + if {$c == " "} {
4449 + lappend spaces $j
4450 + } elseif {$c == "-"} {
4451 + lappend minuses $j
4452 + } elseif {$c == "+"} {
4453 + lappend pluses $j
4454 + } else {
4455 + set isbad 1
4456 + break
4457 + }
4458 }
4388 - }
4389 - set tags {}
4390 - set num {}
4391 - if {!$isbad && $minuses ne {} && $pluses eq {}} {
4392 - # line doesn't appear in result, parents in $minuses have the line
4393 - set num [lindex $minuses 0]
4394 - } elseif {!$isbad && $pluses ne {} && $minuses eq {}} {
4395 - # line appears in result, parents in $pluses don't have the line
4396 - lappend tags mresult
4397 - set num [lindex $spaces 0]
4398 - }
4399 - if {$num ne {}} {
4400 - if {$num >= $mergemax} {
4401 - set num "max"
4459 + set tags {}
4460 + set num {}
4461 + if {!$isbad && $minuses ne {} && $pluses eq {}} {
4462 + # line doesn't appear in result, parents in $minuses have the line
4463 + set num [lindex $minuses 0]
4464 + } elseif {!$isbad && $pluses ne {} && $minuses eq {}} {
4465 + # line appears in result, parents in $pluses don't have the line
4466 + lappend tags mresult
4467 + set num [lindex $spaces 0]
4468 }
4403 - lappend tags m$num
4469 + if {$num ne {}} {
4470 + if {$num >= $mergemax} {
4471 + set num "max"
4472 + }
4473 + lappend tags m$num
4474 + }
4475 + $ctext insert end "$line\n" $tags
4476 }
4405 - $ctext insert end "$line\n" $tags
4477 }
4478 $ctext conf -state disabled
4408 - if {[clock clicks -milliseconds] >= $nextupdate} {
4409 - incr nextupdate 100
4410 - fileevent $mdf readable {}
4411 - update
4412 - fileevent $mdf readable [list getmergediffline $mdf $id $np]
4479 + if {[eof $mdf]} {
4480 + close $mdf
4481 + return 0
4482 }
4483 + return [expr {$nr >= 1000? 2: 1}]
4484 }
4485
4486 proc startdiff {ids} {
@@ -4441,37 +4511,39 @@ proc gettreediffs {ids} {
4511 {set gdtf [open [concat | git diff-tree --no-commit-id -r $ids] r]} \
4512 ]} return
4513 fconfigure $gdtf -blocking 0
4444 - fileevent $gdtf readable [list gettreediffline $gdtf $ids]
4514 + filerun $gdtf [list gettreediffline $gdtf $ids]
4515 }
4516
4517 proc gettreediffline {gdtf ids} {
4518 global treediff treediffs treepending diffids diffmergeid
4519 global cmitmode
4520
4451 - set n [gets $gdtf line]
4452 - if {$n < 0} {
4453 - if {![eof $gdtf]} return
4454 - close $gdtf
4455 - set treediffs($ids) $treediff
4456 - unset treepending
4457 - if {$cmitmode eq "tree"} {
4458 - gettree $diffids
4459 - } elseif {$ids != $diffids} {
4460 - if {![info exists diffmergeid]} {
4461 - gettreediffs $diffids
4462 - }
4463 - } else {
4464 - addtocflist $ids
4521 + set nr 0
4522 + while {[incr nr] <= 1000 && [gets $gdtf line] >= 0} {
4523 + set file [lindex $line 5]
4524 + lappend treediff $file
4525 + }
4526 + if {![eof $gdtf]} {
4527 + return [expr {$nr >= 1000? 2: 1}]
4528 + }
4529 + close $gdtf
4530 + set treediffs($ids) $treediff
4531 + unset treepending
4532 + if {$cmitmode eq "tree"} {
4533 + gettree $diffids
4534 + } elseif {$ids != $diffids} {
4535 + if {![info exists diffmergeid]} {
4536 + gettreediffs $diffids
4537 }
4466 - return
4538 + } else {
4539 + addtocflist $ids
4540 }
4468 - set file [lindex $line 5]
4469 - lappend treediff $file
4541 + return 0
4542 }
4543
4544 proc getblobdiffs {ids} {
4545 global diffopts blobdifffd diffids env curdifftag curtagstart
4474 - global nextupdate diffinhdr treediffs
4546 + global diffinhdr treediffs
4547
4548 set env(GIT_DIFF_OPTS) $diffopts
4549 set cmd [concat | git diff-tree --no-commit-id -r -p -C $ids]
@@ -4484,8 +4556,7 @@ proc getblobdiffs {ids} {
4556 set blobdifffd($ids) $bdf
4557 set curdifftag Comments
4558 set curtagstart 0.0
4487 - fileevent $bdf readable [list getblobdiffline $bdf $diffids]
4488 - set nextupdate [expr {[clock clicks -milliseconds] + 100}]
4559 + filerun $bdf [list getblobdiffline $bdf $diffids]
4560 }
4561
4562 proc setinlist {var i val} {
@@ -4504,81 +4575,78 @@ proc setinlist {var i val} {
4575 proc getblobdiffline {bdf ids} {
4576 global diffids blobdifffd ctext curdifftag curtagstart
4577 global diffnexthead diffnextnote difffilestart
4507 - global nextupdate diffinhdr treediffs
4578 + global diffinhdr treediffs
4579
4509 - set n [gets $bdf line]
4510 - if {$n < 0} {
4511 - if {[eof $bdf]} {
4512 - close $bdf
4513 - if {$ids == $diffids && $bdf == $blobdifffd($ids)} {
4514 - $ctext tag add $curdifftag $curtagstart end
4515 - }
4516 - }
4517 - return
4518 - }
4519 - if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
4520 - return
4521 - }
4580 + set nr 0
4581 $ctext conf -state normal
4523 - if {[regexp {^diff --git a/(.*) b/(.*)} $line match fname newname]} {
4524 - # start of a new file
4525 - $ctext insert end "\n"
4526 - $ctext tag add $curdifftag $curtagstart end
4527 - set here [$ctext index "end - 1c"]
4528 - set curtagstart $here
4529 - set header $newname
4530 - set i [lsearch -exact $treediffs($ids) $fname]
4531 - if {$i >= 0} {
4532 - setinlist difffilestart $i $here
4582 + while {[incr nr] <= 1000 && [gets $bdf line] >= 0} {
4583 + if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
4584 + close $bdf
4585 + return 0
4586 }
4534 - if {$newname ne $fname} {
4535 - set i [lsearch -exact $treediffs($ids) $newname]
4587 + if {[regexp {^diff --git a/(.*) b/(.*)} $line match fname newname]} {
4588 + # start of a new file
4589 + $ctext insert end "\n"
4590 + $ctext tag add $curdifftag $curtagstart end
4591 + set here [$ctext index "end - 1c"]
4592 + set curtagstart $here
4593 + set header $newname
4594 + set i [lsearch -exact $treediffs($ids) $fname]
4595 if {$i >= 0} {
4596 setinlist difffilestart $i $here
4597 }
4539 - }
4540 - set curdifftag "f:$fname"
4541 - $ctext tag delete $curdifftag
4542 - set l [expr {(78 - [string length $header]) / 2}]
4543 - set pad [string range "----------------------------------------" 1 $l]
4544 - $ctext insert end "$pad $header $pad\n" filesep
4545 - set diffinhdr 1
4546 - } elseif {$diffinhdr && [string compare -length 3 $line "---"] == 0} {
4547 - # do nothing
4548 - } elseif {$diffinhdr && [string compare -length 3 $line "+++"] == 0} {
4549 - set diffinhdr 0
4550 - } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
4551 - $line match f1l f1c f2l f2c rest]} {
4552 - $ctext insert end "$line\n" hunksep
4553 - set diffinhdr 0
4554 - } else {
4555 - set x [string range $line 0 0]
4556 - if {$x == "-" || $x == "+"} {
4557 - set tag [expr {$x == "+"}]
4558 - $ctext insert end "$line\n" d$tag
4559 - } elseif {$x == " "} {
4560 - $ctext insert end "$line\n"
4561 - } elseif {$diffinhdr || $x == "\\"} {
4562 - # e.g. "\ No newline at end of file"
4563 - $ctext insert end "$line\n" filesep
4598 + if {$newname ne $fname} {
4599 + set i [lsearch -exact $treediffs($ids) $newname]
4600 + if {$i >= 0} {
4601 + setinlist difffilestart $i $here
4602 + }
4603 + }
4604 + set curdifftag "f:$fname"
4605 + $ctext tag delete $curdifftag
4606 + set l [expr {(78 - [string length $header]) / 2}]
4607 + set pad [string range "----------------------------------------" \
4608 + 1 $l]
4609 + $ctext insert end "$pad $header $pad\n" filesep
4610 + set diffinhdr 1
4611 + } elseif {$diffinhdr && [string compare -length 3 $line "---"] == 0} {
4612 + # do nothing
4613 + } elseif {$diffinhdr && [string compare -length 3 $line "+++"] == 0} {
4614 + set diffinhdr 0
4615 + } elseif {[regexp {^@@ -([0-9]+),([0-9]+) \+([0-9]+),([0-9]+) @@(.*)} \
4616 + $line match f1l f1c f2l f2c rest]} {
4617 + $ctext insert end "$line\n" hunksep
4618 + set diffinhdr 0
4619 } else {
4565 - # Something else we don't recognize
4566 - if {$curdifftag != "Comments"} {
4567 - $ctext insert end "\n"
4568 - $ctext tag add $curdifftag $curtagstart end
4569 - set curtagstart [$ctext index "end - 1c"]
4570 - set curdifftag Comments
4620 + set x [string range $line 0 0]
4621 + if {$x == "-" || $x == "+"} {
4622 + set tag [expr {$x == "+"}]
4623 + $ctext insert end "$line\n" d$tag
4624 + } elseif {$x == " "} {
4625 + $ctext insert end "$line\n"
4626 + } elseif {$diffinhdr || $x == "\\"} {
4627 + # e.g. "\ No newline at end of file"
4628 + $ctext insert end "$line\n" filesep
4629 + } else {
4630 + # Something else we don't recognize
4631 + if {$curdifftag != "Comments"} {
4632 + $ctext insert end "\n"
4633 + $ctext tag add $curdifftag $curtagstart end
4634 + set curtagstart [$ctext index "end - 1c"]
4635 + set curdifftag Comments
4636 + }
4637 + $ctext insert end "$line\n" filesep
4638 }
4572 - $ctext insert end "$line\n" filesep
4639 }
4640 }
4641 $ctext conf -state disabled
4576 - if {[clock clicks -milliseconds] >= $nextupdate} {
4577 - incr nextupdate 100
4578 - fileevent $bdf readable {}
4579 - update
4580 - fileevent $bdf readable "getblobdiffline $bdf {$ids}"
4642 + if {[eof $bdf]} {
4643 + close $bdf
4644 + if {$ids == $diffids && $bdf == $blobdifffd($ids)} {
4645 + $ctext tag add $curdifftag $curtagstart end
4646 + }
4647 + return 0
4648 }
4649 + return [expr {$nr >= 1000? 2: 1}]
4650 }
4651
4652 proc changediffdisp {} {
@@ -5509,11 +5577,7 @@ proc regetallcommits {} {
5577 fconfigure $fd -blocking 0
5578 incr allcommits
5579 nowbusy allcommits
5512 - restartgetall $fd
5513 -}
5514 -
5515 -proc restartgetall {fd} {
5516 - fileevent $fd readable [list getallclines $fd]
5580 + filerun $fd [list getallclines $fd]
5581 }
5582
5583 # Since most commits have 1 parent and 1 child, we group strings of
@@ -5534,13 +5598,10 @@ proc restartgetall {fd} {
5598 proc getallclines {fd} {
5599 global allids allparents allchildren idtags nextarc nbmp
5600 global arcnos arcids arctags arcout arcend arcstart archeads growing
5537 - global seeds allcommits allcstart
5601 + global seeds allcommits
5602
5539 - if {![info exists allcstart]} {
5540 - set allcstart [clock clicks -milliseconds]
5541 - }
5603 set nid 0
5543 - while {[gets $fd line] >= 0} {
5604 + while {[incr nid] <= 1000 && [gets $fd line] >= 0} {
5605 set id [lindex $line 0]
5606 if {[info exists allparents($id)]} {
5607 # seen it already
@@ -5607,22 +5668,16 @@ proc getallclines {fd} {
5668 lappend arcnos($p) $a
5669 }
5670 set arcout($id) $ao
5610 - if {[incr nid] >= 50} {
5611 - set nid 0
5612 - if {[clock clicks -milliseconds] - $allcstart >= 50} {
5613 - fileevent $fd readable {}
5614 - after idle restartgetall $fd
5615 - unset allcstart
5616 - return
5617 - }
5618 - }
5671 }
5620 - if {![eof $fd]} return
5672 + if {![eof $fd]} {
5673 + return [expr {$nid >= 1000? 2: 1}]
5674 + }
5675 close $fd
5676 if {[incr allcommits -1] == 0} {
5677 notbusy allcommits
5678 }
5679 dispneartags 0
5680 + return 0
5681 }
5682
5683 proc recalcarc {a} {
@@ -5919,6 +5974,7 @@ proc is_certain {desc anc} {
5974 if {$dl($x)} {
5975 return 0
5976 }
5977 + return 0
5978 }
5979 return 1
5980 }
@@ -6948,6 +7004,7 @@ if {$i >= 0} {
7004 }
7005 }
7006
7007 +set runq {}
7008 set history {}
7009 set historyindex 0
7010 set fh_serial 0