gitk: Make a row of controls for controlling highlighting
Now there is a bar across the middle (just below the bar containing the sha1 ID, find string etc.) which controls highlighting. There are three ways to highlight: the user can highlight commits affecting a list of paths, commits in a view, or commits where the author or committer matches any of a list of strings (case-insensitive). The elements of the list of paths and list of names are delimited by whitespace with shell quoting rules. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
May 20, 2006 at 09:38 UTC
908c35850a9aed6efd1a6a616e594a28467230fa
1 file changed
+298
-67
gitk
+298
-67
@@ -187,7 +187,7 @@ proc getcommitlines {fd view} {
187
if {$view == $curview} {
188
layoutmore
189
} elseif {[info exists hlview] && $view == $hlview} {
190
- highlightmore
190
+ vhighlightmore
191
}
192
}
193
if {[clock clicks -milliseconds] >= $nextupdate} {
@@ -223,7 +223,7 @@ proc readcommit {id} {
223
224
proc updatecommits {} {
225
global viewdata curview phase displayorder
226
- global children commitrow
226
+ global children commitrow selectedline thickerline
227
228
if {$phase ne {}} {
229
stop_rev_list
@@ -235,6 +235,8 @@ proc updatecommits {} {
235
catch {unset commitrow($n,$id)}
236
}
237
set curview -1
238
+ catch {unset selectedline}
239
+ catch {unset thickerline}
240
catch {unset viewdata($n)}
241
readrefs
242
showview $n
@@ -381,6 +383,7 @@ proc makewindow {} {
383
global entries sha1entry sha1string sha1but
384
global maincursor textcursor curtextcursor
385
global rowctxmenu mergemax
386
+ global highlight_files highlight_names
387
388
menu .bar
389
.bar add cascade -label "File" -menu .bar.file
@@ -396,20 +399,14 @@ proc makewindow {} {
399
.bar.edit configure -font $uifont
400
401
menu .bar.view -font $uifont
399
- menu .bar.view.hl -font $uifont -tearoff 0
402
.bar add cascade -label "View" -menu .bar.view
403
.bar.view add command -label "New view..." -command {newview 0}
404
.bar.view add command -label "Edit view..." -command editview \
405
-state disabled
406
.bar.view add command -label "Delete view" -command delview -state disabled
405
- .bar.view add cascade -label "Highlight" -menu .bar.view.hl
407
.bar.view add separator
408
.bar.view add radiobutton -label "All files" -command {showview 0} \
409
-variable selectedview -value 0
409
- .bar.view.hl add command -label "New view..." -command {newview 1}
410
- .bar.view.hl add command -label "Remove" -command delhighlight \
411
- -state disabled
412
- .bar.view.hl add separator
410
411
menu .bar.help
412
.bar add cascade -label "Help" -menu .bar.help
@@ -436,6 +433,8 @@ proc makewindow {} {
433
}
434
frame .ctop.top
435
frame .ctop.top.bar
436
+ frame .ctop.top.lbar
437
+ pack .ctop.top.lbar -side bottom -fill x
438
pack .ctop.top.bar -side bottom -fill x
439
set cscroll .ctop.top.csb
440
scrollbar $cscroll -command {allcanvs yview} -highlightthickness 0
@@ -497,7 +496,7 @@ proc makewindow {} {
496
set findstring {}
497
set fstring .ctop.top.bar.findstring
498
lappend entries $fstring
500
- entry $fstring -width 30 -font $textfont -textvariable findstring -font $textfont
499
+ entry $fstring -width 30 -font $textfont -textvariable findstring
500
pack $fstring -side left -expand 1 -fill x
501
set findtype Exact
502
set findtypemenu [tk_optionMenu .ctop.top.bar.findtype \
@@ -515,6 +514,29 @@ proc makewindow {} {
514
# for making sure type==Exact whenever loc==Pickaxe
515
trace add variable findloc write findlocchange
516
517
+ label .ctop.top.lbar.flabel -text "Highlight: Commits touching paths:" \
518
+ -font $uifont
519
+ pack .ctop.top.lbar.flabel -side left -fill y
520
+ entry .ctop.top.lbar.fent -width 25 -font $textfont \
521
+ -textvariable highlight_files
522
+ trace add variable highlight_files write hfiles_change
523
+ lappend entries .ctop.top.lbar.fent
524
+ pack .ctop.top.lbar.fent -side left -fill x -expand 1
525
+ label .ctop.top.lbar.vlabel -text " OR in view" -font $uifont
526
+ pack .ctop.top.lbar.vlabel -side left -fill y
527
+ global viewhlmenu selectedhlview
528
+ set viewhlmenu [tk_optionMenu .ctop.top.lbar.vhl selectedhlview None]
529
+ $viewhlmenu entryconf 0 -command delvhighlight
530
+ pack .ctop.top.lbar.vhl -side left -fill y
531
+ label .ctop.top.lbar.alabel -text " OR author/committer:" \
532
+ -font $uifont
533
+ pack .ctop.top.lbar.alabel -side left -fill y
534
+ entry .ctop.top.lbar.aent -width 20 -font $textfont \
535
+ -textvariable highlight_names
536
+ trace add variable highlight_names write hnames_change
537
+ lappend entries .ctop.top.lbar.aent
538
+ pack .ctop.top.lbar.aent -side right -fill x -expand 1
539
+
540
panedwindow .ctop.cdet -orient horizontal
541
.ctop add .ctop.cdet
542
frame .ctop.cdet.left
@@ -664,6 +686,7 @@ proc canvscan {op w x y} {
686
proc scrollcanv {cscroll f0 f1} {
687
$cscroll set $f0 $f1
688
drawfrac $f0 $f1
689
+ flushhighlights
690
}
691
692
# when we make a key binding for the toplevel, make sure
@@ -1313,25 +1336,27 @@ proc vieweditor {top n title} {
1336
focus $top.t
1337
}
1338
1316
-proc doviewmenu {m first cmd op args} {
1339
+proc doviewmenu {m first cmd op argv} {
1340
set nmenu [$m index end]
1341
for {set i $first} {$i <= $nmenu} {incr i} {
1342
if {[$m entrycget $i -command] eq $cmd} {
1320
- eval $m $op $i $args
1343
+ eval $m $op $i $argv
1344
break
1345
}
1346
}
1347
}
1348
1349
proc allviewmenus {n op args} {
1350
+ global viewhlmenu
1351
+
1352
doviewmenu .bar.view 7 [list showview $n] $op $args
1328
- doviewmenu .bar.view.hl 3 [list addhighlight $n] $op $args
1353
+ doviewmenu $viewhlmenu 1 [list addvhighlight $n] $op $args
1354
}
1355
1356
proc newviewok {top n} {
1357
global nextviewnum newviewperm newviewname newishighlight
1358
global viewname viewfiles viewperm selectedview curview
1334
- global viewargs newviewargs
1359
+ global viewargs newviewargs viewhlmenu
1360
1361
if {[catch {
1362
set newargs [shellsplit $newviewargs($n)]
@@ -1359,14 +1384,17 @@ proc newviewok {top n} {
1384
if {!$newishighlight} {
1385
after idle showview $n
1386
} else {
1362
- after idle addhighlight $n
1387
+ after idle addvhighlight $n
1388
}
1389
} else {
1390
# editing an existing view
1391
set viewperm($n) $newviewperm($n)
1392
if {$newviewname($n) ne $viewname($n)} {
1393
set viewname($n) $newviewname($n)
1369
- allviewmenus $n entryconf -label $viewname($n)
1394
+ doviewmenu .bar.view 7 [list showview $n] \
1395
+ entryconf [list -label $viewname($n)]
1396
+ doviewmenu $viewhlmenu 1 [list addvhighlight $n] \
1397
+ entryconf [list -label $viewname($n) -value $viewname($n)]
1398
}
1399
if {$files ne $viewfiles($n) || $newargs ne $viewargs($n)} {
1400
set viewfiles($n) $files
@@ -1380,9 +1408,13 @@ proc newviewok {top n} {
1408
}
1409
1410
proc delview {} {
1383
- global curview viewdata viewperm
1411
+ global curview viewdata viewperm hlview selectedhlview
1412
1413
if {$curview == 0} return
1414
+ if {[info exists hlview] && $hlview == $curview} {
1415
+ set selectedhlview None
1416
+ unset hlview
1417
+ }
1418
allviewmenus $curview delete
1419
set viewdata($curview) {}
1420
set viewperm($curview) 0
@@ -1390,12 +1422,12 @@ proc delview {} {
1422
}
1423
1424
proc addviewmenu {n} {
1393
- global viewname
1425
+ global viewname viewhlmenu
1426
1427
.bar.view add radiobutton -label $viewname($n) \
1428
-command [list showview $n] -variable selectedview -value $n
1397
- .bar.view.hl add radiobutton -label $viewname($n) \
1398
- -command [list addhighlight $n] -variable selectedhlview -value $n
1429
+ $viewhlmenu add radiobutton -label $viewname($n) \
1430
+ -command [list addvhighlight $n] -variable selectedhlview
1431
}
1432
1433
proc flatten {var} {
@@ -1427,8 +1459,9 @@ proc showview {n} {
1459
global pending_select phase
1460
global commitidx rowlaidout rowoptim linesegends
1461
global commfd nextupdate
1430
- global selectedview hlview selectedhlview
1462
+ global selectedview
1463
global vparentlist vchildlist vdisporder vcmitlisted
1464
+ global hlview selectedhlview
1465
1466
if {$n == $curview} return
1467
set selid {}
@@ -1467,14 +1500,15 @@ proc showview {n} {
1500
catch {unset matchinglines}
1501
catch {unset treediffs}
1502
clear_display
1503
+ if {[info exists hlview] && $hlview == $n} {
1504
+ unset hlview
1505
+ set selectedhlview None
1506
+ }
1507
1508
set curview $n
1509
set selectedview $n
1473
- set selectedhlview -1
1510
.bar.view entryconf 2 -state [expr {$n == 0? "disabled": "normal"}]
1511
.bar.view entryconf 3 -state [expr {$n == 0? "disabled": "normal"}]
1476
- catch {unset hlview}
1477
- .bar.view.hl entryconf 1 -state disabled
1512
1513
if {![info exists viewdata($n)]} {
1514
set pending_select $selid
@@ -1539,18 +1573,66 @@ proc showview {n} {
1573
}
1574
}
1575
1542
-proc addhighlight {n} {
1543
- global hlview curview viewdata highlighted highlightedrows
1544
- global selectedhlview
1576
+# Stuff relating to the highlighting facility
1577
+
1578
+proc ishighlighted {row} {
1579
+ global vhighlights fhighlights nhighlights
1580
+
1581
+ if {[info exists nhighlights($row)] && $nhighlights($row) > 0} {
1582
+ return $nhighlights($row)
1583
+ }
1584
+ if {[info exists vhighlights($row)] && $vhighlights($row) > 0} {
1585
+ return $vhighlights($row)
1586
+ }
1587
+ if {[info exists fhighlights($row)] && $fhighlights($row) > 0} {
1588
+ return $fhighlights($row)
1589
+ }
1590
+ return 0
1591
+}
1592
+
1593
+proc bolden {row font} {
1594
+ global canv linehtag selectedline
1595
+
1596
+ $canv itemconf $linehtag($row) -font $font
1597
+ if {$row == $selectedline} {
1598
+ $canv delete secsel
1599
+ set t [eval $canv create rect [$canv bbox $linehtag($row)] \
1600
+ -outline {{}} -tags secsel \
1601
+ -fill [$canv cget -selectbackground]]
1602
+ $canv lower $t
1603
+ }
1604
+}
1605
+
1606
+proc bolden_name {row font} {
1607
+ global canv2 linentag selectedline
1608
+
1609
+ $canv2 itemconf $linentag($row) -font $font
1610
+ if {$row == $selectedline} {
1611
+ $canv2 delete secsel
1612
+ set t [eval $canv2 create rect [$canv2 bbox $linentag($row)] \
1613
+ -outline {{}} -tags secsel \
1614
+ -fill [$canv2 cget -selectbackground]]
1615
+ $canv2 lower $t
1616
+ }
1617
+}
1618
+
1619
+proc unbolden {rows} {
1620
+ global mainfont
1621
+
1622
+ foreach row $rows {
1623
+ if {![ishighlighted $row]} {
1624
+ bolden $row $mainfont
1625
+ }
1626
+ }
1627
+}
1628
+
1629
+proc addvhighlight {n} {
1630
+ global hlview curview viewdata vhl_done vhighlights commitidx
1631
1632
if {[info exists hlview]} {
1547
- delhighlight
1633
+ delvhighlight
1634
}
1635
set hlview $n
1550
- set selectedhlview $n
1551
- .bar.view.hl entryconf 1 -state normal
1552
- set highlighted($n) 0
1553
- set highlightedrows {}
1636
if {$n != $curview && ![info exists viewdata($n)]} {
1637
set viewdata($n) [list getcommits {{}} {{}} {} {} {} 0 0 0 {}]
1638
set vparentlist($n) {}
@@ -1558,34 +1640,29 @@ proc addhighlight {n} {
1640
set vdisporder($n) {}
1641
set vcmitlisted($n) {}
1642
start_rev_list $n
1561
- } else {
1562
- highlightmore
1643
+ }
1644
+ set vhl_done $commitidx($hlview)
1645
+ if {$vhl_done > 0} {
1646
+ drawvisible
1647
}
1648
}
1649
1566
-proc delhighlight {} {
1567
- global hlview highlightedrows canv linehtag mainfont
1568
- global selectedhlview selectedline
1650
+proc delvhighlight {} {
1651
+ global hlview vhighlights
1652
+ global selectedline
1653
1654
if {![info exists hlview]} return
1655
unset hlview
1572
- set selectedhlview {}
1573
- .bar.view.hl entryconf 1 -state disabled
1574
- foreach l $highlightedrows {
1575
- $canv itemconf $linehtag($l) -font $mainfont
1576
- if {$l == $selectedline} {
1577
- $canv delete secsel
1578
- set t [eval $canv create rect [$canv bbox $linehtag($l)] \
1579
- -outline {{}} -tags secsel \
1580
- -fill [$canv cget -selectbackground]]
1581
- $canv lower $t
1582
- }
1656
+ set rows [array names vhighlights]
1657
+ if {$rows ne {}} {
1658
+ unset vhighlights
1659
+ unbolden $rows
1660
}
1661
}
1662
1586
-proc highlightmore {} {
1587
- global hlview highlighted commitidx highlightedrows linehtag mainfont
1588
- global displayorder vdisporder curview canv commitrow selectedline
1663
+proc vhighlightmore {} {
1664
+ global hlview vhl_done commitidx vhighlights
1665
+ global displayorder vdisporder curview mainfont
1666
1667
set font [concat $mainfont bold]
1668
set max $commitidx($hlview)
@@ -1594,25 +1671,158 @@ proc highlightmore {} {
1671
} else {
1672
set disp $vdisporder($hlview)
1673
}
1597
- for {set i $highlighted($hlview)} {$i < $max} {incr i} {
1674
+ set vr [visiblerows]
1675
+ set r0 [lindex $vr 0]
1676
+ set r1 [lindex $vr 1]
1677
+ for {set i $vhl_done} {$i < $max} {incr i} {
1678
set id [lindex $disp $i]
1679
if {[info exists commitrow($curview,$id)]} {
1680
set row $commitrow($curview,$id)
1601
- if {[info exists linehtag($row)]} {
1602
- $canv itemconf $linehtag($row) -font $font
1603
- lappend highlightedrows $row
1604
- if {$row == $selectedline} {
1605
- $canv delete secsel
1606
- set t [eval $canv create rect \
1607
- [$canv bbox $linehtag($row)] \
1608
- -outline {{}} -tags secsel \
1609
- -fill [$canv cget -selectbackground]]
1610
- $canv lower $t
1681
+ if {$r0 <= $row && $row <= $r1} {
1682
+ if {![highlighted $row]} {
1683
+ bolden $row $font
1684
}
1685
+ set vhighlights($row) 1
1686
}
1687
}
1688
}
1615
- set highlighted($hlview) $max
1689
+ set vhl_done $max
1690
+}
1691
+
1692
+proc askvhighlight {row id} {
1693
+ global hlview vhighlights commitrow iddrawn mainfont
1694
+
1695
+ if {[info exists commitrow($hlview,$id)]} {
1696
+ if {[info exists iddrawn($id)] && ![ishighlighted $row]} {
1697
+ bolden $row [concat $mainfont bold]
1698
+ }
1699
+ set vhighlights($row) 1
1700
+ } else {
1701
+ set vhighlights($row) 0
1702
+ }
1703
+}
1704
+
1705
+proc hfiles_change {name ix op} {
1706
+ global highlight_files filehighlight fhighlights fh_serial
1707
+ global mainfont
1708
+
1709
+ if {[info exists filehighlight]} {
1710
+ # delete previous highlights
1711
+ catch {close $filehighlight}
1712
+ unset filehighlight
1713
+ set rows [array names fhighlights]
1714
+ if {$rows ne {}} {
1715
+ unset fhighlights
1716
+ unbolden $rows
1717
+ }
1718
+ }
1719
+ after cancel do_file_hl $fh_serial
1720
+ incr fh_serial
1721
+ if {$highlight_files ne {}} {
1722
+ after 300 do_file_hl $fh_serial
1723
+ }
1724
+}
1725
+
1726
+proc do_file_hl {serial} {
1727
+ global highlight_files filehighlight
1728
+
1729
+ if {[catch {set paths [shellsplit $highlight_files]}]} return
1730
+ set cmd [concat | git-diff-tree -r -s --stdin -- $paths]
1731
+ set filehighlight [open $cmd r+]
1732
+ fconfigure $filehighlight -blocking 0
1733
+ fileevent $filehighlight readable readfhighlight
1734
+ drawvisible
1735
+ flushhighlights
1736
+}
1737
+
1738
+proc flushhighlights {} {
1739
+ global filehighlight
1740
+
1741
+ if {[info exists filehighlight]} {
1742
+ puts $filehighlight ""
1743
+ flush $filehighlight
1744
+ }
1745
+}
1746
+
1747
+proc askfilehighlight {row id} {
1748
+ global filehighlight fhighlights
1749
+
1750
+ set fhighlights($row) 0
1751
+ puts $filehighlight $id
1752
+}
1753
+
1754
+proc readfhighlight {} {
1755
+ global filehighlight fhighlights commitrow curview mainfont iddrawn
1756
+
1757
+ set n [gets $filehighlight line]
1758
+ if {$n < 0} {
1759
+ if {[eof $filehighlight]} {
1760
+ # strange...
1761
+ puts "oops, git-diff-tree died"
1762
+ catch {close $filehighlight}
1763
+ unset filehighlight
1764
+ }
1765
+ return
1766
+ }
1767
+ set line [string trim $line]
1768
+ if {$line eq {}} return
1769
+ if {![info exists commitrow($curview,$line)]} return
1770
+ set row $commitrow($curview,$line)
1771
+ if {[info exists iddrawn($line)] && ![ishighlighted $row]} {
1772
+ bolden $row [concat $mainfont bold]
1773
+ }
1774
+ set fhighlights($row) 1
1775
+}
1776
+
1777
+proc hnames_change {name ix op} {
1778
+ global highlight_names nhighlights nhl_names mainfont
1779
+
1780
+ # delete previous highlights, if any
1781
+ set rows [array names nhighlights]
1782
+ if {$rows ne {}} {
1783
+ foreach row $rows {
1784
+ if {$nhighlights($row) >= 2} {
1785
+ bolden_name $row $mainfont
1786
+ }
1787
+ }
1788
+ unset nhighlights
1789
+ unbolden $rows
1790
+ }
1791
+ if {[catch {set nhl_names [shellsplit $highlight_names]}]} {
1792
+ set nhl_names {}
1793
+ return
1794
+ }
1795
+ drawvisible
1796
+}
1797
+
1798
+proc asknamehighlight {row id} {
1799
+ global nhl_names nhighlights commitinfo iddrawn mainfont
1800
+
1801
+ if {![info exists commitinfo($id)]} {
1802
+ getcommit $id
1803
+ }
1804
+ set isbold 0
1805
+ set author [lindex $commitinfo($id) 1]
1806
+ set committer [lindex $commitinfo($id) 3]
1807
+ foreach name $nhl_names {
1808
+ set pattern "*$name*"
1809
+ if {[string match -nocase $pattern $author]} {
1810
+ set isbold 2
1811
+ break
1812
+ }
1813
+ if {!$isbold && [string match -nocase $pattern $committer]} {
1814
+ set isbold 1
1815
+ }
1816
+ }
1817
+ if {[info exists iddrawn($id)]} {
1818
+ if {$isbold && ![ishighlighted $row]} {
1819
+ bolden $row [concat $mainfont bold]
1820
+ }
1821
+ if {$isbold >= 2} {
1822
+ bolden_name $row [concat $mainfont bold]
1823
+ }
1824
+ }
1825
+ set nhighlights($row) $isbold
1826
}
1827
1828
# Graph layout functions
@@ -2335,7 +2545,6 @@ proc drawcmittext {id row col rmx} {
2545
global rowtextx idpos idtags idheads idotherrefs
2546
global linehtag linentag linedtag
2547
global mainfont canvxmax
2338
- global hlview commitrow highlightedrows
2548
2549
set ofill [expr {[lindex $commitlisted $row]? "blue": "white"}]
2550
set x [xc $row $col]
@@ -2361,15 +2570,19 @@ proc drawcmittext {id row col rmx} {
2570
set date [lindex $commitinfo($id) 2]
2571
set date [formatdate $date]
2572
set font $mainfont
2364
- if {[info exists hlview] && [info exists commitrow($hlview,$id)]} {
2573
+ set nfont $mainfont
2574
+ set isbold [ishighlighted $row]
2575
+ if {$isbold > 0} {
2576
lappend font bold
2366
- lappend highlightedrows $row
2577
+ if {$isbold > 1} {
2578
+ lappend nfont bold
2579
+ }
2580
}
2581
set linehtag($row) [$canv create text $xt $y -anchor w \
2582
-text $headline -font $font]
2583
$canv bind $linehtag($row) <Button-3> "rowmenu %X %Y $id"
2584
set linentag($row) [$canv2 create text 3 $y -anchor w \
2372
- -text $name -font $mainfont]
2585
+ -text $name -font $nfont]
2586
set linedtag($row) [$canv3 create text 3 $y -anchor w \
2587
-text $date -font $mainfont]
2588
set xr [expr {$xt + [font measure $mainfont $headline]}]
@@ -2383,6 +2596,8 @@ proc drawcmitrow {row} {
2596
global displayorder rowidlist
2597
global idrangedrawn iddrawn
2598
global commitinfo parentlist numcommits
2599
+ global filehighlight fhighlights nhl_names nhighlights
2600
+ global hlview vhighlights
2601
2602
if {$row >= $numcommits} return
2603
foreach id [lindex $rowidlist $row] {
@@ -2403,6 +2618,15 @@ proc drawcmitrow {row} {
2618
}
2619
2620
set id [lindex $displayorder $row]
2621
+ if {[info exists hlview] && ![info exists vhighlights($row)]} {
2622
+ askvhighlight $row $id
2623
+ }
2624
+ if {[info exists filehighlight] && ![info exists fhighlights($row)]} {
2625
+ askfilehighlight $row $id
2626
+ }
2627
+ if {$nhl_names ne {} && ![info exists nhighlights($row)]} {
2628
+ asknamehighlight $row $id
2629
+ }
2630
if {[info exists iddrawn($id)]} return
2631
set col [lsearch -exact [lindex $rowidlist $row] $id]
2632
if {$col < 0} {
@@ -2451,10 +2675,14 @@ proc drawvisible {} {
2675
2676
proc clear_display {} {
2677
global iddrawn idrangedrawn
2678
+ global vhighlights fhighlights nhighlights
2679
2680
allcanvs delete all
2681
catch {unset iddrawn}
2682
catch {unset idrangedrawn}
2683
+ catch {unset vhighlights}
2684
+ catch {unset fhighlights}
2685
+ catch {unset nhighlights}
2686
}
2687
2688
proc findcrossings {id} {
@@ -4943,13 +5171,16 @@ if {$i >= 0} {
5171
5172
set history {}
5173
set historyindex 0
5174
+set fh_serial 0
5175
+set highlight_names {}
5176
+set nhl_names {}
5177
5178
set optim_delay 16
5179
5180
set nextviewnum 1
5181
set curview 0
5182
set selectedview 0
4952
-set selectedhlview {}
5183
+set selectedhlview None
5184
set viewfiles(0) {}
5185
set viewperm(0) 0
5186
set viewargs(0) {}