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

[PATCH v2 2/3] git-compat-util: convert string predicates to return bool

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Jul 15, 2025, 13:52 UTC
Message-ID
<0b2402e11cc8a6b096139f796ea280d0ba56b418.1752587571.git.phillip.wood@dunelm.org.uk>
In-Reply-To
<cover.1752587571.git.phillip.wood@dunelm.org.uk>
From: Phillip Wood <phillip.wood@dunelm.org.uk>

Since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16) a number of our string predicates have been returning bool instead of int. Now that we've declared that experiment a success, let's convert the return type of the case-independent skip_iprefix() and skip_iprefix_mem() functions to match the return type of their case-dependent equivalents. Returning bool instead of int makes it clear that these functions are predicates.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 git-compat-util.h | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/git-compat-util.h b/git-compat-util.h
index 5bd69ec0403..9408f463e31 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -897,35 +897,35 @@ static inline size_t xsize_t(off_t len)
  * is done via tolower(), so it is strictly ASCII (no multi-byte characters or
  * locale-specific conversions).
  */
-static inline int skip_iprefix(const char *str, const char *prefix,
+static inline bool skip_iprefix(const char *str, const char *prefix,
 			       const char **out)
 {
 	do {
 		if (!*prefix) {
 			*out = str;
-			return 1;
+			return true;
 		}
 	} while (tolower(*str++) == tolower(*prefix++));
-	return 0;
+	return false;
 }
 
 /*
  * Like skip_prefix_mem, but compare case-insensitively. Note that the
  * comparison is done via tolower(), so it is strictly ASCII (no multi-byte
  * characters or locale-specific conversions).
  */
-static inline int skip_iprefix_mem(const char *buf, size_t len,
+static inline bool skip_iprefix_mem(const char *buf, size_t len,
 				   const char *prefix,
 				   const char **out, size_t *outlen)
 {
 	do {
 		if (!*prefix) {
 			*out = buf;
 			*outlen = len;
-			return 1;
+			return true;
 		}
 	} while (len-- > 0 && tolower(*buf++) == tolower(*prefix++));
-	return 0;
+	return false;
 }
 
 static inline int strtoul_ui(char const *s, int base, unsigned int *result)
-- 
2.49.0.897.gfad3eb7d210
Previous: Elijah NewrenNext: Phillip Wood
Message 15 of 33 in “C99: declare bool experiment a success”
  1. 0/3 C99: declare bool experiment a successPhillip Wood, Jul 14, 2025
  2. 1/3 CodingGuildlines: allow the use of boolPhillip Wood, Jul 14, 2025
  3. Junio C HamanoJul 14, 2025
  4. 2/3 git-compat-util: convert string predicates to return boolPhillip Wood, Jul 14, 2025
  5. Eric SunshineJul 14, 2025
  6. Elijah NewrenJul 14, 2025
  7. brian m. carlsonJul 14, 2025
  8. Phillip WoodJul 15, 2025
  9. 3/3 strbuf: convert predicates to return boolPhillip Wood, Jul 14, 2025
  10. 0/3 C99: declare bool experiment a successPhillip Wood, Jul 15, 2025
  11. 1/3 CodingGuildlines: allow the use of boolPhillip Wood, Jul 15, 2025
  12. Jeff KingJul 16, 2025
  13. Jeff KingJul 16, 2025
  14. Elijah NewrenJul 16, 2025
  15. 2/3 git-compat-util: convert string predicates to return boolPhillip Wood, Jul 15, 2025
  16. 3/3 strbuf: convert predicates to return boolPhillip Wood, Jul 15, 2025
  17. Elijah NewrenJul 15, 2025
  18. rsbecker@nexbridge.comJul 15, 2025
  19. Elijah NewrenJul 15, 2025
  20. rsbecker@nexbridge.comJul 15, 2025
  21. Junio C HamanoJul 15, 2025
  22. Junio C HamanoJul 15, 2025
  23. brian m. carlsonJul 15, 2025
  24. Junio C HamanoJul 15, 2025
  25. 0/3 C99: declare bool experiment a successPhillip Wood, Jul 16, 2025
  26. 1/3 CodingGuidelines: allow the use of boolPhillip Wood, Jul 16, 2025
  27. 2/3 git-compat-util: convert string predicates to return boolPhillip Wood, Jul 16, 2025
  28. Karthik NayakJul 16, 2025
  29. 3/3 strbuf: convert predicates to return boolPhillip Wood, Jul 16, 2025
  30. Karthik NayakJul 16, 2025
  31. Karthik NayakJul 16, 2025
  32. Phillip WoodJul 17, 2025
  33. Karthik NayakJul 22, 2025

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.