From: Junio C Hamano <gitster@pobox.com>
To: "René Scharfe" <l.s.r@web.de>
Cc: Git List <git@vger.kernel.org>
Subject: Re: [PATCH] fetch: convert strncmp() with strlen() to starts_with()
Date: Sat, 24 Feb 2024 15:45:28 -0800 [thread overview]
Message-ID: <xmqqfrxhjujr.fsf@gitster.g> (raw)
In-Reply-To: <cb94b938-03f9-4dd3-84c1-f5244ca81be3@web.de> ("René Scharfe"'s message of "Sat, 24 Feb 2024 22:47:06 +0100")
René Scharfe <l.s.r@web.de> writes:
> Using strncmp() and strlen() to check whether a string starts with
> another one requires repeating the prefix candidate. Use starts_with()
> instead, which reduces repetition and is more readable.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> builtin/fetch.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/fetch.c b/builtin/fetch.c
> index 3aedfd1bb6..0a7a1a3476 100644
> --- a/builtin/fetch.c
> +++ b/builtin/fetch.c
> @@ -448,9 +448,8 @@ static void filter_prefetch_refspec(struct refspec *rs)
> continue;
> if (!rs->items[i].dst ||
> (rs->items[i].src &&
> - !strncmp(rs->items[i].src,
> - ref_namespace[NAMESPACE_TAGS].ref,
> - strlen(ref_namespace[NAMESPACE_TAGS].ref)))) {
> + starts_with(rs->items[i].src,
> + ref_namespace[NAMESPACE_TAGS].ref))) {
The original tries to check that "namespace" fully matches the
initial part of .src string, which is exactly what starts_with()
does. Makes sense.
> int j;
>
> free(rs->items[i].src);
> --
> 2.44.0
next prev parent reply other threads:[~2024-02-24 23:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-24 21:47 [PATCH] fetch: convert strncmp() with strlen() to starts_with() René Scharfe
2024-02-24 23:45 ` Junio C Hamano [this message]
2024-02-26 17:11 ` Junio C Hamano
2024-02-26 20:04 ` René Scharfe
2024-02-27 7:58 ` 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=xmqqfrxhjujr.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=l.s.r@web.de \
/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;
as well as URLs for NNTP newsgroup(s).