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

[PATCH 2/5] grep: skip files outside sparse checkout area

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Jul 29, 2009, 06:49 UTC
Message-ID
<1248850154-5469-3-git-send-email-pclouds@gmail.com>
In-Reply-To
<1248850154-5469-2-git-send-email-pclouds@gmail.com>
---
 Documentation/git-grep.txt |    4 +++-
 builtin-grep.c             |    7 ++++++-
 2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt
index 8c70020..8d9cba7 100644
--- a/Documentation/git-grep.txt
+++ b/Documentation/git-grep.txt
@@ -27,7 +27,9 @@ SYNOPSIS
 DESCRIPTION
 -----------
 Look for specified patterns in the working tree files, blobs
-registered in the index file, or given tree objects.
+registered in the index file, or given tree objects. By default
+it will search in the working tree files. When in sparse checkout
+mode, it only searches checked-out files.
 
 
 OPTIONS
diff --git a/builtin-grep.c b/builtin-grep.c
index ad0e0a5..55078cb 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -455,6 +455,8 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached)
 			continue;
 		if (!pathspec_matches(paths, ce->name, opt->max_depth))
 			continue;
+		if (ce->ce_flags & CE_VALID)
+			continue;
 		name = ce->name;
 		if (name[0] == '-') {
 			int len = ce_namelen(ce);
@@ -522,8 +524,11 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached,
 				continue;
 			hit |= grep_sha1(opt, ce->sha1, ce->name, 0);
 		}
-		else
+		else {
+			if (ce->ce_flags & CE_VALID)
+				continue;
 			hit |= grep_file(opt, ce->name);
+		}
 		if (ce_stage(ce)) {
 			do {
 				nr++;
-- 
1.6.3.2.448.gdf8b6
Previous: Nguyễn Thái Ngọc DuyNext: Nguyễn Thái Ngọc Duy
Message 3 of 15 in “Sparse checkout resurrection”
  1. 0/5 Sparse checkout resurrectionNguyễn Thái Ngọc Duy, Jul 29, 2009
  2. 1/5 Prevent diff machinery from examining worktree outside sparse checkoutNguyễn Thái Ngọc Duy, Jul 29, 2009
  3. 2/5 grep: skip files outside sparse checkout areaNguyễn Thái Ngọc Duy, Jul 29, 2009
  4. 3/5 gitignore: read from index if .gitignore is not in worktreeNguyễn Thái Ngọc Duy, Jul 29, 2009
  5. 4/5 unpack_trees(): keep track of unmerged entriesNguyễn Thái Ngọc Duy, Jul 29, 2009
  6. 5/5 unpack_trees(): add support for sparse checkoutNguyễn Thái Ngọc Duy, Jul 29, 2009
  7. Jakub NarebskiJul 29, 2009
  8. Nguyen Thai Ngoc DuyJul 29, 2009
  9. Jakub NarebskiJul 30, 2009
  10. Junio C HamanoJul 31, 2009
  11. Junio C HamanoJul 31, 2009
  12. Nguyen Thai Ngoc DuyAug 4, 2009
  13. Junio C HamanoJul 31, 2009
  14. skillzero@gmail.comJul 31, 2009
  15. Nguyen Thai Ngoc DuyAug 4, 2009

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.