@matheusbsbs / matheus-bagliano / commits / e23d2d6b76
Fork 0

builtin-grep: -L (--files-without-match).

Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed May 3, 2006 at 21:46 UTC e23d2d6b765162902bd8b722e1659f002b97a302
1 file changed +20
builtin-grep.c
+20
@@ -93,6 +93,7 @@ struct grep_opt {
93 unsigned linenum:1;
94 unsigned invert:1;
95 unsigned name_only:1;
96 + unsigned unmatch_name_only:1;
97 unsigned count:1;
98 unsigned word_regexp:1;
99 #define GREP_BINARY_DEFAULT 0
@@ -241,6 +242,11 @@ static int grep_buffer(struct grep_opt *opt, const char *name,
242 */
243 if (opt->invert)
244 hit = !hit;
245 + if (opt->unmatch_name_only) {
246 + if (hit)
247 + return 0;
248 + goto next_line;
249 + }
250 if (hit) {
251 count++;
252 if (binary_match_only) {
@@ -297,6 +303,8 @@ static int grep_buffer(struct grep_opt *opt, const char *name,
303 prev->bol = bol;
304 prev->eol = eol;
305 }
306 +
307 + next_line:
308 *eol = ch;
309 bol = eol + 1;
310 if (!left)
@@ -304,6 +312,13 @@ static int grep_buffer(struct grep_opt *opt, const char *name,
312 left--;
313 lno++;
314 }
315 +
316 + if (opt->unmatch_name_only) {
317 + /* We did not see any hit, so we want to show this */
318 + printf("%s\n", name);
319 + return 1;
320 + }
321 +
322 /* NEEDSWORK:
323 * The real "grep -c foo *.c" gives many "bar.c:0" lines,
324 * which feels mostly useless but sometimes useful. Maybe
@@ -532,6 +547,11 @@ int cmd_grep(int argc, const char **argv, char **envp)
547 opt.name_only = 1;
548 continue;
549 }
550 + if (!strcmp("-L", arg) ||
551 + !strcmp("--files-without-match", arg)) {
552 + opt.unmatch_name_only = 1;
553 + continue;
554 + }
555 if (!strcmp("-c", arg) ||
556 !strcmp("--count", arg)) {
557 opt.count = 1;