@matheusbsbs / matheus-bagliano / commits / 4dd5d0d9eb
Fork 0

gitk: Some improvements for the code for updating the display

This should be more robust in the case that some does "Update" before the initial drawing is finished. It also avoids having to reset the list of children for each commit and reconstruct it. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Dec 6, 2005 at 09:46 UTC 4dd5d0d9eb8429a217ec43682e2e2eef8a8cbf6d
1 file changed +66 -44
gitk
+66 -44
@@ -133,14 +133,6 @@ proc getcommitlines {commfd} {
133 set id [lindex $ids 0]
134 set olds [lrange $ids 1 end]
135 set cmit [string range $cmit [expr {$j + 1}] end]
136 - if {$phase == "updatecommits"} {
137 - $canv delete all
138 - set oldcommits $commits
139 - set commits {}
140 - unset children
141 - unset nchildren
142 - set phase getcommits
143 - }
136 lappend commits $id
137 set commitlisted($id) 1
138 parsecommit $id $cmit 1 [lrange $ids 1 end]
@@ -751,7 +743,6 @@ proc assigncolor {id} {
743
744 proc initgraph {} {
745 global canvy canvy0 lineno numcommits nextcolor linespc
754 - global mainline mainlinearrow sidelines
746 global nchildren ncleft
747 global displist nhyperspace
748
@@ -760,9 +751,11 @@ proc initgraph {} {
751 set canvy $canvy0
752 set lineno -1
753 set numcommits 0
763 - catch {unset mainline}
764 - catch {unset mainlinearrow}
765 - catch {unset sidelines}
754 + foreach v {mainline mainlinearrow sidelines colormap cornercrossings
755 + crossings idline lineid} {
756 + global $v
757 + catch {unset $v}
758 + }
759 foreach id [array names nchildren] {
760 set ncleft($id) $nchildren($id)
761 }
@@ -1431,30 +1424,23 @@ proc decidenext {{noread 0}} {
1424 }
1425 }
1426 }
1434 - if {$level < 0} {
1435 - if {$todo != {}} {
1436 - puts "ERROR: none of the pending commits can be done yet:"
1437 - foreach p $todo {
1438 - puts " $p ($ncleft($p))"
1439 - }
1440 - }
1441 - return -1
1442 - }
1427
1428 return $level
1429 }
1430
1431 proc drawcommit {id reading} {
1448 - global phase todo nchildren datemode nextupdate revlistorder
1449 - global numcommits ncmupdate displayorder todo onscreen
1432 + global phase todo nchildren datemode nextupdate revlistorder ncleft
1433 global numcommits ncmupdate displayorder todo onscreen parents
1434 + global commitlisted commitordered
1435
1436 if {$phase != "incrdraw"} {
1437 set phase incrdraw
1438 set displayorder {}
1439 set todo {}
1440 initgraph
1441 + catch {unset commitordered}
1442 }
1443 + set commitordered($id) 1
1444 if {$nchildren($id) == 0} {
1445 lappend todo $id
1446 set onscreen($id) 0
@@ -1469,18 +1455,16 @@ proc drawcommit {id reading} {
1455 updatetodo $level 0
1456 } else {
1457 set level [decidenext 1]
1472 - if {$level == {} || $id != [lindex $todo $level]} {
1473 - return
1474 - }
1458 + if {$level == {} || $level < 0} return
1459 while 1 {
1460 + set id [lindex $todo $level]
1461 + if {![info exists commitordered($id)]} {
1462 + break
1463 + }
1464 lappend displayorder [lindex $todo $level]
1465 if {[updatetodo $level $datemode]} {
1466 set level [decidenext 1]
1479 - if {$level == {}} break
1480 - }
1481 - set id [lindex $todo $level]
1482 - if {![info exists commitlisted($id)]} {
1483 - break
1467 + if {$level == {} || $level < 0} break
1468 }
1469 }
1470 }
@@ -1490,17 +1474,19 @@ proc drawcommit {id reading} {
1474 proc finishcommits {} {
1475 global phase oldcommits commits
1476 global canv mainfont ctext maincursor textcursor
1493 - global parents
1477 + global parents displayorder todo
1478
1479 if {$phase == "incrdraw" || $phase == "removecommits"} {
1480 foreach id $oldcommits {
1481 lappend commits $id
1498 - updatechildren $id $parents($id)
1482 drawcommit $id 0
1483 }
1484 set oldcommits {}
1485 drawrest
1486 } elseif {$phase == "updatecommits"} {
1487 + # there were no new commits, in fact
1488 + set commits $oldcommits
1489 + set oldcommits {}
1490 set phase {}
1491 } else {
1492 $canv delete all
@@ -1540,7 +1526,7 @@ proc drawgraph {} {
1526
1527 proc drawrest {} {
1528 global phase stopped redisplaying selectedline
1543 - global datemode todo displayorder
1529 + global datemode todo displayorder ncleft
1530 global numcommits ncmupdate
1531 global nextupdate startmsecs revlistorder
1532
@@ -1556,6 +1542,13 @@ proc drawrest {} {
1542 }
1543 }
1544 }
1545 + if {$todo != {}} {
1546 + puts "ERROR: none of the pending commits can be done yet:"
1547 + foreach p $todo {
1548 + puts " $p ($ncleft($p))"
1549 + }
1550 + }
1551 +
1552 drawmore 0
1553 set phase {}
1554 set drawmsecs [expr {[clock clicks -milliseconds] - $startmsecs}]
@@ -3637,13 +3630,35 @@ proc updatecommits {rargs} {
3630 global idtags idheads idotherrefs
3631 global leftover
3632 global parsed_args
3640 - global canv
3633 + global canv mainfont
3634 global oldcommits commits
3635 global parents nchildren children ncleft
3636
3637 set old_args $parsed_args
3638 parse_args $rargs
3639
3640 + if {$phase == "getcommits" || $phase == "incrdraw"} {
3641 + # havent read all the old commits, just start again from scratch
3642 + stopfindproc
3643 + set oldcommits {}
3644 + set commits {}
3645 + foreach v {children nchildren parents commitlisted commitinfo
3646 + selectedline matchinglines treediffs
3647 + mergefilelist currentid rowtextx} {
3648 + global $v
3649 + catch {unset $v}
3650 + }
3651 + readrefs
3652 + if {$phase == "incrdraw"} {
3653 + allcanvs delete all
3654 + $canv create text 3 3 -anchor nw -text "Reading commits..." \
3655 + -font $mainfont -tags textitems
3656 + set phase getcommits
3657 + }
3658 + start_rev_list $parsed_args
3659 + return
3660 + }
3661 +
3662 foreach id $old_args {
3663 if {![regexp {^[0-9a-f]{40}$} $id]} continue
3664 if {[info exists oldref($id)]} continue
@@ -3664,20 +3679,27 @@ proc updatecommits {rargs} {
3679 }
3680
3681 set phase updatecommits
3682 + set oldcommits $commits
3683 + set commits {}
3684 set removed_commits [split [eval exec git-rev-list $ignorenew] "\n" ]
3685 if {[llength $removed_commits] > 0} {
3669 - $canv delete all
3670 - set oldcommits {}
3671 - foreach c $commits {
3672 - if {[lsearch $c $removed_commits] < 0} {
3673 - lappend oldcommits $c
3674 - } else {
3686 + allcanvs delete all
3687 + foreach c $removed_commits {
3688 + set i [lsearch -exact $oldcommits $c]
3689 + if {$i >= 0} {
3690 + set oldcommits [lreplace $oldcommits $i $i]
3691 unset commitlisted($c)
3692 + foreach p $parents($c) {
3693 + if {[info exists nchildren($p)]} {
3694 + set j [lsearch -exact $children($p) $c]
3695 + if {$j >= 0} {
3696 + set children($p) [lreplace $children($p) $j $j]
3697 + incr nchildren($p) -1
3698 + }
3699 + }
3700 + }
3701 }
3702 }
3678 - set commits {}
3679 - unset children
3680 - unset nchildren
3703 set phase removecommits
3704 }
3705