summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 02ab1c4)
raw | patch | inline | side by side (parent: 02ab1c4)
author | Junio C Hamano <junkio@cox.net> | |
Wed, 10 May 2006 01:28:41 +0000 (18:28 -0700) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Wed, 10 May 2006 01:29:35 +0000 (18:29 -0700) |
Signed-off-by: Junio C Hamano <junkio@cox.net>
Documentation/git-grep.txt | patch | blob | history | |
builtin-grep.c | patch | blob | history |
index 56b683ae56ac65f11932f5cf74bafb7ede800f92..74102b7944fd7153602ea5d9ae0969c150cd945f 100644 (file)
'git-grep' [--cached]
[-a | --text] [-I] [-i | --ignore-case] [-w | --word-regexp]
[-v | --invert-match]
- [-E | --extended-regexp] [-G | --basic-regexp]
+ [-E | --extended-regexp] [-G | --basic-regexp] [-F | --fixed-strings]
[-n] [-l | --files-with-matches] [-L | --files-without-match]
[-c | --count]
[-A <post-context>] [-B <pre-context>] [-C <context>]
diff --git a/builtin-grep.c b/builtin-grep.c
index 52ac521afea67b3de2ee3c5f1fd196ba11f17c9a..fead35662944070f8502ed0484fe6b6085d7ac86 100644 (file)
--- a/builtin-grep.c
+++ b/builtin-grep.c
unsigned unmatch_name_only:1;
unsigned count:1;
unsigned word_regexp:1;
+ unsigned fixed:1;
#define GREP_BINARY_DEFAULT 0
#define GREP_BINARY_NOMATCH 1
#define GREP_BINARY_TEXT 2
return 0;
}
+static int fixmatch(const char *pattern, char *line, regmatch_t *match)
+{
+ char *hit = strstr(line, pattern);
+ if (!hit) {
+ match->rm_so = match->rm_eo = -1;
+ return REG_NOMATCH;
+ }
+ else {
+ match->rm_so = hit - line;
+ match->rm_eo = match->rm_so + strlen(pattern);
+ return 0;
+ }
+}
+
static int grep_buffer(struct grep_opt *opt, const char *name,
char *buf, unsigned long size)
{
*eol = 0;
for (p = opt->pattern_list; p; p = p->next) {
- regex_t *exp = &p->regexp;
- hit = !regexec(exp, bol, ARRAY_SIZE(pmatch),
- pmatch, 0);
+ if (!opt->fixed) {
+ regex_t *exp = &p->regexp;
+ hit = !regexec(exp, bol, ARRAY_SIZE(pmatch),
+ pmatch, 0);
+ }
+ else {
+ hit = !fixmatch(p->pattern, bol, pmatch);
+ }
if (hit && opt->word_regexp) {
/* Match beginning must be either
opt.regflags |= REG_EXTENDED;
continue;
}
+ if (!strcmp("-F", arg) ||
+ !strcmp("--fixed-strings", arg)) {
+ opt.fixed = 1;
+ continue;
+ }
if (!strcmp("-G", arg) ||
!strcmp("--basic-regexp", arg)) {
opt.regflags &= ~REG_EXTENDED;
if (!opt.pattern_list)
die("no pattern given.");
- compile_patterns(&opt);
+ if ((opt.regflags != REG_NEWLINE) && opt.fixed)
+ die("cannot mix --fixed-strings and regexp");
+ if (!opt.fixed)
+ compile_patterns(&opt);
/* Check revs and then paths */
for (i = 1; i < argc; i++) {