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

[PATCH] fetch: convert strncmp() with strlen() to starts_with()

From
René Scharfe <l.s.r@web.de>
Date
Feb 24, 2024, 21:47 UTC
Message-ID
<cb94b938-03f9-4dd3-84c1-f5244ca81be3@web.de>

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))) {
 			int j;

 			free(rs->items[i].src);
--
2.44.0
Next: Junio C Hamano
Message 1 of 5 in “fetch: convert strncmp() with strlen() to starts_with()”
  1. fetch: convert strncmp() with strlen() to starts_with()René Scharfe, Feb 24, 2024
  2. Junio C HamanoFeb 24, 2024
  3. Junio C HamanoFeb 26, 2024
  4. René ScharfeFeb 26, 2024
  5. Patrick SteinhardtFeb 27, 2024

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.