@matheusbsbs / matheus-bagliano / commits / 8ed1648415
Fork 0

gitk: Further speedups

Now we don't parse the commits as we are reading them, we just put commit data on a list as a blob, and instead parse the commit when we need the various parts of it, such as when a commit is drawn on the canvas. This makes searching a bit more interesting: now we scan through the commit blobs doing a string or regexp match to find commits that might match, then for those that might match, we parse the commit info (if it isn't already parsed) and do the matching for the various fields as before. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Mar 2, 2006 at 22:56 UTC 8ed164841564802cc0b063a6b365fb19e9a513d1
1 file changed +55 -24
gitk
+55 -24
@@ -35,6 +35,7 @@ proc parse_args {rargs} {
35 proc start_rev_list {rlargs} {
36 global startmsecs nextupdate ncmupdate
37 global commfd leftover tclencoding datemode
38 + global commitdata
39
40 set startmsecs [clock clicks -milliseconds]
41 set nextupdate [expr {$startmsecs + 100}]
@@ -52,6 +53,7 @@ proc start_rev_list {rlargs} {
53 exit 1
54 }
55 set leftover {}
56 + set commitdata {}
57 fconfigure $commfd -blocking 0 -translation lf
58 if {$tclencoding != {}} {
59 fconfigure $commfd -encoding $tclencoding
@@ -72,11 +74,9 @@ proc getcommits {rargs} {
74 }
75
76 proc getcommitlines {commfd} {
75 - global parents cdate children nchildren
76 - global commitlisted commitinfo phase nextupdate
77 - global stopped leftover
78 - global canv
79 - global displayorder commitidx commitrow
77 + global commitlisted nextupdate
78 + global leftover
79 + global displayorder commitidx commitrow commitdata
80
81 set stuff [read $commfd]
82 if {$stuff == {}} {
@@ -136,12 +136,9 @@ proc getcommitlines {commfd} {
136 }
137 set id [lindex $ids 0]
138 set olds [lrange $ids 1 end]
139 - set cmit [string range $cmit [expr {$j + 1}] end]
139 set commitlisted($id) 1
140 updatechildren $id [lrange $ids 1 end]
142 - if {![info exists commitinfo($id)]} {
143 - parsecommit $id $cmit 1
144 - }
141 + lappend commitdata [string range $cmit [expr {$j + 1}] end]
142 set commitrow($id) $commitidx
143 incr commitidx
144 lappend displayorder $id
@@ -269,6 +266,25 @@ proc parsecommit {id contents listed} {
266 $comname $comdate $comment]
267 }
268
269 +proc getcommit {id {row {}}} {
270 + global commitdata commitrow commitinfo nparents
271 +
272 + if {$row eq {}} {
273 + if {![info exists commitrow($id)]} {return 0}
274 + set row $commitrow($id)
275 + }
276 + if {$row < [llength $commitdata]} {
277 + parsecommit $id [lindex $commitdata $row] 1
278 + } else {
279 + readcommit $id
280 + if {![info exists commitinfo($id)]} {
281 + set commitinfo($id) {"No commit information available"}
282 + set nparents($id) 0
283 + }
284 + }
285 + return 1
286 +}
287 +
288 proc readrefs {} {
289 global tagids idtags headids idheads tagcontents
290 global otherrefids idotherrefs
@@ -1317,6 +1333,7 @@ proc drawcmitrow {row} {
1333 global displayorder rowidlist
1334 global idrowranges idrangedrawn iddrawn
1335 global commitinfo commitlisted parents numcommits
1336 + global commitdata
1337
1338 if {$row >= $numcommits} return
1339 foreach id [lindex $rowidlist $row] {
@@ -1344,11 +1361,7 @@ proc drawcmitrow {row} {
1361 return
1362 }
1363 if {![info exists commitinfo($id)]} {
1347 - readcommit $id
1348 - if {![info exists commitinfo($id)]} {
1349 - set commitinfo($id) {"No commit information available"}
1350 - set nparents($id) 0
1351 - }
1364 + getcommit $id $row
1365 }
1366 assigncolor $id
1367 if {[info exists commitlisted($id)] && [info exists parents($id)]
@@ -1604,19 +1617,19 @@ proc xcoord {i level ln} {
1617 }
1618
1619 proc finishcommits {} {
1607 - global phase
1620 + global commitidx phase
1621 global canv mainfont ctext maincursor textcursor
1622
1610 - if {$phase == "incrdraw"} {
1623 + if {$commitidx > 0} {
1624 drawrest
1625 } else {
1626 $canv delete all
1627 $canv create text 3 3 -anchor nw -text "No commits selected" \
1628 -font $mainfont -tags textitems
1616 - set phase {}
1629 }
1630 . config -cursor $maincursor
1631 settextcursor $textcursor
1632 + set phase {}
1633 }
1634
1635 # Don't change the text pane cursor if it is currently the hand cursor,
@@ -1672,7 +1685,8 @@ proc dofind {} {
1685 global findtype findloc findstring markedmatches commitinfo
1686 global numcommits displayorder linehtag linentag linedtag
1687 global mainfont namefont canv canv2 canv3 selectedline
1675 - global matchinglines foundstring foundstrlen
1688 + global matchinglines foundstring foundstrlen matchstring
1689 + global commitdata
1690
1691 stopfindproc
1692 unmarkmatches
@@ -1689,6 +1703,8 @@ proc dofind {} {
1703 }
1704 set foundstrlen [string length $findstring]
1705 if {$foundstrlen == 0} return
1706 + regsub -all {[*?\[\\]} $foundstring {\\&} matchstring
1707 + set matchstring "*$matchstring*"
1708 if {$findloc == "Files"} {
1709 findfiles
1710 return
@@ -1700,8 +1716,21 @@ proc dofind {} {
1716 }
1717 set didsel 0
1718 set fldtypes {Headline Author Date Committer CDate Comment}
1703 - for {set l 0} {$l < $numcommits} {incr l} {
1719 + set l -1
1720 + foreach d $commitdata {
1721 + incr l
1722 + if {$findtype == "Regexp"} {
1723 + set doesmatch [regexp $foundstring $d]
1724 + } elseif {$findtype == "IgnCase"} {
1725 + set doesmatch [string match -nocase $matchstring $d]
1726 + } else {
1727 + set doesmatch [string match $matchstring $d]
1728 + }
1729 + if {!$doesmatch} continue
1730 set id [lindex $displayorder $l]
1731 + if {![info exists commitinfo($id)]} {
1732 + getcommit $id $l
1733 + }
1734 set info $commitinfo($id)
1735 set doesmatch 0
1736 foreach f $info ty $fldtypes {
@@ -2069,7 +2098,7 @@ proc findcont {id} {
2098 # mark a commit as matching by putting a yellow background
2099 # behind the headline
2100 proc markheadline {l id} {
2072 - global canv mainfont linehtag commitinfo
2101 + global canv mainfont linehtag
2102
2103 drawcmitrow $l
2104 set bbox [$canv bbox $linehtag($l)]
@@ -2725,9 +2754,9 @@ proc gotocommit {} {
2754 set id [string tolower $sha1string]
2755 if {[regexp {^[0-9a-f]{4,39}$} $id]} {
2756 set matches {}
2728 - for {set l 0} {$l < $numcommits} {incr l} {
2729 - if {[string match $id* [lindex $displayorder $l]]} {
2730 - lappend matches [lindex $displayorder $l]
2757 + foreach i $displayorder {
2758 + if {[string match $id* $i]} {
2759 + lappend matches $i
2760 }
2761 }
2762 if {$matches ne {}} {
@@ -2755,7 +2784,7 @@ proc lineenter {x y id} {
2784 global hoverx hovery hoverid hovertimer
2785 global commitinfo canv
2786
2758 - if {![info exists commitinfo($id)]} return
2787 + if {![info exists commitinfo($id)] && ![getcommit $id]} return
2788 set hoverx $x
2789 set hovery $y
2790 set hoverid $id
@@ -2849,6 +2878,7 @@ proc arrowjump {id n y} {
2878 proc lineclick {x y id isnew} {
2879 global ctext commitinfo children cflist canv thickerline
2880
2881 + if {![info exists commitinfo($id)] && ![getcommit $id]} return
2882 unmarkmatches
2883 unselectline
2884 normalline
@@ -2890,6 +2920,7 @@ proc lineclick {x y id isnew} {
2920 set i 0
2921 foreach child $children($id) {
2922 incr i
2923 + if {![info exists commitinfo($child)] && ![getcommit $child]} continue
2924 set info $commitinfo($child)
2925 $ctext insert end "\n\t"
2926 $ctext insert end $child [list link link$i]