diff options
author | Junio C Hamano <junkio@cox.net> | 2006-11-26 12:47:52 -0800 |
---|---|---|
committer | Junio C Hamano <junkio@cox.net> | 2006-11-26 14:22:01 -0800 |
commit | 36f2587ffb6802cb38071510810f48cddfc4f34a (patch) | |
tree | aeb2faed03da23899e3a1d278b0a66bfa7935c10 /builtin-grep.c | |
parent | aabd76930fdc585dd3e198a3351d426583af4081 (diff) | |
download | git-36f2587ffb6802cb38071510810f48cddfc4f34a.tar.gz git-36f2587ffb6802cb38071510810f48cddfc4f34a.tar.xz |
grep: do not skip unmerged entries when grepping in the working tree.
We used to skip unmerged entries, which made sense for grepping
in the cached copies, but not for grepping in the working tree.
Noticed by Johannes Sixt.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Diffstat (limited to 'builtin-grep.c')
-rw-r--r-- | builtin-grep.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/builtin-grep.c b/builtin-grep.c index ad7dc00cd..9873e3d1d 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -268,7 +268,7 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached) for (i = 0; i < active_nr; i++) { struct cache_entry *ce = active_cache[i]; char *name; - if (ce_stage(ce) || !S_ISREG(ntohl(ce->ce_mode))) + if (!S_ISREG(ntohl(ce->ce_mode))) continue; if (!pathspec_matches(paths, ce->name)) continue; @@ -280,12 +280,19 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached) memcpy(name + 2, ce->name, len + 1); } argv[argc++] = name; - if (argc < MAXARGS) + if (argc < MAXARGS && !ce_stage(ce)) continue; status = exec_grep(argc, argv); if (0 < status) hit = 1; argc = nr; + if (ce_stage(ce)) { + do { + i++; + } while (i < active_nr && + !strcmp(ce->name, active_cache[i]->name)); + i--; /* compensate for loop control */ + } } if (argc > nr) { status = exec_grep(argc, argv); @@ -316,14 +323,24 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached) for (nr = 0; nr < active_nr; nr++) { struct cache_entry *ce = active_cache[nr]; - if (ce_stage(ce) || !S_ISREG(ntohl(ce->ce_mode))) + if (!S_ISREG(ntohl(ce->ce_mode))) continue; if (!pathspec_matches(paths, ce->name)) continue; - if (cached) + if (cached) { + if (ce_stage(ce)) + continue; hit |= grep_sha1(opt, ce->sha1, ce->name, 0); + } else hit |= grep_file(opt, ce->name); + if (ce_stage(ce)) { + do { + nr++; + } while (nr < active_nr && + !strcmp(ce->name, active_cache[nr]->name)); + nr--; /* compensate for loop control */ + } } free_grep_patterns(opt); return hit; |