git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] fetch: fix wrong evaluation order in URL trailing-slash trimming

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 25, 2026, 15:36 UTC
Message-ID
<xmqq4in4decx.fsf@gitster.g>
In-Reply-To
<20260225141059.GE2139176@coredump.intra.peff.net>
Jeff King <peff@peff.net> writes:
Show 11 quoted lines
> 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.
Previous: Jeff King
Message 3 of 3 in “fetch: fix wrong evaluation order in URL trailing-slash trimming”
  1. fetch: fix wrong evaluation order in URL trailing-slash trimmingcui via GitGitGadget, Feb 25, 2026
  2. Jeff KingFeb 25, 2026
  3. Junio C HamanoFeb 25, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.