@matheusbsbs / matheus-bagliano / commits / cca5d946d6
Fork 0

gitk: Simplify the code for finding commits

This unifies findmore and findmorerev, and adds the ability to do a search with or without wrap around from the end of the list of commits to the beginning (or vice versa for reverse searches). findnext and findprev are gone, and the buttons and keys for searching all call dofind now. dofind doesn't unmark the matches to start with. Shift-up and shift-down are back by popular request, and the searches they do don't wrap around. The other keys that do searches (/, ?, return, M-f) do wrapping searches except for M-g. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Oct 27, 2007 at 21:16 UTC cca5d946d692fde7ea5408a694cb4b1c97a5a838
1 file changed +54 -152
gitk
+54 -152
@@ -764,8 +764,8 @@ proc makewindow {} {
764
765 # build up the bottom bar of upper window
766 label .tf.lbar.flabel -text "Find " -font uifont
767 - button .tf.lbar.fnext -text "next" -command dofind -font uifont
768 - button .tf.lbar.fprev -text "prev" -command {dofind 1} -font uifont
767 + button .tf.lbar.fnext -text "next" -command {dofind 1 1} -font uifont
768 + button .tf.lbar.fprev -text "prev" -command {dofind -1 1} -font uifont
769 label .tf.lbar.flab2 -text " commit " -font uifont
770 pack .tf.lbar.flabel .tf.lbar.fnext .tf.lbar.fprev .tf.lbar.flab2 \
771 -side left -fill y
@@ -959,6 +959,8 @@ proc makewindow {} {
959 bindkey <End> sellastline
960 bind . <Key-Up> "selnextline -1"
961 bind . <Key-Down> "selnextline 1"
962 + bind . <Shift-Key-Up> "dofind -1 0"
963 + bind . <Shift-Key-Down> "dofind 1 0"
964 bindkey <Key-Right> "goforw"
965 bindkey <Key-Left> "goback"
966 bind . <Key-Prior> "selnextpage -1"
@@ -983,14 +985,14 @@ proc makewindow {} {
985 bindkey b "$ctext yview scroll -1 pages"
986 bindkey d "$ctext yview scroll 18 units"
987 bindkey u "$ctext yview scroll -18 units"
986 - bindkey / {findnext 1}
987 - bindkey <Key-Return> {findnext 0}
988 - bindkey ? findprev
988 + bindkey / {dofind 1 1}
989 + bindkey <Key-Return> {dofind 1 1}
990 + bindkey ? {dofind -1 1}
991 bindkey f nextfile
992 bindkey <F5> updatecommits
993 bind . <$M1B-q> doquit
992 - bind . <$M1B-f> dofind
993 - bind . <$M1B-g> {findnext 0}
994 + bind . <$M1B-f> {dofind 1 1}
995 + bind . <$M1B-g> {dofind 1 0}
996 bind . <$M1B-r> dosearchback
997 bind . <$M1B-s> dosearch
998 bind . <$M1B-equal> {incrfont 1}
@@ -999,7 +1001,7 @@ proc makewindow {} {
1001 bind . <$M1B-KP_Subtract> {incrfont -1}
1002 wm protocol . WM_DELETE_WINDOW doquit
1003 bind . <Button-1> "click %W"
1002 - bind $fstring <Key-Return> dofind
1004 + bind $fstring <Key-Return> {dofind 1 1}
1005 bind $sha1entry <Key-Return> gotocommit
1006 bind $sha1entry <<PasteSelection>> clearsha1
1007 bind $cflist <1> {sel_flist %W %x %y; break}
@@ -1325,8 +1327,8 @@ Gitk key bindings:
1327 <$M1T-Down> Scroll commit list down one line
1328 <$M1T-PageUp> Scroll commit list up one page
1329 <$M1T-PageDown> Scroll commit list down one page
1328 -<Shift-Up> Move to previous highlighted line
1329 -<Shift-Down> Move to next highlighted line
1330 +<Shift-Up> Find backwards (upwards, later commits)
1331 +<Shift-Down> Find forwards (downwards, earlier commits)
1332 <Delete>, b Scroll diff view up one page
1333 <Backspace> Scroll diff view up one page
1334 <Space> Scroll diff view down one page
@@ -2459,11 +2461,7 @@ proc readfhighlight {} {
2461 return 0
2462 }
2463 if {[info exists find_dirn]} {
2462 - if {$find_dirn > 0} {
2463 - run findmore
2464 - } else {
2465 - run findmorerev
2466 - }
2464 + run findmore
2465 }
2466 return 1
2467 }
@@ -4247,15 +4245,18 @@ proc findmatches {f} {
4245 return $matches
4246 }
4247
4250 -proc dofind {{rev 0}} {
4248 +proc dofind {{dirn 1} {wrap 1}} {
4249 global findstring findstartline findcurline selectedline numcommits
4252 - global gdttype filehighlight fh_serial find_dirn
4250 + global gdttype filehighlight fh_serial find_dirn findallowwrap
4251
4254 - unmarkmatches
4252 + if {[info exists find_dirn]} {
4253 + if {$find_dirn == $dirn} return
4254 + stopfinding
4255 + }
4256 focus .
4257 if {$findstring eq {} || $numcommits == 0} return
4258 if {![info exists selectedline]} {
4258 - set findstartline [lindex [visiblerows] $rev]
4259 + set findstartline [lindex [visiblerows] [expr {$dirn < 0}]]
4260 } else {
4261 set findstartline $selectedline
4262 }
@@ -4265,13 +4266,9 @@ proc dofind {{rev 0}} {
4266 after cancel do_file_hl $fh_serial
4267 do_file_hl $fh_serial
4268 }
4268 - if {!$rev} {
4269 - set find_dirn 1
4270 - run findmore
4271 - } else {
4272 - set find_dirn -1
4273 - run findmorerev
4274 - }
4269 + set find_dirn $dirn
4270 + set findallowwrap $wrap
4271 + run findmore
4272 }
4273
4274 proc stopfinding {} {
@@ -4286,147 +4283,52 @@ proc stopfinding {} {
4283 }
4284 }
4285
4289 -proc findnext {restart} {
4290 - global findcurline find_dirn
4291 -
4292 - if {[info exists find_dirn]} return
4293 - if {![info exists findcurline]} {
4294 - if {$restart} {
4295 - dofind
4296 - } else {
4297 - bell
4298 - }
4299 - } else {
4300 - set find_dirn 1
4301 - run findmore
4302 - nowbusy finding "Searching"
4303 - }
4304 -}
4305 -
4306 -proc findprev {} {
4307 - global findcurline find_dirn
4308 -
4309 - if {[info exists find_dirn]} return
4310 - if {![info exists findcurline]} {
4311 - dofind 1
4312 - } else {
4313 - set find_dirn -1
4314 - run findmorerev
4315 - nowbusy finding "Searching"
4316 - }
4317 -}
4318 -
4286 proc findmore {} {
4287 global commitdata commitinfo numcommits findpattern findloc
4288 global findstartline findcurline displayorder
4289 global find_dirn gdttype fhighlights fprogcoord
4290 + global findallowwrap
4291
4292 if {![info exists find_dirn]} {
4293 return 0
4294 }
4295 set fldtypes {Headline Author Date Committer CDate Comments}
4328 - set l [expr {$findcurline + 1}]
4329 - if {$l >= $numcommits} {
4330 - set l 0
4331 - }
4332 - if {$l <= $findstartline} {
4333 - set lim [expr {$findstartline + 1}]
4334 - } else {
4335 - set lim $numcommits
4336 - }
4337 - if {$lim - $l > 500} {
4338 - set lim [expr {$l + 500}]
4339 - }
4340 - set found 0
4341 - set domore 1
4342 - if {$gdttype eq "containing:"} {
4343 - for {} {$l < $lim} {incr l} {
4344 - set id [lindex $displayorder $l]
4345 - # shouldn't happen unless git log doesn't give all the commits...
4346 - if {![info exists commitdata($id)]} continue
4347 - if {![doesmatch $commitdata($id)]} continue
4348 - if {![info exists commitinfo($id)]} {
4349 - getcommit $id
4350 - }
4351 - set info $commitinfo($id)
4352 - foreach f $info ty $fldtypes {
4353 - if {($findloc eq "All fields" || $findloc eq $ty) &&
4354 - [doesmatch $f]} {
4355 - set found 1
4356 - break
4357 - }
4358 - }
4359 - if {$found} break
4296 + set l $findcurline
4297 + set moretodo 0
4298 + if {$find_dirn > 0} {
4299 + incr l
4300 + if {$l >= $numcommits} {
4301 + set l 0
4302 + }
4303 + if {$l <= $findstartline} {
4304 + set lim [expr {$findstartline + 1}]
4305 + } else {
4306 + set lim $numcommits
4307 + set moretodo $findallowwrap
4308 }
4309 } else {
4362 - for {} {$l < $lim} {incr l} {
4363 - set id [lindex $displayorder $l]
4364 - if {![info exists fhighlights($l)]} {
4365 - askfilehighlight $l $id
4366 - if {$domore} {
4367 - set domore 0
4368 - set findcurline [expr {$l - 1}]
4369 - }
4370 - } elseif {$fhighlights($l)} {
4371 - set found $domore
4372 - break
4373 - }
4310 + if {$l == 0} {
4311 + set l $numcommits
4312 }
4375 - }
4376 - if {$found || ($domore && $l == $findstartline + 1)} {
4377 - unset findcurline
4378 - unset find_dirn
4379 - notbusy finding
4380 - set fprogcoord 0
4381 - adjustprogress
4382 - if {$found} {
4383 - findselectline $l
4313 + incr l -1
4314 + if {$l >= $findstartline} {
4315 + set lim [expr {$findstartline - 1}]
4316 } else {
4385 - bell
4317 + set lim -1
4318 + set moretodo $findallowwrap
4319 }
4387 - return 0
4320 }
4389 - if {!$domore} {
4390 - flushhighlights
4391 - } else {
4392 - set findcurline [expr {$l - 1}]
4393 - }
4394 - set n [expr {$findcurline - ($findstartline + 1)}]
4395 - if {$n < 0} {
4396 - incr n $numcommits
4397 - }
4398 - set fprogcoord [expr {$n * 1.0 / $numcommits}]
4399 - adjustprogress
4400 - return $domore
4401 -}
4402 -
4403 -proc findmorerev {} {
4404 - global commitdata commitinfo numcommits findpattern findloc
4405 - global findstartline findcurline displayorder
4406 - global find_dirn gdttype fhighlights fprogcoord
4407 -
4408 - if {![info exists find_dirn]} {
4409 - return 0
4410 - }
4411 - set fldtypes {Headline Author Date Committer CDate Comments}
4412 - set l $findcurline
4413 - if {$l == 0} {
4414 - set l $numcommits
4415 - }
4416 - incr l -1
4417 - if {$l >= $findstartline} {
4418 - set lim [expr {$findstartline - 1}]
4419 - } else {
4420 - set lim -1
4421 - }
4422 - if {$l - $lim > 500} {
4423 - set lim [expr {$l - 500}]
4321 + set n [expr {($lim - $l) * $find_dirn}]
4322 + if {$n > 500} {
4323 + set n 500
4324 + set moretodo 1
4325 }
4326 set found 0
4327 set domore 1
4328 if {$gdttype eq "containing:"} {
4428 - for {} {$l > $lim} {incr l -1} {
4329 + for {} {$n > 0} {incr n -1; incr l $find_dirn} {
4330 set id [lindex $displayorder $l]
4331 + # shouldn't happen unless git log doesn't give all the commits...
4332 if {![info exists commitdata($id)]} continue
4333 if {![doesmatch $commitdata($id)]} continue
4334 if {![info exists commitinfo($id)]} {
@@ -4443,13 +4345,13 @@ proc findmorerev {} {
4345 if {$found} break
4346 }
4347 } else {
4446 - for {} {$l > $lim} {incr l -1} {
4348 + for {} {$n > 0} {incr n -1; incr l $find_dirn} {
4349 set id [lindex $displayorder $l]
4350 if {![info exists fhighlights($l)]} {
4351 askfilehighlight $l $id
4352 if {$domore} {
4353 set domore 0
4452 - set findcurline [expr {$l + 1}]
4354 + set findcurline [expr {$l - $find_dirn}]
4355 }
4356 } elseif {$fhighlights($l)} {
4357 set found $domore
@@ -4457,7 +4359,7 @@ proc findmorerev {} {
4359 }
4360 }
4361 }
4460 - if {$found || ($domore && $l == $findstartline - 1)} {
4362 + if {$found || ($domore && !$moretodo)} {
4363 unset findcurline
4364 unset find_dirn
4365 notbusy finding
@@ -4473,9 +4375,9 @@ proc findmorerev {} {
4375 if {!$domore} {
4376 flushhighlights
4377 } else {
4476 - set findcurline [expr {$l + 1}]
4378 + set findcurline [expr {$l - $find_dirn}]
4379 }
4478 - set n [expr {($findstartline - 1) - $findcurline}]
4380 + set n [expr {($findcurline - $findstartline) * $find_dirn - 1}]
4381 if {$n < 0} {
4382 incr n $numcommits
4383 }