gitk: Add a goto next/previous highlighted commit function
This is invoked by shift-down/shift-up. It relies on a patch to git-diff-tree that has recently gone into the git repository, commit ID e0c97ca6 (without this it may just sit there doing waiting for git-diff-tree when looking for the next/previous highlight). Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
May 30, 2006 at 21:33 UTC
4e7d677949e8ee7617e42f10c1ddf5cd2adee3a1
1 file changed
+144
-52
gitk
+144
-52
@@ -632,6 +632,8 @@ proc makewindow {} {
632
bindkey <End> sellastline
633
bind . <Key-Up> "selnextline -1"
634
bind . <Key-Down> "selnextline 1"
635
+ bind . <Shift-Key-Up> "next_highlight -1"
636
+ bind . <Shift-Key-Down> "next_highlight 1"
637
bindkey <Key-Right> "goforw"
638
bindkey <Key-Left> "goback"
639
bind . <Key-Prior> "selnextpage -1"
@@ -892,6 +894,8 @@ Gitk key bindings:
894
<Ctrl-Down> Scroll commit list down one line
895
<Ctrl-PageUp> Scroll commit list up one page
896
<Ctrl-PageDown> Scroll commit list down one page
897
+<Shift-Up> Move to previous highlighted line
898
+<Shift-Down> Move to next highlighted line
899
<Delete>, b Scroll diff view up one page
900
<Backspace> Scroll diff view up one page
901
<Space> Scroll diff view down one page
@@ -899,11 +903,12 @@ u Scroll diff view up 18 lines
903
d Scroll diff view down 18 lines
904
<Ctrl-F> Find
905
<Ctrl-G> Move to next find hit
902
-<Ctrl-R> Move to previous find hit
906
<Return> Move to next find hit
907
/ Move to next find hit, or redo find
908
? Move to previous find hit
909
f Scroll diff view to next file
910
+<Ctrl-S> Search for next hit in diff view
911
+<Ctrl-R> Search for previous hit in diff view
912
<Ctrl-KP+> Increase font size
913
<Ctrl-plus> Increase font size
914
<Ctrl-KP-> Decrease font size
@@ -1669,8 +1674,9 @@ proc ishighlighted {row} {
1674
}
1675
1676
proc bolden {row font} {
1672
- global canv linehtag selectedline
1677
+ global canv linehtag selectedline boldrows
1678
1679
+ lappend boldrows $row
1680
$canv itemconf $linehtag($row) -font $font
1681
if {[info exists selectedline] && $row == $selectedline} {
1682
$canv delete secsel
@@ -1682,8 +1688,9 @@ proc bolden {row font} {
1688
}
1689
1690
proc bolden_name {row font} {
1685
- global canv2 linentag selectedline
1691
+ global canv2 linentag selectedline boldnamerows
1692
1693
+ lappend boldnamerows $row
1694
$canv2 itemconf $linentag($row) -font $font
1695
if {[info exists selectedline] && $row == $selectedline} {
1696
$canv2 delete secsel
@@ -1694,14 +1701,18 @@ proc bolden_name {row font} {
1701
}
1702
}
1703
1697
-proc unbolden {rows} {
1698
- global mainfont
1704
+proc unbolden {} {
1705
+ global mainfont boldrows
1706
1700
- foreach row $rows {
1707
+ set stillbold {}
1708
+ foreach row $boldrows {
1709
if {![ishighlighted $row]} {
1710
bolden $row $mainfont
1711
+ } else {
1712
+ lappend stillbold $row
1713
}
1714
}
1715
+ set boldrows $stillbold
1716
}
1717
1718
proc addvhighlight {n} {
@@ -1730,11 +1741,8 @@ proc delvhighlight {} {
1741
1742
if {![info exists hlview]} return
1743
unset hlview
1733
- set rows [array names vhighlights]
1734
- if {$rows ne {}} {
1735
- unset vhighlights
1736
- unbolden $rows
1737
- }
1744
+ catch {unset vhighlights}
1745
+ unbolden
1746
}
1747
1748
proc vhighlightmore {} {
@@ -1787,11 +1795,8 @@ proc hfiles_change {name ix op} {
1795
# delete previous highlights
1796
catch {close $filehighlight}
1797
unset filehighlight
1790
- set rows [array names fhighlights]
1791
- if {$rows ne {}} {
1792
- unset fhighlights
1793
- unbolden $rows
1794
- }
1798
+ catch {unset fhighlights}
1799
+ unbolden
1800
unhighlight_filelist
1801
}
1802
set highlight_paths {}
@@ -1817,7 +1822,7 @@ proc makepatterns {l} {
1822
}
1823
1824
proc do_file_hl {serial} {
1820
- global highlight_files filehighlight highlight_paths gdttype
1825
+ global highlight_files filehighlight highlight_paths gdttype fhl_list
1826
1827
if {$gdttype eq "touching paths:"} {
1828
if {[catch {set paths [shellsplit $highlight_files]}]} return
@@ -1831,64 +1836,72 @@ proc do_file_hl {serial} {
1836
set filehighlight [open $cmd r+]
1837
fconfigure $filehighlight -blocking 0
1838
fileevent $filehighlight readable readfhighlight
1839
+ set fhl_list {}
1840
drawvisible
1841
flushhighlights
1842
}
1843
1844
proc flushhighlights {} {
1839
- global filehighlight
1845
+ global filehighlight fhl_list
1846
1847
if {[info exists filehighlight]} {
1848
+ lappend fhl_list {}
1849
puts $filehighlight ""
1850
flush $filehighlight
1851
}
1852
}
1853
1854
proc askfilehighlight {row id} {
1848
- global filehighlight fhighlights
1855
+ global filehighlight fhighlights fhl_list
1856
1850
- set fhighlights($row) 0
1857
+ lappend fhl_list $id
1858
+ set fhighlights($row) -1
1859
puts $filehighlight $id
1860
}
1861
1862
proc readfhighlight {} {
1863
global filehighlight fhighlights commitrow curview mainfont iddrawn
1856
-
1857
- set n [gets $filehighlight line]
1858
- if {$n < 0} {
1859
- if {[eof $filehighlight]} {
1860
- # strange...
1861
- puts "oops, git-diff-tree died"
1862
- catch {close $filehighlight}
1863
- unset filehighlight
1864
+ global fhl_list
1865
+
1866
+ while {[gets $filehighlight line] >= 0} {
1867
+ set line [string trim $line]
1868
+ set i [lsearch -exact $fhl_list $line]
1869
+ if {$i < 0} continue
1870
+ for {set j 0} {$j < $i} {incr j} {
1871
+ set id [lindex $fhl_list $j]
1872
+ if {[info exists commitrow($curview,$id)]} {
1873
+ set fhighlights($commitrow($curview,$id)) 0
1874
+ }
1875
}
1865
- return
1876
+ set fhl_list [lrange $fhl_list [expr {$i+1}] end]
1877
+ if {$line eq {}} continue
1878
+ if {![info exists commitrow($curview,$line)]} continue
1879
+ set row $commitrow($curview,$line)
1880
+ if {[info exists iddrawn($line)] && ![ishighlighted $row]} {
1881
+ bolden $row [concat $mainfont bold]
1882
+ }
1883
+ set fhighlights($row) 1
1884
}
1867
- set line [string trim $line]
1868
- if {$line eq {}} return
1869
- if {![info exists commitrow($curview,$line)]} return
1870
- set row $commitrow($curview,$line)
1871
- if {[info exists iddrawn($line)] && ![ishighlighted $row]} {
1872
- bolden $row [concat $mainfont bold]
1885
+ if {[eof $filehighlight]} {
1886
+ # strange...
1887
+ puts "oops, git-diff-tree died"
1888
+ catch {close $filehighlight}
1889
+ unset filehighlight
1890
}
1874
- set fhighlights($row) 1
1891
+ next_hlcont
1892
}
1893
1894
proc find_change {name ix op} {
1878
- global nhighlights mainfont
1895
+ global nhighlights mainfont boldnamerows
1896
global findstring findpattern findtype
1897
1898
# delete previous highlights, if any
1882
- set rows [array names nhighlights]
1883
- if {$rows ne {}} {
1884
- foreach row $rows {
1885
- if {$nhighlights($row) >= 2} {
1886
- bolden_name $row $mainfont
1887
- }
1888
- }
1889
- unset nhighlights
1890
- unbolden $rows
1899
+ foreach row $boldnamerows {
1900
+ bolden_name $row $mainfont
1901
}
1902
+ set boldnamerows {}
1903
+ catch {unset nhighlights}
1904
+ unbolden
1905
if {$findtype ne "Regexp"} {
1906
set e [string map {"*" "\\*" "?" "\\?" "\[" "\\\[" "\\" "\\\\"} \
1907
$findstring]
@@ -1964,11 +1977,8 @@ proc rhighlight_sel {a} {
1977
proc rhighlight_none {} {
1978
global rhighlights
1979
1967
- set rows [array names rhighlights]
1968
- if {$rows ne {}} {
1969
- unset rhighlights
1970
- unbolden $rows
1971
- }
1980
+ catch {unset rhighlights}
1981
+ unbolden
1982
}
1983
1984
proc is_descendent {a} {
@@ -2066,6 +2076,81 @@ proc askrelhighlight {row id} {
2076
set rhighlights($row) $isbold
2077
}
2078
2079
+proc next_hlcont {} {
2080
+ global fhl_row fhl_dirn displayorder numcommits
2081
+ global vhighlights fhighlights nhighlights rhighlights
2082
+ global hlview filehighlight findstring highlight_related
2083
+
2084
+ if {![info exists fhl_dirn] || $fhl_dirn == 0} return
2085
+ set row $fhl_row
2086
+ while {1} {
2087
+ if {$row < 0 || $row >= $numcommits} {
2088
+ bell
2089
+ set fhl_dirn 0
2090
+ return
2091
+ }
2092
+ set id [lindex $displayorder $row]
2093
+ if {[info exists hlview]} {
2094
+ if {![info exists vhighlights($row)]} {
2095
+ askvhighlight $row $id
2096
+ }
2097
+ if {$vhighlights($row) > 0} break
2098
+ }
2099
+ if {$findstring ne {}} {
2100
+ if {![info exists nhighlights($row)]} {
2101
+ askfindhighlight $row $id
2102
+ }
2103
+ if {$nhighlights($row) > 0} break
2104
+ }
2105
+ if {$highlight_related ne "None"} {
2106
+ if {![info exists rhighlights($row)]} {
2107
+ askrelhighlight $row $id
2108
+ }
2109
+ if {$rhighlights($row) > 0} break
2110
+ }
2111
+ if {[info exists filehighlight]} {
2112
+ if {![info exists fhighlights($row)]} {
2113
+ # ask for a few more while we're at it...
2114
+ set r $row
2115
+ for {set n 0} {$n < 100} {incr n} {
2116
+ if {![info exists fhighlights($r)]} {
2117
+ askfilehighlight $r [lindex $displayorder $r]
2118
+ }
2119
+ incr r $fhl_dirn
2120
+ if {$r < 0 || $r >= $numcommits} break
2121
+ }
2122
+ flushhighlights
2123
+ }
2124
+ if {$fhighlights($row) < 0} {
2125
+ set fhl_row $row
2126
+ return
2127
+ }
2128
+ if {$fhighlights($row) > 0} break
2129
+ }
2130
+ incr row $fhl_dirn
2131
+ }
2132
+ set fhl_dirn 0
2133
+ selectline $row 1
2134
+}
2135
+
2136
+proc next_highlight {dirn} {
2137
+ global selectedline fhl_row fhl_dirn
2138
+ global hlview filehighlight findstring highlight_related
2139
+
2140
+ if {![info exists selectedline]} return
2141
+ if {!([info exists hlview] || $findstring ne {} ||
2142
+ $highlight_related ne "None" || [info exists filehighlight])} return
2143
+ set fhl_row [expr {$selectedline + $dirn}]
2144
+ set fhl_dirn $dirn
2145
+ next_hlcont
2146
+}
2147
+
2148
+proc cancel_next_highlight {} {
2149
+ global fhl_dirn
2150
+
2151
+ set fhl_dirn 0
2152
+}
2153
+
2154
# Graph layout functions
2155
2156
proc shortids {ids} {
@@ -2785,7 +2870,7 @@ proc drawcmittext {id row col rmx} {
2870
global commitlisted commitinfo rowidlist
2871
global rowtextx idpos idtags idheads idotherrefs
2872
global linehtag linentag linedtag
2788
- global mainfont canvxmax
2873
+ global mainfont canvxmax boldrows boldnamerows
2874
2875
set ofill [expr {[lindex $commitlisted $row]? "blue": "white"}]
2876
set x [xc $row $col]
@@ -2814,8 +2899,10 @@ proc drawcmittext {id row col rmx} {
2899
set nfont $mainfont
2900
set isbold [ishighlighted $row]
2901
if {$isbold > 0} {
2902
+ lappend boldrows $row
2903
lappend font bold
2904
if {$isbold > 1} {
2905
+ lappend boldnamerows $row
2906
lappend nfont bold
2907
}
2908
}
@@ -3232,6 +3319,7 @@ proc dofind {} {
3319
3320
stopfindproc
3321
unmarkmatches
3322
+ cancel_next_highlight
3323
focus .
3324
set matchinglines {}
3325
if {$findtype == "IgnCase"} {
@@ -3490,6 +3578,7 @@ proc selectline {l isnew} {
3578
catch {unset pending_select}
3579
$canv delete hover
3580
normalline
3581
+ cancel_next_highlight
3582
if {$l < 0 || $l >= $numcommits} return
3583
set y [expr {$canvy0 + $l * $linespc}]
3584
set ymax [lindex [$canv cget -scrollregion] 3]
@@ -3662,6 +3751,7 @@ proc unselectline {} {
3751
catch {unset currentid}
3752
allcanvs delete secsel
3753
rhighlight_none
3754
+ cancel_next_highlight
3755
}
3756
3757
proc reselectline {} {
@@ -5290,6 +5380,8 @@ set fh_serial 0
5380
set nhl_names {}
5381
set highlight_paths {}
5382
set searchdirn -forwards
5383
+set boldrows {}
5384
+set boldnamerows {}
5385
5386
set optim_delay 16
5387