grep: add option to show whole function as context
Add a new option, -W, to show the whole surrounding function of a match. It uses the same regular expressions as -p and diff to find the beginning of sections. Currently it will not display comments in front of a function, but those that are following one. Despite this shortcoming it is already useful, e.g. to simply see a more complete applicable context or to extract whole functions. Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
b35acb5345
commit
ba8ea7496f
@ -509,6 +509,20 @@ test_expect_success 'grep -p -B5' '
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
cat >expected <<EOF
|
||||
hello.c=int main(int argc, const char **argv)
|
||||
hello.c-{
|
||||
hello.c- printf("Hello world.\n");
|
||||
hello.c: return 0;
|
||||
hello.c- /* char ?? */
|
||||
hello.c-}
|
||||
EOF
|
||||
|
||||
test_expect_success 'grep -W' '
|
||||
git grep -W return >actual &&
|
||||
test_cmp expected actual
|
||||
'
|
||||
|
||||
test_expect_success 'grep from a subdirectory to search wider area (1)' '
|
||||
mkdir -p s &&
|
||||
(
|
||||
|
Reference in New Issue
Block a user