len = nr = 0;
push_arg("grep");
- push_arg("-H");
if (opt->fixed)
push_arg("-F");
if (opt->linenum)
push_arg("-e");
push_arg(p->pattern);
}
- push_arg("--");
+
+ if (NO_H_OPTION_IN_GREP)
+ push_arg("/dev/null");
+ else {
+ push_arg("-H");
+ push_arg("--");
+ }
hit = 0;
argc = nr;
* Use the external "grep" command for the case where
* we grep through the checked-out files. It tends to
* be a lot more optimized
+ *
+ * Some grep implementations do not understand -H nor --
+ * but /dev/null can be used as a substitution in most
+ * cases.
+ *
+ * However -L and -c would slightly misbehave (-L would
+ * list /dev/null as a hit, and -c would report 0 hits
+ * from /dev/null); so do not use the external one on
+ * such platforms.
*/
- if (!cached) {
+ if (!cached &&
+ (!NO_H_OPTION_IN_GREP ||
+ (!opt->count && !opt->unmatch_name_only))) {
hit = external_grep(opt, paths, cached);
if (hit >= 0)
return hit;