[PATCH] grep: -L should show empty files

Subsystems: the rest

DORMANTno replies

5 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] grep: -L should show empty files

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:48:00

The -L (--files-without-match) option is supposed to show paths that
produced no matches.  When running the internal grep on work tree files,
however, we had an optimization to just return on zero-sized files,
without doing anything.

This optimization doesn't matter too much in practice (a tracked empty
file must be rare, or there is something wrong with your project); to
produce results consistent with GNU grep, we should stop the optimization
and show empty files as not having the given pattern.

Signed-off-by: Junio C Hamano <redacted>
---

 * Fix for a longstanding bug meant for maint.

 builtin-grep.c |    2 --
 1 files changed, 0 insertions(+), 2 deletions(-)
diff --git a/builtin-grep.c b/builtin-grep.c
index fd450bc..84a5af3 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -159,8 +159,6 @@ static int grep_file(struct grep_opt *opt, const char *filename)
 			error("'%s': %s", filename, strerror(errno));
 		return 0;
 	}
-	if (!st.st_size)
-		return 0; /* empty file -- no grep hit */
 	if (!S_ISREG(st.st_mode))
 		return 0;
 	sz = xsize_t(st.st_size);
-- 
1.6.6.280.ge295b7.dirty

Re: [PATCH] grep: -L should show empty files

From: Sverre Rabbelier <hidden>
Date: 2016-06-15 22:48:00

Heya,

On Tue, Jan 12, 2010 at 09:32, Junio C Hamano [off-list ref] wrote:
This optimization doesn't matter too much in practice (a tracked empty
file must be rare, or there is something wrong with your project);
How about python projects, where there's an __init__.py file
everywhere you turn your head? ;)

-- 
Cheers,

Sverre Rabbelier

Re: [PATCH] grep: -L should show empty files

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:48:00

Sverre Rabbelier [off-list ref] writes:
Heya,

On Tue, Jan 12, 2010 at 09:32, Junio C Hamano [off-list ref] wrote:
quoted
This optimization doesn't matter too much in practice (a tracked empty
file must be rare, or there is something wrong with your project);
How about python projects, where there's an __init__.py file
everywhere you turn your head? ;)
It's Ok as the price we pay for producing correct result is to open those
empty files, read them, and look for matches which we will never find ;-)

Re: [PATCH] grep: -L should show empty files

From: Sverre Rabbelier <hidden>
Date: 2016-06-15 22:48:00

Heya,

On Wed, Jan 13, 2010 at 07:56, Junio C Hamano [off-list ref] wrote:
It's Ok as the price we pay for producing correct result is to open those
empty files, read them, and look for matches which we will never find ;-)
I'm not that familiar with the code, but wouldn't it be possible to
keep the early abort, but make it dependent on not using the '-L'
flag?

-- 
Cheers,

Sverre Rabbelier

Re: [PATCH] grep: -L should show empty files

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:48:00

Sverre Rabbelier [off-list ref] writes:
I'm not that familiar with the code, but wouldn't it be possible to
keep the early abort, but make it dependent on not using the '-L'
flag?
Anything codable is possible to code, but my point was I don't think such
an optimization to avoid reading empty files is worth the time to write
and maintain extra code necessary for it.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help