grep: expose "status-only" feature via -q
commitc8610a2e7eca60a060f719f0aeb20f146e339de4
authorJunio C Hamano <gitster@pobox.com>
Mon, 25 Jan 2010 23:37:23 +0000 (25 15:37 -0800)
committerJunio C Hamano <gitster@pobox.com>
Mon, 25 Jan 2010 23:42:55 +0000 (25 15:42 -0800)
tree2099d59cbeb047717342a1c175a9e61543161c82
parent2d7f98bac7e1d8b42c558e179ea24f5b06512622
grep: expose "status-only" feature via -q

Teach "git grep" a new "-q" option to report the presense of a match via
its exit status without showing any output, similar to how "grep -q"
works.  Internally "grep" engine already knew this "status-only" mode of
operation because it needed to grep inside log message to filter commits
when called from the "git log" machinery, and this patch only exposes it
to the command line tool.

A somewhat unfair benchmark in the Linux kernel directory shows a dramatic
improvement:

    (with patch)
    $ time ../git.git/git grep -q linux HEAD ; echo $?

    real    0m0.030s
    user    0m0.004s
    sys     0m0.004s
    0

    (without patch)
    $ time git grep linux HEAD >/dev/null; echo $?

    real    0m4.432s
    user    0m4.272s
    sys     0m0.076s
    0

This is "somewhat unfair" because I knew a file with such a string comes
very early in the tree traversal (namely, ".gitignore").

Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin-grep.c