@matheusbsbs / matheus-bagliano / commits / 232475d382
Fork 0

Add -r flag and some speedups

The -r flag means "rev-list order", i.e. just display the commits in the order they come from git-rev-list. The speedups include: - don't process the whole commit line-by-line, only the header - don't convert dates when reading the commits, rather do it when needed - don't do the $canv delete lines.$id in drawlines when drawing the graph initially (it was taking a lot of the total time) - cache the date conversion for each hour (more important with tk8.5, since [clock format] is a lot slower in 8.5 than in 8.4). Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Nov 15, 2005 at 10:34 UTC 232475d38231552f04f2e4221936700a923a531e
1 file changed +102 -68
gitk
+102 -68
@@ -60,7 +60,7 @@ proc getcommits {rargs} {
60
61 proc getcommitlines {commfd} {
62 global commits parents cdate children
63 - global commitlisted phase commitinfo nextupdate
63 + global commitlisted phase nextupdate
64 global stopped redisplaying leftover
65
66 set stuff [read $commfd]
@@ -196,42 +196,41 @@ proc parsecommit {id contents listed olds} {
196 incr ncleft($p)
197 }
198 }
199 - foreach line [split $contents "\n"] {
200 - if {$inhdr} {
201 - if {$line == {}} {
202 - set inhdr 0
203 - } else {
204 - set tag [lindex $line 0]
205 - if {$tag == "author"} {
206 - set x [expr {[llength $line] - 2}]
207 - set audate [lindex $line $x]
208 - set auname [lrange $line 1 [expr {$x - 1}]]
209 - } elseif {$tag == "committer"} {
210 - set x [expr {[llength $line] - 2}]
211 - set comdate [lindex $line $x]
212 - set comname [lrange $line 1 [expr {$x - 1}]]
213 - }
214 - }
215 - } else {
216 - if {$comment == {}} {
217 - set headline [string trim $line]
218 - } else {
219 - append comment "\n"
220 - }
221 - if {!$listed} {
222 - # git-rev-list indents the comment by 4 spaces;
223 - # if we got this via git-cat-file, add the indentation
224 - append comment " "
225 - }
226 - append comment $line
199 + set hdrend [string first "\n\n" $contents]
200 + if {$hdrend < 0} {
201 + # should never happen...
202 + set hdrend [string length $contents]
203 + }
204 + set header [string range $contents 0 [expr {$hdrend - 1}]]
205 + set comment [string range $contents [expr {$hdrend + 2}] end]
206 + foreach line [split $header "\n"] {
207 + set tag [lindex $line 0]
208 + if {$tag == "author"} {
209 + set audate [lindex $line end-1]
210 + set auname [lrange $line 1 end-2]
211 + } elseif {$tag == "committer"} {
212 + set comdate [lindex $line end-1]
213 + set comname [lrange $line 1 end-2]
214 }
215 }
229 - if {$audate != {}} {
230 - set audate [clock format $audate -format "%Y-%m-%d %H:%M:%S"]
216 + set headline {}
217 + # take the first line of the comment as the headline
218 + set i [string first "\n" $comment]
219 + if {$i >= 0} {
220 + set headline [string trim [string range $comment 0 $i]]
221 + }
222 + if {!$listed} {
223 + # git-rev-list indents the comment by 4 spaces;
224 + # if we got this via git-cat-file, add the indentation
225 + set newcomment {}
226 + foreach line [split $comment "\n"] {
227 + append newcomment " "
228 + append newcomment $line
229 + }
230 + set comment $newcomment
231 }
232 if {$comdate != {}} {
233 set cdate($id) $comdate
234 - set comdate [clock format $comdate -format "%Y-%m-%d %H:%M:%S"]
234 }
235 set commitinfo($id) [list $headline $auname $audate \
236 $comname $comdate $comment]
@@ -683,7 +682,7 @@ Use and redistribute under the terms of the GNU General Public License} \
682 }
683
684 proc assigncolor {id} {
686 - global commitinfo colormap commcolors colors nextcolor
685 + global colormap commcolors colors nextcolor
686 global parents nparents children nchildren
687 global cornercrossings crossings
688
@@ -783,10 +782,12 @@ proc bindline {t id} {
782 $canv bind $t <Button-1> "lineclick %x %y $id 1"
783 }
784
786 -proc drawlines {id xtra} {
785 +proc drawlines {id xtra delold} {
786 global mainline mainlinearrow sidelines lthickness colormap canv
787
789 - $canv delete lines.$id
788 + if {$delold} {
789 + $canv delete lines.$id
790 + }
791 if {[info exists mainline($id)]} {
792 set t [$canv create line $mainline($id) \
793 -width [expr {($xtra + 1) * $lthickness}] \
@@ -858,7 +859,7 @@ proc drawcommitline {level} {
859 set mainline($id) [trimdiagstart $mainline($id)]
860 }
861 }
861 - drawlines $id 0
862 + drawlines $id 0 0
863 set orad [expr {$linespc / 3}]
864 set t [$canv create oval [expr $x - $orad] [expr $y1 - $orad] \
865 [expr $x + $orad - 1] [expr $y1 + $orad - 1] \
@@ -878,6 +879,7 @@ proc drawcommitline {level} {
879 set headline [lindex $commitinfo($id) 0]
880 set name [lindex $commitinfo($id) 1]
881 set date [lindex $commitinfo($id) 2]
882 + set date [formatdate $date]
883 set linehtag($lineno) [$canv create text $xt $y1 -anchor w \
884 -text $headline -font $mainfont ]
885 $canv bind $linehtag($lineno) <Button-3> "rowmenu %X %Y $id"
@@ -1446,8 +1448,8 @@ proc decidenext {{noread 0}} {
1448 }
1449
1450 proc drawcommit {id} {
1449 - global phase todo nchildren datemode nextupdate
1450 - global numcommits ncmupdate displayorder todo onscreen
1451 + global phase todo nchildren datemode nextupdate revlistorder
1452 + global numcommits ncmupdate displayorder todo onscreen parents
1453
1454 if {$phase != "incrdraw"} {
1455 set phase incrdraw
@@ -1459,19 +1461,29 @@ proc drawcommit {id} {
1461 lappend todo $id
1462 set onscreen($id) 0
1463 }
1462 - set level [decidenext 1]
1463 - if {$level == {} || $id != [lindex $todo $level]} {
1464 - return
1465 - }
1466 - while 1 {
1467 - lappend displayorder [lindex $todo $level]
1468 - if {[updatetodo $level $datemode]} {
1469 - set level [decidenext 1]
1470 - if {$level == {}} break
1464 + if {$revlistorder} {
1465 + set level [lsearch -exact $todo $id]
1466 + if {$level < 0} {
1467 + error_popup "oops, $id isn't in todo"
1468 + return
1469 }
1472 - set id [lindex $todo $level]
1473 - if {![info exists commitlisted($id)]} {
1474 - break
1470 + lappend displayorder $id
1471 + updatetodo $level 0
1472 + } else {
1473 + set level [decidenext 1]
1474 + if {$level == {} || $id != [lindex $todo $level]} {
1475 + return
1476 + }
1477 + while 1 {
1478 + lappend displayorder [lindex $todo $level]
1479 + if {[updatetodo $level $datemode]} {
1480 + set level [decidenext 1]
1481 + if {$level == {}} break
1482 + }
1483 + set id [lindex $todo $level]
1484 + if {![info exists commitlisted($id)]} {
1485 + break
1486 + }
1487 }
1488 }
1489 drawmore 1
@@ -1523,21 +1535,23 @@ proc drawrest {} {
1535 global phase stopped redisplaying selectedline
1536 global datemode todo displayorder
1537 global numcommits ncmupdate
1526 - global nextupdate startmsecs
1527 -
1528 - set level [decidenext]
1529 - if {$level >= 0} {
1530 - set phase drawgraph
1531 - while 1 {
1532 - lappend displayorder [lindex $todo $level]
1533 - set hard [updatetodo $level $datemode]
1534 - if {$hard} {
1535 - set level [decidenext]
1536 - if {$level < 0} break
1538 + global nextupdate startmsecs revlistorder
1539 +
1540 + if {!$revlistorder} {
1541 + set level [decidenext]
1542 + if {$level >= 0} {
1543 + set phase drawgraph
1544 + while 1 {
1545 + lappend displayorder [lindex $todo $level]
1546 + set hard [updatetodo $level $datemode]
1547 + if {$hard} {
1548 + set level [decidenext]
1549 + if {$level < 0} break
1550 + }
1551 }
1552 }
1539 - drawmore 0
1553 }
1554 + drawmore 0
1555 set phase {}
1556 set drawmsecs [expr [clock clicks -milliseconds] - $startmsecs]
1557 #puts "overall $drawmsecs ms for $numcommits commits"
@@ -2146,8 +2160,10 @@ proc selectline {l isnew} {
2160 $ctext mark set fmark.0 0.0
2161 $ctext mark gravity fmark.0 left
2162 set info $commitinfo($id)
2149 - $ctext insert end "Author: [lindex $info 1] [lindex $info 2]\n"
2150 - $ctext insert end "Committer: [lindex $info 3] [lindex $info 4]\n"
2163 + set date [formatdate [lindex $info 2]]
2164 + $ctext insert end "Author: [lindex $info 1] $date\n"
2165 + set date [formatdate [lindex $info 4]]
2166 + $ctext insert end "Committer: [lindex $info 3] $date\n"
2167 if {[info exists idtags($id)]} {
2168 $ctext insert end "Tags:"
2169 foreach tag $idtags($id) {
@@ -3226,7 +3242,7 @@ proc lineclick {x y id isnew} {
3242 normalline
3243 $canv delete hover
3244 # draw this line thicker than normal
3229 - drawlines $id 1
3245 + drawlines $id 1 1
3246 set thickerline $id
3247 if {$isnew} {
3248 set ymax [lindex [$canv cget -scrollregion] 3]
@@ -3255,7 +3271,8 @@ proc lineclick {x y id isnew} {
3271 set info $commitinfo($id)
3272 $ctext insert end "\n\t[lindex $info 0]\n"
3273 $ctext insert end "\tAuthor:\t[lindex $info 1]\n"
3258 - $ctext insert end "\tDate:\t[lindex $info 2]\n"
3274 + set date [formatdate [lindex $info 2]]
3275 + $ctext insert end "\tDate:\t$date\n"
3276 if {[info exists children($id)]} {
3277 $ctext insert end "\nChildren:"
3278 set i 0
@@ -3267,7 +3284,8 @@ proc lineclick {x y id isnew} {
3284 $ctext tag bind link$i <1> [list selbyid $child]
3285 $ctext insert end "\n\t[lindex $info 0]"
3286 $ctext insert end "\n\tAuthor:\t[lindex $info 1]"
3270 - $ctext insert end "\n\tDate:\t[lindex $info 2]\n"
3287 + set date [formatdate [lindex $info 2]]
3288 + $ctext insert end "\n\tDate:\t$date\n"
3289 }
3290 }
3291 $ctext conf -state disabled
@@ -3278,7 +3296,7 @@ proc lineclick {x y id isnew} {
3296 proc normalline {} {
3297 global thickerline
3298 if {[info exists thickerline]} {
3281 - drawlines $thickerline 0
3299 + drawlines $thickerline 0 1
3300 unset thickerline
3301 }
3302 }
@@ -3650,6 +3668,20 @@ proc doquit {} {
3668 destroy .
3669 }
3670
3671 +proc formatdate {d} {
3672 + global hours nhours tfd
3673 +
3674 + set hr [expr {$d / 3600}]
3675 + set ms [expr {$d % 3600}]
3676 + if {![info exists hours($hr)]} {
3677 + set hours($hr) [clock format $d -format "%Y-%m-%d %H"]
3678 + set nhours($hr) 0
3679 + }
3680 + incr nhours($hr)
3681 + set minsec [format "%.2d:%.2d" [expr {$ms/60}] [expr {$ms%60}]]
3682 + return "$hours($hr):$minsec"
3683 +}
3684 +
3685 # defaults...
3686 set datemode 0
3687 set boldnames 0
@@ -3662,6 +3694,7 @@ set findmergefiles 0
3694 set gaudydiff 0
3695 set maxgraphpct 50
3696 set maxwidth 16
3697 +set revlistorder 0
3698
3699 set colors {green red blue magenta darkgrey brown orange}
3700
@@ -3678,6 +3711,7 @@ foreach arg $argv {
3711 "^$" { }
3712 "^-b" { set boldnames 1 }
3713 "^-d" { set datemode 1 }
3714 + "^-r" { set revlistorder 1 }
3715 default {
3716 lappend revtreeargs $arg
3717 }