builtin-grep: support '-l' option.
Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
@ -81,6 +81,7 @@ struct grep_opt {
|
|||||||
regex_t regexp;
|
regex_t regexp;
|
||||||
unsigned linenum:1;
|
unsigned linenum:1;
|
||||||
unsigned invert:1;
|
unsigned invert:1;
|
||||||
|
unsigned name_only:1;
|
||||||
int regflags;
|
int regflags;
|
||||||
unsigned pre_context;
|
unsigned pre_context;
|
||||||
unsigned post_context;
|
unsigned post_context;
|
||||||
@ -139,6 +140,10 @@ static int grep_buffer(struct grep_opt *opt, const char *name,
|
|||||||
if (opt->invert)
|
if (opt->invert)
|
||||||
hit = !hit;
|
hit = !hit;
|
||||||
if (hit) {
|
if (hit) {
|
||||||
|
if (opt->name_only) {
|
||||||
|
printf("%s\n", name);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
/* Hit at this line. If we haven't shown the
|
/* Hit at this line. If we haven't shown the
|
||||||
* pre-context lines, we would need to show them.
|
* pre-context lines, we would need to show them.
|
||||||
*/
|
*/
|
||||||
@ -406,6 +411,11 @@ int cmd_grep(int argc, const char **argv, char **envp)
|
|||||||
*/
|
*/
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (!strcmp("-l", arg) ||
|
||||||
|
!strcmp("--files-with-matches", arg)) {
|
||||||
|
opt.name_only = 1;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if (!strcmp("-A", arg) ||
|
if (!strcmp("-A", arg) ||
|
||||||
!strcmp("-B", arg) ||
|
!strcmp("-B", arg) ||
|
||||||
!strcmp("-C", arg)) {
|
!strcmp("-C", arg)) {
|
||||||
|
Reference in New Issue
Block a user