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

Re: [PATCH] grep: fix grepping for "intent to add" files

From
Duy Nguyen <pclouds@gmail.com>
Date
Jun 16, 2016, 07:47 UTC
Message-ID
<20160616074709.GA24412@duynguyen-vnpc.vn.dektech.internal>
In-Reply-To
<20160616065324.GA14967@hashpling.org>
On Thu, Jun 16, 2016 at 07:53:24AM +0100, Charles Bailey wrote:
Show 7 quoted lines
> From: Charles Bailey <cbailey32@bloomberg.net>
> 
> This reverts commit 4d552005323034c1d6311796ac1074e9a4b4b57e.
> 
> This commit caused 'git grep' to no longer find matches in new files in
> the working tree where the corresponding index entry had the "intent to
> add" bit set.

I don't think revert is right. It rather needs a re-fix like below. Basically we want grep_file() to run as normal, but grep_sha1() (i.e. git grep --cached) should ignore i-t-a entries, because empty SHA-1 is not the right content to grep. It does not matter in positive matching, sure, but it may in -v cache.

-- 8< --
diff --git a/builtin/grep.c b/builtin/grep.c
index 462e607..ae73831 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -386,7 +386,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
 
 	for (nr = 0; nr < active_nr; nr++) {
 		const struct cache_entry *ce = active_cache[nr];
-		if (!S_ISREG(ce->ce_mode) || ce_intent_to_add(ce))
+		if (!S_ISREG(ce->ce_mode))
 			continue;
 		if (!ce_path_match(ce, pathspec, NULL))
 			continue;
@@ -396,7 +396,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int
 		 * cache version instead
 		 */
 		if (cached || (ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) {
-			if (ce_stage(ce))
+			if (ce_stage(ce) || ce_intent_to_add(ce))
 				continue;
 			hit |= grep_sha1(opt, ce->sha1, ce->name, 0, ce->name);
 		}
-- 8< --
--
Duy
Previous: Junio C HamanoNext: Charles Bailey
Message 3 of 8 in “grep: fix grepping for "intent to add" files”
  1. grep: fix grepping for "intent to add" filesCharles Bailey, Jun 16, 2016
  2. Junio C HamanoJun 16, 2016
  3. Duy NguyenJun 16, 2016
  4. Charles BaileyJun 16, 2016
  5. Duy NguyenJun 16, 2016
  6. Charles BaileyJun 16, 2016
  7. Duy NguyenJun 16, 2016
  8. Junio C HamanoJun 16, 2016

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.