@matheusbsbs / matheus-bagliano / commits / c961b228bc
Fork 0

gitk: Use git log and add support for --left-right

This is based on patches from Linus Torvalds and Junio Hamano, so the ideas here are theirs. This makes gitk use "git log -z --pretty=raw" instead of "git rev-list" to generate the list of commits, and also makes it grok the "<" and ">" markers that git log (and git rev-list) output with the --left-right flag to indicate which side of a symmetric diff a commit is reachable from. Left-side commits are drawn with a triangle pointing leftwards instead of a circle, and right-side commits are drawn with a triangle pointing rightwards. The commitlisted list is used to store the left/right information as well as the information about whether each commit is on the boundary. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Jul 9, 2007 at 22:45 UTC c961b228bcab390a1b42d517b6ed5a1edb55efed
1 file changed +34 -12
gitk
+34 -12
@@ -96,8 +96,8 @@ proc start_rev_list {view} {
96 set order "--date-order"
97 }
98 if {[catch {
99 - set fd [open [concat | git rev-list --header $order \
100 - --parents --boundary --default HEAD $args] r]
99 + set fd [open [concat | git log -z --pretty=raw $order \
100 + --parents --boundary $args] r]
101 } err]} {
102 puts stderr "Error executing git rev-list: $err"
103 exit 1
@@ -194,10 +194,14 @@ proc getcommitlines {fd view} {
194 set j [string first "\n" $cmit]
195 set ok 0
196 set listed 1
197 - if {$j >= 0} {
198 - set ids [string range $cmit 0 [expr {$j - 1}]]
199 - if {[string range $ids 0 0] == "-"} {
200 - set listed 0
197 + if {$j >= 0 && [string match "commit *" $cmit]} {
198 + set ids [string range $cmit 7 [expr {$j - 1}]]
199 + if {[string match {[-<>]*} $ids]} {
200 + switch -- [string index $ids 0] {
201 + "-" {set listed 0}
202 + "<" {set listed 2}
203 + ">" {set listed 3}
204 + }
205 set ids [string range $ids 1 end]
206 }
207 set ok 1
@@ -213,7 +217,7 @@ proc getcommitlines {fd view} {
217 if {[string length $shortcmit] > 80} {
218 set shortcmit "[string range $shortcmit 0 80]..."
219 }
216 - error_popup "Can't parse git rev-list output: {$shortcmit}"
220 + error_popup "Can't parse git log output: {$shortcmit}"
221 exit 1
222 }
223 set id [lindex $ids 0]
@@ -3334,23 +3338,41 @@ proc drawlines {id} {
3338 }
3339
3340 proc drawcmittext {id row col} {
3337 - global linespc canv canv2 canv3 canvy0 fgcolor
3341 + global linespc canv canv2 canv3 canvy0 fgcolor curview
3342 global commitlisted commitinfo rowidlist parentlist
3343 global rowtextx idpos idtags idheads idotherrefs
3344 global linehtag linentag linedtag markingmatches
3345 global mainfont canvxmax boldrows boldnamerows fgcolor nullid
3346
3347 + # listed is 0 for boundary, 1 for normal, 2 for left, 3 for right
3348 + set listed [lindex $commitlisted $row]
3349 if {$id eq $nullid} {
3350 set ofill red
3351 } else {
3346 - set ofill [expr {[lindex $commitlisted $row]? "blue": "white"}]
3352 + set ofill [expr {$listed != 0? "blue": "white"}]
3353 }
3354 set x [xc $row $col]
3355 set y [yc $row]
3356 set orad [expr {$linespc / 3}]
3351 - set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
3352 - [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
3353 - -fill $ofill -outline $fgcolor -width 1 -tags circle]
3357 + if {$listed <= 1} {
3358 + set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
3359 + [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
3360 + -fill $ofill -outline $fgcolor -width 1 -tags circle]
3361 + } elseif {$listed == 2} {
3362 + # triangle pointing left for left-side commits
3363 + set t [$canv create polygon \
3364 + [expr {$x - $orad}] $y \
3365 + [expr {$x + $orad - 1}] [expr {$y - $orad}] \
3366 + [expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
3367 + -fill $ofill -outline $fgcolor -width 1 -tags circle]
3368 + } else {
3369 + # triangle pointing right for right-side commits
3370 + set t [$canv create polygon \
3371 + [expr {$x + $orad - 1}] $y \
3372 + [expr {$x - $orad}] [expr {$y - $orad}] \
3373 + [expr {$x - $orad}] [expr {$y + $orad - 1}] \
3374 + -fill $ofill -outline $fgcolor -width 1 -tags circle]
3375 + }
3376 $canv raise $t
3377 $canv bind $t <1> {selcanvline {} %x %y}
3378 set rmx [llength [lindex $rowidlist $row]]