Skip to content

Commit fa4da7b

Browse files
committed
Better graph line details display and expand history coverage.
Now the history remembers when we have clicked on a graph line and when we have asked for a diff between two commits, as well as when we have displayed a commit. The display when you click on a graph line now uses clickable SHA1 IDs instead of the embedded "Go" buttons. Also made the IDs clickable in the header for a diff between two commits.
1 parent 8b19280 commit fa4da7b

File tree

1 file changed

+78
-39
lines changed

1 file changed

+78
-39
lines changed

gitk

Lines changed: 78 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ proc bindline {t id} {
715715
$canv bind $t <Enter> "lineenter %x %y $id"
716716
$canv bind $t <Motion> "linemotion %x %y $id"
717717
$canv bind $t <Leave> "lineleave $id"
718-
$canv bind $t <Button-1> "lineclick %x %y $id"
718+
$canv bind $t <Button-1> "lineclick %x %y $id 1"
719719
}
720720

721721
proc drawcommitline {level} {
@@ -1687,7 +1687,7 @@ proc unmarkmatches {} {
16871687
}
16881688

16891689
proc selcanvline {w x y} {
1690-
global canv canvy0 ctext linespc selectedline
1690+
global canv canvy0 ctext linespc
16911691
global lineid linehtag linentag linedtag rowtextx
16921692
set ymax [lindex [$canv cget -scrollregion] 3]
16931693
if {$ymax == {}} return
@@ -1710,7 +1710,6 @@ proc selectline {l isnew} {
17101710
global canvy0 linespc parents nparents
17111711
global cflist currentid sha1entry
17121712
global commentend idtags idline
1713-
global history historyindex
17141713

17151714
$canv delete hover
17161715
if {![info exists lineid($l)] || ![info exists linehtag($l)]} return
@@ -1761,19 +1760,8 @@ proc selectline {l isnew} {
17611760
allcanvs yview moveto [expr $newtop * 1.0 / $ymax]
17621761
}
17631762

1764-
if {$isnew && (![info exists selectedline] || $selectedline != $l)} {
1765-
if {$historyindex < [llength $history]} {
1766-
set history [lreplace $history $historyindex end $l]
1767-
} else {
1768-
lappend history $l
1769-
}
1770-
incr historyindex
1771-
if {$historyindex > 1} {
1772-
.ctop.top.bar.leftbut conf -state normal
1773-
} else {
1774-
.ctop.top.bar.leftbut conf -state disabled
1775-
}
1776-
.ctop.top.bar.rightbut conf -state disabled
1763+
if {$isnew} {
1764+
addtohistory [list selectline $l 0]
17771765
}
17781766

17791767
set selectedline $l
@@ -1857,12 +1845,42 @@ proc selnextline {dir} {
18571845
selectline $l 1
18581846
}
18591847

1848+
proc unselectline {} {
1849+
global selectedline
1850+
1851+
catch {unset selectedline}
1852+
allcanvs delete secsel
1853+
}
1854+
1855+
proc addtohistory {cmd} {
1856+
global history historyindex
1857+
1858+
if {$historyindex > 0
1859+
&& [lindex $history [expr {$historyindex - 1}]] == $cmd} {
1860+
return
1861+
}
1862+
1863+
if {$historyindex < [llength $history]} {
1864+
set history [lreplace $history $historyindex end $cmd]
1865+
} else {
1866+
lappend history $cmd
1867+
}
1868+
incr historyindex
1869+
if {$historyindex > 1} {
1870+
.ctop.top.bar.leftbut conf -state normal
1871+
} else {
1872+
.ctop.top.bar.leftbut conf -state disabled
1873+
}
1874+
.ctop.top.bar.rightbut conf -state disabled
1875+
}
1876+
18601877
proc goback {} {
18611878
global history historyindex
18621879

18631880
if {$historyindex > 1} {
18641881
incr historyindex -1
1865-
selectline [lindex $history [expr {$historyindex - 1}]] 0
1882+
set cmd [lindex $history [expr {$historyindex - 1}]]
1883+
eval $cmd
18661884
.ctop.top.bar.rightbut conf -state normal
18671885
}
18681886
if {$historyindex <= 1} {
@@ -1874,9 +1892,9 @@ proc goforw {} {
18741892
global history historyindex
18751893

18761894
if {$historyindex < [llength $history]} {
1877-
set l [lindex $history $historyindex]
1895+
set cmd [lindex $history $historyindex]
18781896
incr historyindex
1879-
selectline $l 0
1897+
eval $cmd
18801898
.ctop.top.bar.leftbut conf -state normal
18811899
}
18821900
if {$historyindex >= [llength $history]} {
@@ -2624,7 +2642,7 @@ proc setcoords {} {
26242642
}
26252643

26262644
proc redisplay {} {
2627-
global selectedline stopped redisplaying phase
2645+
global stopped redisplaying phase
26282646
if {$stopped > 1} return
26292647
if {$phase == "getcommits"} return
26302648
set redisplaying 1
@@ -2636,7 +2654,7 @@ proc redisplay {} {
26362654
}
26372655

26382656
proc incrfont {inc} {
2639-
global mainfont namefont textfont selectedline ctext canv phase
2657+
global mainfont namefont textfont ctext canv phase
26402658
global stopped entries
26412659
unmarkmatches
26422660
set mainfont [lreplace $mainfont 1 1 [expr {[lindex $mainfont 1] + $inc}]]
@@ -2778,34 +2796,40 @@ proc linehover {} {
27782796
$canv raise $t
27792797
}
27802798

2781-
proc lineclick {x y id} {
2799+
proc lineclick {x y id isnew} {
27822800
global ctext commitinfo children cflist canv
27832801

27842802
unmarkmatches
2803+
unselectline
2804+
if {$isnew} {
2805+
addtohistory [list lineclick $x $x $id 0]
2806+
}
27852807
$canv delete hover
27862808
# fill the details pane with info about this line
27872809
$ctext conf -state normal
27882810
$ctext delete 0.0 end
2789-
$ctext insert end "Parent:\n "
2790-
catch {destroy $ctext.$id}
2791-
button $ctext.$id -text "Go:" -command "selbyid $id" \
2792-
-padx 4 -pady 0
2793-
$ctext window create end -window $ctext.$id -align center
2811+
$ctext tag conf link -foreground blue -underline 1
2812+
$ctext tag bind link <Enter> { %W configure -cursor hand2 }
2813+
$ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
2814+
$ctext insert end "Parent:\t"
2815+
$ctext insert end $id [list link link0]
2816+
$ctext tag bind link0 <1> [list selbyid $id]
27942817
set info $commitinfo($id)
2795-
$ctext insert end "\t[lindex $info 0]\n"
2818+
$ctext insert end "\n\t[lindex $info 0]\n"
27962819
$ctext insert end "\tAuthor:\t[lindex $info 1]\n"
27972820
$ctext insert end "\tDate:\t[lindex $info 2]\n"
2798-
$ctext insert end "\tID:\t$id\n"
27992821
if {[info exists children($id)]} {
28002822
$ctext insert end "\nChildren:"
2823+
set i 0
28012824
foreach child $children($id) {
2802-
$ctext insert end "\n "
2803-
catch {destroy $ctext.$child}
2804-
button $ctext.$child -text "Go:" -command "selbyid $child" \
2805-
-padx 4 -pady 0
2806-
$ctext window create end -window $ctext.$child -align center
2825+
incr i
28072826
set info $commitinfo($child)
2808-
$ctext insert end "\t[lindex $info 0]"
2827+
$ctext insert end "\n\t"
2828+
$ctext insert end $child [list link link$i]
2829+
$ctext tag bind link$i <1> [list selbyid $child]
2830+
$ctext insert end "\n\t[lindex $info 0]"
2831+
$ctext insert end "\n\tAuthor:\t[lindex $info 1]"
2832+
$ctext insert end "\n\tDate:\t[lindex $info 2]\n"
28092833
}
28102834
}
28112835
$ctext conf -state disabled
@@ -2845,8 +2869,6 @@ proc rowmenu {x y id} {
28452869

28462870
proc diffvssel {dirn} {
28472871
global rowmenuid selectedline lineid
2848-
global ctext cflist
2849-
global commitinfo
28502872

28512873
if {![info exists selectedline]} return
28522874
if {$dirn} {
@@ -2856,15 +2878,32 @@ proc diffvssel {dirn} {
28562878
set oldid $rowmenuid
28572879
set newid $lineid($selectedline)
28582880
}
2881+
addtohistory [list doseldiff $oldid $newid]
2882+
doseldiff $oldid $newid
2883+
}
2884+
2885+
proc doseldiff {oldid newid} {
2886+
global ctext cflist
2887+
global commitinfo
2888+
28592889
$ctext conf -state normal
28602890
$ctext delete 0.0 end
28612891
$ctext mark set fmark.0 0.0
28622892
$ctext mark gravity fmark.0 left
28632893
$cflist delete 0 end
28642894
$cflist insert end "Top"
2865-
$ctext insert end "From $oldid\n "
2895+
$ctext insert end "From "
2896+
$ctext tag conf link -foreground blue -underline 1
2897+
$ctext tag bind link <Enter> { %W configure -cursor hand2 }
2898+
$ctext tag bind link <Leave> { %W configure -cursor $curtextcursor }
2899+
$ctext tag bind link0 <1> [list selbyid $oldid]
2900+
$ctext insert end $oldid [list link link0]
2901+
$ctext insert end "\n "
28662902
$ctext insert end [lindex $commitinfo($oldid) 0]
2867-
$ctext insert end "\n\nTo $newid\n "
2903+
$ctext insert end "\n\nTo "
2904+
$ctext tag bind link1 <1> [list selbyid $newid]
2905+
$ctext insert end $newid [list link link1]
2906+
$ctext insert end "\n "
28682907
$ctext insert end [lindex $commitinfo($newid) 0]
28692908
$ctext insert end "\n"
28702909
$ctext conf -state disabled

0 commit comments

Comments
 (0)