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

[RFC/PATCHv2 3/5] grep_cache: check pathspec first

From
Chris Packham <judge.packham@gmail.com>
Date
Oct 15, 2010, 23:26 UTC
Message-ID
<1287185204-843-4-git-send-email-judge.packham@gmail.com>
In-Reply-To
<1287185204-843-1-git-send-email-judge.packham@gmail.com>
This makes grep_cache consistent with grep_tree.
Signed-off-by: Chris Packham <judge.packham@gmail.com>
---
In addition to consistency, moving the pathspec check up allows the
addition of a simple if clause for submodules later.
 builtin/grep.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index a51eb2c..251c4e7 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -595,10 +595,10 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
 
 	for (nr = 0; nr < active_nr; nr++) {
 		struct cache_entry *ce = active_cache[nr];
-		if (!S_ISREG(ce->ce_mode))
-			continue;
 		if (!pathspec_matches(paths, ce->name, opt->max_depth))
 			continue;
+		if (!S_ISREG(ce->ce_mode))
+			continue;
 		/*
 		 * If CE_VALID is on, we assume worktree file and its cache entry
 		 * are identical, even if worktree file has been modified, so use
-- 
1.7.3.1
Previous: Chris PackhamNext: Chris Packham
Message 8 of 15 in “[RGC/PATCHv2] grep: submodule support”
  1. Chris PackhamOct 15, 2010
  2. 1/5 worktree: provide better prefix to go back to original cwdChris Packham, Oct 15, 2010
  3. Jonathan NiederOct 16, 2010
  4. Chris PackhamOct 17, 2010
  5. Nguyen Thai Ngoc DuyOct 17, 2010
  6. Chris PackhamOct 18, 2010
  7. 2/5 grep: output the path from cwd to worktreeChris Packham, Oct 15, 2010
  8. 3/5 grep_cache: check pathspec firstChris Packham, Oct 15, 2010
  9. 4/5 add test for git grep --recursiveChris Packham, Oct 15, 2010
  10. 5/5 grep: add support for grepping in submodulesChris Packham, Oct 15, 2010
  11. Nguyen Thai Ngoc DuyOct 17, 2010
  12. Chris PackhamOct 18, 2010
  13. Nguyen Thai Ngoc DuyOct 18, 2010
  14. Jens LehmannOct 16, 2010
  15. Chris PackhamOct 17, 2010

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.