Skip to content

Commit 67e31d6

Browse files
author
Junio C Hamano
committed
Merge git://git.kernel.org/pub/scm/gitk/gitk
* git://git.kernel.org/pub/scm/gitk/gitk: gitk: Show the currently checked-out head in bold font gitk: Allow the user to set some colors
2 parents 6c7f4ce + 8a48571 commit 67e31d6

File tree

1 file changed

+121
-26
lines changed

1 file changed

+121
-26
lines changed

gitk

Lines changed: 121 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ proc getcommit {id} {
312312

313313
proc readrefs {} {
314314
global tagids idtags headids idheads tagcontents
315-
global otherrefids idotherrefs
315+
global otherrefids idotherrefs mainhead
316316

317317
foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
318318
catch {unset $v}
@@ -358,6 +358,13 @@ proc readrefs {} {
358358
}
359359
}
360360
close $refd
361+
set mainhead {}
362+
catch {
363+
set thehead [exec git symbolic-ref HEAD]
364+
if {[string match "refs/heads/*" $thehead]} {
365+
set mainhead [string range $thehead 11 end]
366+
}
367+
}
361368
}
362369

363370
proc show_error {w top msg} {
@@ -386,6 +393,7 @@ proc makewindow {} {
386393
global rowctxmenu mergemax wrapcomment
387394
global highlight_files gdttype
388395
global searchstring sstring
396+
global bgcolor fgcolor bglist fglist diffcolors
389397

390398
menu .bar
391399
.bar add cascade -label "File" -menu .bar.file
@@ -446,18 +454,19 @@ proc makewindow {} {
446454
.ctop add .ctop.top
447455
set canv .ctop.top.clist.canv
448456
canvas $canv -height $geometry(canvh) -width $geometry(canv1) \
449-
-bg white -bd 0 \
457+
-background $bgcolor -bd 0 \
450458
-yscrollincr $linespc -yscrollcommand "scrollcanv $cscroll"
451459
.ctop.top.clist add $canv
452460
set canv2 .ctop.top.clist.canv2
453461
canvas $canv2 -height $geometry(canvh) -width $geometry(canv2) \
454-
-bg white -bd 0 -yscrollincr $linespc
462+
-background $bgcolor -bd 0 -yscrollincr $linespc
455463
.ctop.top.clist add $canv2
456464
set canv3 .ctop.top.clist.canv3
457465
canvas $canv3 -height $geometry(canvh) -width $geometry(canv3) \
458-
-bg white -bd 0 -yscrollincr $linespc
466+
-background $bgcolor -bd 0 -yscrollincr $linespc
459467
.ctop.top.clist add $canv3
460468
bind .ctop.top.clist <Configure> {resizeclistpanes %W %w}
469+
lappend bglist $canv $canv2 $canv3
461470

462471
set sha1entry .ctop.top.bar.sha1
463472
set entries $sha1entry
@@ -563,19 +572,22 @@ proc makewindow {} {
563572
trace add variable searchstring write incrsearch
564573
pack $sstring -side left -expand 1 -fill x
565574
set ctext .ctop.cdet.left.ctext
566-
text $ctext -bg white -state disabled -font $textfont \
575+
text $ctext -background $bgcolor -foreground $fgcolor \
576+
-state disabled -font $textfont \
567577
-width $geometry(ctextw) -height $geometry(ctexth) \
568578
-yscrollcommand scrolltext -wrap none
569579
scrollbar .ctop.cdet.left.sb -command "$ctext yview"
570580
pack .ctop.cdet.left.sb -side right -fill y
571581
pack $ctext -side left -fill both -expand 1
572582
.ctop.cdet add .ctop.cdet.left
583+
lappend bglist $ctext
584+
lappend fglist $ctext
573585

574586
$ctext tag conf comment -wrap $wrapcomment
575587
$ctext tag conf filesep -font [concat $textfont bold] -back "#aaaaaa"
576-
$ctext tag conf hunksep -fore blue
577-
$ctext tag conf d0 -fore red
578-
$ctext tag conf d1 -fore "#00a000"
588+
$ctext tag conf hunksep -fore [lindex $diffcolors 2]
589+
$ctext tag conf d0 -fore [lindex $diffcolors 0]
590+
$ctext tag conf d1 -fore [lindex $diffcolors 1]
579591
$ctext tag conf m0 -fore red
580592
$ctext tag conf m1 -fore blue
581593
$ctext tag conf m2 -fore green
@@ -608,11 +620,15 @@ proc makewindow {} {
608620
pack .ctop.cdet.right.mode -side top -fill x
609621
set cflist .ctop.cdet.right.cfiles
610622
set indent [font measure $mainfont "nn"]
611-
text $cflist -width $geometry(cflistw) -background white -font $mainfont \
623+
text $cflist -width $geometry(cflistw) \
624+
-background $bgcolor -foreground $fgcolor \
625+
-font $mainfont \
612626
-tabs [list $indent [expr {2 * $indent}]] \
613627
-yscrollcommand ".ctop.cdet.right.sb set" \
614628
-cursor [. cget -cursor] \
615629
-spacing1 1 -spacing3 1
630+
lappend bglist $cflist
631+
lappend fglist $cflist
616632
scrollbar .ctop.cdet.right.sb -command "$cflist yview"
617633
pack .ctop.cdet.right.sb -side right -fill y
618634
pack $cflist -side left -fill both -expand 1
@@ -747,6 +763,7 @@ proc savestuff {w} {
747763
global maxwidth showneartags
748764
global viewname viewfiles viewargs viewperm nextviewnum
749765
global cmitmode wrapcomment
766+
global colors bgcolor fgcolor diffcolors
750767

751768
if {$stuffsaved} return
752769
if {![winfo viewable .]} return
@@ -761,6 +778,10 @@ proc savestuff {w} {
761778
puts $f [list set cmitmode $cmitmode]
762779
puts $f [list set wrapcomment $wrapcomment]
763780
puts $f [list set showneartags $showneartags]
781+
puts $f [list set bgcolor $bgcolor]
782+
puts $f [list set fgcolor $fgcolor]
783+
puts $f [list set colors $colors]
784+
puts $f [list set diffcolors $diffcolors]
764785
puts $f "set geometry(width) [winfo width .ctop]"
765786
puts $f "set geometry(height) [winfo height .ctop]"
766787
puts $f "set geometry(canv1) [expr {[winfo width $canv]-2}]"
@@ -2870,19 +2891,19 @@ proc drawlines {id} {
28702891
}
28712892

28722893
proc drawcmittext {id row col rmx} {
2873-
global linespc canv canv2 canv3 canvy0
2894+
global linespc canv canv2 canv3 canvy0 fgcolor
28742895
global commitlisted commitinfo rowidlist
28752896
global rowtextx idpos idtags idheads idotherrefs
28762897
global linehtag linentag linedtag
2877-
global mainfont canvxmax boldrows boldnamerows
2898+
global mainfont canvxmax boldrows boldnamerows fgcolor
28782899

28792900
set ofill [expr {[lindex $commitlisted $row]? "blue": "white"}]
28802901
set x [xc $row $col]
28812902
set y [yc $row]
28822903
set orad [expr {$linespc / 3}]
28832904
set t [$canv create oval [expr {$x - $orad}] [expr {$y - $orad}] \
28842905
[expr {$x + $orad - 1}] [expr {$y + $orad - 1}] \
2885-
-fill $ofill -outline black -width 1]
2906+
-fill $ofill -outline $fgcolor -width 1 -tags circle]
28862907
$canv raise $t
28872908
$canv bind $t <1> {selcanvline {} %x %y}
28882909
set xt [xc $row [llength [lindex $rowidlist $row]]]
@@ -2910,13 +2931,13 @@ proc drawcmittext {id row col rmx} {
29102931
lappend nfont bold
29112932
}
29122933
}
2913-
set linehtag($row) [$canv create text $xt $y -anchor w \
2914-
-text $headline -font $font]
2934+
set linehtag($row) [$canv create text $xt $y -anchor w -fill $fgcolor \
2935+
-text $headline -font $font -tags text]
29152936
$canv bind $linehtag($row) <Button-3> "rowmenu %X %Y $id"
2916-
set linentag($row) [$canv2 create text 3 $y -anchor w \
2917-
-text $name -font $nfont]
2918-
set linedtag($row) [$canv3 create text 3 $y -anchor w \
2919-
-text $date -font $mainfont]
2937+
set linentag($row) [$canv2 create text 3 $y -anchor w -fill $fgcolor \
2938+
-text $name -font $nfont -tags text]
2939+
set linedtag($row) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
2940+
-text $date -font $mainfont -tags text]
29202941
set xr [expr {$xt + [font measure $mainfont $headline]}]
29212942
if {$xr > $canvxmax} {
29222943
set canvxmax $xr
@@ -3136,9 +3157,9 @@ proc bindline {t id} {
31363157
}
31373158

31383159
proc drawtags {id x xt y1} {
3139-
global idtags idheads idotherrefs
3160+
global idtags idheads idotherrefs mainhead
31403161
global linespc lthickness
3141-
global canv mainfont commitrow rowtextx curview
3162+
global canv mainfont commitrow rowtextx curview fgcolor bgcolor
31423163

31433164
set marks {}
31443165
set ntags 0
@@ -3163,8 +3184,14 @@ proc drawtags {id x xt y1} {
31633184
set yb [expr {$yt + $linespc - 1}]
31643185
set xvals {}
31653186
set wvals {}
3187+
set i -1
31663188
foreach tag $marks {
3167-
set wid [font measure $mainfont $tag]
3189+
incr i
3190+
if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
3191+
set wid [font measure [concat $mainfont bold] $tag]
3192+
} else {
3193+
set wid [font measure $mainfont $tag]
3194+
}
31683195
lappend xvals $xt
31693196
lappend wvals $wid
31703197
set xt [expr {$xt + $delta + $wid + $lthickness + $linespc}]
@@ -3175,6 +3202,7 @@ proc drawtags {id x xt y1} {
31753202
foreach tag $marks x $xvals wid $wvals {
31763203
set xl [expr {$x + $delta}]
31773204
set xr [expr {$x + $delta + $wid + $lthickness}]
3205+
set font $mainfont
31783206
if {[incr ntags -1] >= 0} {
31793207
# draw a tag
31803208
set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
@@ -3186,6 +3214,9 @@ proc drawtags {id x xt y1} {
31863214
# draw a head or other ref
31873215
if {[incr nheads -1] >= 0} {
31883216
set col green
3217+
if {$tag eq $mainhead} {
3218+
lappend font bold
3219+
}
31893220
} else {
31903221
set col "#ddddff"
31913222
}
@@ -3201,8 +3232,8 @@ proc drawtags {id x xt y1} {
32013232
-width 0 -fill "#ffddaa" -tags tag.$id
32023233
}
32033234
}
3204-
set t [$canv create text $xl $y1 -anchor w -text $tag \
3205-
-font $mainfont -tags tag.$id]
3235+
set t [$canv create text $xl $y1 -anchor w -text $tag -fill $fgcolor \
3236+
-font $font -tags [list tag.$id text]]
32063237
if {$ntags >= 0} {
32073238
$canv bind $t <1> [list showtag $tag 1]
32083239
}
@@ -3223,10 +3254,11 @@ proc xcoord {i level ln} {
32233254
}
32243255

32253256
proc show_status {msg} {
3226-
global canv mainfont
3257+
global canv mainfont fgcolor
32273258

32283259
clear_display
3229-
$canv create text 3 3 -anchor nw -text $msg -font $mainfont -tags textitems
3260+
$canv create text 3 3 -anchor nw -text $msg -font $mainfont \
3261+
-tags text -fill $fgcolor
32303262
}
32313263

32323264
proc finishcommits {} {
@@ -4574,7 +4606,8 @@ proc linehover {} {
45744606
set t [$canv create rectangle $x0 $y0 $x1 $y1 \
45754607
-fill \#ffff80 -outline black -width 1 -tags hover]
45764608
$canv raise $t
4577-
set t [$canv create text $x $y -anchor nw -text $text -tags hover -font $mainfont]
4609+
set t [$canv create text $x $y -anchor nw -text $text -tags hover \
4610+
-font $mainfont]
45784611
$canv raise $t
45794612
}
45804613

@@ -5242,6 +5275,7 @@ proc doquit {} {
52425275
proc doprefs {} {
52435276
global maxwidth maxgraphpct diffopts
52445277
global oldprefs prefstop showneartags
5278+
global bgcolor fgcolor ctext diffcolors
52455279

52465280
set top .gitkprefs
52475281
set prefstop $top
@@ -5265,6 +5299,7 @@ proc doprefs {} {
52655299
-font optionfont
52665300
spinbox $top.maxpct -from 1 -to 100 -width 4 -textvariable maxgraphpct
52675301
grid x $top.maxpctl $top.maxpct -sticky w
5302+
52685303
label $top.ddisp -text "Diff display options"
52695304
grid $top.ddisp - -sticky w -pady 10
52705305
label $top.diffoptl -text "Options for diff program" \
@@ -5276,6 +5311,34 @@ proc doprefs {} {
52765311
checkbutton $top.ntag.b -variable showneartags
52775312
pack $top.ntag.b $top.ntag.l -side left
52785313
grid x $top.ntag -sticky w
5314+
5315+
label $top.cdisp -text "Colors: press to choose"
5316+
grid $top.cdisp - -sticky w -pady 10
5317+
label $top.bg -padx 40 -relief sunk -background $bgcolor
5318+
button $top.bgbut -text "Background" -font optionfont \
5319+
-command [list choosecolor bgcolor 0 $top.bg background setbg]
5320+
grid x $top.bgbut $top.bg -sticky w
5321+
label $top.fg -padx 40 -relief sunk -background $fgcolor
5322+
button $top.fgbut -text "Foreground" -font optionfont \
5323+
-command [list choosecolor fgcolor 0 $top.fg foreground setfg]
5324+
grid x $top.fgbut $top.fg -sticky w
5325+
label $top.diffold -padx 40 -relief sunk -background [lindex $diffcolors 0]
5326+
button $top.diffoldbut -text "Diff: old lines" -font optionfont \
5327+
-command [list choosecolor diffcolors 0 $top.diffold "diff old lines" \
5328+
[list $ctext tag conf d0 -foreground]]
5329+
grid x $top.diffoldbut $top.diffold -sticky w
5330+
label $top.diffnew -padx 40 -relief sunk -background [lindex $diffcolors 1]
5331+
button $top.diffnewbut -text "Diff: new lines" -font optionfont \
5332+
-command [list choosecolor diffcolors 1 $top.diffnew "diff new lines" \
5333+
[list $ctext tag conf d1 -foreground]]
5334+
grid x $top.diffnewbut $top.diffnew -sticky w
5335+
label $top.hunksep -padx 40 -relief sunk -background [lindex $diffcolors 2]
5336+
button $top.hunksepbut -text "Diff: hunk header" -font optionfont \
5337+
-command [list choosecolor diffcolors 2 $top.hunksep \
5338+
"diff hunk header" \
5339+
[list $ctext tag conf hunksep -foreground]]
5340+
grid x $top.hunksepbut $top.hunksep -sticky w
5341+
52795342
frame $top.buts
52805343
button $top.buts.ok -text "OK" -command prefsok
52815344
button $top.buts.can -text "Cancel" -command prefscan
@@ -5285,6 +5348,35 @@ proc doprefs {} {
52855348
grid $top.buts - - -pady 10 -sticky ew
52865349
}
52875350

5351+
proc choosecolor {v vi w x cmd} {
5352+
global $v
5353+
5354+
set c [tk_chooseColor -initialcolor [lindex [set $v] $vi] \
5355+
-title "Gitk: choose color for $x"]
5356+
if {$c eq {}} return
5357+
$w conf -background $c
5358+
lset $v $vi $c
5359+
eval $cmd $c
5360+
}
5361+
5362+
proc setbg {c} {
5363+
global bglist
5364+
5365+
foreach w $bglist {
5366+
$w conf -background $c
5367+
}
5368+
}
5369+
5370+
proc setfg {c} {
5371+
global fglist canv
5372+
5373+
foreach w $fglist {
5374+
$w conf -foreground $c
5375+
}
5376+
allcanvs itemconf text -fill $c
5377+
$canv itemconf circle -outline $c
5378+
}
5379+
52885380
proc prefscan {} {
52895381
global maxwidth maxgraphpct diffopts
52905382
global oldprefs prefstop showneartags
@@ -5620,6 +5712,9 @@ set wrapcomment "none"
56205712
set showneartags 1
56215713

56225714
set colors {green red blue magenta darkgrey brown orange}
5715+
set bgcolor white
5716+
set fgcolor black
5717+
set diffcolors {red "#00a000" blue}
56235718

56245719
catch {source ~/.gitk}
56255720

0 commit comments

Comments
 (0)