gitk: Add a window to list branches, tags and other references
This adds an entry to the File menu labelled "List references" which pops up a window showing a sorted list of branches, tags, and other references, with a little icon beside each to indicate what sort it is. The list only shows refs that point to a commit that is included in the graph, and if you click on a ref, the corresponding commit is selected in the main window. The list of refs gets updated dynamically. Signed-off-by: Paul Mackerras <paulus@samba.org>
Paul Mackerras committed
Aug 20, 2007 at 19:36 UTC
887c996e4698dcb7ee95c48a98f7da2c3bae158b
1 file changed
+210
-2
gitk
+210
-2
@@ -533,6 +533,7 @@ proc makewindow {} {
533
menu .bar.file
534
.bar.file add command -label "Update" -command updatecommits
535
.bar.file add command -label "Reread references" -command rereadrefs
536
+ .bar.file add command -label "List references" -command showrefs
537
.bar.file add command -label "Quit" -command doquit
538
.bar.file configure -font $uifont
539
menu .bar.edit
@@ -1466,6 +1467,38 @@ image create bitmap tri-dn -background black -foreground blue -data {
1467
0x00, 0x00};
1468
}
1469
1470
+image create bitmap reficon-T -background black -foreground yellow -data {
1471
+ #define tagicon_width 13
1472
+ #define tagicon_height 9
1473
+ static unsigned char tagicon_bits[] = {
1474
+ 0x00, 0x00, 0x00, 0x00, 0xf0, 0x07, 0xf8, 0x07,
1475
+ 0xfc, 0x07, 0xf8, 0x07, 0xf0, 0x07, 0x00, 0x00, 0x00, 0x00};
1476
+} -maskdata {
1477
+ #define tagicon-mask_width 13
1478
+ #define tagicon-mask_height 9
1479
+ static unsigned char tagicon-mask_bits[] = {
1480
+ 0x00, 0x00, 0xf0, 0x0f, 0xf8, 0x0f, 0xfc, 0x0f,
1481
+ 0xfe, 0x0f, 0xfc, 0x0f, 0xf8, 0x0f, 0xf0, 0x0f, 0x00, 0x00};
1482
+}
1483
+set rectdata {
1484
+ #define headicon_width 13
1485
+ #define headicon_height 9
1486
+ static unsigned char headicon_bits[] = {
1487
+ 0x00, 0x00, 0x00, 0x00, 0xf8, 0x07, 0xf8, 0x07,
1488
+ 0xf8, 0x07, 0xf8, 0x07, 0xf8, 0x07, 0x00, 0x00, 0x00, 0x00};
1489
+}
1490
+set rectmask {
1491
+ #define headicon-mask_width 13
1492
+ #define headicon-mask_height 9
1493
+ static unsigned char headicon-mask_bits[] = {
1494
+ 0x00, 0x00, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f,
1495
+ 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0xfc, 0x0f, 0x00, 0x00};
1496
+}
1497
+image create bitmap reficon-H -background black -foreground green \
1498
+ -data $rectdata -maskdata $rectmask
1499
+image create bitmap reficon-o -background black -foreground "#ddddff" \
1500
+ -data $rectdata -maskdata $rectmask
1501
+
1502
proc init_flist {first} {
1503
global cflist cflist_top selectedline difffilestart
1504
@@ -1988,6 +2021,7 @@ proc showview {n} {
2021
} elseif {$numcommits == 0} {
2022
show_status "No commits selected"
2023
}
2024
+ run refill_reflist
2025
}
2026
2027
# Stuff relating to the highlighting facility
@@ -2751,13 +2785,22 @@ proc layoutmore {tmax allread} {
2785
proc showstuff {canshow last} {
2786
global numcommits commitrow pending_select selectedline curview
2787
global lookingforhead mainheadid displayorder selectfirst
2754
- global lastscrollset
2788
+ global lastscrollset commitinterest
2789
2790
if {$numcommits == 0} {
2791
global phase
2792
set phase "incrdraw"
2793
allcanvs delete all
2794
}
2795
+ for {set l $numcommits} {$l < $canshow} {incr l} {
2796
+ set id [lindex $displayorder $l]
2797
+ if {[info exists commitinterest($id)]} {
2798
+ foreach script $commitinterest($id) {
2799
+ eval [string map [list "%I" $id] $script]
2800
+ }
2801
+ unset commitinterest($id)
2802
+ }
2803
+ }
2804
set r0 $numcommits
2805
set prev $numcommits
2806
set numcommits $canshow
@@ -4484,6 +4527,7 @@ proc selectline {l isnew} {
4527
$canv delete hover
4528
normalline
4529
cancel_next_highlight
4530
+ unsel_reflist
4531
if {$l < 0 || $l >= $numcommits} return
4532
set y [expr {$canvy0 + $l * $linespc}]
4533
set ymax [lindex [$canv cget -scrollregion] 3]
@@ -5414,7 +5458,7 @@ proc redisplay {} {
5458
}
5459
5460
proc incrfont {inc} {
5417
- global mainfont textfont ctext canv phase cflist
5461
+ global mainfont textfont ctext canv phase cflist showrefstop
5462
global charspc tabstop
5463
global stopped entries
5464
unmarkmatches
@@ -5430,6 +5474,9 @@ proc incrfont {inc} {
5474
if {$phase eq "getcommits"} {
5475
$canv itemconf textitems -font $mainfont
5476
}
5477
+ if {[info exists showrefstop] && [winfo exists $showrefstop]} {
5478
+ $showrefstop.list conf -font $mainfont
5479
+ }
5480
redisplay
5481
}
5482
@@ -5888,6 +5935,8 @@ proc domktag {} {
5935
lappend idtags($id) $tag
5936
redrawtags $id
5937
addedtag $id
5938
+ dispneartags 0
5939
+ run refill_reflist
5940
}
5941
5942
proc redrawtags {id} {
@@ -6029,6 +6078,7 @@ proc mkbrgo {top} {
6078
notbusy newbranch
6079
redrawtags $id
6080
dispneartags 0
6081
+ run refill_reflist
6082
}
6083
}
6084
@@ -6227,6 +6277,163 @@ proc rmbranch {} {
6277
redrawtags $id
6278
notbusy rmbranch
6279
dispneartags 0
6280
+ run refill_reflist
6281
+}
6282
+
6283
+# Display a list of tags and heads
6284
+proc showrefs {} {
6285
+ global showrefstop bgcolor fgcolor selectbgcolor mainfont
6286
+ global bglist fglist uifont reflistfilter reflist maincursor
6287
+
6288
+ set top .showrefs
6289
+ set showrefstop $top
6290
+ if {[winfo exists $top]} {
6291
+ raise $top
6292
+ refill_reflist
6293
+ return
6294
+ }
6295
+ toplevel $top
6296
+ wm title $top "Tags and heads: [file tail [pwd]]"
6297
+ text $top.list -background $bgcolor -foreground $fgcolor \
6298
+ -selectbackground $selectbgcolor -font $mainfont \
6299
+ -xscrollcommand "$top.xsb set" -yscrollcommand "$top.ysb set" \
6300
+ -width 30 -height 20 -cursor $maincursor \
6301
+ -spacing1 1 -spacing3 1 -state disabled
6302
+ $top.list tag configure highlight -background $selectbgcolor
6303
+ lappend bglist $top.list
6304
+ lappend fglist $top.list
6305
+ scrollbar $top.ysb -command "$top.list yview" -orient vertical
6306
+ scrollbar $top.xsb -command "$top.list xview" -orient horizontal
6307
+ grid $top.list $top.ysb -sticky nsew
6308
+ grid $top.xsb x -sticky ew
6309
+ frame $top.f
6310
+ label $top.f.l -text "Filter: " -font $uifont
6311
+ entry $top.f.e -width 20 -textvariable reflistfilter -font $uifont
6312
+ set reflistfilter "*"
6313
+ trace add variable reflistfilter write reflistfilter_change
6314
+ pack $top.f.e -side right -fill x -expand 1
6315
+ pack $top.f.l -side left
6316
+ grid $top.f - -sticky ew -pady 2
6317
+ button $top.close -command [list destroy $top] -text "Close" \
6318
+ -font $uifont
6319
+ grid $top.close -
6320
+ grid columnconfigure $top 0 -weight 1
6321
+ grid rowconfigure $top 0 -weight 1
6322
+ bind $top.list <1> {break}
6323
+ bind $top.list <B1-Motion> {break}
6324
+ bind $top.list <ButtonRelease-1> {sel_reflist %W %x %y; break}
6325
+ set reflist {}
6326
+ refill_reflist
6327
+}
6328
+
6329
+proc sel_reflist {w x y} {
6330
+ global showrefstop reflist headids tagids otherrefids
6331
+
6332
+ if {![winfo exists $showrefstop]} return
6333
+ set l [lindex [split [$w index "@$x,$y"] "."] 0]
6334
+ set ref [lindex $reflist [expr {$l-1}]]
6335
+ set n [lindex $ref 0]
6336
+ switch -- [lindex $ref 1] {
6337
+ "H" {selbyid $headids($n)}
6338
+ "T" {selbyid $tagids($n)}
6339
+ "o" {selbyid $otherrefids($n)}
6340
+ }
6341
+ $showrefstop.list tag add highlight $l.0 "$l.0 lineend"
6342
+}
6343
+
6344
+proc unsel_reflist {} {
6345
+ global showrefstop
6346
+
6347
+ if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
6348
+ $showrefstop.list tag remove highlight 0.0 end
6349
+}
6350
+
6351
+proc reflistfilter_change {n1 n2 op} {
6352
+ global reflistfilter
6353
+
6354
+ after cancel refill_reflist
6355
+ after 200 refill_reflist
6356
+}
6357
+
6358
+proc refill_reflist {} {
6359
+ global reflist reflistfilter showrefstop headids tagids otherrefids
6360
+ global commitrow curview commitinterest
6361
+
6362
+ if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
6363
+ set refs {}
6364
+ foreach n [array names headids] {
6365
+ if {[string match $reflistfilter $n]} {
6366
+ if {[info exists commitrow($curview,$headids($n))]} {
6367
+ lappend refs [list $n H]
6368
+ } else {
6369
+ set commitinterest($headids($n)) {run refill_reflist}
6370
+ }
6371
+ }
6372
+ }
6373
+ foreach n [array names tagids] {
6374
+ if {[string match $reflistfilter $n]} {
6375
+ if {[info exists commitrow($curview,$tagids($n))]} {
6376
+ lappend refs [list $n T]
6377
+ } else {
6378
+ set commitinterest($tagids($n)) {run refill_reflist}
6379
+ }
6380
+ }
6381
+ }
6382
+ foreach n [array names otherrefids] {
6383
+ if {[string match $reflistfilter $n]} {
6384
+ if {[info exists commitrow($curview,$otherrefids($n))]} {
6385
+ lappend refs [list $n o]
6386
+ } else {
6387
+ set commitinterest($otherrefids($n)) {run refill_reflist}
6388
+ }
6389
+ }
6390
+ }
6391
+ set refs [lsort -index 0 $refs]
6392
+ if {$refs eq $reflist} return
6393
+
6394
+ # Update the contents of $showrefstop.list according to the
6395
+ # differences between $reflist (old) and $refs (new)
6396
+ $showrefstop.list conf -state normal
6397
+ $showrefstop.list insert end "\n"
6398
+ set i 0
6399
+ set j 0
6400
+ while {$i < [llength $reflist] || $j < [llength $refs]} {
6401
+ if {$i < [llength $reflist]} {
6402
+ if {$j < [llength $refs]} {
6403
+ set cmp [string compare [lindex $reflist $i 0] \
6404
+ [lindex $refs $j 0]]
6405
+ if {$cmp == 0} {
6406
+ set cmp [string compare [lindex $reflist $i 1] \
6407
+ [lindex $refs $j 1]]
6408
+ }
6409
+ } else {
6410
+ set cmp -1
6411
+ }
6412
+ } else {
6413
+ set cmp 1
6414
+ }
6415
+ switch -- $cmp {
6416
+ -1 {
6417
+ $showrefstop.list delete "[expr {$j+1}].0" "[expr {$j+2}].0"
6418
+ incr i
6419
+ }
6420
+ 0 {
6421
+ incr i
6422
+ incr j
6423
+ }
6424
+ 1 {
6425
+ set l [expr {$j + 1}]
6426
+ $showrefstop.list image create $l.0 -align baseline \
6427
+ -image reficon-[lindex $refs $j 1] -padx 2
6428
+ $showrefstop.list insert $l.1 "[lindex $refs $j 0]\n"
6429
+ incr j
6430
+ }
6431
+ }
6432
+ }
6433
+ set reflist $refs
6434
+ # delete last newline
6435
+ $showrefstop.list delete end-2c end-1c
6436
+ $showrefstop.list conf -state disabled
6437
}
6438
6439
# Stuff for finding nearby tags
@@ -7124,6 +7331,7 @@ proc rereadrefs {} {
7331
redrawtags $id
7332
}
7333
}
7334
+ run refill_reflist
7335
}
7336
7337
proc listrefs {id} {