From 28593d3fa0e667bfccfe48e87a580db7c1a8d769 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Thu, 13 Nov 2008 23:01:46 +1100 Subject: gitk: Index line[hnd]tag arrays by id rather than row number This simplifies things a bit and is better because ids are stable but row numbers aren't. It also means we can avoid one [rowofcommit] call. Signed-off-by: Paul Mackerras diff --git a/gitk b/gitk index 3353f4a..26ff802 100755 --- a/gitk +++ b/gitk @@ -4004,31 +4004,31 @@ proc ishighlighted {id} { return 0 } -proc bolden {row font} { - global canv linehtag selectedline boldrows need_redisplay +proc bolden {id font} { + global canv linehtag currentid boldids need_redisplay # need_redisplay = 1 means the display is stale and about to be redrawn if {$need_redisplay} return - lappend boldrows $row - $canv itemconf $linehtag($row) -font $font - if {$row == $selectedline} { + lappend boldids $id + $canv itemconf $linehtag($id) -font $font + if {[info exists currentid] && $id eq $currentid} { $canv delete secsel - set t [eval $canv create rect [$canv bbox $linehtag($row)] \ + set t [eval $canv create rect [$canv bbox $linehtag($id)] \ -outline {{}} -tags secsel \ -fill [$canv cget -selectbackground]] $canv lower $t } } -proc bolden_name {row font} { - global canv2 linentag selectedline boldnamerows need_redisplay +proc bolden_name {id font} { + global canv2 linentag currentid boldnameids need_redisplay if {$need_redisplay} return - lappend boldnamerows $row - $canv2 itemconf $linentag($row) -font $font - if {$row == $selectedline} { + lappend boldnameids $id + $canv2 itemconf $linentag($id) -font $font + if {[info exists currentid] && $id eq $currentid} { $canv2 delete secsel - set t [eval $canv2 create rect [$canv2 bbox $linentag($row)] \ + set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] \ -outline {{}} -tags secsel \ -fill [$canv2 cget -selectbackground]] $canv2 lower $t @@ -4036,17 +4036,17 @@ proc bolden_name {row font} { } proc unbolden {} { - global boldrows + global boldids set stillbold {} - foreach row $boldrows { - if {![ishighlighted [commitonrow $row]]} { - bolden $row mainfont + foreach id $boldids { + if {![ishighlighted $id]} { + bolden $id mainfont } else { - lappend stillbold $row + lappend stillbold $id } } - set boldrows $stillbold + set boldids $stillbold } proc addvhighlight {n} { @@ -4087,7 +4087,7 @@ proc vhighlightmore {} { set row [rowofcommit $id] if {$r0 <= $row && $row <= $r1} { if {![highlighted $row]} { - bolden $row mainfontbold + bolden $id mainfontbold } set vhighlights($id) 1 } @@ -4102,7 +4102,7 @@ proc askvhighlight {row id} { if {[commitinview $id $hlview]} { if {[info exists iddrawn($id)] && ![ishighlighted $id]} { - bolden $row mainfontbold + bolden $id mainfontbold } set vhighlights($id) 1 } else { @@ -4170,15 +4170,15 @@ proc find_change {name ix op} { } proc findcom_change args { - global nhighlights boldnamerows + global nhighlights boldnameids global findpattern findtype findstring gdttype stopfinding # delete previous highlights, if any - foreach row $boldnamerows { - bolden_name $row mainfont + foreach id $boldnameids { + bolden_name $id mainfont } - set boldnamerows {} + set boldnameids {} catch {unset nhighlights} unbolden unmarkmatches @@ -4267,9 +4267,8 @@ proc readfhighlight {} { set fhl_list [lrange $fhl_list [expr {$i+1}] end] if {$line eq {}} continue if {![commitinview $line $curview]} continue - set row [rowofcommit $line] if {[info exists iddrawn($line)] && ![ishighlighted $line]} { - bolden $row mainfontbold + bolden $line mainfontbold } set fhighlights($line) 1 } @@ -4321,9 +4320,9 @@ proc askfindhighlight {row id} { } if {$isbold && [info exists iddrawn($id)]} { if {![ishighlighted $id]} { - bolden $row mainfontbold + bolden $id mainfontbold if {$isbold > 1} { - bolden_name $row mainfontbold + bolden_name $id mainfontbold } } if {$markingmatches} { @@ -4343,15 +4342,15 @@ proc markrowmatches {row id} { if {$findloc eq [mc "All fields"] || $findloc eq [mc "Headline"]} { set m [findmatches $headline] if {$m ne {}} { - markmatches $canv $row $headline $linehtag($row) $m \ - [$canv itemcget $linehtag($row) -font] $row + markmatches $canv $row $headline $linehtag($id) $m \ + [$canv itemcget $linehtag($id) -font] $row } } if {$findloc eq [mc "All fields"] || $findloc eq [mc "Author"]} { set m [findmatches $author] if {$m ne {}} { - markmatches $canv2 $row $author $linentag($row) $m \ - [$canv2 itemcget $linentag($row) -font] $row + markmatches $canv2 $row $author $linentag($id) $m \ + [$canv2 itemcget $linentag($id) -font] $row } } } @@ -4476,7 +4475,7 @@ proc askrelhighlight {row id} { } if {[info exists iddrawn($id)]} { if {$isbold && ![ishighlighted $id]} { - bolden $row mainfontbold + bolden $id mainfontbold } } set rhighlights($id) $isbold @@ -5469,7 +5468,7 @@ proc drawcmittext {id row col} { global cmitlisted commitinfo rowidlist parentlist global rowtextx idpos idtags idheads idotherrefs global linehtag linentag linedtag selectedline - global canvxmax boldrows boldnamerows fgcolor + global canvxmax boldids boldnameids fgcolor global mainheadid nullid nullid2 circleitem circlecolors ctxbut # listed is 0 for boundary, 1 for normal, 2 for negative, 3 for left, 4 for right @@ -5534,22 +5533,22 @@ proc drawcmittext {id row col} { set nfont mainfont set isbold [ishighlighted $id] if {$isbold > 0} { - lappend boldrows $row + lappend boldids $id set font mainfontbold if {$isbold > 1} { - lappend boldnamerows $row + lappend boldnameids $id set nfont mainfontbold } } - set linehtag($row) [$canv create text $xt $y -anchor w -fill $fgcolor \ - -text $headline -font $font -tags text] - $canv bind $linehtag($row) $ctxbut "rowmenu %X %Y $id" - set linentag($row) [$canv2 create text 3 $y -anchor w -fill $fgcolor \ - -text $name -font $nfont -tags text] - set linedtag($row) [$canv3 create text 3 $y -anchor w -fill $fgcolor \ - -text $date -font mainfont -tags text] + set linehtag($id) [$canv create text $xt $y -anchor w -fill $fgcolor \ + -text $headline -font $font -tags text] + $canv bind $linehtag($id) $ctxbut "rowmenu %X %Y $id" + set linentag($id) [$canv2 create text 3 $y -anchor w -fill $fgcolor \ + -text $name -font $nfont -tags text] + set linedtag($id) [$canv3 create text 3 $y -anchor w -fill $fgcolor \ + -text $date -font mainfont -tags text] if {$selectedline == $row} { - make_secsel $row + make_secsel $id } set xr [expr {$xt + [font measure $font $headline]}] if {$xr > $canvxmax} { @@ -5757,7 +5756,7 @@ proc drawvisible {} { proc clear_display {} { global iddrawn linesegs need_redisplay nrows_drawn global vhighlights fhighlights nhighlights rhighlights - global linehtag linentag linedtag boldrows boldnamerows + global linehtag linentag linedtag boldids boldnameids allcanvs delete all catch {unset iddrawn} @@ -5765,8 +5764,8 @@ proc clear_display {} { catch {unset linehtag} catch {unset linentag} catch {unset linedtag} - set boldrows {} - set boldnamerows {} + set boldids {} + set boldnameids {} catch {unset vhighlights} catch {unset fhighlights} catch {unset nhighlights} @@ -6474,20 +6473,20 @@ proc dispnexttag {} { } } -proc make_secsel {l} { +proc make_secsel {id} { global linehtag linentag linedtag canv canv2 canv3 - if {![info exists linehtag($l)]} return + if {![info exists linehtag($id)]} return $canv delete secsel - set t [eval $canv create rect [$canv bbox $linehtag($l)] -outline {{}} \ + set t [eval $canv create rect [$canv bbox $linehtag($id)] -outline {{}} \ -tags secsel -fill [$canv cget -selectbackground]] $canv lower $t $canv2 delete secsel - set t [eval $canv2 create rect [$canv2 bbox $linentag($l)] -outline {{}} \ + set t [eval $canv2 create rect [$canv2 bbox $linentag($id)] -outline {{}} \ -tags secsel -fill [$canv2 cget -selectbackground]] $canv2 lower $t $canv3 delete secsel - set t [eval $canv3 create rect [$canv3 bbox $linedtag($l)] -outline {{}} \ + set t [eval $canv3 create rect [$canv3 bbox $linedtag($id)] -outline {{}} \ -tags secsel -fill [$canv3 cget -selectbackground]] $canv3 lower $t } @@ -6553,7 +6552,7 @@ proc selectline {l isnew {desired_loc {}}} { drawvisible } - make_secsel $l + make_secsel $id if {$isnew} { addtohistory [list selbyid $id] @@ -8109,16 +8108,16 @@ proc redrawtags {id} { $canv itemconf $circleitem($row) -fill $ofill $canv delete tag.$id set xt [eval drawtags $id $idpos($id)] - $canv coords $linehtag($row) $xt [lindex $idpos($id) 2] - set text [$canv itemcget $linehtag($row) -text] - set font [$canv itemcget $linehtag($row) -font] + $canv coords $linehtag($id) $xt [lindex $idpos($id) 2] + set text [$canv itemcget $linehtag($id) -text] + set font [$canv itemcget $linehtag($id) -font] set xr [expr {$xt + [font measure $font $text]}] if {$xr > $canvxmax} { set canvxmax $xr setcanvscroll } if {[info exists currentid] && $currentid == $id} { - make_secsel $row + make_secsel $id } } @@ -10766,8 +10765,8 @@ set nhl_names {} set highlight_paths {} set findpattern {} set searchdirn -forwards -set boldrows {} -set boldnamerows {} +set boldids {} +set boldnameids {} set diffelide {0 0} set markingmatches 0 set linkentercount 0 -- cgit v0.10.2-6-g49f6 From 2958228430b63f2e38c55519d1f98d8d6d9e23f3 Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Tue, 18 Nov 2008 19:44:20 +1100 Subject: gitk: Fix switch statement in parseviewargs In Tcl, a comment in a switch command where a pattern would be expected doesn't do what one would expect, so this moves the comments inside the actions. Doing that shows up an extra "-" which this also removes. With this, --merge is now handled properly. Signed-off-by: Paul Mackerras diff --git a/gitk b/gitk index 26ff802..158af6a 100755 --- a/gitk +++ b/gitk @@ -155,18 +155,16 @@ proc parseviewargs {n arglist} { set origargs [lreplace $origargs $i $i] incr i -1 } - # These request or affect diff output, which we don't want. - # Some could be used to set our defaults for diff display. "-[puabwcrRBMC]" - "--no-renames" - "--full-index" - "--binary" - "--abbrev=*" - "--find-copies-harder" - "-l*" - "--ext-diff" - "--no-ext-diff" - "--src-prefix=*" - "--dst-prefix=*" - "--no-prefix" - "-O*" - "--text" - "--full-diff" - "--ignore-space-at-eol" - "--ignore-space-change" - "-U*" - "--unified=*" { + # These request or affect diff output, which we don't want. + # Some could be used to set our defaults for diff display. lappend diffargs $arg } - # These cause our parsing of git log's output to fail, or else - # they're options we want to set ourselves, so ignore them. "--raw" - "--patch-with-raw" - "--patch-with-stat" - "--name-only" - "--name-status" - "--color" - "--color-words" - "--log-size" - "--pretty=*" - "--decorate" - "--abbrev-commit" - @@ -174,27 +172,29 @@ proc parseviewargs {n arglist} { "--no-color" - "-g" - "--walk-reflogs" - "--no-walk" - "--timestamp" - "relative-date" - "--date=*" - "--stdin" - "--objects" - "--objects-edge" - "--reverse" { + # These cause our parsing of git log's output to fail, or else + # they're options we want to set ourselves, so ignore them. } - # These are harmless, and some are even useful "--stat=*" - "--numstat" - "--shortstat" - "--summary" - "--check" - "--exit-code" - "--quiet" - "--topo-order" - "--full-history" - "--dense" - "--sparse" - "--follow" - "--left-right" - "--encoding=*" { + # These are harmless, and some are even useful lappend glflags $arg } - # These mean that we get a subset of the commits "--diff-filter=*" - "--no-merges" - "--unpacked" - "--max-count=*" - "--skip=*" - "--since=*" - "--after=*" - "--until=*" - "--before=*" - "--max-age=*" - "--min-age=*" - "--author=*" - "--committer=*" - "--grep=*" - "-[iE]" - "--remove-empty" - "--first-parent" - "--cherry-pick" - - "-S*" - "--pickaxe-all" - "--pickaxe-regex" - { + "-S*" - "--pickaxe-all" - "--pickaxe-regex" { + # These mean that we get a subset of the commits set filtered 1 lappend glflags $arg } - # This appears to be the only one that has a value as a - # separate word following it "-n" { + # This appears to be the only one that has a value as a + # separate word following it set filtered 1 set nextisval 1 lappend glflags $arg @@ -211,8 +211,8 @@ proc parseviewargs {n arglist} { # git rev-parse doesn't understand --merge lappend revargs --gitk-symmetric-diff-marker MERGE_HEAD...HEAD } - # Other flag arguments including - "-*" { + # Other flag arguments including - if {[string is digit -strict [string range $arg 1 end]]} { set filtered 1 } else { @@ -222,8 +222,8 @@ proc parseviewargs {n arglist} { } lappend glflags $arg } - # Non-flag arguments specify commits or ranges of commits default { + # Non-flag arguments specify commits or ranges of commits if {[string match "*...*" $arg]} { lappend revargs --gitk-symmetric-diff-marker } -- cgit v0.10.2-6-g49f6 From cdc8429c94e43181ac0bd48225c2af85499d2f5a Mon Sep 17 00:00:00 2001 From: Paul Mackerras Date: Tue, 18 Nov 2008 19:54:14 +1100 Subject: gitk: Show local changes properly when we have a path limit Since gitk looks for the HEAD commit to attach the fake commits for local changes to, we can miss out on seeing the fake commits if we have a path limit and the HEAD commit doesn't alter any of the files in the path limit. This fixes it by running git rev-list -1 $head -- $paths if we have a path limit, and taking the result of that as the commit to attach the fake commits to. This means that we can be attaching the fake commits to a different commit in each view, so we use a new $viewmainhead($view) for that. This also fixes a buglet where updatecommits would only fix up the fake commits if the HEAD changed since the last call to updatecommits, whereas it should fix them up if the HEAD has changed since this view was last created or updated. Signed-off-by: Paul Mackerras diff --git a/gitk b/gitk index 158af6a..c3b4eb2 100755 --- a/gitk +++ b/gitk @@ -309,7 +309,7 @@ proc start_rev_list {view} { global viewargs viewargscmd viewfiles vfilelimit global showlocalchanges global viewactive viewinstances vmergeonly - global mainheadid + global mainheadid viewmainheadid viewmainheadid_orig global vcanopt vflags vrevs vorigargs set startmsecs [clock clicks -milliseconds] @@ -367,8 +367,13 @@ proc start_rev_list {view} { } set i [reg_instance $fd] set viewinstances($view) [list $i] - if {$showlocalchanges && $mainheadid ne {}} { - interestedin $mainheadid dodiffindex + set viewmainheadid($view) $mainheadid + set viewmainheadid_orig($view) $mainheadid + if {$files ne {} && $mainheadid ne {}} { + get_viewmainhead $view + } + if {$showlocalchanges && $viewmainheadid($view) ne {}} { + interestedin $viewmainheadid($view) dodiffindex } fconfigure $fd -blocking 0 -translation lf -eofchar {} if {$tclencoding != {}} { @@ -446,22 +451,26 @@ proc updatecommits {} { global curview vcanopt vorigargs vfilelimit viewinstances global viewactive viewcomplete tclencoding global startmsecs showneartags showlocalchanges - global mainheadid pending_select + global mainheadid viewmainheadid viewmainheadid_orig pending_select global isworktree global varcid vposids vnegids vflags vrevs set isworktree [expr {[exec git rev-parse --is-inside-work-tree] == "true"}] - set oldmainid $mainheadid rereadrefs - if {$showlocalchanges} { - if {$mainheadid ne $oldmainid} { + set view $curview + if {$mainheadid ne $viewmainheadid_orig($view)} { + if {$showlocalchanges} { dohidelocalchanges } - if {[commitinview $mainheadid $curview]} { - dodiffindex + set viewmainheadid($view) $mainheadid + set viewmainheadid_orig($view) $mainheadid + if {$vfilelimit($view) ne {}} { + get_viewmainhead $view } } - set view $curview + if {$showlocalchanges} { + doshowlocalchanges + } if {$vcanopt($view)} { set oldpos $vposids($view) set oldneg $vnegids($view) @@ -4643,14 +4652,56 @@ proc layoutmore {} { drawvisible } +# With path limiting, we mightn't get the actual HEAD commit, +# so ask git rev-list what is the first ancestor of HEAD that +# touches a file in the path limit. +proc get_viewmainhead {view} { + global viewmainheadid vfilelimit viewinstances mainheadid + + catch { + set rfd [open [concat | git rev-list -1 $mainheadid \ + -- $vfilelimit($view)] r] + set j [reg_instance $rfd] + lappend viewinstances($view) $j + fconfigure $rfd -blocking 0 + filerun $rfd [list getviewhead $rfd $j $view] + set viewmainheadid($curview) {} + } +} + +# git rev-list should give us just 1 line to use as viewmainheadid($view) +proc getviewhead {fd inst view} { + global viewmainheadid commfd curview viewinstances showlocalchanges + + set id {} + if {[gets $fd line] < 0} { + if {![eof $fd]} { + return 1 + } + } elseif {[string length $line] == 40 && [string is xdigit $line]} { + set id $line + } + set viewmainheadid($view) $id + close $fd + unset commfd($inst) + set i [lsearch -exact $viewinstances($view) $inst] + if {$i >= 0} { + set viewinstances($view) [lreplace $viewinstances($view) $i $i] + } + if {$showlocalchanges && $id ne {} && $view == $curview} { + doshowlocalchanges + } + return 0 +} + proc doshowlocalchanges {} { - global curview mainheadid + global curview viewmainheadid - if {$mainheadid eq {}} return - if {[commitinview $mainheadid $curview]} { + if {$viewmainheadid($curview) eq {}} return + if {[commitinview $viewmainheadid($curview) $curview]} { dodiffindex } else { - interestedin $mainheadid dodiffindex + interestedin $viewmainheadid($curview) dodiffindex } } @@ -4668,19 +4719,24 @@ proc dohidelocalchanges {} { # spawn off a process to do git diff-index --cached HEAD proc dodiffindex {} { - global lserial showlocalchanges + global lserial showlocalchanges vfilelimit curview global isworktree if {!$showlocalchanges || !$isworktree} return incr lserial - set fd [open "|git diff-index --cached HEAD" r] + set cmd "|git diff-index --cached HEAD" + if {$vfilelimit($curview) ne {}} { + set cmd [concat $cmd -- $vfilelimit($curview)] + } + set fd [open $cmd r] fconfigure $fd -blocking 0 set i [reg_instance $fd] filerun $fd [list readdiffindex $fd $lserial $i] } proc readdiffindex {fd serial inst} { - global mainheadid nullid nullid2 curview commitinfo commitdata lserial + global viewmainheadid nullid nullid2 curview commitinfo commitdata lserial + global vfilelimit set isdiff 1 if {[gets $fd line] < 0} { @@ -4697,7 +4753,11 @@ proc readdiffindex {fd serial inst} { } # now see if there are any local changes not checked in to the index - set fd [open "|git diff-files" r] + set cmd "|git diff-files" + if {$vfilelimit($curview) ne {}} { + set cmd [concat $cmd -- $vfilelimit($curview)] + } + set fd [open $cmd r] fconfigure $fd -blocking 0 set i [reg_instance $fd] filerun $fd [list readdifffiles $fd $serial $i] @@ -4710,15 +4770,18 @@ proc readdiffindex {fd serial inst} { if {[commitinview $nullid $curview]} { removefakerow $nullid } - insertfakerow $nullid2 $mainheadid + insertfakerow $nullid2 $viewmainheadid($curview) } elseif {!$isdiff && [commitinview $nullid2 $curview]} { + if {[commitinview $nullid $curview]} { + removefakerow $nullid + } removefakerow $nullid2 } return 0 } proc readdifffiles {fd serial inst} { - global mainheadid nullid nullid2 curview + global viewmainheadid nullid nullid2 curview global commitinfo commitdata lserial set isdiff 1 @@ -4743,7 +4806,7 @@ proc readdifffiles {fd serial inst} { if {[commitinview $nullid2 $curview]} { set p $nullid2 } else { - set p $mainheadid + set p $viewmainheadid($curview) } insertfakerow $nullid $p } elseif {!$isdiff && [commitinview $nullid $curview]} { @@ -8341,6 +8404,7 @@ proc cherrypick {} { } addnewchild $newhead $oldhead if {[commitinview $oldhead $curview]} { + # XXX this isn't right if we have a path limit... insertrow $newhead $oldhead $curview if {$mainhead ne {}} { movehead $newhead $mainhead @@ -8448,7 +8512,7 @@ proc headmenu {x y id head} { proc cobranch {} { global headmenuid headmenuhead headids - global showlocalchanges mainheadid + global showlocalchanges # check the tree is clean first?? nowbusy checkout [mc "Checking out"] @@ -8469,6 +8533,7 @@ proc cobranch {} { proc readcheckoutstat {fd newhead newheadid} { global mainhead mainheadid headids showlocalchanges progresscoords + global viewmainheadid curview if {[gets $fd line] >= 0} { if {[regexp {([0-9]+)% \(([0-9]+)/([0-9]+)\)} $line match p m n]} { @@ -8486,6 +8551,7 @@ proc readcheckoutstat {fd newhead newheadid} { set oldmainid $mainheadid set mainhead $newhead set mainheadid $newheadid + set viewmainheadid($curview) $newheadid redrawtags $oldmainid redrawtags $newheadid selbyid $newheadid -- cgit v0.10.2-6-g49f6 From 68149a71978564aaef7a5fe956cf1de2864c16d3 Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Thu, 13 Nov 2008 23:09:18 +0300 Subject: gitk: Avoid handling the Return key twice in Add Branch This reverts commit 63767d5fb8fe236d8fdeba44297ac925701b27a0. A similar change was made as part of commit 76f15947af7, that added bindings to all dialogs, and this duplication causes mkbrgo to be called twice, the second time after the window has been destroyed. As a result, an error window appears when the code tries to access widgets. Signed-off-by: Alexander Gavrilov Signed-off-by: Paul Mackerras diff --git a/gitk b/gitk index c3b4eb2..f7f1776 100755 --- a/gitk +++ b/gitk @@ -8270,7 +8270,6 @@ proc mkbranch {} { grid $top.id $top.sha1 -sticky w label $top.nlab -text [mc "Name:"] entry $top.name -width 40 - bind $top.name "[list mkbrgo $top]" grid $top.nlab $top.name -sticky w frame $top.buts button $top.buts.go -text [mc "Create"] -command [list mkbrgo $top] -- cgit v0.10.2-6-g49f6