builtin-grep: support '-l' option.
Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
May 1, 2006 at 12:39 UTC
df0e7aa8644eef5ebc018bf838739e25f3494b6c
1 file changed
+10
builtin-grep.c
+10
@@ -81,6 +81,7 @@ struct grep_opt {
81
regex_t regexp;
82
unsigned linenum:1;
83
unsigned invert:1;
84
+ unsigned name_only:1;
85
int regflags;
86
unsigned pre_context;
87
unsigned post_context;
@@ -139,6 +140,10 @@ static int grep_buffer(struct grep_opt *opt, const char *name,
140
if (opt->invert)
141
hit = !hit;
142
if (hit) {
143
+ if (opt->name_only) {
144
+ printf("%s\n", name);
145
+ return 1;
146
+ }
147
/* Hit at this line. If we haven't shown the
148
* pre-context lines, we would need to show them.
149
*/
@@ -406,6 +411,11 @@ int cmd_grep(int argc, const char **argv, char **envp)
411
*/
412
continue;
413
}
414
+ if (!strcmp("-l", arg) ||
415
+ !strcmp("--files-with-matches", arg)) {
416
+ opt.name_only = 1;
417
+ continue;
418
+ }
419
if (!strcmp("-A", arg) ||
420
!strcmp("-B", arg) ||
421
!strcmp("-C", arg)) {