gitk: Fix bugs in the Find function

This fixes the problem reported by Brian Downing where searching for
a string that doesn't exist would give a Tcl error.  The basic problem
was that we weren't reading the data for the last commit since it
wasn't terminated with a null.  This effectively adds a null on the end
(if there isn't one already) to make sure we process the last commit.

This also makes the yellow background behind instances of the search
string appear more consistently, and fixes a bug where the "/" key
would just find the same commit again and again instead of advancing.

Signed-off-by: Paul Mackerras <paulus@samba.org>
maint
Paul Mackerras 2007-07-26 22:36:39 +10:00
parent 0eafba1405
commit 005a2f4e6d
1 changed files with 53 additions and 35 deletions

58
gitk
View File

@ -139,6 +139,10 @@ proc getcommitlines {fd view} {
global vparentlist vdisporder vcmitlisted global vparentlist vdisporder vcmitlisted


set stuff [read $fd 500000] set stuff [read $fd 500000]
# git log doesn't terminate the last commit with a null...
if {$stuff == {} && $leftover($view) ne {} && [eof $fd]} {
set stuff "\0"
}
if {$stuff == {}} { if {$stuff == {}} {
if {![eof $fd]} { if {![eof $fd]} {
return 1 return 1
@ -2157,7 +2161,7 @@ proc readfhighlight {} {


proc find_change {name ix op} { proc find_change {name ix op} {
global nhighlights mainfont boldnamerows global nhighlights mainfont boldnamerows
global findstring findpattern findtype markingmatches global findstring findpattern findtype


# delete previous highlights, if any # delete previous highlights, if any
foreach row $boldnamerows { foreach row $boldnamerows {
@ -2172,7 +2176,6 @@ proc find_change {name ix op} {
$findstring] $findstring]
set findpattern "*$e*" set findpattern "*$e*"
} }
set markingmatches [expr {$findstring ne {}}]
drawvisible drawvisible
} }


@ -2218,26 +2221,32 @@ proc askfindhighlight {row id} {
} }
} }
if {$markingmatches} { if {$markingmatches} {
markrowmatches $row [lindex $info 0] [lindex $info 1] markrowmatches $row $id
} }
} }
set nhighlights($row) $isbold set nhighlights($row) $isbold
} }


proc markrowmatches {row headline author} { proc markrowmatches {row id} {
global canv canv2 linehtag linentag global canv canv2 linehtag linentag commitinfo findloc


set headline [lindex $commitinfo($id) 0]
set author [lindex $commitinfo($id) 1]
$canv delete match$row $canv delete match$row
$canv2 delete match$row $canv2 delete match$row
if {$findloc eq "All fields" || $findloc eq "Headline"} {
set m [findmatches $headline] set m [findmatches $headline]
if {$m ne {}} { if {$m ne {}} {
markmatches $canv $row $headline $linehtag($row) $m \ markmatches $canv $row $headline $linehtag($row) $m \
[$canv itemcget $linehtag($row) -font] [$canv itemcget $linehtag($row) -font] $row
} }
}
if {$findloc eq "All fields" || $findloc eq "Author"} {
set m [findmatches $author] set m [findmatches $author]
if {$m ne {}} { if {$m ne {}} {
markmatches $canv2 $row $author $linentag($row) $m \ markmatches $canv2 $row $author $linentag($row) $m \
[$canv2 itemcget $linentag($row) -font] [$canv2 itemcget $linentag($row) -font] $row
}
} }
} }


@ -3406,7 +3415,7 @@ proc drawcmittext {id row col} {
global linespc canv canv2 canv3 canvy0 fgcolor curview global linespc canv canv2 canv3 canvy0 fgcolor curview
global commitlisted commitinfo rowidlist parentlist global commitlisted commitinfo rowidlist parentlist
global rowtextx idpos idtags idheads idotherrefs global rowtextx idpos idtags idheads idotherrefs
global linehtag linentag linedtag markingmatches global linehtag linentag linedtag
global mainfont canvxmax boldrows boldnamerows fgcolor nullid nullid2 global mainfont canvxmax boldrows boldnamerows fgcolor nullid nullid2


# listed is 0 for boundary, 1 for normal, 2 for left, 3 for right # listed is 0 for boundary, 1 for normal, 2 for left, 3 for right
@ -3483,9 +3492,6 @@ proc drawcmittext {id row col} {
set linedtag($row) [$canv3 create text 3 $y -anchor w -fill $fgcolor \ set linedtag($row) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
-text $date -font $mainfont -tags text] -text $date -font $mainfont -tags text]
set xr [expr {$xt + [font measure $mainfont $headline]}] set xr [expr {$xt + [font measure $mainfont $headline]}]
if {$markingmatches} {
markrowmatches $row $headline $name
}
if {$xr > $canvxmax} { if {$xr > $canvxmax} {
set canvxmax $xr set canvxmax $xr
setcanvscroll setcanvscroll
@ -3494,7 +3500,7 @@ proc drawcmittext {id row col} {


proc drawcmitrow {row} { proc drawcmitrow {row} {
global displayorder rowidlist global displayorder rowidlist
global iddrawn global iddrawn markingmatches
global commitinfo parentlist numcommits global commitinfo parentlist numcommits
global filehighlight fhighlights findstring nhighlights global filehighlight fhighlights findstring nhighlights
global hlview vhighlights global hlview vhighlights
@ -3515,7 +3521,7 @@ proc drawcmitrow {row} {
if {$highlight_related ne "None" && ![info exists rhighlights($row)]} { if {$highlight_related ne "None" && ![info exists rhighlights($row)]} {
askrelhighlight $row $id askrelhighlight $row $id
} }
if {[info exists iddrawn($id)]} return if {![info exists iddrawn($id)]} {
set col [lsearch -exact [lindex $rowidlist $row] $id] set col [lsearch -exact [lindex $rowidlist $row] $id]
if {$col < 0} { if {$col < 0} {
puts "oops, row $row id $id not in list" puts "oops, row $row id $id not in list"
@ -3528,6 +3534,10 @@ proc drawcmitrow {row} {
drawcmittext $id $row $col drawcmittext $id $row $col
set iddrawn($id) 1 set iddrawn($id) 1
} }
if {$markingmatches} {
markrowmatches $row $id
}
}


proc drawcommits {row {endrow {}}} { proc drawcommits {row {endrow {}}} {
global numcommits iddrawn displayorder curview global numcommits iddrawn displayorder curview
@ -4044,7 +4054,6 @@ proc dofind {{rev 0}} {
if {!$rev} { if {!$rev} {
run findmore run findmore
} else { } else {
set findcurline $findstartline
if {$findcurline == 0} { if {$findcurline == 0} {
set findcurline $numcommits set findcurline $numcommits
} }
@ -4079,7 +4088,7 @@ proc findprev {} {


proc findmore {} { proc findmore {} {
global commitdata commitinfo numcommits findstring findpattern findloc global commitdata commitinfo numcommits findstring findpattern findloc
global findstartline findcurline markingmatches displayorder global findstartline findcurline displayorder


set fldtypes {Headline Author Date Committer CDate Comments} set fldtypes {Headline Author Date Committer CDate Comments}
set l [expr {$findcurline + 1}] set l [expr {$findcurline + 1}]
@ -4097,6 +4106,8 @@ proc findmore {} {
set last 0 set last 0
for {} {$l < $lim} {incr l} { for {} {$l < $lim} {incr l} {
set id [lindex $displayorder $l] set id [lindex $displayorder $l]
# shouldn't happen unless git log doesn't give all the commits...
if {![info exists commitdata($id)]} continue
if {![doesmatch $commitdata($id)]} continue if {![doesmatch $commitdata($id)]} continue
if {![info exists commitinfo($id)]} { if {![info exists commitinfo($id)]} {
getcommit $id getcommit $id
@ -4105,7 +4116,6 @@ proc findmore {} {
foreach f $info ty $fldtypes { foreach f $info ty $fldtypes {
if {($findloc eq "All fields" || $findloc eq $ty) && if {($findloc eq "All fields" || $findloc eq $ty) &&
[doesmatch $f]} { [doesmatch $f]} {
set markingmatches 1
findselectline $l findselectline $l
notbusy finding notbusy finding
return 0 return 0
@ -4124,7 +4134,7 @@ proc findmore {} {


proc findmorerev {} { proc findmorerev {} {
global commitdata commitinfo numcommits findstring findpattern findloc global commitdata commitinfo numcommits findstring findpattern findloc
global findstartline findcurline markingmatches displayorder global findstartline findcurline displayorder


set fldtypes {Headline Author Date Committer CDate Comments} set fldtypes {Headline Author Date Committer CDate Comments}
set l $findcurline set l $findcurline
@ -4151,7 +4161,6 @@ proc findmorerev {} {
foreach f $info ty $fldtypes { foreach f $info ty $fldtypes {
if {($findloc eq "All fields" || $findloc eq $ty) && if {($findloc eq "All fields" || $findloc eq $ty) &&
[doesmatch $f]} { [doesmatch $f]} {
set markingmatches 1
findselectline $l findselectline $l
notbusy finding notbusy finding
return 0 return 0
@ -4169,7 +4178,10 @@ proc findmorerev {} {
} }


proc findselectline {l} { proc findselectline {l} {
global findloc commentend ctext global findloc commentend ctext findcurline markingmatches

set markingmatches 1
set findcurline $l
selectline $l 1 selectline $l 1
if {$findloc == "All fields" || $findloc == "Comments"} { if {$findloc == "All fields" || $findloc == "Comments"} {
# highlight the matches in the comments # highlight the matches in the comments
@ -4181,10 +4193,13 @@ proc findselectline {l} {
$ctext tag add found "1.0 + $start c" "1.0 + $end c" $ctext tag add found "1.0 + $start c" "1.0 + $end c"
} }
} }
drawvisible
} }


# mark the bits of a headline or author that match a find string # mark the bits of a headline or author that match a find string
proc markmatches {canv l str tag matches font} { proc markmatches {canv l str tag matches font row} {
global selectedline

set bbox [$canv bbox $tag] set bbox [$canv bbox $tag]
set x0 [lindex $bbox 0] set x0 [lindex $bbox 0]
set y0 [lindex $bbox 1] set y0 [lindex $bbox 1]
@ -4199,6 +4214,9 @@ proc markmatches {canv l str tag matches font} {
[expr {$x0+$xlen+2}] $y1 \ [expr {$x0+$xlen+2}] $y1 \
-outline {} -tags [list match$l matches] -fill yellow] -outline {} -tags [list match$l matches] -fill yellow]
$canv lower $t $canv lower $t
if {[info exists selectedline] && $row == $selectedline} {
$canv raise $t secsel
}
} }
} }