unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#11703: 23.4; `grep-compute-defaults' passes useless, incompatible "-e" flag to "xargs -0"
@ 2012-06-13 23:49 Samuel Bronson
  2012-11-30  7:38 ` Chong Yidong
  0 siblings, 1 reply; 2+ messages in thread
From: Samuel Bronson @ 2012-06-13 23:49 UTC (permalink / raw)
  To: 11703


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"





^ permalink raw reply	[flat|nested] 2+ messages in thread

* bug#11703: 23.4; `grep-compute-defaults' passes useless, incompatible "-e" flag to "xargs -0"
  2012-06-13 23:49 bug#11703: 23.4; `grep-compute-defaults' passes useless, incompatible "-e" flag to "xargs -0" Samuel Bronson
@ 2012-11-30  7:38 ` Chong Yidong
  0 siblings, 0 replies; 2+ messages in thread
From: Chong Yidong @ 2012-11-30  7:38 UTC (permalink / raw)
  To: Samuel Bronson; +Cc: 11703-done

Samuel Bronson <naesten@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.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2012-11-30  7:38 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-06-13 23:49 bug#11703: 23.4; `grep-compute-defaults' passes useless, incompatible "-e" flag to "xargs -0" Samuel Bronson
2012-11-30  7:38 ` Chong Yidong

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).