@matheusbsbs / matheus-bagliano / commits / f3ea5ede23
Fork 0

gitk: Implement date mode in the new framework

This restores date mode, which lists commits by date, as far as possible given the constraint that parents come after all their children. To implement this in the new framework, we (1) only join a new commit onto an existing arc if the arc is the last arc created, (2) treat arcs as seeds unless they have a child arc that comes later, and (3) never decrease the token value for an arc. This means we get lots of "seeds", which exposed some quadratic behaviour in adding and removing seeds. To fix this, we add a vbackptr array, which points to the arc whose vleftptr entry points to us, and a vlastins array, which shows where in an arc's vdownptr/vleftptr list we last inserted a parent, which acts as a hint of a good place to start looking for where to insert a new child. This also ensures the children array elements stay in sorted order at all times. We weren't resorting the children lists when reassigning tokens in renumbervarc. Since the children lists are now always sorted, we don't have to search through all elements to find the one with the highest token; we can just use the last element. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Dec 20, 2007 at 10:03 UTC f3ea5ede23a2f8a7514583d2665e7a72aad7c9b8
1 file changed +130 -98
gitk
+130 -98
@@ -269,19 +269,21 @@ proc strrep {n} {
269 # --topo-order) into the order for display.
270
271 proc varcinit {view} {
272 - global varcstart vupptr vdownptr vleftptr varctok varcrow
273 - global vtokmod varcmod vrowmod varcix
272 + global varcstart vupptr vdownptr vleftptr vbackptr varctok varcrow
273 + global vtokmod varcmod vrowmod varcix vlastins
274
275 set varcstart($view) {{}}
276 set vupptr($view) {0}
277 set vdownptr($view) {0}
278 set vleftptr($view) {0}
279 + set vbackptr($view) {0}
280 set varctok($view) {{}}
281 set varcrow($view) {{}}
282 set vtokmod($view) {}
283 set varcmod($view) 0
284 set vrowmod($view) 0
285 set varcix($view) {{}}
286 + set vlastins($view) {0}
287 }
288
289 proc resetvarcs {view} {
@@ -306,13 +308,13 @@ proc resetvarcs {view} {
308 }
309
310 proc newvarc {view id} {
309 - global varcid varctok parents children
310 - global vupptr vdownptr vleftptr varcrow varcix varcstart
311 - global commitdata commitinfo vseedcount varccommits
311 + global varcid varctok parents children datemode
312 + global vupptr vdownptr vleftptr vbackptr varcrow varcix varcstart
313 + global commitdata commitinfo vseedcount varccommits vlastins
314
315 set a [llength $varctok($view)]
316 set vid $view,$id
315 - if {[llength $children($vid)] == 0} {
317 + if {[llength $children($vid)] == 0 || $datemode} {
318 if {![info exists commitinfo($id)]} {
319 parsecommit $id $commitdata($id) 1
320 }
@@ -326,64 +328,61 @@ proc newvarc {view id} {
328 set c [incr vseedcount($view,$cdate)]
329 set cdate [expr {$cdate ^ 0xffffffff}]
330 set tok "s[strrep $cdate][strrep $c]"
329 - lappend vupptr($view) 0
330 - set ka [lindex $vdownptr($view) 0]
331 - if {$ka == 0 ||
332 - [string compare $tok [lindex $varctok($view) $ka]] < 0} {
333 - lset vdownptr($view) 0 $a
334 - lappend vleftptr($view) $ka
335 - } else {
336 - while {[set b [lindex $vleftptr($view) $ka]] != 0 &&
337 - [string compare $tok [lindex $varctok($view) $b]] >= 0} {
338 - set ka $b
339 - }
340 - lset vleftptr($view) $ka $a
341 - lappend vleftptr($view) $b
342 - }
331 } else {
332 set tok {}
345 - foreach k $children($vid) {
346 - set ka $varcid($view,$k)
347 - if {[string compare [lindex $varctok($view) $ka] $tok] > 0} {
348 - set ki $k
349 - set tok [lindex $varctok($view) $ka]
350 - }
333 + }
334 + set ka 0
335 + if {[llength $children($vid)] > 0} {
336 + set kid [lindex $children($vid) end]
337 + set k $varcid($view,$kid)
338 + if {[string compare [lindex $varctok($view) $k] $tok] > 0} {
339 + set ki $kid
340 + set ka $k
341 + set tok [lindex $varctok($view) $k]
342 }
352 - set ka $varcid($view,$ki)
353 - lappend vupptr($view) $ka
343 + }
344 + if {$ka != 0} {
345 set i [lsearch -exact $parents($view,$ki) $id]
346 set j [expr {[llength $parents($view,$ki)] - 1 - $i}]
356 - set rsib 0
357 - while {[incr i] < [llength $parents($view,$ki)]} {
358 - set bi [lindex $parents($view,$ki) $i]
359 - if {[info exists varcid($view,$bi)]} {
360 - set b $varcid($view,$bi)
361 - if {[lindex $vupptr($view) $b] == $ka} {
362 - set rsib $b
363 - lappend vleftptr($view) [lindex $vleftptr($view) $b]
364 - lset vleftptr($view) $b $a
365 - break
366 - }
367 - }
368 - }
369 - if {$rsib == 0} {
370 - lappend vleftptr($view) [lindex $vdownptr($view) $ka]
371 - lset vdownptr($view) $ka $a
372 - }
347 append tok [strrep $j]
348 }
349 + set c [lindex $vlastins($view) $ka]
350 + if {$c == 0 || [string compare $tok [lindex $varctok($view) $c]] < 0} {
351 + set c $ka
352 + set b [lindex $vdownptr($view) $ka]
353 + } else {
354 + set b [lindex $vleftptr($view) $c]
355 + }
356 + while {$b != 0 && [string compare $tok [lindex $varctok($view) $b]] >= 0} {
357 + set c $b
358 + set b [lindex $vleftptr($view) $c]
359 + }
360 + if {$c == $ka} {
361 + lset vdownptr($view) $ka $a
362 + lappend vbackptr($view) 0
363 + } else {
364 + lset vleftptr($view) $c $a
365 + lappend vbackptr($view) $c
366 + }
367 + lset vlastins($view) $ka $a
368 + lappend vupptr($view) $ka
369 + lappend vleftptr($view) $b
370 + if {$b != 0} {
371 + lset vbackptr($view) $b $a
372 + }
373 lappend varctok($view) $tok
374 lappend varcstart($view) $id
375 lappend vdownptr($view) 0
376 lappend varcrow($view) {}
377 lappend varcix($view) {}
378 set varccommits($view,$a) {}
379 + lappend vlastins($view) 0
380 return $a
381 }
382
383 proc splitvarc {p v} {
384 global varcid varcstart varccommits varctok
386 - global vupptr vdownptr vleftptr varcix varcrow
385 + global vupptr vdownptr vleftptr vbackptr varcix varcrow vlastins
386
387 set oa $varcid($v,$p)
388 set ac $varccommits($v,$oa)
@@ -405,6 +404,8 @@ proc splitvarc {p v} {
404 lset vdownptr($v) $oa $na
405 lappend vupptr($v) $oa
406 lappend vleftptr($v) 0
407 + lappend vbackptr($v) 0
408 + lappend vlastins($v) 0
409 for {set b [lindex $vdownptr($v) $na]} {$b != 0} {set b [lindex $vleftptr($v) $b]} {
410 lset vupptr($v) $b $na
411 }
@@ -412,11 +413,12 @@ proc splitvarc {p v} {
413
414 proc renumbervarc {a v} {
415 global parents children varctok varcstart varccommits
415 - global vupptr vdownptr vleftptr varcid vtokmod
416 + global vupptr vdownptr vleftptr vbackptr vlastins varcid vtokmod datemode
417
418 set t1 [clock clicks -milliseconds]
419 set todo {}
420 set isrelated($a) 1
421 + set kidchanged($a) 1
422 set ntot 0
423 while {$a != 0} {
424 if {[info exists isrelated($a)]} {
@@ -440,26 +442,45 @@ proc renumbervarc {a v} {
442 set a $b
443 }
444 foreach a $todo {
445 + if {![info exists kidchanged($a)]} continue
446 set id [lindex $varcstart($v) $a]
444 - set tok {}
445 - foreach k $children($v,$id) {
446 - set ka $varcid($v,$k)
447 - if {[string compare [lindex $varctok($v) $ka] $tok] > 0} {
448 - set ki $k
449 - set tok [lindex $varctok($v) $ka]
447 + if {[llength $children($v,$id)] > 1} {
448 + set children($v,$id) [lsort -command [list vtokcmp $v] \
449 + $children($v,$id)]
450 + }
451 + set oldtok [lindex $varctok($v) $a]
452 + if {!$datemode} {
453 + set tok {}
454 + } else {
455 + set tok $oldtok
456 + }
457 + set ka 0
458 + if {[llength $children($v,$id)] > 0} {
459 + set kid [lindex $children($v,$id) end]
460 + set k $varcid($v,$kid)
461 + if {[string compare [lindex $varctok($v) $k] $tok] > 0} {
462 + set ki $kid
463 + set ka $k
464 + set tok [lindex $varctok($v) $k]
465 }
466 }
452 - if {$tok ne {}} {
453 - set ka $varcid($v,$ki)
467 + if {$ka != 0} {
468 set i [lsearch -exact $parents($v,$ki) $id]
469 set j [expr {[llength $parents($v,$ki)] - 1 - $i}]
470 append tok [strrep $j]
457 - set oldtok [lindex $varctok($v) $a]
458 - if {$tok eq $oldtok} continue
459 - lset varctok($v) $a $tok
460 - } else {
461 - set ka 0
471 }
472 + if {$tok eq $oldtok} {
473 + continue
474 + }
475 + set id [lindex $varccommits($v,$a) end]
476 + foreach p $parents($v,$id) {
477 + if {[info exists varcid($v,$p)]} {
478 + set kidchanged($varcid($v,$p)) 1
479 + } else {
480 + set sortkids($p) 1
481 + }
482 + }
483 + lset varctok($v) $a $tok
484 set b [lindex $vupptr($v) $a]
485 if {$b != $ka} {
486 if {[string compare [lindex $varctok($v) $ka] $vtokmod($v)] < 0} {
@@ -468,38 +489,48 @@ proc renumbervarc {a v} {
489 if {[string compare [lindex $varctok($v) $b] $vtokmod($v)] < 0} {
490 modify_arc $v $b
491 }
471 - set c [lindex $vdownptr($v) $b]
472 - if {$c == $a} {
473 - lset vdownptr($v) $b [lindex $vleftptr($v) $a]
492 + set c [lindex $vbackptr($v) $a]
493 + set d [lindex $vleftptr($v) $a]
494 + if {$c == 0} {
495 + lset vdownptr($v) $b $d
496 } else {
475 - set b $c
476 - while {$b != 0 && [lindex $vleftptr($v) $b] != $a} {
477 - set b [lindex $vleftptr($v) $b]
478 - }
479 - if {$b != 0} {
480 - lset vleftptr($v) $b [lindex $vleftptr($v) $a]
481 - } else {
482 - puts "oops couldn't find $a in chain for [lindex $vupptr($v) $a]"
483 - }
497 + lset vleftptr($v) $c $d
498 + }
499 + if {$d != 0} {
500 + lset vbackptr($v) $d $c
501 }
502 lset vupptr($v) $a $ka
486 - set rsib 0
487 - while {[incr i] < [llength $parents($v,$ki)]} {
488 - set bi [lindex $parents($v,$ki) $i]
489 - if {[info exists varcid($v,$bi)]} {
490 - set b $varcid($v,$bi)
491 - if {[lindex $vupptr($v) $b] == $ka} {
492 - set rsib $b
493 - lset vleftptr($v) $a [lindex $vleftptr($v) $b]
494 - lset vleftptr($v) $b $a
495 - break
496 - }
497 - }
503 + set c [lindex $vlastins($v) $ka]
504 + if {$c == 0 || \
505 + [string compare $tok [lindex $varctok($v) $c]] < 0} {
506 + set c $ka
507 + set b [lindex $vdownptr($v) $ka]
508 + } else {
509 + set b [lindex $vleftptr($v) $c]
510 + }
511 + while {$b != 0 && \
512 + [string compare $tok [lindex $varctok($v) $b]] >= 0} {
513 + set c $b
514 + set b [lindex $vleftptr($v) $c]
515 }
499 - if {$rsib == 0} {
500 - lset vleftptr($v) $a [lindex $vdownptr($v) $ka]
501 - lset vdownptr($v) $ka $a
516 + if {$c == $ka} {
517 + lset vdownptr($v) $ka $a
518 + lset vbackptr($v) $a 0
519 + } else {
520 + lset vleftptr($v) $c $a
521 + lset vbackptr($v) $a $c
522 + }
523 + lset vleftptr($v) $a $b
524 + if {$b != 0} {
525 + lset vbackptr($v) $b $a
526 }
527 + lset vlastins($v) $ka $a
528 + }
529 + }
530 + foreach id [array names sortkids] {
531 + if {[llength $children($v,$id)] > 1} {
532 + set children($v,$id) [lsort -command [list vtokcmp $v] \
533 + $children($v,$id)]
534 }
535 }
536 set t2 [clock clicks -milliseconds]
@@ -831,7 +862,7 @@ proc closevarcs {v} {
862
863 proc getcommitlines {fd inst view} {
864 global cmitlisted commitinterest leftover
834 - global commitidx commitdata
865 + global commitidx commitdata datemode
866 global parents children curview hlview
867 global vnextroot idpending ordertok
868 global varccommits varcid varctok vtokmod
@@ -946,12 +977,12 @@ proc getcommitlines {fd inst view} {
977 set a 0
978 if {![info exists children($vid)]} {
979 set children($vid) {}
949 - } else {
950 - if {[llength $children($vid)] == 1} {
951 - set k [lindex $children($vid) 0]
952 - if {[llength $parents($view,$k)] == 1} {
953 - set a $varcid($view,$k)
954 - }
980 + } elseif {[llength $children($vid)] == 1} {
981 + set k [lindex $children($vid) 0]
982 + if {[llength $parents($view,$k)] == 1 &&
983 + (!$datemode ||
984 + $varcid($view,$k) == [llength $varctok($view)] - 1)} {
985 + set a $varcid($view,$k)
986 }
987 }
988 if {$a == 0} {
@@ -974,9 +1005,9 @@ proc getcommitlines {fd inst view} {
1005 $children($vp)]
1006 catch {unset ordertok}
1007 }
977 - }
978 - if {[info exists varcid($view,$p)]} {
979 - fix_reversal $p $a $view
1008 + if {[info exists varcid($view,$p)]} {
1009 + fix_reversal $p $a $view
1010 + }
1011 }
1012 incr i
1013 }
@@ -1033,7 +1064,7 @@ proc chewcommits {view} {
1064 if {$view == $curview} {
1065 layoutmore
1066 if {$viewcomplete($view)} {
1036 - global commitidx
1067 + global commitidx varctok
1068 global numcommits startmsecs
1069 global mainheadid commitinfo nullid
1070
@@ -1044,6 +1075,7 @@ proc chewcommits {view} {
1075 if {$commitidx($curview) > 0} {
1076 #set ms [expr {[clock clicks -milliseconds] - $startmsecs}]
1077 #puts "overall $ms ms for $numcommits commits"
1078 + #puts "[llength $varctok($view)] arcs, $commitidx($view) commits"
1079 } else {
1080 show_status "No commits selected"
1081 }