fetch: convert strncmp() with strlen() to starts_with()
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>
René Scharfe committed
Feb 24, 2024 at 22:47 UTC
87bd7fbb9c3e165a68046e04bf12f5a76cae2965
1 file changed
+2
-3
builtin/fetch.c
+2
-3
@@ -448,9 +448,8 @@ static void filter_prefetch_refspec(struct refspec *rs)
448
continue;
449
if (!rs->items[i].dst ||
450
(rs->items[i].src &&
451
- !strncmp(rs->items[i].src,
452
- ref_namespace[NAMESPACE_TAGS].ref,
453
- strlen(ref_namespace[NAMESPACE_TAGS].ref)))) {
451
+ starts_with(rs->items[i].src,
452
+ ref_namespace[NAMESPACE_TAGS].ref))) {
453
int j;
454
455
free(rs->items[i].src);