From: igor@9lab.org
To: 9front@9front.org
Subject: Re: [9front] [PATCH] g: use xargs instead of finding complete file list before greping
Date: Wed, 05 Jan 2022 01:05:34 +0100 [thread overview]
Message-ID: <6EE8BEFB8528D5322A5A014D730B5275@9lab.org> (raw)
In-Reply-To: <F6C25774810194975DF835D286F1D76D@arrow>
Hi Michael,
Thanks! I have tested your patch and can confirm it works.
Quoth Michael Forney <mforney@mforney.org>:
[…]
> I'm not sure if this error message is desired or not for cases like
> this, but regardless, I think g could be a bit more efficient by using
> xargs rather than enumerating the complete list of files up front,
> avoiding the issue completely.
[…]
xargs also has a parallel mode that comes in handy to speed up search
in this case.
[…]
> One slight issue with this patch is that files named '-n' are skipped.
> I don't think it's too big a deal, but I wasn't quite sure how to
> handle this. One idea is to use `walk -f -- $f` instead of `echo $f`.
> Another idea is `echo -n $f$nl`. In general, is there a good way to
> print a variable, regardless of its value (similar to POSIX `printf
> '%s\n' "$f"`)?
[…]
Not sure if there is something similar to POSIX `printf`. I am using
`echo -n $f$nl`.
Below is your patch with minor modifications if anyone else want's to
give this a go and provide further feedback.
Cheers,
Igor
---
diff 31957c1aa36808a2ba4a496fd5a1559ef46b9517 02d9badb3c55e01a8e9d274b89d99f67433f15ec
--- a/rc/bin/g Tue Jan 4 20:11:07 2022
+++ b/rc/bin/g Wed Jan 5 00:59:10 2022
@@ -14,25 +14,25 @@
}
if(~ $1 --)
shift
+if(~ $#* 0) {
+ echo 'usage: g [flags] pattern [files]' >[1=2]
+ exit usage
+}
+pattern=$1
+shift
suffixes='\.([bcChlmsy]|asm|awk|cc|cgi|cpp|cs|go|goc|hs|java|lua|lx|mk|ml|mli|ms|myr|pl|py|rc|sh|tex|xy)$'
fullnames='(^|/)mkfile$'
switch($#*){
case 0
- echo 'usage: g [flags] pattern [files]' >[1=2]
+ walk -f $recurse | grep -e $fullnames -e $suffixes >[2]/dev/null
exit usage
-case 1
- pattern=$1
- files=`$nl{walk -f $recurse | grep -e $fullnames -e $suffixes >[2]/dev/null}
case *
- pattern=$1
- shift
for(f in $*){
if(test -d $f)
- files=($files `$nl{walk -f $recurse -- $* \
- | grep -e $fullnames -e $suffixes >[2]/dev/null})
+ walk -f $recurse -- $f \
+ | grep -e $fullnames -e $suffixes >[2]/dev/null
if not
- files=($files $f)
+ echo -n $f$nl
}
-}
-grep -n $flags -- $pattern $files /dev/null
+} | xargs -p4 grep -n $flags -- $pattern
next prev parent reply other threads:[~2022-01-05 0:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-01-01 10:26 Michael Forney
2022-01-02 1:13 ` 有澤 健治
2022-01-02 1:20 ` ori
2022-01-02 4:56 ` 有澤 健治
2022-01-02 2:34 ` Michael Forney
2022-01-02 1:28 ` 有澤 健治
2022-01-05 0:05 ` igor [this message]
2022-01-05 3:05 ` Michael Forney
2022-01-06 1:35 ` ori
2022-01-06 10:47 ` igor
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=6EE8BEFB8528D5322A5A014D730B5275@9lab.org \
--to=igor@9lab.org \
--cc=9front@9front.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.
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 NNTP newsgroup(s).