Mercurial > hg
comparison contrib/hgk @ 5464:7dafd9ab3979
hgk: colorize commits by authors
Color commits by author. Colors will be assigned to authors by using a configurable list of colors. The line corresponding to current id (the version currently in the working tree) is highlighted in a special font which is also configurable. There is provision to assign fixed colors to authors. See .gitk comment for details.
author | Georg.Koltermann@mscsoftware.com |
---|---|
date | Thu, 12 Apr 2007 13:11:30 +0200 |
parents | b8872655f951 |
children | be20a42f27a1 |
comparison
equal
deleted
inserted
replaced
5463:3b204881f959 | 5464:7dafd9ab3979 |
---|---|
336 set commitinfo($id) [list $headline $auname $audate \ | 336 set commitinfo($id) [list $headline $auname $audate \ |
337 $comname $comdate $comment $rev] | 337 $comname $comdate $comment $rev] |
338 } | 338 } |
339 | 339 |
340 proc readrefs {} { | 340 proc readrefs {} { |
341 global tagids idtags headids idheads tagcontents env | 341 global tagids idtags headids idheads tagcontents env curid |
342 | |
343 set curid [exec $env(HG) --config ui.report_untrusted=false id] | |
344 regexp -- {[[:xdigit:]]+} $curid curid | |
342 | 345 |
343 set tags [exec $env(HG) --config ui.report_untrusted=false tags] | 346 set tags [exec $env(HG) --config ui.report_untrusted=false tags] |
344 regsub -all "\r\n" $tags "\n" tags | 347 regsub -all "\r\n" $tags "\n" tags |
345 set lines [split $tags "\n"] | 348 set lines [split $tags "\n"] |
346 foreach f $lines { | 349 foreach f $lines { |
639 } | 642 } |
640 | 643 |
641 proc savestuff {w} { | 644 proc savestuff {w} { |
642 global canv canv2 canv3 ctext cflist mainfont textfont | 645 global canv canv2 canv3 ctext cflist mainfont textfont |
643 global stuffsaved findmergefiles gaudydiff maxgraphpct | 646 global stuffsaved findmergefiles gaudydiff maxgraphpct |
644 global maxwidth | 647 global maxwidth authorcolors curidfont |
645 | 648 |
646 if {$stuffsaved} return | 649 if {$stuffsaved} return |
647 if {![winfo viewable .]} return | 650 if {![winfo viewable .]} return |
648 catch { | 651 catch { |
649 set f [open "~/.gitk-new" w] | 652 set f [open "~/.gitk-new" w] |
650 puts $f [list set mainfont $mainfont] | 653 puts $f [list set mainfont $mainfont] |
654 puts $f [list set curidfont $curidfont] | |
651 puts $f [list set textfont $textfont] | 655 puts $f [list set textfont $textfont] |
652 puts $f [list set findmergefiles $findmergefiles] | 656 puts $f [list set findmergefiles $findmergefiles] |
653 puts $f [list set gaudydiff $gaudydiff] | 657 puts $f [list set gaudydiff $gaudydiff] |
654 puts $f [list set maxgraphpct $maxgraphpct] | 658 puts $f [list set maxgraphpct $maxgraphpct] |
655 puts $f [list set maxwidth $maxwidth] | 659 puts $f [list set maxwidth $maxwidth] |
663 / [font measure $textfont "0"]}] | 667 / [font measure $textfont "0"]}] |
664 puts $f "set geometry(ctextw) $wid" | 668 puts $f "set geometry(ctextw) $wid" |
665 set wid [expr {([winfo width $cflist] - 11) \ | 669 set wid [expr {([winfo width $cflist] - 11) \ |
666 / [font measure [$cflist cget -font] "0"]}] | 670 / [font measure [$cflist cget -font] "0"]}] |
667 puts $f "set geometry(cflistw) $wid" | 671 puts $f "set geometry(cflistw) $wid" |
672 puts $f "#" | |
673 puts $f "# authorcolors format:" | |
674 puts $f "#" | |
675 puts $f "# zero or more sublists of" | |
676 puts $f "#" | |
677 puts $f "# { regex color }" | |
678 puts $f "#" | |
679 puts $f "# followed by a list of colors" | |
680 puts $f "#" | |
681 puts $f "# If the commit author matches a regex in a sublist," | |
682 puts $f "# the commit will be colored by that color" | |
683 puts $f "# otherwise the next unused entry from the list of colors" | |
684 puts $f "# will be assigned to this commit and also all other commits" | |
685 puts $f "# of the same author. When the list of colors is exhausted," | |
686 puts $f "# the last entry will be reused." | |
687 puts $f "#" | |
688 puts $f "set authorcolors {$authorcolors}" | |
668 close $f | 689 close $f |
669 file rename -force "~/.gitk-new" "~/.gitk" | 690 file rename -force "~/.gitk-new" "~/.gitk" |
670 } | 691 } |
671 set stuffsaved 1 | 692 set stuffsaved 1 |
672 } | 693 } |
755 pack $w.m -side top -fill x -padx 20 -pady 20 | 776 pack $w.m -side top -fill x -padx 20 -pady 20 |
756 button $w.ok -text Close -command "destroy $w" | 777 button $w.ok -text Close -command "destroy $w" |
757 pack $w.ok -side bottom | 778 pack $w.ok -side bottom |
758 } | 779 } |
759 | 780 |
781 set aunextcolor 0 | |
782 proc assignauthorcolor {name} { | |
783 global authorcolors aucolormap aunextcolor | |
784 if [info exists aucolormap($name)] return | |
785 | |
786 set randomcolors {black} | |
787 for {set i 0} {$i < [llength $authorcolors]} {incr i} { | |
788 set col [lindex $authorcolors $i] | |
789 if {[llength $col] > 1} { | |
790 set re [lindex $col 0] | |
791 set c [lindex $col 1] | |
792 if {[regexp -- $re $name]} { | |
793 set aucolormap($name) $c | |
794 return | |
795 } | |
796 } else { | |
797 set randomcolors [lrange $authorcolors $i end] | |
798 break | |
799 } | |
800 } | |
801 | |
802 set ncolors [llength $randomcolors] | |
803 set c [lindex $randomcolors $aunextcolor] | |
804 if {[incr aunextcolor] >= $ncolors} { | |
805 incr aunextcolor -1 | |
806 } | |
807 set aucolormap($name) $c | |
808 } | |
809 | |
760 proc assigncolor {id} { | 810 proc assigncolor {id} { |
761 global commitinfo colormap commcolors colors nextcolor | 811 global commitinfo colormap commcolors colors nextcolor |
762 global parents nparents children nchildren | 812 global parents nparents children nchildren |
763 global cornercrossings crossings | 813 global cornercrossings crossings |
764 | 814 |
892 global colormap numcommits currentparents dupparents | 942 global colormap numcommits currentparents dupparents |
893 global idtags idline idheads idotherrefs | 943 global idtags idline idheads idotherrefs |
894 global lineno lthickness mainline mainlinearrow sidelines | 944 global lineno lthickness mainline mainlinearrow sidelines |
895 global commitlisted rowtextx idpos lastuse displist | 945 global commitlisted rowtextx idpos lastuse displist |
896 global oldnlines olddlevel olddisplist | 946 global oldnlines olddlevel olddisplist |
947 global aucolormap curid curidfont | |
897 | 948 |
898 incr numcommits | 949 incr numcommits |
899 incr lineno | 950 incr lineno |
900 set id [lindex $displist $level] | 951 set id [lindex $displist $level] |
901 set lastuse($id) $lineno | 952 set lastuse($id) $lineno |
950 || [info exists idotherrefs($id)]} { | 1001 || [info exists idotherrefs($id)]} { |
951 set xt [drawtags $id $x $xt $y1] | 1002 set xt [drawtags $id $x $xt $y1] |
952 } | 1003 } |
953 set headline [lindex $commitinfo($id) 0] | 1004 set headline [lindex $commitinfo($id) 0] |
954 set name [lindex $commitinfo($id) 1] | 1005 set name [lindex $commitinfo($id) 1] |
1006 assignauthorcolor $name | |
1007 set fg $aucolormap($name) | |
1008 if {$id == $curid} { | |
1009 set fn $curidfont | |
1010 } else { | |
1011 set fn $mainfont | |
1012 } | |
1013 | |
955 set date [lindex $commitinfo($id) 2] | 1014 set date [lindex $commitinfo($id) 2] |
956 set linehtag($lineno) [$canv create text $xt $y1 -anchor w \ | 1015 set linehtag($lineno) [$canv create text $xt $y1 -anchor w \ |
957 -text $headline -font $mainfont ] | 1016 -text $headline -font $fn \ |
1017 -fill $fg] | |
958 $canv bind $linehtag($lineno) <<B3>> "rowmenu %X %Y $id" | 1018 $canv bind $linehtag($lineno) <<B3>> "rowmenu %X %Y $id" |
959 set linentag($lineno) [$canv2 create text 3 $y1 -anchor w \ | 1019 set linentag($lineno) [$canv2 create text 3 $y1 -anchor w \ |
960 -text $name -font $namefont] | 1020 -text $name -font $namefont \ |
1021 -fill $fg] | |
961 set linedtag($lineno) [$canv3 create text 3 $y1 -anchor w \ | 1022 set linedtag($lineno) [$canv3 create text 3 $y1 -anchor w \ |
962 -text $date -font $mainfont] | 1023 -text $date -font $mainfont \ |
1024 -fill $fg] | |
963 | 1025 |
964 set olddlevel $level | 1026 set olddlevel $level |
965 set olddisplist $displist | 1027 set olddisplist $displist |
966 set oldnlines [llength $displist] | 1028 set oldnlines [llength $displist] |
967 } | 1029 } |
3087 } | 3149 } |
3088 } | 3150 } |
3089 | 3151 |
3090 proc incrfont {inc} { | 3152 proc incrfont {inc} { |
3091 global mainfont namefont textfont ctext canv phase | 3153 global mainfont namefont textfont ctext canv phase |
3092 global stopped entries | 3154 global stopped entries curidfont |
3093 unmarkmatches | 3155 unmarkmatches |
3094 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]] | 3156 set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]] |
3157 set curidfont [lreplace $curidfont 1 1 [expr {[lindex $curidfont 1] + $inc}]] | |
3095 set namefont [lreplace $namefont 1 1 [expr {[lindex $namefont 1] + $inc}]] | 3158 set namefont [lreplace $namefont 1 1 [expr {[lindex $namefont 1] + $inc}]] |
3096 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]] | 3159 set textfont [lreplace $textfont 1 1 [expr {[lindex $textfont 1] + $inc}]] |
3097 setcoords | 3160 setcoords |
3098 $ctext conf -font $textfont | 3161 $ctext conf -font $textfont |
3099 $ctext tag conf filesep -font [concat $textfont bold] | 3162 $ctext tag conf filesep -font [concat $textfont bold] |
3770 set boldnames 0 | 3833 set boldnames 0 |
3771 set diffopts "-U 5 -p" | 3834 set diffopts "-U 5 -p" |
3772 set wrcomcmd "\"\$HG\" --config ui.report_untrusted=false debug-diff-tree --stdin -p --pretty" | 3835 set wrcomcmd "\"\$HG\" --config ui.report_untrusted=false debug-diff-tree --stdin -p --pretty" |
3773 | 3836 |
3774 set mainfont {Helvetica 9} | 3837 set mainfont {Helvetica 9} |
3838 set curidfont {} | |
3775 set textfont {Courier 9} | 3839 set textfont {Courier 9} |
3776 set findmergefiles 0 | 3840 set findmergefiles 0 |
3777 set gaudydiff 0 | 3841 set gaudydiff 0 |
3778 set maxgraphpct 50 | 3842 set maxgraphpct 50 |
3779 set maxwidth 16 | 3843 set maxwidth 16 |
3780 | 3844 |
3781 set colors {green red blue magenta darkgrey brown orange} | 3845 set colors {green red blue magenta darkgrey brown orange} |
3846 set authorcolors { | |
3847 deeppink mediumorchid blue burlywood4 goldenrod slateblue red2 navy dimgrey | |
3848 } | |
3782 | 3849 |
3783 catch {source ~/.gitk} | 3850 catch {source ~/.gitk} |
3851 | |
3852 if {$curidfont == ""} { # initialize late based on current mainfont | |
3853 set curidfont "$mainfont bold italic underline" | |
3854 } | |
3784 | 3855 |
3785 set namefont $mainfont | 3856 set namefont $mainfont |
3786 if {$boldnames} { | 3857 if {$boldnames} { |
3787 lappend namefont bold | 3858 lappend namefont bold |
3788 } | 3859 } |