Add commit row context menu and handle left-click on graph lines

Right-click on a context row now brings up a menu allowing the user to
generate a diff between that row and the selected row.  Left-click on
a graph line shows the parent and children connected by the line in
the details pane.  Left-click on a circle in the graph selects that
commit.  Left-click elsewhere in the graph does nothing.

When displaying a diff, the bottom-right file list box behaves
slightly differently now; instead of eliding all other files' diffs,
it now just scrolls the details pane so that the selected file's diff
starts at the top of the pane.

Since the diffs can be rather large, arrange for an update to be done
every 100ms while reading diffs.

Also removed the CVS revision keywords and bumped the version number
to 1.2.
This commit is contained in:
Paul Mackerras 2005-06-25 15:39:21 +10:00
parent 6c20ff3423
commit c8dfbcf995

266
gitk
View File

@ -7,8 +7,6 @@ exec wish "$0" -- "${1+$@}"
# and distributed under the terms of the GNU General Public Licence, # and distributed under the terms of the GNU General Public Licence,
# either version 2, or (at your option) any later version. # either version 2, or (at your option) any later version.
# CVS $Revision: 1.24 $
proc getcommits {rargs} { proc getcommits {rargs} {
global commits commfd phase canv mainfont global commits commfd phase canv mainfont
global startmsecs nextupdate global startmsecs nextupdate
@ -260,7 +258,7 @@ proc makewindow {} {
global findtype findloc findstring fstring geometry global findtype findloc findstring fstring geometry
global entries sha1entry sha1string sha1but global entries sha1entry sha1string sha1but
global maincursor textcursor global maincursor textcursor
global linectxmenu global rowctxmenu
menu .bar menu .bar
.bar add cascade -label "File" -menu .bar.file .bar add cascade -label "File" -menu .bar.file
@ -366,8 +364,8 @@ proc makewindow {} {
pack .ctop -side top -fill both -expand 1 pack .ctop -side top -fill both -expand 1
bindall <1> {selcanvline %x %y} bindall <1> {selcanvline %W %x %y}
bindall <B1-Motion> {selcanvline %x %y} #bindall <B1-Motion> {selcanvline %W %x %y}
bindall <ButtonRelease-4> "allcanvs yview scroll -5 units" bindall <ButtonRelease-4> "allcanvs yview scroll -5 units"
bindall <ButtonRelease-5> "allcanvs yview scroll 5 units" bindall <ButtonRelease-5> "allcanvs yview scroll 5 units"
bindall <2> "allcanvs scan mark 0 %y" bindall <2> "allcanvs scan mark 0 %y"
@ -404,9 +402,12 @@ proc makewindow {} {
set maincursor [. cget -cursor] set maincursor [. cget -cursor]
set textcursor [$ctext cget -cursor] set textcursor [$ctext cget -cursor]
set linectxmenu .linectxmenu set rowctxmenu .rowctxmenu
menu $linectxmenu -tearoff 0 menu $rowctxmenu -tearoff 0
$linectxmenu add command -label "Select" -command lineselect $rowctxmenu add command -label "Diff this -> selected" \
-command {diffvssel 0}
$rowctxmenu add command -label "Diff selected -> this" \
-command {diffvssel 1}
} }
# when we make a key binding for the toplevel, make sure # when we make a key binding for the toplevel, make sure
@ -536,13 +537,11 @@ proc about {} {
toplevel $w toplevel $w
wm title $w "About gitk" wm title $w "About gitk"
message $w.m -text { message $w.m -text {
Gitk version 1.1 Gitk version 1.2
Copyright © 2005 Paul Mackerras Copyright © 2005 Paul Mackerras
Use and redistribute under the terms of the GNU General Public License Use and redistribute under the terms of the GNU General Public License} \
(CVS $Revision: 1.24 $)} \
-justify center -aspect 400 -justify center -aspect 400
pack $w.m -side top -fill x -padx 20 -pady 20 pack $w.m -side top -fill x -padx 20 -pady 20
button $w.ok -text Close -command "destroy $w" button $w.ok -text Close -command "destroy $w"
@ -641,10 +640,10 @@ proc initgraph {} {
proc bindline {t id} { proc bindline {t id} {
global canv global canv
$canv bind $t <Button-3> "linemenu %X %Y $id"
$canv bind $t <Enter> "lineenter %x %y $id" $canv bind $t <Enter> "lineenter %x %y $id"
$canv bind $t <Motion> "linemotion %x %y $id" $canv bind $t <Motion> "linemotion %x %y $id"
$canv bind $t <Leave> "lineleave $id" $canv bind $t <Leave> "lineleave $id"
$canv bind $t <Button-1> "lineclick %x %y $id"
} }
proc drawcommitline {level} { proc drawcommitline {level} {
@ -655,7 +654,7 @@ proc drawcommitline {level} {
global oldlevel oldnlines oldtodo global oldlevel oldnlines oldtodo
global idtags idline idheads global idtags idline idheads
global lineno lthickness mainline sidelines global lineno lthickness mainline sidelines
global commitlisted global commitlisted rowtextx
incr numcommits incr numcommits
incr lineno incr lineno
@ -710,10 +709,12 @@ proc drawcommitline {level} {
[expr $x + $orad - 1] [expr $y1 + $orad - 1] \ [expr $x + $orad - 1] [expr $y1 + $orad - 1] \
-fill $ofill -outline black -width 1] -fill $ofill -outline black -width 1]
$canv raise $t $canv raise $t
$canv bind $t <1> {selcanvline {} %x %y}
set xt [expr $canvx0 + [llength $todo] * $linespc] set xt [expr $canvx0 + [llength $todo] * $linespc]
if {[llength $currentparents] > 2} { if {[llength $currentparents] > 2} {
set xt [expr {$xt + ([llength $currentparents] - 2) * $linespc}] set xt [expr {$xt + ([llength $currentparents] - 2) * $linespc}]
} }
set rowtextx($lineno) $xt
set marks {} set marks {}
set ntags 0 set ntags 0
if {[info exists idtags($id)]} { if {[info exists idtags($id)]} {
@ -761,6 +762,7 @@ proc drawcommitline {level} {
set date [lindex $commitinfo($id) 2] set date [lindex $commitinfo($id) 2]
set linehtag($lineno) [$canv create text $xt $y1 -anchor w \ set linehtag($lineno) [$canv create text $xt $y1 -anchor w \
-text $headline -font $mainfont ] -text $headline -font $mainfont ]
$canv bind $linehtag($lineno) <Button-3> "rowmenu %X %Y $id"
set linentag($lineno) [$canv2 create text 3 $y1 -anchor w \ set linentag($lineno) [$canv2 create text 3 $y1 -anchor w \
-text $name -font $namefont] -text $name -font $namefont]
set linedtag($lineno) [$canv3 create text 3 $y1 -anchor w \ set linedtag($lineno) [$canv3 create text 3 $y1 -anchor w \
@ -1218,9 +1220,9 @@ proc unmarkmatches {} {
catch {unset matchinglines} catch {unset matchinglines}
} }
proc selcanvline {x y} { proc selcanvline {w x y} {
global canv canvy0 ctext linespc selectedline global canv canvy0 ctext linespc selectedline
global lineid linehtag linentag linedtag global lineid linehtag linentag linedtag rowtextx
set ymax [lindex [$canv cget -scrollregion] 3] set ymax [lindex [$canv cget -scrollregion] 3]
if {$ymax == {}} return if {$ymax == {}} return
set yfrac [lindex [$canv yview] 0] set yfrac [lindex [$canv yview] 0]
@ -1229,7 +1231,9 @@ proc selcanvline {x y} {
if {$l < 0} { if {$l < 0} {
set l 0 set l 0
} }
if {[info exists selectedline] && $selectedline == $l} return if {$w eq $canv} {
if {![info exists rowtextx($l)] || $x < $rowtextx($l)} return
}
unmarkmatches unmarkmatches
selectline $l selectline $l
} }
@ -1237,8 +1241,8 @@ proc selcanvline {x y} {
proc selectline {l} { proc selectline {l} {
global canv canv2 canv3 ctext commitinfo selectedline global canv canv2 canv3 ctext commitinfo selectedline
global lineid linehtag linentag linedtag global lineid linehtag linentag linedtag
global canvy0 linespc nparents treepending global canvy0 linespc parents nparents
global cflist treediffs currentid sha1entry global cflist currentid sha1entry diffids
global commentend seenfile idtags global commentend seenfile idtags
$canv delete hover $canv delete hover
if {![info exists lineid($l)] || ![info exists linehtag($l)]} return if {![info exists lineid($l)] || ![info exists linehtag($l)]} return
@ -1292,6 +1296,7 @@ proc selectline {l} {
set id $lineid($l) set id $lineid($l)
set currentid $id set currentid $id
set diffids [concat $id $parents($id)]
$sha1entry delete 0 end $sha1entry delete 0 end
$sha1entry insert 0 $id $sha1entry insert 0 $id
$sha1entry selection from 0 $sha1entry selection from 0
@ -1299,6 +1304,8 @@ proc selectline {l} {
$ctext conf -state normal $ctext conf -state normal
$ctext delete 0.0 end $ctext delete 0.0 end
$ctext mark set fmark.0 0.0
$ctext mark gravity fmark.0 left
set info $commitinfo($id) set info $commitinfo($id)
$ctext insert end "Author: [lindex $info 1] [lindex $info 2]\n" $ctext insert end "Author: [lindex $info 1] [lindex $info 2]\n"
$ctext insert end "Committer: [lindex $info 3] [lindex $info 4]\n" $ctext insert end "Committer: [lindex $info 3] [lindex $info 4]\n"
@ -1318,18 +1325,25 @@ proc selectline {l} {
set commentend [$ctext index "end - 1c"] set commentend [$ctext index "end - 1c"]
$cflist delete 0 end $cflist delete 0 end
$cflist insert end "Comments"
if {$nparents($id) == 1} { if {$nparents($id) == 1} {
if {![info exists treediffs($id)]} { startdiff
if {![info exists treepending]} {
gettreediffs $id
}
} else {
addtocflist $id
}
} }
catch {unset seenfile} catch {unset seenfile}
} }
proc startdiff {} {
global treediffs diffids treepending
if {![info exists treediffs($diffids)]} {
if {![info exists treepending]} {
gettreediffs $diffids
}
} else {
addtocflist $diffids
}
}
proc selnextline {dir} { proc selnextline {dir} {
global selectedline global selectedline
if {![info exists selectedline]} return if {![info exists selectedline]} return
@ -1338,76 +1352,81 @@ proc selnextline {dir} {
selectline $l selectline $l
} }
proc addtocflist {id} { proc addtocflist {ids} {
global currentid treediffs cflist treepending global diffids treediffs cflist
if {$id != $currentid} { if {$ids != $diffids} {
gettreediffs $currentid gettreediffs $diffids
return return
} }
$cflist insert end "All files" foreach f $treediffs($ids) {
foreach f $treediffs($currentid) {
$cflist insert end $f $cflist insert end $f
} }
getblobdiffs $id getblobdiffs $ids
} }
proc gettreediffs {id} { proc gettreediffs {ids} {
global treediffs parents treepending global treediffs parents treepending
set treepending $id set treepending $ids
set treediffs($id) {} set treediffs($ids) {}
set p [lindex $parents($id) 0] set id [lindex $ids 0]
set p [lindex $ids 1]
if [catch {set gdtf [open "|git-diff-tree -r $p $id" r]}] return if [catch {set gdtf [open "|git-diff-tree -r $p $id" r]}] return
fconfigure $gdtf -blocking 0 fconfigure $gdtf -blocking 0
fileevent $gdtf readable "gettreediffline $gdtf $id" fileevent $gdtf readable "gettreediffline $gdtf {$ids}"
} }
proc gettreediffline {gdtf id} { proc gettreediffline {gdtf ids} {
global treediffs treepending global treediffs treepending
set n [gets $gdtf line] set n [gets $gdtf line]
if {$n < 0} { if {$n < 0} {
if {![eof $gdtf]} return if {![eof $gdtf]} return
close $gdtf close $gdtf
unset treepending unset treepending
addtocflist $id addtocflist $ids
return return
} }
set file [lindex $line 5] set file [lindex $line 5]
lappend treediffs($id) $file lappend treediffs($ids) $file
} }
proc getblobdiffs {id} { proc getblobdiffs {ids} {
global parents diffopts blobdifffd env curdifftag curtagstart global diffopts blobdifffd env curdifftag curtagstart
global diffindex difffilestart global diffindex difffilestart nextupdate
set p [lindex $parents($id) 0]
set id [lindex $ids 0]
set p [lindex $ids 1]
set env(GIT_DIFF_OPTS) $diffopts set env(GIT_DIFF_OPTS) $diffopts
if [catch {set bdf [open "|git-diff-tree -r -p $p $id" r]} err] { if [catch {set bdf [open "|git-diff-tree -r -p $p $id" r]} err] {
puts "error getting diffs: $err" puts "error getting diffs: $err"
return return
} }
fconfigure $bdf -blocking 0 fconfigure $bdf -blocking 0
set blobdifffd($id) $bdf set blobdifffd($ids) $bdf
set curdifftag Comments set curdifftag Comments
set curtagstart 0.0 set curtagstart 0.0
set diffindex 0 set diffindex 0
catch {unset difffilestart} catch {unset difffilestart}
fileevent $bdf readable "getblobdiffline $bdf $id" fileevent $bdf readable "getblobdiffline $bdf {$ids}"
set nextupdate [expr {[clock clicks -milliseconds] + 100}]
} }
proc getblobdiffline {bdf id} { proc getblobdiffline {bdf ids} {
global currentid blobdifffd ctext curdifftag curtagstart seenfile global diffids blobdifffd ctext curdifftag curtagstart seenfile
global diffnexthead diffnextnote diffindex difffilestart global diffnexthead diffnextnote diffindex difffilestart
global nextupdate
set n [gets $bdf line] set n [gets $bdf line]
if {$n < 0} { if {$n < 0} {
if {[eof $bdf]} { if {[eof $bdf]} {
close $bdf close $bdf
if {$id == $currentid && $bdf == $blobdifffd($id)} { if {$ids == $diffids && $bdf == $blobdifffd($ids)} {
$ctext tag add $curdifftag $curtagstart end $ctext tag add $curdifftag $curtagstart end
set seenfile($curdifftag) 1 set seenfile($curdifftag) 1
} }
} }
return return
} }
if {$id != $currentid || $bdf != $blobdifffd($id)} { if {$ids != $diffids || $bdf != $blobdifffd($ids)} {
return return
} }
$ctext conf -state normal $ctext conf -state normal
@ -1423,8 +1442,12 @@ proc getblobdiffline {bdf id} {
set header "$diffnexthead ($diffnextnote)" set header "$diffnexthead ($diffnextnote)"
unset diffnexthead unset diffnexthead
} }
set difffilestart($diffindex) [$ctext index "end - 1c"] set here [$ctext index "end - 1c"]
set difffilestart($diffindex) $here
incr diffindex incr diffindex
# start mark names at fmark.1 for first file
$ctext mark set fmark.$diffindex $here
$ctext mark gravity fmark.$diffindex left
set curdifftag "f:$fname" set curdifftag "f:$fname"
$ctext tag delete $curdifftag $ctext tag delete $curdifftag
set l [expr {(78 - [string length $header]) / 2}] set l [expr {(78 - [string length $header]) / 2}]
@ -1476,6 +1499,12 @@ proc getblobdiffline {bdf id} {
} }
} }
$ctext conf -state disabled $ctext conf -state disabled
if {[clock clicks -milliseconds] >= $nextupdate} {
incr nextupdate 100
fileevent $bdf readable {}
update
fileevent $bdf readable "getblobdiffline $bdf {$ids}"
}
} }
proc nextfile {} { proc nextfile {} {
@ -1492,27 +1521,10 @@ proc nextfile {} {
proc listboxsel {} { proc listboxsel {} {
global ctext cflist currentid treediffs seenfile global ctext cflist currentid treediffs seenfile
if {![info exists currentid]} return if {![info exists currentid]} return
set sel [$cflist curselection] set sel [lsort [$cflist curselection]]
if {$sel == {} || [lsearch -exact $sel 0] >= 0} { if {$sel eq {}} return
# show everything set first [lindex $sel 0]
$ctext tag conf Comments -elide 0 catch {$ctext yview fmark.$first}
foreach f $treediffs($currentid) {
if [info exists seenfile(f:$f)] {
$ctext tag conf "f:$f" -elide 0
}
}
} else {
# just show selected files
$ctext tag conf Comments -elide 1
set i 1
foreach f $treediffs($currentid) {
set elide [expr {[lsearch -exact $sel $i] < 0}]
if [info exists seenfile(f:$f)] {
$ctext tag conf "f:$f" -elide $elide
}
incr i
}
}
} }
proc setcoords {} { proc setcoords {} {
@ -1591,19 +1603,6 @@ proc gotocommit {} {
error_popup "$type $sha1string is not known" error_popup "$type $sha1string is not known"
} }
proc linemenu {x y id} {
global linectxmenu linemenuid
set linemenuid $id
$linectxmenu post $x $y
}
proc lineselect {} {
global linemenuid idline
if {[info exists linemenuid] && [info exists idline($linemenuid)]} {
selectline $idline($linemenuid)
}
}
proc lineenter {x y id} { proc lineenter {x y id} {
global hoverx hovery hoverid hovertimer global hoverx hovery hoverid hovertimer
global commitinfo canv global commitinfo canv
@ -1667,6 +1666,101 @@ proc linehover {} {
$canv raise $t $canv raise $t
} }
proc lineclick {x y id} {
global ctext commitinfo children cflist canv
unmarkmatches
$canv delete hover
# fill the details pane with info about this line
$ctext conf -state normal
$ctext delete 0.0 end
$ctext insert end "Parent:\n "
catch {destroy $ctext.$id}
button $ctext.$id -text "Go:" -command "selbyid $id" \
-padx 4 -pady 0
$ctext window create end -window $ctext.$id -align center
set info $commitinfo($id)
$ctext insert end "\t[lindex $info 0]\n"
$ctext insert end "\tAuthor:\t[lindex $info 1]\n"
$ctext insert end "\tDate:\t[lindex $info 2]\n"
$ctext insert end "\tID:\t$id\n"
if {[info exists children($id)]} {
$ctext insert end "\nChildren:"
foreach child $children($id) {
$ctext insert end "\n "
catch {destroy $ctext.$child}
button $ctext.$child -text "Go:" -command "selbyid $child" \
-padx 4 -pady 0
$ctext window create end -window $ctext.$child -align center
set info $commitinfo($child)
$ctext insert end "\t[lindex $info 0]"
}
}
$ctext conf -state disabled
$cflist delete 0 end
}
proc selbyid {id} {
global idline
if {[info exists idline($id)]} {
selectline $idline($id)
}
}
proc mstime {} {
global startmstime
if {![info exists startmstime]} {
set startmstime [clock clicks -milliseconds]
}
return [format "%.3f" [expr {([clock click -milliseconds] - $startmstime) / 1000.0}]]
}
proc rowmenu {x y id} {
global rowctxmenu idline selectedline rowmenuid
if {![info exists selectedline] || $idline($id) eq $selectedline} {
set state disabled
} else {
set state normal
}
$rowctxmenu entryconfigure 0 -state $state
$rowctxmenu entryconfigure 1 -state $state
set rowmenuid $id
tk_popup $rowctxmenu $x $y
}
proc diffvssel {dirn} {
global rowmenuid selectedline lineid
global ctext cflist
global diffids commitinfo
if {![info exists selectedline]} return
if {$dirn} {
set oldid $lineid($selectedline)
set newid $rowmenuid
} else {
set oldid $rowmenuid
set newid $lineid($selectedline)
}
$ctext conf -state normal
$ctext delete 0.0 end
$ctext mark set fmark.0 0.0
$ctext mark gravity fmark.0 left
$cflist delete 0 end
$cflist insert end "Top"
$ctext insert end "From $oldid\n "
$ctext insert end [lindex $commitinfo($oldid) 0]
$ctext insert end "\n\nTo $newid\n "
$ctext insert end [lindex $commitinfo($newid) 0]
$ctext insert end "\n"
$ctext conf -state disabled
$ctext tag delete Comments
$ctext tag remove found 1.0 end
set diffids [list $newid $oldid]
startdiff
}
proc doquit {} { proc doquit {} {
global stopped global stopped
set stopped 100 set stopped 100