From d2355d76150316104b89443065e62a71342c36be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kiedrowicz?= Date: Thu, 5 May 2011 00:00:17 +0200 Subject: [PATCH 1/3] Documentation: Add --line-number to git-grep synopsis MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 7d6cb10b ("grep: Add the option '--line-number'", 2011-03-28) introduced the --line-number option and added its description to OPTIONS section, but forgot to update SYNOPSIS. Signed-off-by: Michał Kiedrowicz Signed-off-by: Junio C Hamano --- Documentation/git-grep.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt index d7523b3e45..4a5837881d 100644 --- a/Documentation/git-grep.txt +++ b/Documentation/git-grep.txt @@ -12,7 +12,7 @@ SYNOPSIS 'git grep' [-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp] [-v | --invert-match] [-h|-H] [--full-name] [-E | --extended-regexp] [-G | --basic-regexp] - [-F | --fixed-strings] [-n] + [-F | --fixed-strings] [-n | --line-number] [-l | --files-with-matches] [-L | --files-without-match] [(-O | --open-files-in-pager) []] [-z | --null] From 5a69eaf5541b8449ede74f148d395abd0acbf20f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kiedrowicz?= Date: Thu, 5 May 2011 00:00:18 +0200 Subject: [PATCH 2/3] contrib/completion: --line-number to git grep MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The "-n" option of "git grep" gained a synonym "--line-number" with commit 7d6cb10b ("grep: Add the option '--line-number'", 2011-03-28). Teach bash-completion about it. Signed-off-by: Michał Kiedrowicz Signed-off-by: Junio C Hamano --- contrib/completion/git-completion.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/completion/git-completion.bash b/contrib/completion/git-completion.bash index 840ae38760..3dc9cbe9f9 100755 --- a/contrib/completion/git-completion.bash +++ b/contrib/completion/git-completion.bash @@ -1485,7 +1485,7 @@ _git_grep () __gitcomp " --cached --text --ignore-case --word-regexp --invert-match - --full-name + --full-name --line-number --extended-regexp --basic-regexp --fixed-strings --files-with-matches --name-only --files-without-match From 97e777842260a5339bb5272a35ebeaeaae554937 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kiedrowicz?= Date: Thu, 5 May 2011 00:00:19 +0200 Subject: [PATCH 3/3] grep: Put calls to fixmatch() and regmatch() into patmatch() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Both match_one_pattern() and look_ahead() use fixmatch() and regmatch() in the same way. They really want to match a pattern againt a string, but now they need to know if the pattern is fixed or regexp. This change cleans this up by introducing patmatch() (from "pattern match") and also simplifies inserting other ways of matching a string. Signed-off-by: Michał Kiedrowicz Signed-off-by: Junio C Hamano --- grep.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/grep.c b/grep.c index 63c4280cac..d67baf9566 100644 --- a/grep.c +++ b/grep.c @@ -412,6 +412,19 @@ static int regmatch(const regex_t *preg, char *line, char *eol, return regexec(preg, line, 1, match, eflags); } +static int patmatch(struct grep_pat *p, char *line, char *eol, + regmatch_t *match, int eflags) +{ + int hit; + + if (p->fixed) + hit = !fixmatch(p, line, eol, match); + else + hit = !regmatch(&p->regexp, line, eol, match, eflags); + + return hit; +} + static int strip_timestamp(char *bol, char **eol_p) { char *eol = *eol_p; @@ -461,10 +474,7 @@ static int match_one_pattern(struct grep_pat *p, char *bol, char *eol, } again: - if (p->fixed) - hit = !fixmatch(p, bol, eol, pmatch); - else - hit = !regmatch(&p->regexp, bol, eol, pmatch, eflags); + hit = patmatch(p, bol, eol, pmatch, eflags); if (hit && p->word_regexp) { if ((pmatch[0].rm_so < 0) || @@ -791,10 +801,7 @@ static int look_ahead(struct grep_opt *opt, int hit; regmatch_t m; - if (p->fixed) - hit = !fixmatch(p, bol, bol + *left_p, &m); - else - hit = !regmatch(&p->regexp, bol, bol + *left_p, &m, 0); + hit = patmatch(p, bol, bol + *left_p, &m, 0); if (!hit || m.rm_so < 0 || m.rm_eo < 0) continue; if (earliest < 0 || m.rm_so < earliest)