Re: [PATCH] grep: do not do external grep on skip-worktree entries

3 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: [PATCH] grep: do not do external grep on skip-worktree entries

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:47:57

Nguyen Thai Ngoc Duy [off-list ref] writes:
quoted
 > +support_external_grep() {
 > +     case "$(git grep -h 2>&1 >/dev/null|grep -e --ext-grep)" in
 > +     *"(default)"*)  return 0;;
 > +     *"(ignored by this build)"*) return 1;;
 > +     *) test_expect_success 'External grep check is broken' 'false';;
 > +     esac
 > +}


Heh, clever.

        git grep -h 2>&1 | grep 'allow calling of grep.*default' >/dev/null

 may be sufficient, though.
Yes, until somebody changes help text in builtin-grep.c and all
external grep tests become disable. I wanted to catch that case too.
Ok, that is a worthwhile thing to do.

Then please at least make the second grep "grep ext-grep", droping "-e --"
from it.  We assume some implementation of external grep to lack "-e"
(e.g. Solaris).

[PATCH 2/2] t7002: add tests for skip-worktree fixes in commit a67e281

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:47:58

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 builtin-grep.c  |    1 +
 t/t7002-grep.sh |   12 ++++++++++++
 2 files changed, 13 insertions(+), 0 deletions(-)
diff --git a/builtin-grep.c b/builtin-grep.c
index f093b60..59c4b12 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -222,6 +222,7 @@ static int exec_grep(int argc, const char **argv)
 	int status;
 
 	argv[argc] = NULL;
+	trace_argv_printf(argv, "trace: grep:");
 	pid = fork();
 	if (pid < 0)
 		return pid;
diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh
index ffda0df..ac0a658 100755
--- a/t/t7002-grep.sh
+++ b/t/t7002-grep.sh
@@ -438,4 +438,16 @@ test_expect_success 'grep -Fi' '
 	test_cmp expected actual
 '
 
+test_expect_success external-grep 'external grep is called' '
+	GIT_TRACE=2 git grep foo >/dev/null 2>actual &&
+	grep "trace: grep:.*foo" actual >/dev/null
+'
+
+test_expect_success external-grep 'no external grep when skip-worktree entries exist' '
+	git update-index --skip-worktree file &&
+	GIT_TRACE=2 git grep foo >/dev/null 2>actual &&
+	! grep "trace: grep:" actual >/dev/null &&
+	git update-index --no-skip-worktree file
+'
+
 test_done
-- 
1.6.6.315.g1a406

[PATCH 1/2] t7002: set test prerequisite "external-grep" if supported

From: Nguyễn Thái Ngọc Duy <hidden>
Date: 2016-06-15 22:47:58

Add another test to set prerequisite "external-grep" if the current
build supports external grep. This can be used to skip external grep
only tests on builds that do not support this optimization.

Signed-off-by: Nguyễn Thái Ngọc Duy <redacted>
---
 t/t7002-grep.sh |   12 ++++++++++++
 1 files changed, 12 insertions(+), 0 deletions(-)
diff --git a/t/t7002-grep.sh b/t/t7002-grep.sh
index abd14bf..ffda0df 100755
--- a/t/t7002-grep.sh
+++ b/t/t7002-grep.sh
@@ -8,6 +8,18 @@ test_description='git grep various.
 
 . ./test-lib.sh
 
+test_expect_success 'Check for external grep support' '
+	case "$(git grep -h 2>&1|grep ext-grep)" in
+	*"(default)"*)
+		test_set_prereq external-grep
+		true;;
+	*"(ignored by this build)"*)
+		true;;
+	*)
+		false;;
+	esac
+'
+
 cat >hello.c <<EOF
 #include <stdio.h>
 int main(int argc, const char **argv)
-- 
1.6.6.315.g1a406
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help