From: Jonathan Nieder <jrnieder@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: Elia Pinto <gitter.spiros@gmail.com>,
git@vger.kernel.org, tboegi@web.de, dak@gnu.org
Subject: Re: [PATCH v2] Get rid of the non portable shell export VAR=VALUE costruct
Date: Fri, 23 May 2014 11:44:05 -0700 [thread overview]
Message-ID: <20140523184405.GE12314@google.com> (raw)
In-Reply-To: <xmqqmwe8jr44.fsf@gitster.dls.corp.google.com>
Junio C Hamano wrote:
> Elia Pinto <gitter.spiros@gmail.com> writes:
>> Found by check-non-portable-shell.pl
>
> Thanks.
>
> Makes me wonder why these two were missed, though.
Good catch. check-non-portable-shell.pl uses an anchored regex:
/^\s*export\s+[^=]*=/
Perhaps something like
/\bexport\s+[A-Za-z0-9_]*=/
without anchoring would work better.
-- >8 --
Subject: test-lint: find unportable sed, echo, test, and export usage after &&
Instead of anchoring these checks with "^\s*", just check that the
usage is preceded by a word boundary. So now we can catch
test $cond && export foo=bar
just like we already catch
test $cond &&
export foo=bar
As a side effect, this will detect usage of "sed -i", "echo -n", "test
a == b", and "export a=b" in comments. That is not ideal but it's
potentially useful because people sometimes copy code from comments so
it can be good to also avoid nonportable patterns there.
To avoid false positives, keep the checks for 'declare' and 'which'
anchored. Those are frequently used words in normal English-language
comments.
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
t/check-non-portable-shell.pl | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git i/t/check-non-portable-shell.pl w/t/check-non-portable-shell.pl
index 45971f4..b170cbc 100755
--- i/t/check-non-portable-shell.pl
+++ w/t/check-non-portable-shell.pl
@@ -16,12 +16,12 @@ sub err {
while (<>) {
chomp;
- /^\s*sed\s+-i/ and err 'sed -i is not portable';
- /^\s*echo\s+-n/ and err 'echo -n is not portable (please use printf)';
+ /\bsed\s+-i/ and err 'sed -i is not portable';
+ /\becho\s+-n/ and err 'echo -n is not portable (please use printf)';
/^\s*declare\s+/ and err 'arrays/declare not portable';
/^\s*[^#]\s*which\s/ and err 'which is not portable (please use type)';
- /test\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
- /^\s*export\s+[^=]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';
+ /\btest\s+[^=]*==/ and err '"test a == b" is not portable (please use =)';
+ /\bexport\s+[A-Za-z0-9_]*=/ and err '"export FOO=bar" is not portable (please use FOO=bar && export FOO)';
# this resets our $. for each file
close ARGV if eof;
}
next prev parent reply other threads:[~2014-05-23 18:44 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-23 10:15 [PATCH v2] Get rid of the non portable shell export VAR=VALUE costruct Elia Pinto
2014-05-23 16:18 ` Jonathan Nieder
2014-05-23 18:18 ` Junio C Hamano
2014-05-23 18:39 ` Junio C Hamano
2014-05-23 18:48 ` Jonathan Nieder
2014-05-23 18:44 ` Jonathan Nieder [this message]
2014-05-23 20:40 ` Torsten Bögershausen
2014-05-23 21:25 ` Junio C Hamano
2014-05-23 21:56 ` Junio C Hamano
2014-05-23 20:38 ` Eric Sunshine
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=20140523184405.GE12314@google.com \
--to=jrnieder@gmail.com \
--cc=dak@gnu.org \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=gitter.spiros@gmail.com \
--cc=tboegi@web.de \
/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).