grep: given --threads with NO_PTHREADS=YesPlease, warn

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>

Ævar Arnfjörð Bjarmason committed May 25, 2017 at 19:45 UTC d1edee4adac8f516f1545d080fbffcdb148ac7b7
2 files changed +31
builtin/grep.c
+13
@@ -289,6 +289,17 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
289 if (num_threads < 0)
290 die(_("invalid number of threads specified (%d) for %s"),
291 num_threads, var);
292 +#ifdef NO_PTHREADS
293 + else if (num_threads && num_threads != 1) {
294 + /*
295 + * TRANSLATORS: %s is the configuration
296 + * variable for tweaking threads, currently
297 + * grep.threads
298 + */
299 + warning(_("no threads support, ignoring %s"), var);
300 + num_threads = 0;
301 + }
302 +#endif
303 }
304
305 return st;
@@ -1229,6 +1240,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1240 else if (num_threads < 0)
1241 die(_("invalid number of threads specified (%d)"), num_threads);
1242 #else
1243 + if (num_threads)
1244 + warning(_("no threads support, ignoring --threads"));
1245 num_threads = 0;
1246 #endif
1247
t/t7810-grep.sh
+18
@@ -791,6 +791,24 @@ do
791 "
792 done
793
794 +test_expect_success !PTHREADS,C_LOCALE_OUTPUT 'grep --threads=N or pack.threads=N warns when no pthreads' '
795 + git grep --threads=2 Hello hello_world 2>err &&
796 + grep ^warning: err >warnings &&
797 + test_line_count = 1 warnings &&
798 + grep -F "no threads support, ignoring --threads" err &&
799 + git -c grep.threads=2 grep Hello hello_world 2>err &&
800 + grep ^warning: err >warnings &&
801 + test_line_count = 1 warnings &&
802 + grep -F "no threads support, ignoring grep.threads" err &&
803 + git -c grep.threads=2 grep --threads=4 Hello hello_world 2>err &&
804 + grep ^warning: err >warnings &&
805 + test_line_count = 2 warnings &&
806 + grep -F "no threads support, ignoring --threads" err &&
807 + grep -F "no threads support, ignoring grep.threads" err &&
808 + git -c grep.threads=0 grep --threads=0 Hello hello_world 2>err &&
809 + test_line_count = 0 err
810 +'
811 +
812 test_expect_success 'grep from a subdirectory to search wider area (1)' '
813 mkdir -p s &&
814 (