public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Ulrich Müller" <ulm@gentoo.org>
To: "Michał Górny" <mgorny@gentoo.org>
Cc: gentoo-dev@lists.gentoo.org
Subject: Re: [gentoo-dev] New eclass: eapi9-pipestatus.eclass
Date: Sun, 24 Nov 2024 15:12:36 +0100	[thread overview]
Message-ID: <uttbwpvor@gentoo.org> (raw)
In-Reply-To: <5e0e2dd372bf3a60a9c2dfb8b68bf7b18b7c2b99.camel@gentoo.org> ("Michał Górny"'s message of "Sun, 24 Nov 2024 13:58:04 +0100")

[-- Attachment #1: Type: text/plain, Size: 1953 bytes --]

>>>>> On Sun, 24 Nov 2024, Michał Górny wrote:

>> # @CODE
>> # local status
>> # foo | bar
>> # status=$(pipestatus -v) || die "foo | bar failed, status ${status}"

> I suppose you may want to put a verbose warning not to put "local"
> on the same line, because people are going to do that as an "obvious"
> optimization.

Thank you for the feedback. I have added the following:

# Caveat: "pipestatus" must be the next command following the pipeline.
# In particular, the "local" declaration must be before the pipeline,
# otherwise it will reset the status.

>> [[ $# -gt 0 && ${1} != -v || $# -gt 1 ]] \

> Please use parentheses when you combine && and ||, if only for the sake
> of readability.

I've replaced it by:

    [[ $# -gt 0 && ( ${1} != -v || $# -gt 1 ) ]]

Note that

    [[ ( $# -gt 0 && ${1} != -v ) || $# -gt 1 ]]

would also work, i.e. order doesn't matter (the reason is that "-gt 1"
implies "-gt 0").

>> && die "${FUNCNAME}: bad arguments: $@"

> Replace the '\' with the '&&'.

We don't have any policy on this, and IMHO it is clearer to split the
line before the operator. (This is also what the GNU coding standards
say, and what is used in mathematical typesetting.)

>> [[ ${1} == -v ]] && echo "${status[@]}"
>> 
>> for s in "${status[@]}"; do
>> [[ ${s} -ne 0 ]] && ret=${s}

> I suppose it's just my C-foo talking and completely needless
> optimization here, but it really itches me to iterate the array
> backwards and return on the first match.

I had considered this and decided against it, see the last paragraph
of https://bugs.gentoo.org/566342#c13:

| Alternatively, one could loop backwards over the array (and return
| for the first nonzero status) but it would be more complicated.
| I don't think that would be more efficient because the normal case
| is that all statūs are zero. Plus, pipelines rarely consist of more
| than 3 commands.

Ulrich

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 507 bytes --]

  reply	other threads:[~2024-11-24 14:12 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-24 12:24 [gentoo-dev] New eclass: eapi9-pipestatus.eclass Ulrich Müller
2024-11-24 12:58 ` Michał Górny
2024-11-24 14:12   ` Ulrich Müller [this message]
2024-11-26  6:52 ` [gentoo-dev] New eclass v2: eapi9-pipestatus.eclass Ulrich Müller
2024-11-27 10:41 ` [gentoo-dev] New eclass: eapi9-pipestatus.eclass Florian Schmaus
2024-11-27 11:52   ` Michał Górny
2024-11-27 12:32   ` Ulrich Müller

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=uttbwpvor@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