GNU bug report logs - #11703
23.4; `grep-compute-defaults' passes useless, incompatible "-e" flag to "xargs -0"

Previous Next

Package: emacs;

Reported by: Samuel Bronson <naesten <at> gmail.com>

Date: Wed, 13 Jun 2012 23:53:01 UTC

Severity: normal

Tags: patch

Found in version 23.4

Done: Chong Yidong <cyd <at> gnu.org>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 11703 in the body.
You can then email your comments to 11703 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#11703; Package emacs. (Wed, 13 Jun 2012 23:53:01 GMT) Full text and rfc822 format available.

Acknowledgement sent to Samuel Bronson <naesten <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Wed, 13 Jun 2012 23:53:01 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Samuel Bronson <naesten <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 23.4;
	`grep-compute-defaults' passes useless, incompatible "-e" flag to
	"xargs -0"
Date: Wed, 13 Jun 2012 19:49:55 -0400
Consider the following defun:

> (defvar grep-find-use-xargs nil
>   "Non-nil means that `grep-find' uses the `xargs' utility by  
default.
> If `exec', use `find -exec'.
> If `gnu', use `find -print0' and `xargs -0'.
> Any other non-nil value means to use `find -print' and `xargs'.
>
> This variable's value takes effect when `grep-compute-defaults' is  
called.")

and the following code from `grep-compute-defaults':

> 	(unless grep-find-use-xargs
> 	  (setq grep-find-use-xargs
> 		(cond
> 		 ((and
> 		   (grep-probe find-program `(nil nil nil ,null-device "-print0"))
> 		   (grep-probe xargs-program `(nil nil nil "-0" "-e" "echo")))
> 		  'gnu)
> 		 (t
> 		  'exec)))

This checks whether find(1) supports `-print0', and whether xargs(1)
supports `-0' and `-e', and if they don't, it falls back to using `find
-exec'.  (Further down, there is of course code that computes commands
that actually *use* `xargs -0 -e'.)

This use of `-e' appears to be intended to disable the "logical
EOF" processing that pre-2004 versions of POSIX demanded (and did not
specify a flag to disable), in which an argument of "_" would be treated
as if it were the EOF.

Unfortunately, BSD xargs does not accept `-e', so with it Emacs falls
back to using `find -exec', which gives less-convenient-to-edit command
lines (since this puts the grep pattern somehere way in the middle of
the `find' command, rather than at the end).

Furthermore, this use of `-e' seems to be rather pointless, since GNU
xargs does not appear to have actually done this logical EOF processing
when `-0' was active within recorded history.  (I could only get as far
back as find 4.0, thanks to findutils/findutils-4.0-4.1.diff.gz in the
GNU ftp tree.  Both the findutils VCS history and snaphsot.debian.org
both only go back to findutils 4.1, and the GNU ftp tree only seems to
go back to find 4.0 because the diff was originally intended as a
distribution of findutils 4.1.)

(BSD, on the other hand, seems to do such processing even with `-0', but
thankfully they seem to never have had a default EOF marker string; on
FreeBSD, the line where the default is set has been unchanged since
<http://svnweb.freebsd.org/base/head/usr.bin/xargs/xargs.c?revision=95080&view=markup 
>.)

So, my suggestion is to apply the following patch (in context format,
because I haven't yet customized this Emacs to use unified):


*** /Applications/Emacs.app/Contents/Resources/lisp/progmodes/ 
grep.el.pristine.gz
--- /Applications/Emacs.app/Contents/Resources/lisp/progmodes/grep.el.gz
***************
*** 554,560 ****
  		(cond
  		 ((and
  		   (grep-probe find-program `(nil nil nil ,null-device "-print0"))
! 		   (grep-probe xargs-program `(nil nil nil "-0" "-e" "echo")))
  		  'gnu)
  		 (t
  		  'exec))))
--- 554,560 ----
  		(cond
  		 ((and
  		   (grep-probe find-program `(nil nil nil ,null-device "-print0"))
! 		   (grep-probe xargs-program `(nil nil nil "-0" "echo")))
  		  'gnu)
  		 (t
  		  'exec))))
***************
*** 564,570 ****
  		       ;; Windows shells need the program file name
  		       ;; after the pipe symbol be quoted if they use
  		       ;; forward slashes as directory separators.
! 		       (format "%s . -type f -print0 | \"%s\" -0 -e %s"
  			       find-program xargs-program grep-command))
  		      ((eq grep-find-use-xargs 'exec)
  		       (let ((cmd0 (format "%s . -type f -exec %s"
--- 564,570 ----
  		       ;; Windows shells need the program file name
  		       ;; after the pipe symbol be quoted if they use
  		       ;; forward slashes as directory separators.
! 		       (format "%s . -type f -print0 | \"%s\" -0 %s"
  			       find-program xargs-program grep-command))
  		      ((eq grep-find-use-xargs 'exec)
  		       (let ((cmd0 (format "%s . -type f -exec %s"
***************
*** 582,588 ****
  		(let ((gcmd (format "%s <C> %s <R>"
  				    grep-program grep-options)))
  		  (cond ((eq grep-find-use-xargs 'gnu)
! 			 (format "%s . <X> -type f <F> -print0 | \"%s\" -0 -e %s"
  				 find-program xargs-program gcmd))
  			((eq grep-find-use-xargs 'exec)
  			 (format "%s . <X> -type f <F> -exec %s {} %s %s"
--- 582,588 ----
  		(let ((gcmd (format "%s <C> %s <R>"
  				    grep-program grep-options)))
  		  (cond ((eq grep-find-use-xargs 'gnu)
! 			 (format "%s . <X> -type f <F> -print0 | \"%s\" -0 %s"
  				 find-program xargs-program gcmd))
  			((eq grep-find-use-xargs 'exec)
  			 (format "%s . <X> -type f <F> -exec %s {} %s %s"




Added tag(s) patch. Request was from Samuel Bronson <naesten <at> gmail.com> to control <at> debbugs.gnu.org. (Wed, 27 Jun 2012 18:57:01 GMT) Full text and rfc822 format available.

Reply sent to Chong Yidong <cyd <at> gnu.org>:
You have taken responsibility. (Fri, 30 Nov 2012 07:43:02 GMT) Full text and rfc822 format available.

Notification sent to Samuel Bronson <naesten <at> gmail.com>:
bug acknowledged by developer. (Fri, 30 Nov 2012 07:43:03 GMT) Full text and rfc822 format available.

Message #12 received at 11703-done <at> debbugs.gnu.org (full text, mbox):

From: Chong Yidong <cyd <at> gnu.org>
To: Samuel Bronson <naesten <at> gmail.com>
Cc: 11703-done <at> debbugs.gnu.org
Subject: Re: bug#11703: 23.4;
	`grep-compute-defaults' passes useless, incompatible "-e" flag to
	"xargs -0"
Date: Fri, 30 Nov 2012 15:38:34 +0800
Samuel Bronson <naesten <at> gmail.com> writes:

> Unfortunately, BSD xargs does not accept `-e', so with it Emacs falls
> back to using `find -exec', which gives less-convenient-to-edit command
> lines (since this puts the grep pattern somehere way in the middle of
> the `find' command, rather than at the end).
>
> Furthermore, this use of `-e' seems to be rather pointless, since GNU
> xargs does not appear to have actually done this logical EOF processing
> when `-0' was active within recorded history.

I've committed your patch to trunk.  Thanks.




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Fri, 28 Dec 2012 12:24:03 GMT) Full text and rfc822 format available.

This bug report was last modified 11 years and 143 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.