tags 465776 + patch thanks Frédéric Brière wrote:
> (In particular, the amount of repeated code would probably give a Ruby > programmer seizures.) Ah, I imagine refactoring would be welcome. :) > So, I did the cowardly thing: I ripped the whole thing off. Hey, it > works. :) And well. Thanks for the patch --- I think it does exactly the right thing. Could you send a copy to g...@vger.kernel.org with sign-off [1], cc-ing Paul Mackerras <pau...@samba.org>? Many thanks, Jonathan [1] http://repo.or.cz/w/git.git/blob_plain/master:/Documentation/SubmittingPatches explains. -- %< -- Subject: gitk: Factor out common code from askfindhighlight and findmore The loops over fields in these two contexts are almost identical. Technically, this should slow down the search, since findmore previously quit this loop early when it found a match. The loop is so short that the difference is not very noticeable. Signed-off-by: Jonathan Nieder <jrnie...@gmail.com> --- Patch is against git://git.kernel.org/pub/scm/gitk/gitk master with your patch applied. gitk | 38 +++++++++++++++++--------------------- 1 files changed, 17 insertions(+), 21 deletions(-) diff --git a/gitk b/gitk index d7e3c45..3ce09e5 100755 --- a/gitk +++ b/gitk @@ -4581,28 +4581,36 @@ proc doesmatch {f} { } } -proc askfindhighlight {row id} { - global nhighlights commitinfo iddrawn - global findloc - global markingmatches +# 1 if matches, 2 if matches author +proc findmatchescommit {id} { + global findloc commitinfo if {![info exists commitinfo($id)]} { getcommit $id } set info $commitinfo($id) - set isbold 0 + set matched 0 + set fldtypes [list [mc Headline] [mc Author] "" [mc Committer] "" [mc Comments]] foreach f $info ty $fldtypes { if {$ty eq ""} continue if {($findloc eq [mc "All fields"] || $findloc eq $ty) && [doesmatch $f]} { if {$ty eq [mc "Author"]} { - set isbold 2 + set matched 2 break } - set isbold 1 + set matched 1 } } + return $matched +} + +proc askfindhighlight {row id} { + global nhighlights iddrawn + global markingmatches + + set isbold [findmatchescommit $id] if {$isbold && [info exists iddrawn($id)]} { if {![ishighlighted $id]} { bolden $id mainfontbold @@ -6431,7 +6439,7 @@ proc stopfinding {} { } proc findmore {} { - global commitdata commitinfo numcommits findpattern findloc + global commitdata numcommits findpattern global findstartline findcurline findallowwrap global find_dirn gdttype fhighlights fprogcoord global curview varcorder vrownum varccommits vrowmod @@ -6439,7 +6447,6 @@ proc findmore {} { if {![info exists find_dirn]} { return 0 } - set fldtypes [list [mc "Headline"] [mc "Author"] "" [mc "Committer"] "" [mc "Comments"]] set l $findcurline set moretodo 0 if {$find_dirn > 0} { @@ -6495,18 +6502,7 @@ proc findmore {} { ![doesmatch $commitdata($id)]} { continue } - if {![info exists commitinfo($id)]} { - getcommit $id - } - set info $commitinfo($id) - foreach f $info ty $fldtypes { - if {$ty eq ""} continue - if {($findloc eq [mc "All fields"] || $findloc eq $ty) && - [doesmatch $f]} { - set found 1 - break - } - } + set found [findmatchescommit $id] if {$found} break } } else { -- 1.7.0 -- To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org