@matheusbsbs / matheus-bagliano / commits / 22626ef4fd
Fork 0

gitk: Don't reread git-rev-list output from scratch on view switch

Previously, if we switched away from a view before we had finished reading the git-rev-list output for it and laying out the graph, we would discard the partially-laid-out graph and reread it from scratch if we switched back to the view. With this, we preserve the state of the partially-laid-out graph in viewdata($view) and restore it if we switch back. The pipe to git-rev-list remains open but we just don't read from it any more until we switch back to that view. This also makes linesegends a list rather than an array, which turns out to be slightly faster, as well as being easier to save and restore. The `update' menu item now kills the git-rev-list process if there is one still running when we do the update. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Apr 17, 2006 at 09:56 UTC 22626ef4fd5a0b2cf1fc8e90bbb23f8ff0ed43ea
1 file changed +116 -41
gitk
+116 -41
@@ -80,6 +80,18 @@ proc start_rev_list {rlargs} {
80 settextcursor watch
81 }
82
83 +proc stop_rev_list {} {
84 + global commfd
85 +
86 + if {![info exists commfd]} return
87 + catch {
88 + set pid [pid $commfd]
89 + exec kill $pid
90 + }
91 + catch {close $commfd}
92 + unset commfd
93 +}
94 +
95 proc getcommits {rargs} {
96 global phase canv mainfont
97
@@ -173,6 +185,7 @@ proc getcommitlines {commfd} {
185 lappend parentlist $olds
186 if {[info exists children($id)]} {
187 lappend childlist $children($id)
188 + unset children($id)
189 } else {
190 lappend childlist {}
191 }
@@ -217,8 +230,12 @@ proc readcommit {id} {
230 }
231
232 proc updatecommits {} {
220 - global viewdata curview revtreeargs
233 + global viewdata curview revtreeargs phase
234
235 + if {$phase ne {}} {
236 + stop_rev_list
237 + set phase {}
238 + }
239 set n $curview
240 set curview -1
241 catch {unset viewdata($n)}
@@ -883,6 +900,25 @@ proc delview {} {
900 showview 0
901 }
902
903 +proc flatten {var} {
904 + global $var
905 +
906 + set ret {}
907 + foreach i [array names $var] {
908 + lappend ret $i [set $var\($i\)]
909 + }
910 + return $ret
911 +}
912 +
913 +proc unflatten {var l} {
914 + global $var
915 +
916 + catch {unset $var}
917 + foreach {i v} $l {
918 + set $var\($i\) $v
919 + }
920 +}
921 +
922 proc showview {n} {
923 global curview viewdata viewfiles
924 global displayorder parentlist childlist rowidlist rowoffsets
@@ -892,6 +928,8 @@ proc showview {n} {
928 global matchinglines treediffs
929 global parsed_args
930 global pending_select phase
931 + global commitidx rowlaidout rowoptim linesegends leftover
932 + global commfd nextupdate
933
934 if {$n == $curview} return
935 set selid {}
@@ -911,10 +949,21 @@ proc showview {n} {
949 unselectline
950 normalline
951 stopfindproc
914 - if {$curview >= 0 && $phase eq {} && ![info exists viewdata($curview)]} {
915 - set viewdata($curview) \
916 - [list $displayorder $parentlist $childlist $rowidlist \
917 - $rowoffsets $rowrangelist $commitlisted]
952 + if {$curview >= 0} {
953 + if {$phase ne {}} {
954 + set viewdata($curview) \
955 + [list $phase $displayorder $parentlist $childlist $rowidlist \
956 + $rowoffsets $rowrangelist $commitlisted \
957 + [flatten children] [flatten idrowranges] \
958 + [flatten idinlist] \
959 + $commitidx $rowlaidout $rowoptim $numcommits \
960 + $linesegends $leftover $commfd]
961 + fileevent $commfd readable {}
962 + } elseif {![info exists viewdata($curview)]} {
963 + set viewdata($curview) \
964 + [list {} $displayorder $parentlist $childlist $rowidlist \
965 + $rowoffsets $rowrangelist $commitlisted]
966 + }
967 }
968 catch {unset matchinglines}
969 catch {unset treediffs}
@@ -933,18 +982,37 @@ proc showview {n} {
982 return
983 }
984
936 - set displayorder [lindex $viewdata($n) 0]
937 - set parentlist [lindex $viewdata($n) 1]
938 - set childlist [lindex $viewdata($n) 2]
939 - set rowidlist [lindex $viewdata($n) 3]
940 - set rowoffsets [lindex $viewdata($n) 4]
941 - set rowrangelist [lindex $viewdata($n) 5]
942 - set commitlisted [lindex $viewdata($n) 6]
943 - set numcommits [llength $displayorder]
985 + set v $viewdata($n)
986 + set phase [lindex $v 0]
987 + set displayorder [lindex $v 1]
988 + set parentlist [lindex $v 2]
989 + set childlist [lindex $v 3]
990 + set rowidlist [lindex $v 4]
991 + set rowoffsets [lindex $v 5]
992 + set rowrangelist [lindex $v 6]
993 + set commitlisted [lindex $v 7]
994 + if {$phase eq {}} {
995 + set numcommits [llength $displayorder]
996 + catch {unset idrowranges}
997 + catch {unset children}
998 + } else {
999 + unflatten children [lindex $v 8]
1000 + unflatten idrowranges [lindex $v 9]
1001 + unflatten idinlist [lindex $v 10]
1002 + set commitidx [lindex $v 11]
1003 + set rowlaidout [lindex $v 12]
1004 + set rowoptim [lindex $v 13]
1005 + set numcommits [lindex $v 14]
1006 + set linesegends [lindex $v 15]
1007 + set leftover [lindex $v 16]
1008 + set commfd [lindex $v 17]
1009 + fileevent $commfd readable [list getcommitlines $commfd]
1010 + set nextupdate [expr {[clock clicks -milliseconds] + 100}]
1011 + }
1012 +
1013 catch {unset colormap}
1014 catch {unset rowtextx}
1015 catch {unset commitrow}
947 - catch {unset idrowranges}
1016 set curview $n
1017 set row 0
1018 foreach id $displayorder {
@@ -1004,20 +1072,21 @@ proc ntimes {n o} {
1072 }
1073
1074 proc usedinrange {id l1 l2} {
1007 - global children commitrow
1075 + global children commitrow childlist
1076
1077 if {[info exists commitrow($id)]} {
1078 set r $commitrow($id)
1079 if {$l1 <= $r && $r <= $l2} {
1080 return [expr {$r - $l1 + 1}]
1081 }
1082 + set kids [lindex $childlist $r]
1083 + } else {
1084 + set kids $children($id)
1085 }
1015 - foreach c $children($id) {
1016 - if {[info exists commitrow($c)]} {
1017 - set r $commitrow($c)
1018 - if {$l1 <= $r && $r <= $l2} {
1019 - return [expr {$r - $l1 + 1}]
1020 - }
1086 + foreach c $kids {
1087 + set r $commitrow($c)
1088 + if {$l1 <= $r && $r <= $l2} {
1089 + return [expr {$r - $l1 + 1}]
1090 }
1091 }
1092 return 0
@@ -1112,7 +1181,7 @@ proc initlayout {} {
1181 catch {unset rowtextx}
1182 catch {unset commitrow}
1183 catch {unset idrowranges}
1115 - catch {unset linesegends}
1184 + set linesegends {}
1185 }
1186
1187 proc setcanvscroll {} {
@@ -1177,16 +1246,14 @@ proc showstuff {canshow} {
1246 set r1 [lindex $rows 1]
1247 set selrow -1
1248 for {set r $row} {$r < $canshow} {incr r} {
1180 - if {[info exists linesegends($r)]} {
1181 - foreach id $linesegends($r) {
1182 - set i -1
1183 - foreach {s e} $idrowranges($id) {
1184 - incr i
1185 - if {$e ne {} && $e < $numcommits && $s <= $r1 && $e >= $r0
1186 - && ![info exists idrangedrawn($id,$i)]} {
1187 - drawlineseg $id $i
1188 - set idrangedrawn($id,$i) 1
1189 - }
1249 + foreach id [lindex $linesegends [expr {$r+1}]] {
1250 + set i -1
1251 + foreach {s e} [rowranges $id] {
1252 + incr i
1253 + if {$e ne {} && $e < $numcommits && $s <= $r1 && $e >= $r0
1254 + && ![info exists idrangedrawn($id,$i)]} {
1255 + drawlineseg $id $i
1256 + set idrangedrawn($id,$i) 1
1257 }
1258 }
1259 }
@@ -1229,6 +1296,7 @@ proc layoutrows {row endrow last} {
1296 lappend oldolds $p
1297 }
1298 }
1299 + set lse {}
1300 set nev [expr {[llength $idlist] + [llength $newolds]
1301 + [llength $oldolds] - $maxwidth + 1}]
1302 if {$nev > 0} {
@@ -1244,7 +1312,7 @@ proc layoutrows {row endrow last} {
1312 set offs [incrange $offs $x 1]
1313 set idinlist($i) 0
1314 set rm1 [expr {$row - 1}]
1247 - lappend linesegends($rm1) $i
1315 + lappend lse $i
1316 lappend idrowranges($i) $rm1
1317 if {[incr nev -1] <= 0} break
1318 continue
@@ -1255,6 +1323,7 @@ proc layoutrows {row endrow last} {
1323 lset rowidlist $row $idlist
1324 lset rowoffsets $row $offs
1325 }
1326 + lappend linesegends $lse
1327 set col [lsearch -exact $idlist $id]
1328 if {$col < 0} {
1329 set col [llength $idlist]
@@ -1275,8 +1344,9 @@ proc layoutrows {row endrow last} {
1344 }
1345 set ranges {}
1346 if {[info exists idrowranges($id)]} {
1278 - lappend idrowranges($id) $row
1347 set ranges $idrowranges($id)
1348 + lappend ranges $row
1349 + unset idrowranges($id)
1350 }
1351 lappend rowrangelist $ranges
1352 incr row
@@ -1331,6 +1401,7 @@ proc addextraid {id row} {
1401 }
1402 if {[info exists children($id)]} {
1403 lappend childlist $children($id)
1404 + unset children($id)
1405 } else {
1406 lappend childlist {}
1407 }
@@ -1349,6 +1420,7 @@ proc layouttail {} {
1420 unset idinlist($id)
1421 lappend idrowranges($id) $row
1422 lappend rowrangelist $idrowranges($id)
1423 + unset idrowranges($id)
1424 incr row
1425 set offs [ntimes $col 0]
1426 set idlist [lreplace $idlist $col $col]
@@ -1363,6 +1435,7 @@ proc layouttail {} {
1435 makeuparrow $id 0 $row 0
1436 lappend idrowranges($id) $row
1437 lappend rowrangelist $idrowranges($id)
1438 + unset idrowranges($id)
1439 incr row
1440 lappend rowidlist {}
1441 lappend rowoffsets {}
@@ -1398,8 +1471,8 @@ proc optimize_rows {row col endrow} {
1471 set z0 [lindex $rowoffsets $y0 $x0]
1472 if {$z0 eq {}} {
1473 set id [lindex $idlist $col]
1401 - if {[info exists idrowranges($id)] &&
1402 - $y0 > [lindex $idrowranges($id) 0]} {
1474 + set ranges [rowranges $id]
1475 + if {$ranges ne {} && $y0 > [lindex $ranges 0]} {
1476 set isarrow 1
1477 }
1478 }
@@ -1457,8 +1530,8 @@ proc optimize_rows {row col endrow} {
1530 if {$o eq {}} {
1531 # check if this is the link to the first child
1532 set id [lindex $idlist $col]
1460 - if {[info exists idrowranges($id)] &&
1461 - $row == [lindex $idrowranges($id) 0]} {
1533 + set ranges [rowranges $id]
1534 + if {$ranges ne {} && $row == [lindex $ranges 0]} {
1535 # it is, work out offset to child
1536 set y0 [expr {$row - 1}]
1537 set id [lindex $displayorder $y0]
@@ -1513,10 +1586,11 @@ proc linewidth {id} {
1586 }
1587
1588 proc rowranges {id} {
1516 - global idrowranges commitrow numcommits rowrangelist
1589 + global phase idrowranges commitrow rowlaidout rowrangelist
1590
1591 set ranges {}
1519 - if {[info exists commitrow($id)] && $commitrow($id) < $numcommits} {
1592 + if {$phase eq {} ||
1593 + ([info exists commitrow($id)] && $commitrow($id) < $rowlaidout)} {
1594 set ranges [lindex $rowrangelist $commitrow($id)]
1595 } elseif {[info exists idrowranges($id)]} {
1596 set ranges $idrowranges($id)
@@ -1727,6 +1801,7 @@ proc drawcmitrow {row} {
1801
1802 if {$row >= $numcommits} return
1803 foreach id [lindex $rowidlist $row] {
1804 + if {$id eq {}} continue
1805 set i -1
1806 foreach {s e} [rowranges $id] {
1807 incr i
@@ -3142,7 +3217,7 @@ proc incrfont {inc} {
3217 foreach e $entries {
3218 $e conf -font $mainfont
3219 }
3145 - if {$phase == "getcommits"} {
3220 + if {$phase eq "getcommits"} {
3221 $canv itemconf textitems -font $mainfont
3222 }
3223 redisplay