From: Junio C Hamano <gitster@pobox.com>
To: Patrick Steinhardt <ps@pks.im>
Cc: git@vger.kernel.org
Subject: Re: [PATCH 2/3] revision: small readability improvement for reading from stdin
Date: Wed, 14 Jun 2023 09:03:32 -0700 [thread overview]
Message-ID: <xmqqh6raxc8b.fsf@gitster.g> (raw)
In-Reply-To: 38c0415ee9074276e9832bbbafdee8833cd7ddb9.1686744685.git.ps@pks.im
Patrick Steinhardt <ps@pks.im> writes:
> The code that reads lines from standard input manually compares whether
> the read line matches "--", which is a bit awkward to read. Refactor it
> to instead use strcmp(3P) for a small code style improvement.
It is unclear if it is an "improvement". We've already checked the
first byte to be "-" and we only need to check the second one (and
the length of the string) to see if we have a double-dash, instead
of checking the first byte again.
I am not sure if these excessive blank lines are helping, either.
The only reason I would be inclined to support the main change in
this patch (but not additional blank lines) is because I will be
suggesting to lift the logic to detect double-dash from the "line
begins with dash" block in my review of the next step. Once that is
done, double-dash detection cannot rely on the fact that we have
already checked the first byte.
I do agree with the change to remove the temporary variable "len",
if we were to remove the "len == 2" comparison, as it makes "len"
less useful.
Thanks.
> Signed-off-by: Patrick Steinhardt <ps@pks.im>
> ---
> revision.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/revision.c b/revision.c
> index cc22ccd76e..dcb7951b4e 100644
> --- a/revision.c
> +++ b/revision.c
> @@ -2795,16 +2795,18 @@ static void read_revisions_from_stdin(struct rev_info *revs,
>
> strbuf_init(&sb, 1000);
> while (strbuf_getline(&sb, stdin) != EOF) {
> - int len = sb.len;
> - if (!len)
> + if (!sb.len)
> break;
> +
> if (sb.buf[0] == '-') {
> - if (len == 2 && sb.buf[1] == '-') {
> + if (!strcmp(sb.buf, "--")) {
> seen_dashdash = 1;
> break;
> }
> +
> die("options not supported in --stdin mode");
> }
> +
> if (handle_revision_arg(sb.buf, revs, 0,
> REVARG_CANNOT_BE_FILENAME))
> die("bad revision '%s'", sb.buf);
next prev parent reply other threads:[~2023-06-14 16:03 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-14 12:18 [PATCH 0/3] revision: handle pseudo-opts in `--stdin` mode Patrick Steinhardt
2023-06-14 12:18 ` [PATCH 1/3] revision: reorder `read_revisions_from_stdin()` Patrick Steinhardt
2023-06-14 16:01 ` Junio C Hamano
2023-06-14 12:18 ` [PATCH 2/3] revision: small readability improvement for reading from stdin Patrick Steinhardt
2023-06-14 16:03 ` Junio C Hamano [this message]
2023-06-14 12:18 ` [PATCH 3/3] revision: handle pseudo-opts in `--stdin` mode Patrick Steinhardt
2023-06-14 15:56 ` Junio C Hamano
2023-06-15 14:25 ` Patrick Steinhardt
2023-06-15 14:39 ` [PATCH v2 0/3] " Patrick Steinhardt
2023-06-15 14:39 ` [PATCH v2 1/3] revision: reorder `read_revisions_from_stdin()` Patrick Steinhardt
2023-06-15 14:39 ` [PATCH v2 2/3] revision: small readability improvement for reading from stdin Patrick Steinhardt
2023-06-15 14:39 ` [PATCH v2 3/3] revision: handle pseudo-opts in `--stdin` mode Patrick Steinhardt
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=xmqqh6raxc8b.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=ps@pks.im \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.