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>
Junio C Hamano committed
Nov 26, 2006 at 12:47 UTC
36f2587ffb6802cb38071510810f48cddfc4f34a
1 file changed
+21
-4
builtin-grep.c
+21
-4
@@ -268,7 +268,7 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
268
for (i = 0; i < active_nr; i++) {
269
struct cache_entry *ce = active_cache[i];
270
char *name;
271
- if (ce_stage(ce) || !S_ISREG(ntohl(ce->ce_mode)))
271
+ if (!S_ISREG(ntohl(ce->ce_mode)))
272
continue;
273
if (!pathspec_matches(paths, ce->name))
274
continue;
@@ -280,12 +280,19 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
280
memcpy(name + 2, ce->name, len + 1);
281
}
282
argv[argc++] = name;
283
- if (argc < MAXARGS)
283
+ if (argc < MAXARGS && !ce_stage(ce))
284
continue;
285
status = exec_grep(argc, argv);
286
if (0 < status)
287
hit = 1;
288
argc = nr;
289
+ if (ce_stage(ce)) {
290
+ do {
291
+ i++;
292
+ } while (i < active_nr &&
293
+ !strcmp(ce->name, active_cache[i]->name));
294
+ i--; /* compensate for loop control */
295
+ }
296
}
297
if (argc > nr) {
298
status = exec_grep(argc, argv);
@@ -316,14 +323,24 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
323
324
for (nr = 0; nr < active_nr; nr++) {
325
struct cache_entry *ce = active_cache[nr];
319
- if (ce_stage(ce) || !S_ISREG(ntohl(ce->ce_mode)))
326
+ if (!S_ISREG(ntohl(ce->ce_mode)))
327
continue;
328
if (!pathspec_matches(paths, ce->name))
329
continue;
323
- if (cached)
330
+ if (cached) {
331
+ if (ce_stage(ce))
332
+ continue;
333
hit |= grep_sha1(opt, ce->sha1, ce->name, 0);
334
+ }
335
else
336
hit |= grep_file(opt, ce->name);
337
+ if (ce_stage(ce)) {
338
+ do {
339
+ nr++;
340
+ } while (nr < active_nr &&
341
+ !strcmp(ce->name, active_cache[nr]->name));
342
+ nr--; /* compensate for loop control */
343
+ }
344
}
345
free_grep_patterns(opt);
346
return hit;