git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH/RFC] Fix the result of "git grep -l -C <num>"

From
AYAlbert Yale <surfingalbert@gmail.com>
Date
Jan 23, 2012, 16:01 UTC
Message-ID
<1327334484-35196-1-git-send-email-surfingalbert@gmail.com>

When combining "git grep -l" with "-C <num>", the first result is omitted.

Signed-off-by: Albert Yale <surfingalbert@gmail.com>
---
For example, if the following command should output a list of 3
different files (a.txt, b.txt, c.txt):

$ git grep -l -C 1 albert_yale b.txt c.txt

The first result (a.txt) will be missing.

Understandably, you wouldn't normally use "-C" with "-l", but the output should still be correct.

My solution is to take "opt.name_only" into account before setting "skip_first_line" in grep.c.

I've reproduced this bug with git version 1.7.8.3 and git version 1.7.9.rc2, both under Mac OS X 10.7.2.

Albert Yale
 builtin/grep.c |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index 9ce064a..076de21 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -1036,7 +1036,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 	if (use_threads) {
 		if (opt.pre_context || opt.post_context || opt.file_break ||
 		    opt.funcbody)
-			skip_first_line = 1;
+		{
+			if( ! opt.name_only )
+				skip_first_line = 1;
+		}
 		start_threads(&opt);
 	}
 #endif
-- 
1.7.8.3
Next: Thomas Rast
Message 1 of 6 in “Fix the result of "git grep -l -C <num>"”
  1. Fix the result of "git grep -l -C <num>"Albert Yale, Jan 23, 2012
  2. Thomas RastJan 23, 2012
  3. Albert YaleJan 23, 2012
  4. grep: fix -l/-L interaction with decoration linesThomas Rast, Jan 23, 2012
  5. Albert YaleJan 23, 2012
  6. Junio C HamanoJan 29, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.