emacs-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[debbugs-tracker] bug#11703: closed (23.4; `grep-compute-defaults' passe


From: GNU bug Tracking System
Subject: [debbugs-tracker] bug#11703: closed (23.4; `grep-compute-defaults' passes useless, incompatible "-e" flag to "xargs -0")
Date: Fri, 30 Nov 2012 07:43:02 +0000

Your message dated Fri, 30 Nov 2012 15:38:34 +0800
with message-id <address@hidden>
and subject line Re: bug#11703: 23.4; `grep-compute-defaults' passes useless, 
incompatible "-e" flag to "xargs -0"
has caused the debbugs.gnu.org bug report #11703,
regarding 23.4; `grep-compute-defaults' passes useless, incompatible "-e" flag 
to "xargs -0"
to be marked as done.

(If you believe you have received this mail in error, please contact
address@hidden)


-- 
11703: http://debbugs.gnu.org/cgi/bugreport.cgi?bug=11703
GNU Bug Tracking System
Contact address@hidden with problems
--- Begin Message --- 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"



--- End Message ---
--- Begin Message --- 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 User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.2.90 (gnu/linux)
Samuel Bronson <address@hidden> 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.


--- End Message ---

reply via email to

[Prev in Thread] Current Thread [Next in Thread]