From: Ulrich Mueller <ulm@gentoo.org>
To: "Michał Górny" <mgorny@gentoo.org>
Cc: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] [PATCH 7/7] pypi.eclass: Avoid subshell for extglob setting
Date: Tue, 13 Jun 2023 11:07:57 +0200 [thread overview]
Message-ID: <upm5zwx02@gentoo.org> (raw)
In-Reply-To: <20230613064742.413335-8-mgorny@gentoo.org> ("Michał Górny"'s message of "Tue, 13 Jun 2023 08:45:07 +0200")
[-- Attachment #1: Type: text/plain, Size: 792 bytes --]
>>>>> On Tue, 13 Jun 2023, Michał Górny wrote:
> _pypi_normalize_name() {
> local name=${1}
> - local shopt_save=$(shopt -p extglob)
> - shopt -s extglob
> + local prev_extglob=-s
> + if ! shopt -p extglob >/dev/null; then
> + prev_extglob=-u
> + shopt -s extglob
> + fi
> name=${name//+([._-])/_}
> - ${shopt_save}
> + shopt "${prev_extglob}" extglob
> _PYPI_NORMALIZED_NAME="${name,,}"
> }
In principle you could also do something like this:
if shopt -pq extglob; then
name=${name//+([._-])/_}
else
shopt -s extglob
name=${name//+([._-])/_}
shopt -u extglob
fi
It duplicates one line of code, but saves a variable and IMHO the code
would be easier to understand.
Also, with the -q option no output redirection is needed.
Ulrich
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]
next prev parent reply other threads:[~2023-06-13 9:08 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-13 6:45 [gentoo-dev] [PATCH 0/7] pypi.eclass: performance optimizations Michał Górny
2023-06-13 6:45 ` [gentoo-dev] [PATCH 1/7] pypi.eclass: Move setting globals to a function Michał Górny
2023-06-13 6:45 ` [gentoo-dev] [PATCH 2/7] eclass/tests: Add pypi-bench.sh for global scope logic Michał Górny
2023-06-13 6:45 ` [gentoo-dev] [PATCH 3/7] pypi.eclass: Translate version once in the default scenario Michał Górny
2023-06-13 6:45 ` [gentoo-dev] [PATCH 4/7] pypi.eclass: Normalize names without subshell Michał Górny
2023-06-13 6:45 ` [gentoo-dev] [PATCH 5/7] pypi.eclass: Translate version without subshell in common case Michał Górny
2023-06-13 6:45 ` [gentoo-dev] [PATCH 6/7] pypi.eclass: Replace pypi_sdist_url in global scope Michał Górny
2023-06-13 6:45 ` [gentoo-dev] [PATCH 7/7] pypi.eclass: Avoid subshell for extglob setting Michał Górny
2023-06-13 9:07 ` Ulrich Mueller [this message]
2023-06-13 13:37 ` Michał Górny
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=upm5zwx02@gentoo.org \
--to=ulm@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
--cc=mgorny@gentoo.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