git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 2/2] grep: grep cache entries if they are "assume unchanged"
@ 2008-12-27  8:21 Nguyễn Thái Ngọc Duy
  2008-12-27  8:21 ` [PATCH 1/2] grep: support --no-ext-grep to test builtin grep Nguyễn Thái Ngọc Duy
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2008-12-27  8:21 UTC (permalink / raw)
  To: Junio C Hamano, git, Daniel Barkalow
  Cc: Nguyễn Thái Ngọc Duy

"Assume unchanged" bit means "please pretend that I have never touched
this file", so  if user removes the file, we should not care.

This patch teaches "git grep" to use cache version in such
situations. External grep case has not been fixed yet. But given that
on the platform that CE_VALID bit may be used like Windows, external
grep is not available anyway, I would wait for people to raise their
hands before touching it.

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I will do git-grep fixes for sparse checkout later because it will require
 nd/narrow. This series does not, so it can be applied separatedly.

 builtin-grep.c  |    7 ++++++-
 t/t7002-grep.sh |    7 +++++++
 2 files changed, 13 insertions(+), 1 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index 3c97c2c..bebf15c 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -404,7 +404,12 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
 			continue;
 		if (!pathspec_matches(paths, ce->name))
 			continue;
-		if (cached) {
+		/*
+		 * If CE_VALID is on, we assume worktree file and its cache entry
+		 * are identical, even if worktree file has been modified, so use
+		 * cache version instead
+		 */
+		if (cached || (ce->ce_flags & CE_VALID)) {
 			if (ce_stage(ce))
 				continue;
 			hit |= grep_sha1(opt, ce->sha1, ce->name, 0);
diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh
index 18fe6f2..e12b5dc 100755
--- a/t/t7002-grep.sh
+++ b/t/t7002-grep.sh
@@ -161,7 +161,14 @@ test_expect_success 'log grep (6)' '
 	git log --author=-0700  --pretty=tformat:%s >actual &&
 	>expect &&
 	test_cmp expect actual
+'
 
+test_expect_success 'grep with CE_VALID file' '
+	git update-index --assume-unchanged t/t &&
+	rm t/t &&
+	test "$(git grep --no-ext-grep t)" = "t/t:test" &&
+	git update-index --no-assume-unchanged t/t &&
+	git checkout t/t
 '
 
 test_done
-- 
1.6.0.4.1116.g25b13

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 1/2] grep: support --no-ext-grep to test builtin grep
  2008-12-27  8:21 [PATCH 2/2] grep: grep cache entries if they are "assume unchanged" Nguyễn Thái Ngọc Duy
@ 2008-12-27  8:21 ` Nguyễn Thái Ngọc Duy
  2008-12-27 22:39 ` [PATCH 2/2] grep: grep cache entries if they are "assume unchanged" Junio C Hamano
  2008-12-28  6:53 ` Junio C Hamano
  2 siblings, 0 replies; 4+ messages in thread
From: Nguyễn Thái Ngọc Duy @ 2008-12-27  8:21 UTC (permalink / raw)
  To: Junio C Hamano, git, Daniel Barkalow
  Cc: Nguyễn Thái Ngọc Duy


Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 used by the next patch

 builtin-grep.c |    8 +++++++-
 1 files changed, 7 insertions(+), 1 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index 624f86e..3c97c2c 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -20,6 +20,8 @@
 #endif
 #endif
 
+static int builtin_grep;
+
 /*
  * git grep pathspecs are somewhat different from diff-tree pathspecs;
  * pathname wildcards are allowed.
@@ -389,7 +391,7 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached)
 	 * we grep through the checked-out files. It tends to
 	 * be a lot more optimized
 	 */
-	if (!cached) {
+	if (!cached && !builtin_grep) {
 		hit = external_grep(opt, paths, cached);
 		if (hit >= 0)
 			return hit;
@@ -545,6 +547,10 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
 			cached = 1;
 			continue;
 		}
+		if (!strcmp("--no-ext-grep", arg)) {
+			builtin_grep = 1;
+			continue;
+		}
 		if (!strcmp("-a", arg) ||
 		    !strcmp("--text", arg)) {
 			opt.binary = GREP_BINARY_TEXT;
-- 
1.6.0.4.1116.g25b13

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] grep: grep cache entries if they are "assume unchanged"
  2008-12-27  8:21 [PATCH 2/2] grep: grep cache entries if they are "assume unchanged" Nguyễn Thái Ngọc Duy
  2008-12-27  8:21 ` [PATCH 1/2] grep: support --no-ext-grep to test builtin grep Nguyễn Thái Ngọc Duy
@ 2008-12-27 22:39 ` Junio C Hamano
  2008-12-28  6:53 ` Junio C Hamano
  2 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2008-12-27 22:39 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, Daniel Barkalow

Nguyễn Thái Ngọc Duy  <pclouds@gmail.com> writes:

> ... External grep case has not been fixed yet. But given that
> on the platform that CE_VALID bit may be used like Windows, external
> grep is not available anyway, I would wait for people to raise their
> hands before touching it.

My gut feeling is that it would suffice to always use the internal grep if
there is any index entry with CE_VALID set.  Having the bit is an unusual
case.

Also I am guessing that your above statement that users on Windows would
be the ones who want CE_VALID implies that CE_VALID is for platforms where
file operations are slow.  If that is really the case, the internal grep
might even have performance advantage over external grep.

No, I haven't benched the internal grep recently.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] grep: grep cache entries if they are "assume unchanged"
  2008-12-27  8:21 [PATCH 2/2] grep: grep cache entries if they are "assume unchanged" Nguyễn Thái Ngọc Duy
  2008-12-27  8:21 ` [PATCH 1/2] grep: support --no-ext-grep to test builtin grep Nguyễn Thái Ngọc Duy
  2008-12-27 22:39 ` [PATCH 2/2] grep: grep cache entries if they are "assume unchanged" Junio C Hamano
@ 2008-12-28  6:53 ` Junio C Hamano
  2 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2008-12-28  6:53 UTC (permalink / raw)
  To: Nguyễn Thái Ngọc Duy; +Cc: git, Daniel Barkalow

Thanks.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-12-28  6:55 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-27  8:21 [PATCH 2/2] grep: grep cache entries if they are "assume unchanged" Nguyễn Thái Ngọc Duy
2008-12-27  8:21 ` [PATCH 1/2] grep: support --no-ext-grep to test builtin grep Nguyễn Thái Ngọc Duy
2008-12-27 22:39 ` [PATCH 2/2] grep: grep cache entries if they are "assume unchanged" Junio C Hamano
2008-12-28  6:53 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).