summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>2017-04-16 22:21:02 +0000
committerJunio C Hamano <gitster@pobox.com>2017-04-16 21:34:04 -0700
commit0003643246f15f7beb4e83efa90dc54eed9bc591 (patch)
tree781118705fa95c6cbd9bf7e5d2b1e4fc17afbf93
parent1b6f38a8d6555d8a60b372a8a00e609e26cd3a44 (diff)
downloadgit-ab/grep-threading-cleanup.tar.gz
grep: given --threads with NO_PTHREADS=YesPlease, warnab/grep-threading-cleanup
Add a warning about missing thread support when grep.threads or --threads is set to a non 0 (default) or 1 (no parallelism) value under NO_PTHREADS=YesPlease. This is for consistency with the index-pack & pack-objects commands, which also take a --threads option & are configurable via pack.threads, and have long warned about the same under NO_PTHREADS=YesPlease. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--builtin/grep.c8
-rwxr-xr-xt/t7810-grep.sh18
2 files changed, 26 insertions, 0 deletions
diff --git a/builtin/grep.c b/builtin/grep.c
index 8ab2005c2f..249c683c92 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -290,6 +290,12 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
if (num_threads < 0)
die(_("invalid number of threads specified (%d) for %s"),
num_threads, var);
+#ifdef NO_PTHREADS
+ else if (num_threads && num_threads != 1) {
+ warning(_("no threads support, ignoring %s"), var);
+ num_threads = 0;
+ }
+#endif
}
return st;
@@ -1222,6 +1228,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
if (num_threads == 1)
num_threads = 0;
#else
+ if (num_threads)
+ warning(_("no threads support, ignoring --threads"));
num_threads = 0;
#endif
diff --git a/t/t7810-grep.sh b/t/t7810-grep.sh
index 4523ca926b..f4c225b410 100755
--- a/t/t7810-grep.sh
+++ b/t/t7810-grep.sh
@@ -787,6 +787,24 @@ do
"
done
+test_expect_success !PTHREADS,!GETTEXT_POISON 'grep --threads=N or pack.threads=N warns when no pthreads' '
+ git grep --threads=2 Hello hello_world 2>err &&
+ grep ^warning: err >warnings &&
+ test_line_count = 1 warnings &&
+ grep "no threads support, ignoring --threads" err &&
+ git -c grep.threads=2 grep Hello hello_world 2>err &&
+ grep ^warning: err >warnings &&
+ test_line_count = 1 warnings &&
+ grep "no threads support, ignoring grep\.threads" err &&
+ git -c grep.threads=2 grep --threads=4 Hello hello_world 2>err &&
+ grep ^warning: err >warnings &&
+ test_line_count = 2 warnings &&
+ grep "no threads support, ignoring --threads" err &&
+ grep "no threads support, ignoring grep\.threads" err &&
+ git -c grep.threads=0 grep --threads=0 Hello hello_world 2>err &&
+ test_line_count = 0 err
+'
+
test_expect_success 'grep from a subdirectory to search wider area (1)' '
mkdir -p s &&
(