From: Junio C Hamano <gitster@pobox.com>
To: Jeff King <peff@peff.net>
Cc: cui via GitGitGadget <gitgitgadget@gmail.com>,
git@vger.kernel.org, cui <523516579@qq.com>,
cuiweixie <cuiweixie@gmail.com>
Subject: Re: [PATCH] fetch: fix wrong evaluation order in URL trailing-slash trimming
Date: Wed, 25 Feb 2026 07:36:46 -0800 [thread overview]
Message-ID: <xmqq4in4decx.fsf@gitster.g> (raw)
In-Reply-To: <20260225141059.GE2139176@coredump.intra.peff.net> (Jeff King's message of "Wed, 25 Feb 2026 09:10:59 -0500")
Jeff King <peff@peff.net> writes:
> I can't help but think this would be easier to read without an empty
> loop body, like:
>
> for (len = strlen(display_state->url); len > 0; len--) {
> if (display_state->url[len-1] != '/')
> break;
> }
>
> which makes it much more clear we never leave the bounds of the string
> (and also works with a size_t, which is a more appropriate type than int
> here).
Yes, this is vastly more readable, even though what it does is
exactly the same as the original.
Or instead of having strlen() to scan the entire string once and
then ourselves scan backwards from the end, scan forward ourselves
only once while noting where the last non-slash byte was, or
something.
> But it may not be worth polishing this bit of code too much (if we did,
> I'd also suggest strip_suffix_mem() to drop ".git" rather than all of
> those magic numbers. Or even stuffing it in a strbuf and using
> strbuf_setlen() and strbuf_strip_suffix().
True. None of these "we could do it this way too" bikeshedding has
much value. The patch posted is an obvious and trivial enough
improvement.
Thanks.
next prev parent reply other threads:[~2026-02-25 15:36 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-25 2:00 [PATCH] fetch: fix wrong evaluation order in URL trailing-slash trimming cui via GitGitGadget
2026-02-25 14:10 ` Jeff King
2026-02-25 15:36 ` Junio C Hamano [this message]
-- strict thread matches above, loose matches on Subject: below --
2026-02-23 10:07 cuiweixie
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=xmqq4in4decx.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=523516579@qq.com \
--cc=cuiweixie@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=peff@peff.net \
/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