all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Samuel Bronson <naesten@gmail.com>
To: 11703@debbugs.gnu.org
Subject: bug#11703: 23.4; `grep-compute-defaults' passes useless, incompatible "-e" flag to "xargs -0"
Date: Wed, 13 Jun 2012 19:49:55 -0400	[thread overview]
Message-ID: <51EDAD95-F992-4C23-A3F6-FD55D9EC6F98@gmail.com> (raw)


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"





             reply	other threads:[~2012-06-13 23:49 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-13 23:49 Samuel Bronson [this message]
2012-11-30  7:38 ` bug#11703: 23.4; `grep-compute-defaults' passes useless, incompatible "-e" flag to "xargs -0" Chong Yidong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=51EDAD95-F992-4C23-A3F6-FD55D9EC6F98@gmail.com \
    --to=naesten@gmail.com \
    --cc=11703@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.