From mboxrd@z Thu Jan 1 00:00:00 1970 From: =?UTF-8?B?UmVuw6kgU2NoYXJmZQ==?= Subject: [PATCH v2 2/2] grep: long context options Date: Mon, 01 Aug 2011 19:22:52 +0200 Message-ID: <4E36E0EC.1000508@lsrfire.ath.cx> References: <4E357BE2.8030409@lsrfire.ath.cx> <4E36C840.9000808@lsrfire.ath.cx> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit Cc: Sverre Rabbelier , Junio C Hamano To: Git Mailing List X-From: git-owner@vger.kernel.org Mon Aug 01 19:23:02 2011 Return-path: Envelope-to: gcvg-git-2@lo.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1QnwCi-0007vM-8Y for gcvg-git-2@lo.gmane.org; Mon, 01 Aug 2011 19:23:00 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753181Ab1HARW4 (ORCPT ); Mon, 1 Aug 2011 13:22:56 -0400 Received: from india601.server4you.de ([85.25.151.105]:57296 "EHLO india601.server4you.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752876Ab1HARWy (ORCPT ); Mon, 1 Aug 2011 13:22:54 -0400 Received: from [192.168.2.104] (p4FFD8EFC.dip.t-dialin.net [79.253.142.252]) by india601.server4you.de (Postfix) with ESMTPSA id 331C62F8035; Mon, 1 Aug 2011 19:22:53 +0200 (CEST) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:5.0) Gecko/20110624 Thunderbird/5.0 In-Reply-To: Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: Take long option names for -A (--after-context), -B (--before-context) and -C (--context) from GNU grep and add a similar long option name for -W (--function-context). Signed-off-by: Rene Scharfe --- Documentation/git-grep.txt | 26 +++++++++++++++++--------- builtin/grep.c | 8 ++++---- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index 6cd0c50..af501d2 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -155,15 +155,6 @@ OPTIONS Show the filename above the matches in that file instead of at the start of each shown line. --[ABC] :: - Show `context` trailing (`A` -- after), or leading (`B` - -- before), or both (`C` -- context) lines, and place a - line containing `--` between contiguous groups of - matches. - --:: - A shortcut for specifying `-C`. - -p:: --show-function:: Show the preceding line that contains the function name of @@ -172,7 +163,24 @@ OPTIONS patch hunk headers (see 'Defining a custom hunk-header' in linkgit:gitattributes[5]). +-:: +-C :: +--context :: + Show leading and trailing lines, and place a line + containing `--` between contiguous groups of matches. + +-A :: +--after-context :: + Show trailing lines, and place a line containing + `--` between contiguous groups of matches. + +-B :: +--before-context :: + Show leading lines, and place a line containing + `--` between contiguous groups of matches. + -W:: +--function-context:: Show the surrounding text from the previous line containing a function name up to the one before the next function name, effectively showing the whole function in which the match was diff --git a/builtin/grep.c b/builtin/grep.c index 1fae662..1851797 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -827,18 +827,18 @@ int cmd_grep(int argc, const char **argv, const char *prefix) OPT_BOOLEAN(0, "heading", &opt.heading, "show filename only once above matches from same file"), OPT_GROUP(""), - OPT_CALLBACK('C', NULL, &opt, "n", + OPT_CALLBACK('C', "context", &opt, "n", "show context lines before and after matches", context_callback), - OPT_INTEGER('B', NULL, &opt.pre_context, + OPT_INTEGER('B', "before-context", &opt.pre_context, "show context lines before matches"), - OPT_INTEGER('A', NULL, &opt.post_context, + OPT_INTEGER('A', "after-context", &opt.post_context, "show context lines after matches"), OPT_NUMBER_CALLBACK(&opt, "shortcut for -C NUM", context_callback), OPT_BOOLEAN('p', "show-function", &opt.funcname, "show a line with the function name before matches"), - OPT_BOOLEAN('W', NULL, &opt.funcbody, + OPT_BOOLEAN('W', "function-context", &opt.funcbody, "show the surrounding function"), OPT_GROUP(""), OPT_CALLBACK('f', NULL, &opt, "file", -- 1.7.6