Thread (29 messages) read the whole thread 29 messages, 7 authors, 2025-07-22

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

From: Karthik Nayak <hidden>
Date: 2025-07-16 10:26:55
Subsystem: the rest · Maintainer: Linus Torvalds

Phillip Wood [off-list ref] writes:
quoted hunk ↗ jump to hunk
From: Phillip Wood <redacted>

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 <redacted>
---
 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)
Nit: clang-format complains that we should also format the arguments now
that the first line's length changes

$ ./ci/run-style-check.sh @~1
diff --git a/git-compat-util.h b/git-compat-util.h
index 9408f463e3..e01abf6eb6 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -898,7 +898,7 @@ static inline size_t xsize_t(off_t len)
  * locale-specific conversions).
  */
 static inline bool skip_iprefix(const char *str, const char *prefix,
-			       const char **out)
+				const char **out)
 {
 	do {
 		if (!*prefix) {
@@ -915,8 +915,8 @@ static inline bool skip_iprefix(const char *str,
const char *prefix,
  * characters or locale-specific conversions).
  */
 static inline bool skip_iprefix_mem(const char *buf, size_t len,
-				   const char *prefix,
-				   const char **out, size_t *outlen)
+				    const char *prefix,
+				    const char **out, size_t *outlen)
 {
 	do {
 		if (!*prefix) {

[snip]

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help