@matheusbsbs / matheus-bagliano / commits / 79b2c75e04
Fork 0

gitk: replace parent and children arrays with lists

This will make it easier to switch between views efficiently, and turns out to be slightly faster as well. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Apr 2, 2006 at 20:47 UTC 79b2c75e043ad85f9a6b1a8d890b601a2f761a0e
1 file changed +95 -93
gitk
+95 -93
@@ -75,6 +75,7 @@ proc getcommitlines {commfd} {
75 global commitlisted nextupdate
76 global leftover
77 global displayorder commitidx commitrow commitdata
78 + global parentlist childlist children
79
80 set stuff [read $commfd]
81 if {$stuff == {}} {
@@ -140,15 +141,26 @@ proc getcommitlines {commfd} {
141 set id [lindex $ids 0]
142 if {$listed} {
143 set olds [lrange $ids 1 end]
143 - set commitlisted($id) 1
144 + if {[llength $olds] > 1} {
145 + set olds [lsort -unique $olds]
146 + }
147 + foreach p $olds {
148 + lappend children($p) $id
149 + }
150 } else {
151 set olds {}
152 }
147 - updatechildren $id $olds
153 + lappend parentlist $olds
154 + if {[info exists children($id)]} {
155 + lappend childlist $children($id)
156 + } else {
157 + lappend childlist {}
158 + }
159 set commitdata($id) [string range $cmit [expr {$j + 1}] end]
160 set commitrow($id) $commitidx
161 incr commitidx
162 lappend displayorder $id
163 + lappend commitlisted $listed
164 set gotsome 1
165 }
166 if {$gotsome} {
@@ -181,14 +193,12 @@ proc doupdate {reading} {
193
194 proc readcommit {id} {
195 if {[catch {set contents [exec git-cat-file commit $id]}]} return
184 - updatechildren $id {}
196 parsecommit $id $contents 0
197 }
198
199 proc updatecommits {rargs} {
200 stopfindproc
190 - foreach v {children nchildren parents nparents commitlisted
191 - colormap selectedline matchinglines treediffs
201 + foreach v {colormap selectedline matchinglines treediffs
202 mergefilelist currentid rowtextx commitrow
203 rowidlist rowoffsets idrowranges idrangedrawn iddrawn
204 linesegends crossings cornercrossings} {
@@ -200,26 +210,6 @@ proc updatecommits {rargs} {
210 getcommits $rargs
211 }
212
203 -proc updatechildren {id olds} {
204 - global children nchildren parents nparents
205 -
206 - if {![info exists nchildren($id)]} {
207 - set children($id) {}
208 - set nchildren($id) 0
209 - }
210 - set parents($id) $olds
211 - set nparents($id) [llength $olds]
212 - foreach p $olds {
213 - if {![info exists nchildren($p)]} {
214 - set children($p) [list $id]
215 - set nchildren($p) 1
216 - } elseif {[lsearch -exact $children($p) $id] < 0} {
217 - lappend children($p) $id
218 - incr nchildren($p)
219 - }
220 - }
221 -}
222 -
213 proc parsecommit {id contents listed} {
214 global commitinfo cdate
215
@@ -274,7 +264,7 @@ proc parsecommit {id contents listed} {
264 }
265
266 proc getcommit {id} {
277 - global commitdata commitinfo nparents
267 + global commitdata commitinfo
268
269 if {[info exists commitdata($id)]} {
270 parsecommit $id $commitdata($id) 1
@@ -282,7 +272,6 @@ proc getcommit {id} {
272 readcommit $id
273 if {![info exists commitinfo($id)]} {
274 set commitinfo($id) {"No commit information available"}
285 - set nparents($id) 0
275 }
276 }
277 return 1
@@ -843,15 +832,20 @@ proc makeuparrow {oid x y z} {
832 }
833
834 proc initlayout {} {
846 - global rowidlist rowoffsets displayorder
835 + global rowidlist rowoffsets displayorder commitlisted
836 global rowlaidout rowoptim
837 global idinlist rowchk
838 global commitidx numcommits canvxmax canv
839 global nextcolor
840 + global parentlist childlist children
841
842 set commitidx 0
843 set numcommits 0
844 set displayorder {}
845 + set commitlisted {}
846 + set parentlist {}
847 + set childlist {}
848 + catch {unset children}
849 set nextcolor 0
850 set rowidlist {{}}
851 set rowoffsets {{}}
@@ -950,7 +944,7 @@ proc showstuff {canshow} {
944 proc layoutrows {row endrow last} {
945 global rowidlist rowoffsets displayorder
946 global uparrowlen downarrowlen maxwidth mingaplen
953 - global nchildren parents nparents
947 + global childlist parentlist
948 global idrowranges linesegends
949 global commitidx
950 global idinlist rowchk
@@ -961,7 +955,7 @@ proc layoutrows {row endrow last} {
955 set id [lindex $displayorder $row]
956 set oldolds {}
957 set newolds {}
964 - foreach p $parents($id) {
958 + foreach p [lindex $parentlist $row] {
959 if {![info exists idinlist($p)]} {
960 lappend newolds $p
961 } elseif {!$idinlist($p)} {
@@ -1000,7 +994,7 @@ proc layoutrows {row endrow last} {
994 lappend idlist $id
995 lset rowidlist $row $idlist
996 set z {}
1003 - if {$nchildren($id) > 0} {
997 + if {[lindex $childlist $row] ne {}} {
998 set z [expr {[llength [lindex $rowidlist [expr {$row-1}]]] - $col}]
999 unset idinlist($id)
1000 }
@@ -1053,16 +1047,22 @@ proc layoutrows {row endrow last} {
1047 }
1048
1049 proc addextraid {id row} {
1056 - global displayorder commitrow commitinfo nparents
1050 + global displayorder commitrow commitinfo
1051 global commitidx
1052 + global parentlist childlist children
1053
1054 incr commitidx
1055 lappend displayorder $id
1056 + lappend parentlist {}
1057 set commitrow($id) $row
1058 readcommit $id
1059 if {![info exists commitinfo($id)]} {
1060 set commitinfo($id) {"No commit information available"}
1065 - set nparents($id) 0
1061 + }
1062 + if {[info exists children($id)]} {
1063 + lappend childlist $children($id)
1064 + } else {
1065 + lappend childlist {}
1066 }
1067 }
1068
@@ -1365,7 +1365,7 @@ proc drawparentlinks {id row col olds} {
1365 proc drawlines {id} {
1366 global colormap canv
1367 global idrowranges idrangedrawn
1368 - global children iddrawn commitrow rowidlist
1368 + global childlist iddrawn commitrow rowidlist
1369
1370 $canv delete lines.$id
1371 set nr [expr {[llength $idrowranges($id)] / 2}]
@@ -1374,14 +1374,12 @@ proc drawlines {id} {
1374 drawlineseg $id $i
1375 }
1376 }
1377 - if {[info exists children($id)]} {
1378 - foreach child $children($id) {
1379 - if {[info exists iddrawn($child)]} {
1380 - set row $commitrow($child)
1381 - set col [lsearch -exact [lindex $rowidlist $row] $child]
1382 - if {$col >= 0} {
1383 - drawparentlinks $child $row $col [list $id]
1384 - }
1377 + foreach child [lindex $childlist $commitrow($id)] {
1378 + if {[info exists iddrawn($child)]} {
1379 + set row $commitrow($child)
1380 + set col [lsearch -exact [lindex $rowidlist $row] $child]
1381 + if {$col >= 0} {
1382 + drawparentlinks $child $row $col [list $id]
1383 }
1384 }
1385 }
@@ -1394,7 +1392,7 @@ proc drawcmittext {id row col rmx} {
1392 global linehtag linentag linedtag
1393 global mainfont namefont canvxmax
1394
1397 - set ofill [expr {[info exists commitlisted($id)]? "blue": "white"}]
1395 + set ofill [expr {[lindex $commitlisted $row]? "blue": "white"}]
1396 set x [xc $row $col]
1397 set y [yc $row]
1398 set orad [expr {$linespc / 3}]
@@ -1434,7 +1432,7 @@ proc drawcmittext {id row col rmx} {
1432 proc drawcmitrow {row} {
1433 global displayorder rowidlist
1434 global idrowranges idrangedrawn iddrawn
1437 - global commitinfo commitlisted parents numcommits
1435 + global commitinfo commitlisted parentlist numcommits
1436
1437 if {$row >= $numcommits} return
1438 foreach id [lindex $rowidlist $row] {
@@ -1465,9 +1463,9 @@ proc drawcmitrow {row} {
1463 getcommit $id
1464 }
1465 assigncolor $id
1468 - if {[info exists commitlisted($id)] && [info exists parents($id)]
1469 - && $parents($id) ne {}} {
1470 - set rmx [drawparentlinks $id $row $col $parents($id)]
1466 + set olds [lindex $parentlist $row]
1467 + if {$olds ne {}} {
1468 + set rmx [drawparentlinks $id $row $col $olds]
1469 } else {
1470 set rmx 0
1471 }
@@ -1511,15 +1509,22 @@ proc clear_display {} {
1509
1510 proc assigncolor {id} {
1511 global colormap colors nextcolor
1514 - global parents nparents children nchildren
1512 + global commitrow parentlist children childlist
1513 global cornercrossings crossings
1514
1515 if {[info exists colormap($id)]} return
1516 set ncolors [llength $colors]
1519 - if {$nchildren($id) == 1} {
1520 - set child [lindex $children($id) 0]
1517 + if {[info exists commitrow($id)]} {
1518 + set kids [lindex $childlist $commitrow($id)]
1519 + } elseif {[info exists children($id)]} {
1520 + set kids $children($id)
1521 + } else {
1522 + set kids {}
1523 + }
1524 + if {[llength $kids] == 1} {
1525 + set child [lindex $kids 0]
1526 if {[info exists colormap($child)]
1522 - && $nparents($child) == 1} {
1527 + && [llength [lindex $parentlist $commitrow($child)]] == 1} {
1528 set colormap($id) $colormap($child)
1529 return
1530 }
@@ -1552,17 +1557,15 @@ proc assigncolor {id} {
1557 set origbad $badcolors
1558 }
1559 if {[llength $badcolors] < $ncolors - 1} {
1555 - foreach child $children($id) {
1560 + foreach child $kids {
1561 if {[info exists colormap($child)]
1562 && [lsearch -exact $badcolors $colormap($child)] < 0} {
1563 lappend badcolors $colormap($child)
1564 }
1560 - if {[info exists parents($child)]} {
1561 - foreach p $parents($child) {
1562 - if {[info exists colormap($p)]
1563 - && [lsearch -exact $badcolors $colormap($p)] < 0} {
1564 - lappend badcolors $colormap($p)
1565 - }
1565 + foreach p [lindex $parentlist $commitrow($child)] {
1566 + if {[info exists colormap($p)]
1567 + && [lsearch -exact $badcolors $colormap($p)] < 0} {
1568 + lappend badcolors $colormap($p)
1569 }
1570 }
1571 }
@@ -1657,14 +1660,14 @@ proc drawtags {id x xt y1} {
1660 }
1661
1662 proc checkcrossings {row endrow} {
1660 - global displayorder parents rowidlist
1663 + global displayorder parentlist rowidlist
1664
1665 for {} {$row < $endrow} {incr row} {
1666 set id [lindex $displayorder $row]
1667 set i [lsearch -exact [lindex $rowidlist $row] $id]
1668 if {$i < 0} continue
1669 set idlist [lindex $rowidlist [expr {$row+1}]]
1667 - foreach p $parents($id) {
1670 + foreach p [lindex $parentlist $row] {
1671 set j [lsearch -exact $idlist $p]
1672 if {$j > 0} {
1673 if {$j < $i - 1} {
@@ -1760,7 +1763,7 @@ proc drawrest {} {
1763 showstuff $commitidx
1764
1765 set drawmsecs [expr {[clock clicks -milliseconds] - $startmsecs}]
1763 - #puts "overall $drawmsecs ms for $numcommits commits"
1766 + puts "overall $drawmsecs ms for $numcommits commits"
1767 }
1768
1769 proc findmatches {f} {
@@ -2046,7 +2049,7 @@ proc insertmatch {l id} {
2049
2050 proc findfiles {} {
2051 global selectedline numcommits displayorder ctext
2049 - global ffileline finddidsel parents nparents
2052 + global ffileline finddidsel parentlist
2053 global findinprogress findstartline findinsertpos
2054 global treediffs fdiffid fdiffsneeded fdiffpos
2055 global findmergefiles
@@ -2064,7 +2067,7 @@ proc findfiles {} {
2067 set fdiffsneeded {}
2068 while 1 {
2069 set id [lindex $displayorder $l]
2067 - if {$findmergefiles || $nparents($id) == 1} {
2070 + if {$findmergefiles || [llength [lindex $parentlist $l]] == 1} {
2071 if {![info exists treediffs($id)]} {
2072 append diffsneeded "$id\n"
2073 lappend fdiffsneeded $id
@@ -2096,7 +2099,7 @@ proc findfiles {} {
2099 . config -cursor watch
2100 settextcursor watch
2101 set findinprogress 1
2099 - findcont $id
2102 + findcont
2103 update
2104 }
2105
@@ -2143,7 +2146,7 @@ proc donefilediff {} {
2146 set treediffs($nullid) {}
2147 if {[info exists findid] && $nullid eq $findid} {
2148 unset findid
2146 - findcont $nullid
2149 + findcont
2150 }
2151 incr fdiffpos
2152 }
@@ -2154,20 +2157,21 @@ proc donefilediff {} {
2157 }
2158 if {[info exists findid] && $fdiffid eq $findid} {
2159 unset findid
2157 - findcont $fdiffid
2160 + findcont
2161 }
2162 }
2163 }
2164
2165 proc findcont {id} {
2163 - global findid treediffs parents nparents
2166 + global findid treediffs parentlist
2167 global ffileline findstartline finddidsel
2168 global displayorder numcommits matchinglines findinprogress
2169 global findmergefiles
2170
2171 set l $ffileline
2169 - while 1 {
2170 - if {$findmergefiles || $nparents($id) == 1} {
2172 + while {1} {
2173 + set id [lindex $displayorder $l]
2174 + if {$findmergefiles || [llength [lindex $parentlist $l]] == 1} {
2175 if {![info exists treediffs($id)]} {
2176 set findid $id
2177 set ffileline $l
@@ -2189,7 +2193,6 @@ proc findcont {id} {
2193 set l 0
2194 }
2195 if {$l == $findstartline} break
2192 - set id [lindex $displayorder $l]
2196 }
2197 stopfindproc
2198 if {!$finddidsel} {
@@ -2289,7 +2292,7 @@ proc appendwithlinks {text} {
2292 proc selectline {l isnew} {
2293 global canv canv2 canv3 ctext commitinfo selectedline
2294 global displayorder linehtag linentag linedtag
2292 - global canvy0 linespc parents nparents children
2295 + global canvy0 linespc parentlist childlist
2296 global cflist currentid sha1entry
2297 global commentend idtags linknum
2298 global mergemax numcommits
@@ -2379,9 +2382,10 @@ proc selectline {l isnew} {
2382 }
2383
2384 set comment {}
2382 - if {$nparents($id) > 1} {
2385 + set olds [lindex $parentlist $l]
2386 + if {[llength $olds] > 1} {
2387 set np 0
2384 - foreach p $parents($id) {
2388 + foreach p $olds {
2389 if {$np >= $mergemax} {
2390 set tag mmax
2391 } else {
@@ -2392,17 +2396,13 @@ proc selectline {l isnew} {
2396 incr np
2397 }
2398 } else {
2395 - if {[info exists parents($id)]} {
2396 - foreach p $parents($id) {
2397 - append comment "Parent: [commit_descriptor $p]\n"
2398 - }
2399 + foreach p $olds {
2400 + append comment "Parent: [commit_descriptor $p]\n"
2401 }
2402 }
2403
2402 - if {[info exists children($id)]} {
2403 - foreach c $children($id) {
2404 - append comment "Child: [commit_descriptor $c]\n"
2405 - }
2404 + foreach c [lindex $childlist $l] {
2405 + append comment "Child: [commit_descriptor $c]\n"
2406 }
2407 append comment "\n"
2408 append comment [lindex $info 5]
@@ -2417,10 +2417,10 @@ proc selectline {l isnew} {
2417
2418 $cflist delete 0 end
2419 $cflist insert end "Comments"
2420 - if {$nparents($id) <= 1} {
2420 + if {[llength $olds] <= 1} {
2421 startdiff $id
2422 } else {
2423 - mergediff $id
2423 + mergediff $id $l
2424 }
2425 }
2426
@@ -2489,9 +2489,10 @@ proc goforw {} {
2489 }
2490 }
2491
2492 -proc mergediff {id} {
2493 - global parents diffmergeid diffopts mdifffd
2492 +proc mergediff {id l} {
2493 + global diffmergeid diffopts mdifffd
2494 global difffilestart diffids
2495 + global parentlist
2496
2497 set diffmergeid $id
2498 set diffids $id
@@ -2505,12 +2506,13 @@ proc mergediff {id} {
2506 }
2507 fconfigure $mdf -blocking 0
2508 set mdifffd($id) $mdf
2508 - fileevent $mdf readable [list getmergediffline $mdf $id]
2509 + set np [llength [lindex $parentlist $l]]
2510 + fileevent $mdf readable [list getmergediffline $mdf $id $np]
2511 set nextupdate [expr {[clock clicks -milliseconds] + 100}]
2512 }
2513
2512 -proc getmergediffline {mdf id} {
2513 - global diffmergeid ctext cflist nextupdate nparents mergemax
2514 +proc getmergediffline {mdf id np} {
2515 + global diffmergeid ctext cflist nextupdate mergemax
2516 global difffilestart mdifffd
2517
2518 set n [gets $mdf line]
@@ -2543,7 +2545,6 @@ proc getmergediffline {mdf id} {
2545 # do nothing
2546 } else {
2547 # parse the prefix - one ' ', '-' or '+' for each parent
2546 - set np $nparents($id)
2548 set spaces {}
2549 set minuses {}
2550 set pluses {}
@@ -2611,7 +2612,7 @@ proc addtocflist {ids} {
2612 }
2613
2614 proc gettreediffs {ids} {
2614 - global treediff parents treepending
2615 + global treediff treepending
2616 set treepending $ids
2617 set treediff {}
2618 if {[catch \
@@ -2979,7 +2980,7 @@ proc arrowjump {id n y} {
2980 }
2981
2982 proc lineclick {x y id isnew} {
2982 - global ctext commitinfo children cflist canv thickerline
2983 + global ctext commitinfo childlist commitrow cflist canv thickerline
2984
2985 if {![info exists commitinfo($id)] && ![getcommit $id]} return
2986 unmarkmatches
@@ -3018,10 +3019,11 @@ proc lineclick {x y id isnew} {
3019 $ctext insert end "\tAuthor:\t[lindex $info 1]\n"
3020 set date [formatdate [lindex $info 2]]
3021 $ctext insert end "\tDate:\t$date\n"
3021 - if {[info exists children($id)]} {
3022 + set kids [lindex $childlist $commitrow($id)]
3023 + if {$kids ne {}} {
3024 $ctext insert end "\nChildren:"
3025 set i 0
3024 - foreach child $children($id) {
3026 + foreach child $kids {
3027 incr i
3028 if {![info exists commitinfo($child)] && ![getcommit $child]} continue
3029 set info $commitinfo($child)