@matheusbsbs / matheus-bagliano / commits / 164ff275ad
Fork 0

gitk: Provide ability to highlight based on relationship to selected commit

This provides a way to highlight commits that are, or are not, descendents or ancestors of the currently selected commit. It's still rough around the edges but seems to be useful even so. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed May 29, 2006 at 19:50 UTC 164ff275adf2e212ef21632c21eef191a1c7420d
1 file changed +150 -2
gitk
+150 -2
@@ -538,6 +538,15 @@ proc makewindow {} {
538 $viewhlmenu conf -font $uifont
539 .ctop.top.lbar.vhl conf -font $uifont
540 pack .ctop.top.lbar.vhl -side left -fill y
541 + label .ctop.top.lbar.rlabel -text " OR " -font $uifont
542 + pack .ctop.top.lbar.rlabel -side left -fill y
543 + global highlight_related
544 + set m [tk_optionMenu .ctop.top.lbar.relm highlight_related None \
545 + "Descendent" "Not descendent" "Ancestor" "Not ancestor"]
546 + $m conf -font $uifont
547 + .ctop.top.lbar.relm conf -font $uifont
548 + trace add variable highlight_related write vrel_change
549 + pack .ctop.top.lbar.relm -side left -fill y
550
551 panedwindow .ctop.cdet -orient horizontal
552 .ctop add .ctop.cdet
@@ -1642,7 +1651,7 @@ proc showview {n} {
1651 # Stuff relating to the highlighting facility
1652
1653 proc ishighlighted {row} {
1645 - global vhighlights fhighlights nhighlights
1654 + global vhighlights fhighlights nhighlights rhighlights
1655
1656 if {[info exists nhighlights($row)] && $nhighlights($row) > 0} {
1657 return $nhighlights($row)
@@ -1653,6 +1662,9 @@ proc ishighlighted {row} {
1662 if {[info exists fhighlights($row)] && $fhighlights($row) > 0} {
1663 return $fhighlights($row)
1664 }
1665 + if {[info exists rhighlights($row)] && $rhighlights($row) > 0} {
1666 + return $rhighlights($row)
1667 + }
1668 return 0
1669 }
1670
@@ -1925,6 +1937,135 @@ proc askfindhighlight {row id} {
1937 set nhighlights($row) $isbold
1938 }
1939
1940 +proc vrel_change {name ix op} {
1941 + global highlight_related
1942 +
1943 + rhighlight_none
1944 + if {$highlight_related ne "None"} {
1945 + after idle drawvisible
1946 + }
1947 +}
1948 +
1949 +# prepare for testing whether commits are descendents or ancestors of a
1950 +proc rhighlight_sel {a} {
1951 + global descendent desc_todo ancestor anc_todo
1952 + global highlight_related rhighlights
1953 +
1954 + catch {unset descendent}
1955 + set desc_todo [list $a]
1956 + catch {unset ancestor}
1957 + set anc_todo [list $a]
1958 + if {$highlight_related ne "None"} {
1959 + rhighlight_none
1960 + after idle drawvisible
1961 + }
1962 +}
1963 +
1964 +proc rhighlight_none {} {
1965 + global rhighlights
1966 +
1967 + set rows [array names rhighlights]
1968 + if {$rows ne {}} {
1969 + unset rhighlights
1970 + unbolden $rows
1971 + }
1972 +}
1973 +
1974 +proc is_descendent {a} {
1975 + global curview children commitrow descendent desc_todo
1976 +
1977 + set v $curview
1978 + set la $commitrow($v,$a)
1979 + set todo $desc_todo
1980 + set leftover {}
1981 + set done 0
1982 + for {set i 0} {$i < [llength $todo]} {incr i} {
1983 + set do [lindex $todo $i]
1984 + if {$commitrow($v,$do) < $la} {
1985 + lappend leftover $do
1986 + continue
1987 + }
1988 + foreach nk $children($v,$do) {
1989 + if {![info exists descendent($nk)]} {
1990 + set descendent($nk) 1
1991 + lappend todo $nk
1992 + if {$nk eq $a} {
1993 + set done 1
1994 + }
1995 + }
1996 + }
1997 + if {$done} {
1998 + set desc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
1999 + return
2000 + }
2001 + }
2002 + set descendent($a) 0
2003 + set desc_todo $leftover
2004 +}
2005 +
2006 +proc is_ancestor {a} {
2007 + global curview parentlist commitrow ancestor anc_todo
2008 +
2009 + set v $curview
2010 + set la $commitrow($v,$a)
2011 + set todo $anc_todo
2012 + set leftover {}
2013 + set done 0
2014 + for {set i 0} {$i < [llength $todo]} {incr i} {
2015 + set do [lindex $todo $i]
2016 + if {![info exists commitrow($v,$do)] || $commitrow($v,$do) > $la} {
2017 + lappend leftover $do
2018 + continue
2019 + }
2020 + foreach np [lindex $parentlist $commitrow($v,$do)] {
2021 + if {![info exists ancestor($np)]} {
2022 + set ancestor($np) 1
2023 + lappend todo $np
2024 + if {$np eq $a} {
2025 + set done 1
2026 + }
2027 + }
2028 + }
2029 + if {$done} {
2030 + set anc_todo [concat $leftover [lrange $todo [expr {$i+1}] end]]
2031 + return
2032 + }
2033 + }
2034 + set ancestor($a) 0
2035 + set anc_todo $leftover
2036 +}
2037 +
2038 +proc askrelhighlight {row id} {
2039 + global descendent highlight_related iddrawn mainfont rhighlights
2040 + global selectedline ancestor
2041 +
2042 + if {![info exists selectedline]} return
2043 + set isbold 0
2044 + if {$highlight_related eq "Descendent" ||
2045 + $highlight_related eq "Not descendent"} {
2046 + if {![info exists descendent($id)]} {
2047 + is_descendent $id
2048 + }
2049 + if {$descendent($id) == ($highlight_related eq "Descendent")} {
2050 + set isbold 1
2051 + }
2052 + } elseif {$highlight_related eq "Ancestor" ||
2053 + $highlight_related eq "Not ancestor"} {
2054 + if {![info exists ancestor($id)]} {
2055 + is_ancestor $id
2056 + }
2057 + if {$ancestor($id) == ($highlight_related eq "Ancestor")} {
2058 + set isbold 1
2059 + }
2060 + }
2061 + if {[info exists iddrawn($id)]} {
2062 + if {$isbold && ![ishighlighted $row]} {
2063 + bolden $row [concat $mainfont bold]
2064 + }
2065 + }
2066 + set rhighlights($row) $isbold
2067 +}
2068 +
2069 # Graph layout functions
2070
2071 proc shortids {ids} {
@@ -2698,6 +2839,7 @@ proc drawcmitrow {row} {
2839 global commitinfo parentlist numcommits
2840 global filehighlight fhighlights findstring nhighlights
2841 global hlview vhighlights
2842 + global highlight_related rhighlights
2843
2844 if {$row >= $numcommits} return
2845 foreach id [lindex $rowidlist $row] {
@@ -2727,6 +2869,9 @@ proc drawcmitrow {row} {
2869 if {$findstring ne {} && ![info exists nhighlights($row)]} {
2870 askfindhighlight $row $id
2871 }
2872 + if {$highlight_related ne "None" && ![info exists rhighlights($row)]} {
2873 + askrelhighlight $row $id
2874 + }
2875 if {[info exists iddrawn($id)]} return
2876 set col [lsearch -exact [lindex $rowidlist $row] $id]
2877 if {$col < 0} {
@@ -2775,7 +2920,7 @@ proc drawvisible {} {
2920
2921 proc clear_display {} {
2922 global iddrawn idrangedrawn
2778 - global vhighlights fhighlights nhighlights
2923 + global vhighlights fhighlights nhighlights rhighlights
2924
2925 allcanvs delete all
2926 catch {unset iddrawn}
@@ -2783,6 +2928,7 @@ proc clear_display {} {
2928 catch {unset vhighlights}
2929 catch {unset fhighlights}
2930 catch {unset nhighlights}
2931 + catch {unset rhighlights}
2932 }
2933
2934 proc findcrossings {id} {
@@ -3407,6 +3553,7 @@ proc selectline {l isnew} {
3553 $sha1entry insert 0 $id
3554 $sha1entry selection from 0
3555 $sha1entry selection to end
3556 + rhighlight_sel $id
3557
3558 $ctext conf -state normal
3559 clear_ctext
@@ -3514,6 +3661,7 @@ proc unselectline {} {
3661 catch {unset selectedline}
3662 catch {unset currentid}
3663 allcanvs delete secsel
3664 + rhighlight_none
3665 }
3666
3667 proc reselectline {} {