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>
Paul Mackerras committed
Jul 26, 2007 at 22:36 UTC
005a2f4e6df7060561817828d4fa4245f87ccadf
1 file changed
+53
-35
gitk
+53
-35
@@ -139,6 +139,10 @@ proc getcommitlines {fd view} {
139
global vparentlist vdisporder vcmitlisted
140
141
set stuff [read $fd 500000]
142
+ # git log doesn't terminate the last commit with a null...
143
+ if {$stuff == {} && $leftover($view) ne {} && [eof $fd]} {
144
+ set stuff "\0"
145
+ }
146
if {$stuff == {}} {
147
if {![eof $fd]} {
148
return 1
@@ -2157,7 +2161,7 @@ proc readfhighlight {} {
2161
2162
proc find_change {name ix op} {
2163
global nhighlights mainfont boldnamerows
2160
- global findstring findpattern findtype markingmatches
2164
+ global findstring findpattern findtype
2165
2166
# delete previous highlights, if any
2167
foreach row $boldnamerows {
@@ -2172,7 +2176,6 @@ proc find_change {name ix op} {
2176
$findstring]
2177
set findpattern "*$e*"
2178
}
2175
- set markingmatches [expr {$findstring ne {}}]
2179
drawvisible
2180
}
2181
@@ -2218,26 +2221,32 @@ proc askfindhighlight {row id} {
2221
}
2222
}
2223
if {$markingmatches} {
2221
- markrowmatches $row [lindex $info 0] [lindex $info 1]
2224
+ markrowmatches $row $id
2225
}
2226
}
2227
set nhighlights($row) $isbold
2228
}
2229
2227
-proc markrowmatches {row headline author} {
2228
- global canv canv2 linehtag linentag
2230
+proc markrowmatches {row id} {
2231
+ global canv canv2 linehtag linentag commitinfo findloc
2232
2233
+ set headline [lindex $commitinfo($id) 0]
2234
+ set author [lindex $commitinfo($id) 1]
2235
$canv delete match$row
2236
$canv2 delete match$row
2232
- set m [findmatches $headline]
2233
- if {$m ne {}} {
2234
- markmatches $canv $row $headline $linehtag($row) $m \
2235
- [$canv itemcget $linehtag($row) -font]
2237
+ if {$findloc eq "All fields" || $findloc eq "Headline"} {
2238
+ set m [findmatches $headline]
2239
+ if {$m ne {}} {
2240
+ markmatches $canv $row $headline $linehtag($row) $m \
2241
+ [$canv itemcget $linehtag($row) -font] $row
2242
+ }
2243
}
2237
- set m [findmatches $author]
2238
- if {$m ne {}} {
2239
- markmatches $canv2 $row $author $linentag($row) $m \
2240
- [$canv2 itemcget $linentag($row) -font]
2244
+ if {$findloc eq "All fields" || $findloc eq "Author"} {
2245
+ set m [findmatches $author]
2246
+ if {$m ne {}} {
2247
+ markmatches $canv2 $row $author $linentag($row) $m \
2248
+ [$canv2 itemcget $linentag($row) -font] $row
2249
+ }
2250
}
2251
}
2252
@@ -3406,7 +3415,7 @@ proc drawcmittext {id row col} {
3415
global linespc canv canv2 canv3 canvy0 fgcolor curview
3416
global commitlisted commitinfo rowidlist parentlist
3417
global rowtextx idpos idtags idheads idotherrefs
3409
- global linehtag linentag linedtag markingmatches
3418
+ global linehtag linentag linedtag
3419
global mainfont canvxmax boldrows boldnamerows fgcolor nullid nullid2
3420
3421
# listed is 0 for boundary, 1 for normal, 2 for left, 3 for right
@@ -3483,9 +3492,6 @@ proc drawcmittext {id row col} {
3492
set linedtag($row) [$canv3 create text 3 $y -anchor w -fill $fgcolor \
3493
-text $date -font $mainfont -tags text]
3494
set xr [expr {$xt + [font measure $mainfont $headline]}]
3486
- if {$markingmatches} {
3487
- markrowmatches $row $headline $name
3488
- }
3495
if {$xr > $canvxmax} {
3496
set canvxmax $xr
3497
setcanvscroll
@@ -3494,7 +3500,7 @@ proc drawcmittext {id row col} {
3500
3501
proc drawcmitrow {row} {
3502
global displayorder rowidlist
3497
- global iddrawn
3503
+ global iddrawn markingmatches
3504
global commitinfo parentlist numcommits
3505
global filehighlight fhighlights findstring nhighlights
3506
global hlview vhighlights
@@ -3515,18 +3521,22 @@ proc drawcmitrow {row} {
3521
if {$highlight_related ne "None" && ![info exists rhighlights($row)]} {
3522
askrelhighlight $row $id
3523
}
3518
- if {[info exists iddrawn($id)]} return
3519
- set col [lsearch -exact [lindex $rowidlist $row] $id]
3520
- if {$col < 0} {
3521
- puts "oops, row $row id $id not in list"
3522
- return
3524
+ if {![info exists iddrawn($id)]} {
3525
+ set col [lsearch -exact [lindex $rowidlist $row] $id]
3526
+ if {$col < 0} {
3527
+ puts "oops, row $row id $id not in list"
3528
+ return
3529
+ }
3530
+ if {![info exists commitinfo($id)]} {
3531
+ getcommit $id
3532
+ }
3533
+ assigncolor $id
3534
+ drawcmittext $id $row $col
3535
+ set iddrawn($id) 1
3536
}
3524
- if {![info exists commitinfo($id)]} {
3525
- getcommit $id
3537
+ if {$markingmatches} {
3538
+ markrowmatches $row $id
3539
}
3527
- assigncolor $id
3528
- drawcmittext $id $row $col
3529
- set iddrawn($id) 1
3540
}
3541
3542
proc drawcommits {row {endrow {}}} {
@@ -4044,7 +4054,6 @@ proc dofind {{rev 0}} {
4054
if {!$rev} {
4055
run findmore
4056
} else {
4047
- set findcurline $findstartline
4057
if {$findcurline == 0} {
4058
set findcurline $numcommits
4059
}
@@ -4079,7 +4088,7 @@ proc findprev {} {
4088
4089
proc findmore {} {
4090
global commitdata commitinfo numcommits findstring findpattern findloc
4082
- global findstartline findcurline markingmatches displayorder
4091
+ global findstartline findcurline displayorder
4092
4093
set fldtypes {Headline Author Date Committer CDate Comments}
4094
set l [expr {$findcurline + 1}]
@@ -4097,6 +4106,8 @@ proc findmore {} {
4106
set last 0
4107
for {} {$l < $lim} {incr l} {
4108
set id [lindex $displayorder $l]
4109
+ # shouldn't happen unless git log doesn't give all the commits...
4110
+ if {![info exists commitdata($id)]} continue
4111
if {![doesmatch $commitdata($id)]} continue
4112
if {![info exists commitinfo($id)]} {
4113
getcommit $id
@@ -4105,7 +4116,6 @@ proc findmore {} {
4116
foreach f $info ty $fldtypes {
4117
if {($findloc eq "All fields" || $findloc eq $ty) &&
4118
[doesmatch $f]} {
4108
- set markingmatches 1
4119
findselectline $l
4120
notbusy finding
4121
return 0
@@ -4124,7 +4134,7 @@ proc findmore {} {
4134
4135
proc findmorerev {} {
4136
global commitdata commitinfo numcommits findstring findpattern findloc
4127
- global findstartline findcurline markingmatches displayorder
4137
+ global findstartline findcurline displayorder
4138
4139
set fldtypes {Headline Author Date Committer CDate Comments}
4140
set l $findcurline
@@ -4151,7 +4161,6 @@ proc findmorerev {} {
4161
foreach f $info ty $fldtypes {
4162
if {($findloc eq "All fields" || $findloc eq $ty) &&
4163
[doesmatch $f]} {
4154
- set markingmatches 1
4164
findselectline $l
4165
notbusy finding
4166
return 0
@@ -4169,7 +4178,10 @@ proc findmorerev {} {
4178
}
4179
4180
proc findselectline {l} {
4172
- global findloc commentend ctext
4181
+ global findloc commentend ctext findcurline markingmatches
4182
+
4183
+ set markingmatches 1
4184
+ set findcurline $l
4185
selectline $l 1
4186
if {$findloc == "All fields" || $findloc == "Comments"} {
4187
# highlight the matches in the comments
@@ -4181,10 +4193,13 @@ proc findselectline {l} {
4193
$ctext tag add found "1.0 + $start c" "1.0 + $end c"
4194
}
4195
}
4196
+ drawvisible
4197
}
4198
4199
# mark the bits of a headline or author that match a find string
4187
-proc markmatches {canv l str tag matches font} {
4200
+proc markmatches {canv l str tag matches font row} {
4201
+ global selectedline
4202
+
4203
set bbox [$canv bbox $tag]
4204
set x0 [lindex $bbox 0]
4205
set y0 [lindex $bbox 1]
@@ -4199,6 +4214,9 @@ proc markmatches {canv l str tag matches font} {
4214
[expr {$x0+$xlen+2}] $y1 \
4215
-outline {} -tags [list match$l matches] -fill yellow]
4216
$canv lower $t
4217
+ if {[info exists selectedline] && $row == $selectedline} {
4218
+ $canv raise $t secsel
4219
+ }
4220
}
4221
}
4222