public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] [PATCH 7/7] pypi.eclass: Avoid subshell for extglob setting
Date: Tue, 13 Jun 2023 15:37:06 +0200	[thread overview]
Message-ID: <4bc9c92dac990f4c4ad67d49c2efef055ea5d860.camel@gentoo.org> (raw)
In-Reply-To: <upm5zwx02@gentoo.org>

On Tue, 2023-06-13 at 11:07 +0200, Ulrich Mueller wrote:
> > > > > > 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.
> 

I was thinking about this but I really dislike repeating the logic
twice.  In my opinion, having such block would be confusing: why are
there two logics for extglob on and off?  Why are both the same?  Is
this some mistake?

Even though this is unlikely, someone could actually end up creating
a missync there, and things would go downhill from there.

-q is a good idea though.

Ideally, we'd avoid extglob at all but I can't think of another pure
bash way of doing this.

-- 
Best regards,
Michał Górny



      reply	other threads:[~2023-06-13 13:37 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
2023-06-13 13:37     ` Michał Górny [this message]

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=4bc9c92dac990f4c4ad67d49c2efef055ea5d860.camel@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=gentoo-dev@lists.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