From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FROM,NICE_REPLY_A autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 9627 invoked from network); 2 Jan 2022 02:31:06 -0000 Received: from 4ess.inri.net (216.126.196.42) by inbox.vuxu.org with ESMTPUTF8; 2 Jan 2022 02:31:06 -0000 Received: from mail-pg1-f181.google.com ([209.85.215.181]) by 4ess; Sat Jan 1 21:23:47 -0500 2022 Received: by mail-pg1-f181.google.com with SMTP id m15so27305324pgu.11 for <9front@9front.org>; Sat, 01 Jan 2022 18:23:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language :references:to:from:in-reply-to:content-transfer-encoding; bh=rjLQ4DpwNK/II0zfxF9l1ywazh1KiG76zuAQGzNbkSE=; b=E921pRvvcO7ggQQm7sIsUxpKE36Cz8exL4sSagKVCpI6cJHzFe4CmBzhlYww6fc+7v cJH49xACYBzTwlQGc+EaK6sWIGJVujUTZHQkUrffBgG24mv6iumhB6bzVphAWNnFprCs sx3tLYgDyWUA5A4T1mM0+Ykz3WAZxLslTccAmtJpZqZ8OGb1mFudNKmn10kkrx7pkl0R smcE5v7353caeGvfYb3cjldwioewKx+YDOFaXS5v9EtSE9RDIWNTC6xNcgFvUtPrDg1d YGe1nUjblQlOXGVg/CImNApIQEl2UNYoM/CsV9nIZBhqt/pHiswhAAZR7EAfY4W4txLy FpfA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:references:to:from:in-reply-to :content-transfer-encoding; bh=rjLQ4DpwNK/II0zfxF9l1ywazh1KiG76zuAQGzNbkSE=; b=fF6JvtBl4Z9Yd9m+CQRl4afQ2tNUGTfCGEu5I/ITKMolintqxiG3/G3mlL4B453Clv IuqtXltQ5O5n2Bum8phZwqwimreBA5S/kHt8RrTIXFvnPtm2pRycnYel9IGnSVa7xMXq 1Gdwf/UHpdrD9oS47I5hoiBAhipm/Z0YFdfddvJgfbiU//cWOx6lALO7Nc2lcpLel84f geCHk5Pc6E8+IO7ZyJCyIKbbmJ4u4Z4YIygtrmnN99AVUx1QeiNveCqXOPmaMzngr9DS gtD9nOI+XK8goHLth+CjlIuAODcE07n3YPtqN6aYBypzeVE93QB/Le8DlDWg1px2Arf+ 7VeQ== X-Gm-Message-State: AOAM531Kl5qP1rTL7Csst98XfVV/cXaNlCBaG/14eeGtHeA80o/vvXcB KFsw1GlFFE7q2jO5DzFpP0kT8Awsl2Q= X-Google-Smtp-Source: ABdhPJw7bMbEu0RoZKYGIqiTkttrUygJbEt1xMZLnv6exgS4ArhV9Q/LzuIS75ZrfvMyPWIpPVEHUg== X-Received: by 2002:a63:af08:: with SMTP id w8mr8721084pge.70.1641086887032; Sat, 01 Jan 2022 17:28:07 -0800 (PST) Return-Path: Received: from ?IPV6:2402:6b00:7e7a:6200:7d05:18b6:8df0:fff6? ([2402:6b00:7e7a:6200:7d05:18b6:8df0:fff6]) by smtp.gmail.com with ESMTPSA id e21sm16995888pff.24.2022.01.01.17.28.05 for <9front@9front.org> (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 01 Jan 2022 17:28:06 -0800 (PST) Message-ID: Date: Sun, 2 Jan 2022 10:28:04 +0900 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:91.0) Gecko/20100101 Thunderbird/91.3.2 Content-Language: en-US References: To: 9front@9front.org From: =?UTF-8?B?5pyJ5r6kIOWBpeayuw==?= In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: self-healing private reduce/map realtime-java blockchain-based framework Subject: Re: [9front] [PATCH] g: use xargs instead of finding complete file list before greping Reply-To: 9front@9front.org Precedence: bulk Hello, >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. I agree with this point. I have been working on recursive g (named gr) that works efficient and easy to use, and also works on unix. look http://p9.nyx.link/netlib/ Kenji Arisawa On 2022/01/01 19:26, Michael Forney wrote: > --- > This patch requires the other g patch I sent earlier to apply cleanly. > > I noticed that with the recent rc changes, I see the message 'Write > error' on stderr when using g in a large directory (such as > /sys/src/cmd). This is because rc now uses io.c code to write env > files before executing a child, and this fails when the size of a list > exceeds Maxenvsize. Previously, these write errors were just ignored. > > It can be reproduced with > > % a=`{seq 1 4000} > % echo > Write error > > % > > 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. > > 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"`)? > > diff 525c7bc4922fc86ba0bbe2281fbe92e697a4f6d8 dd997a744e5ec3704d48dedc259d06c062d56aec > --- a/rc/bin/g Sat Jan 1 14:51:39 2022 > +++ b/rc/bin/g Sat Jan 1 02:26:14 2022 > @@ -14,25 +14,24 @@ > } > 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] > - exit usage > -case 1 > - pattern=$1 > - files=`$nl{walk -f $recurse | grep -e $fullnames -e $suffixes >[2]/dev/null} > + 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 -- $f \ > - | 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 $f > } > -} > -grep -n $flags -- $pattern $files /dev/null > +} | xargs grep -n $flags -- $pattern