Skip to content

Commit d1edee4

Browse files
avargitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2e96d81 commit d1edee4

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

builtin/grep.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,17 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)
289289
if (num_threads < 0)
290290
die(_("invalid number of threads specified (%d) for %s"),
291291
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
292303
}
293304

294305
return st;
@@ -1229,6 +1240,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
12291240
else if (num_threads < 0)
12301241
die(_("invalid number of threads specified (%d)"), num_threads);
12311242
#else
1243+
if (num_threads)
1244+
warning(_("no threads support, ignoring --threads"));
12321245
num_threads = 0;
12331246
#endif
12341247

t/t7810-grep.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,24 @@ do
791791
"
792792
done
793793

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+
794812
test_expect_success 'grep from a subdirectory to search wider area (1)' '
795813
mkdir -p s &&
796814
(

0 commit comments

Comments
 (0)