Re: [PATCH] Don't search files with an unset "grep" attribute
- From
Conrad Irwin <conrad.irwin@gmail.com>
- Date
- Feb 1, 2012, 09:28 UTC
- Message-ID
- <CAOTq_ptj06aNGsQRjV0fVRxnQFBHmU2FFSXwWDUUk9MM77k2LQ@mail.gmail.com>
- In-Reply-To
- <20120201091009.GA20984@sigill.intra.peff.net>
On Wed, Feb 1, 2012 at 1:10 AM, Jeff King <peff@peff.net> wrote:
Show 6 quoted lines
> On Wed, Feb 01, 2012 at 03:20:05AM -0500, Jeff King wrote: > > Actually, it's a little bit more complicated. I was looking at a > slightly old version of grep.c. Since 0579f91 (grep: enable threading > with -p and -W using lazy attribute lookup, 2011-12-12), the lookup > happens in lots of sub-functions, and locking is required.
Heh, you just beat me to it.
> But there's more. Respecting binary attributes does mean looking up > attributes for _every_ file. And that has a noticeable impact. My > best-of-five for "git grep foo" on linux-2.6 went from 0.302s to 0.392s. > Yuck.
The first time I introduced this behaviour[1], I made it conditional on a preference — those who wanted "good" grep could set the preference, while those who wanted "fast" grep could not. I think that's not a good idea, though if the performance issues are show-stoppers, I'd suggest the opposite preference (so speed-freaks can disable the checks).
Tests from [1] included below in case they're still useful (they pass with your change)
[1] http://article.gmane.org/gmane.comp.version-control.git/179299/match=grep ---
diff --git a/t/t7008-grep-binary.sh b/t/t7008-grep-binary.sh index 917a264..4d94461 100755 --- a/t/t7008-grep-binary.sh +++ b/t/t7008-grep-binary.sh @@ -99,4 +99,23 @@ test_expect_success 'git grep y<NUL>x a' " test_must_fail git grep -f f a " +test_expect_success 'git -c grep.binaryFiles=1 grep ina a' " + echo 'a diff' > .gitattributes && + printf 'binaryQfile' | q_to_nul >a && + echo 'a:binaryQfile' | q_to_nul >expect && + git -c grep.binaryFiles=1 grep ina a > actual && + rm .gitattributes && + test_cmp expect actual +" +test_expect_success 'git -c grep.binaryFiles=1 grep tex t' " + echo 'text' > t && + git add t && + echo 't -diff' > .gitattributes && + echo Binary file t matches >expect && + git -c grep.binaryFiles=1 grep tex t >actual && + rm .gitattributes && + test_cmp expect actual +" + + test_done