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

gitk: Add a way to mark a commit, plus a "find descendant" command

This adds a context-menu command to put a mark on this commit. There is at most one marked commit at any time, and it is indicated by a box drawn around the headline. Once a commit is marked, two other context-menu commands become available: one to select the marked commit, and another to find the closest common descendant of this commit and the marked commit. The "find common descendant" command uses the displayed parent/child relationships (i.e. the rewritten parent pointers produced by git log), not the real parent/child relationships. Currently the UI will be unresponsive while gitk is working out the nearest common descendant; this should be improved in future. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Apr 9, 2009 at 09:34 UTC b9fdba7ff87d2e032df00508d06e586c17ea8216
1 file changed +87 -4
gitk
+87 -4
@@ -2359,6 +2359,9 @@ proc makewindow {} {
2359 {mc "Create new branch" command mkbranch}
2360 {mc "Cherry-pick this commit" command cherrypick}
2361 {mc "Reset HEAD branch to here" command resethead}
2362 + {mc "Mark this commit" command markhere}
2363 + {mc "Return to mark" command gotomark}
2364 + {mc "Find descendant of this and mark" command find_common_desc}
2365 }
2366 $rowctxmenu configure -tearoff 0
2367
@@ -4074,7 +4077,7 @@ proc ishighlighted {id} {
4077 }
4078
4079 proc bolden {id font} {
4077 - global canv linehtag currentid boldids need_redisplay
4080 + global canv linehtag currentid boldids need_redisplay markedid
4081
4082 # need_redisplay = 1 means the display is stale and about to be redrawn
4083 if {$need_redisplay} return
@@ -4087,6 +4090,9 @@ proc bolden {id font} {
4090 -fill [$canv cget -selectbackground]]
4091 $canv lower $t
4092 }
4093 + if {[info exists markedid] && $id eq $markedid} {
4094 + make_idmark $id
4095 + }
4096 }
4097
4098 proc bolden_name {id font} {
@@ -5591,7 +5597,7 @@ proc drawcmittext {id row col} {
5597 global cmitlisted commitinfo rowidlist parentlist
5598 global rowtextx idpos idtags idheads idotherrefs
5599 global linehtag linentag linedtag selectedline
5594 - global canvxmax boldids boldnameids fgcolor
5600 + global canvxmax boldids boldnameids fgcolor markedid
5601 global mainheadid nullid nullid2 circleitem circlecolors ctxbut
5602
5603 # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right
@@ -5673,6 +5679,9 @@ proc drawcmittext {id row col} {
5679 if {$selectedline == $row} {
5680 make_secsel $id
5681 }
5682 + if {[info exists markedid] && $markedid eq $id} {
5683 + make_idmark $id
5684 + }
5685 set xr [expr {$xt + [font measure $font $headline]}]
5686 if {$xr > $canvxmax} {
5687 set canvxmax $xr
@@ -6614,6 +6623,16 @@ proc make_secsel {id} {
6623 $canv3 lower $t
6624 }
6625
6626 +proc make_idmark {id} {
6627 + global linehtag canv fgcolor
6628 +
6629 + if {![info exists linehtag($id)]} return
6630 + $canv delete markid
6631 + set t [eval $canv create rect [$canv bbox $linehtag($id)] \
6632 + -tags markid -outline $fgcolor]
6633 + $canv raise $t
6634 +}
6635 +
6636 proc selectline {l isnew {desired_loc {}}} {
6637 global canv ctext commitinfo selectedline
6638 global canvy0 linespc parents children curview
@@ -7999,7 +8018,7 @@ proc mstime {} {
8018
8019 proc rowmenu {x y id} {
8020 global rowctxmenu selectedline rowmenuid curview
8002 - global nullid nullid2 fakerowmenu mainhead
8021 + global nullid nullid2 fakerowmenu mainhead markedid
8022
8023 stopfinding
8024 set rowmenuid $id
@@ -8015,6 +8034,13 @@ proc rowmenu {x y id} {
8034 } else {
8035 $menu entryconfigure 7 -label [mc "Detached head: can't reset" $mainhead] -state disabled
8036 }
8037 + if {[info exists markedid] && $markedid ne $id} {
8038 + $menu entryconfigure 9 -state normal
8039 + $menu entryconfigure 10 -state normal
8040 + } else {
8041 + $menu entryconfigure 9 -state disabled
8042 + $menu entryconfigure 10 -state disabled
8043 + }
8044 } else {
8045 set menu $fakerowmenu
8046 }
@@ -8024,6 +8050,59 @@ proc rowmenu {x y id} {
8050 tk_popup $menu $x $y
8051 }
8052
8053 +proc markhere {} {
8054 + global rowmenuid markedid canv
8055 +
8056 + set markedid $rowmenuid
8057 + make_idmark $markedid
8058 +}
8059 +
8060 +proc gotomark {} {
8061 + global markedid
8062 +
8063 + if {[info exists markedid]} {
8064 + selbyid $markedid
8065 + }
8066 +}
8067 +
8068 +proc replace_by_kids {l r} {
8069 + global curview children
8070 +
8071 + set id [commitonrow $r]
8072 + set l [lreplace $l 0 0]
8073 + foreach kid $children($curview,$id) {
8074 + lappend l [rowofcommit $kid]
8075 + }
8076 + return [lsort -integer -decreasing -unique $l]
8077 +}
8078 +
8079 +proc find_common_desc {} {
8080 + global markedid rowmenuid curview children
8081 +
8082 + if {![info exists markedid]} return
8083 + if {![commitinview $markedid $curview] ||
8084 + ![commitinview $rowmenuid $curview]} return
8085 + #set t1 [clock clicks -milliseconds]
8086 + set l1 [list [rowofcommit $markedid]]
8087 + set l2 [list [rowofcommit $rowmenuid]]
8088 + while 1 {
8089 + set r1 [lindex $l1 0]
8090 + set r2 [lindex $l2 0]
8091 + if {$r1 eq {} || $r2 eq {}} break
8092 + if {$r1 == $r2} {
8093 + selectline $r1 1
8094 + break
8095 + }
8096 + if {$r1 > $r2} {
8097 + set l1 [replace_by_kids $l1 $r1]
8098 + } else {
8099 + set l2 [replace_by_kids $l2 $r2]
8100 + }
8101 + }
8102 + #set t2 [clock clicks -milliseconds]
8103 + #puts "took [expr {$t2-$t1}]ms"
8104 +}
8105 +
8106 proc diffvssel {dirn} {
8107 global rowmenuid selectedline
8108
@@ -8218,7 +8297,7 @@ proc domktag {} {
8297 }
8298
8299 proc redrawtags {id} {
8221 - global canv linehtag idpos currentid curview cmitlisted
8300 + global canv linehtag idpos currentid curview cmitlisted markedid
8301 global canvxmax iddrawn circleitem mainheadid circlecolors
8302
8303 if {![commitinview $id $curview]} return
@@ -8243,6 +8322,9 @@ proc redrawtags {id} {
8322 if {[info exists currentid] && $currentid == $id} {
8323 make_secsel $id
8324 }
8325 + if {[info exists markedid] && $markedid eq $id} {
8326 + make_idmark $id
8327 + }
8328 }
8329
8330 proc mktagcan {} {
@@ -10269,6 +10351,7 @@ proc setfg {c} {
10351 }
10352 allcanvs itemconf text -fill $c
10353 $canv itemconf circle -outline $c
10354 + $canv itemconf markid -outline $c
10355 }
10356
10357 proc prefscan {} {