]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fetch: convert strncmp() with strlen() to starts_with()
authorRené Scharfe <l.s.r@web.de>
Sat, 24 Feb 2024 21:47:06 +0000 (22:47 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 26 Feb 2024 16:58:45 +0000 (08:58 -0800)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fetch.c

index 3aedfd1bb6361c6bbfd651970f9e9767d0595734..0a7a1a34765483e9f207ec26c5ca408df88c9dfc 100644 (file)
@@ -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))) {
                        int j;
 
                        free(rs->items[i].src);