• J
    grep: expose "status-only" feature via -q · c8610a2e
    Junio C Hamano 提交于
    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: NJunio C Hamano <gitster@pobox.com>
    c8610a2e
builtin-grep.c 17.2 KB