threads / patch / 63791

patch, 3 partsC99: declare bool experiment a success

Subject: [PATCH 0/3] C99: declare bool experiment a success

## tl;dr

33 messages between Jul 14, 2025 and Jul 22, 2025. Diffs are folded; open one to read it.

replies: 32people: 8as markdown or json

Phillip Wood· Jul 14, 2025, 13:26 UTC · lore
From: Phillip Wood <phillip.wood@dunelm.org.uk>

We've had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.

Base-Commit: a30f80fde927d70950b3b4d1820813480968fb0d
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fuse-c99-bool%2Fv1
View-Changes-At: https://github.com/phillipwood/git/compare/a30f80fde...7eaf80420
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/use-c99-bool/v1
Phillip Wood (3):
  CodingGuildlines: allow the use of bool
  git-compat-util: convert string predicates to return bool
  strbuf: convert predicates to return bool
 Documentation/CodingGuidelines |  3 +++
 git-compat-util.h              | 12 ++++++------
 strbuf.c                       | 28 ++++++++++++++--------------
 strbuf.h                       | 12 ++++++------
 4 files changed, 29 insertions(+), 26 deletions(-)
-- 
2.49.0.897.gfad3eb7d210
Phillip Wood· Jul 14, 2025, 13:27 UTC · re: Phillip Wood · lore

[PATCH 1/3] CodingGuildlines: allow the use of bool

From: Phillip Wood <phillip.wood@dunelm.org.uk>

We have had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As we've had it over 18 months without any complaints let's declare it a success.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 Documentation/CodingGuidelines | 3 +++
 1 file changed, 3 insertions(+)
Show changes to Documentation/CodingGuidelines +3 −0
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 6350949f2ef..528b42d1dd1 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -298,6 +298,9 @@ For C programs:
    . since late 2021 with 44ba10d6, we have had variables declared in
      the for loop "for (int i = 0; i < 10; i++)".
 
+   . since late 2023 with 8277dbe987 we have been using the bool type
+     from <stdbool.h>.
+
    New C99 features that we cannot use yet:
 
    . %z and %zu as a printf() argument for a size_t (the %z being for
-- 
2.49.0.897.gfad3eb7d210
Junio C Hamano· Jul 14, 2025, 16:37 UTC · re: Phillip Wood · lore

Re: [PATCH 1/3] CodingGuildlines: allow the use of bool

Phillip Wood <phillip.wood123@gmail.com> writes:
Show 22 quoted lines
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> We have had a test balloon for C99's bool type since 8277dbe987
> (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool,
> 2023-12-16). As we've had it over 18 months without any complaints
> let's declare it a success.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  Documentation/CodingGuidelines | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
> index 6350949f2ef..528b42d1dd1 100644
> --- a/Documentation/CodingGuidelines
> +++ b/Documentation/CodingGuidelines
> @@ -298,6 +298,9 @@ For C programs:
>     . since late 2021 with 44ba10d6, we have had variables declared in
>       the for loop "for (int i = 0; i < 10; i++)".
>  
> +   . since late 2023 with 8277dbe987 we have been using the bool type
> +     from <stdbool.h>.
Let's see the other ones in the same list.
 * initializer elements that are not static (used since 2b6854c8
   (Cleanup variables in cat-file, 2007-04-21), declared official
   with 442c27dd (CodingGuidelines: mention dynamic C99 initializer
   elements, 2022-10-10).
 * trailing comma in enum definition (used since e1327023 (grep:
   refactor the concept of "grep source" into an object,
   2012-02-02), declared official with cc0c4297 (CodingGuidelines:
   spell out post-C89 rules, 2019-07-16).
 * designated initialiers for struct and arrays (used since cbc0f81d
   (strbuf: use designated initializers in STRBUF_INIT, 2017-07-10)
   and 512f41cf (clean.c: use designated initializer, 2017-07-14),
   declared official with cc0c4297 (CodingGuidelines: spell out
   post-C89 rules, 2019-07-16).
 * variadic macros (used since 765dc168 (git-compat-util: always
   enable variadic macros, 2021-01-28), declared official with
   56a29d2c (C99: remove hardcoded-out !HAVE_VARIADIC_MACROS code,
   2022-02-21).
 * declaring a control variable in for(;;) loop (used since 44ba10d6
   (revision: use C99 declaration of variable in for() loop,
   2021-11-14), declared official with 82dd01d8 (CodingGuidelines:
   allow declaring variables in for loops, 2022-10-10).
A year and a half sounds roughly the average timespan.
Will queue.  Thanks.
Phillip Wood· Jul 14, 2025, 13:27 UTC · re: Phillip Wood · lore

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

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 sting predicates have been returning bool instead of int. Now we've declared that experiment a success lets convert the return type 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(-)
Show changes to git-compat-util.h +6 −6
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
Eric Sunshine· Jul 14, 2025, 16:46 UTC · re: Phillip Wood · lore

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

On Mon, Jul 14, 2025 at 9:31 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
> Since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem}
> to bool, 2023-12-16) a number of our sting predicates have been
s/sting/string/
> returning bool instead of int. Now we've declared that experiment
> a success lets convert the return type the case independent

s/lets/let's/ /type/& of/

Show 5 quoted lines
> 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>
Elijah Newren· Jul 14, 2025, 17:20 UTC · re: Phillip Wood · lore

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

On Mon, Jul 14, 2025 at 6:32 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 6 quoted lines
>
> 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 sting predicates have been
> returning bool instead of int. Now we've declared that experiment
Now we've -> Now that we've
> a success lets convert the return type the case independent

success lets -> success, let's type the -> type of the

> skip_iprefix() and skip_iprefix_mem() functions to match the return
> type of their case dependent equivalents. Returning bool instead of

I wonder if case-independent and case-dependent should be hyphenated, or as separate words as you had them. Anyone know?

Show 55 quoted lines
> 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
Patch looks good.
brian m. carlson· Jul 14, 2025, 21:14 UTC · re: Elijah Newren · lore

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

On 2025-07-14 at 17:20:08, Elijah Newren wrote:
Show 20 quoted lines
> On Mon, Jul 14, 2025 at 6:32 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
> >
> > 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 sting predicates have been
> > returning bool instead of int. Now we've declared that experiment
> 
> Now we've -> Now that we've
> 
> > a success lets convert the return type the case independent
> 
> success lets -> success, let's
> type the -> type of the
> 
> > skip_iprefix() and skip_iprefix_mem() functions to match the return
> > type of their case dependent equivalents. Returning bool instead of
> 
> I wonder if case-independent and case-dependent should be hyphenated,
> or as separate words as you had them.  Anyone know?

I would hyphenate them. The Chicago Manual of Style, 18th Edition, says in § 7.91, “When compound modifiers (also called phrasal adjectives) such as _high-profile_ or _book-length_ precede a noun, hyphenation usually lends clarity. With the exception of proper nouns (such as _United States_) and compounds formed by an adverb ending in _-ly_ plus an adjective…, it is never incorrect to hyphenate adjectival compounds before a noun.”

They go on to state that hyphenation is usually omitted _after_ a noun.

I usually follow this rule in my writing and commit messages and I haven't gotten any complaints or comments about it, for what it's worth.

-- 
brian m. carlson (they/them)
Toronto, Ontario, CA
Phillip Wood· Jul 15, 2025, 09:36 UTC · re: brian m. carlson · lore

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

On 14/07/2025 22:14, brian m. carlson wrote:
Show 18 quoted lines
> On 2025-07-14 at 17:20:08, Elijah Newren wrote:
>> On Mon, Jul 14, 2025 at 6:32 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
>>>
>> I wonder if case-independent and case-dependent should be hyphenated,
>> or as separate words as you had them.  Anyone know?
> 
> I would hyphenate them.  The Chicago Manual of Style, 18th Edition, says
> in § 7.91, “When compound modifiers (also called phrasal adjectives)
> such as _high-profile_ or _book-length_ precede a noun, hyphenation
> usually lends clarity.  With the exception of proper nouns (such as
> _United States_) and compounds formed by an adverb ending in _-ly_ plus
> an adjective…, it is never incorrect to hyphenate adjectival compounds
> before a noun.”
> 
> They go on to state that hyphenation is usually omitted _after_ a noun.
> 
> I usually follow this rule in my writing and commit messages and I
> haven't gotten any complaints or comments about it, for what it's worth.
Thanks for that - I'll hyphenate them then.

Thank you also to Elijah and Eric for the typo fixes - I seem to have had my brain turned off when I proofread this message.

Phillip
Phillip Wood· Jul 14, 2025, 13:27 UTC · re: Phillip Wood · lore

[PATCH 3/3] strbuf: convert predicates to return bool

From: Phillip Wood <phillip.wood@dunelm.org.uk>

Now that the string predicates defined in git-compat-util.h all return bool let's convert the return type of the string predicates in strbuf.{c,h} to match them.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 strbuf.c | 28 ++++++++++++++--------------
 strbuf.h | 12 ++++++------
 2 files changed, 20 insertions(+), 20 deletions(-)
Show changes to 2 files +20 −20

strbuf.c, strbuf.h

diff --git a/strbuf.c b/strbuf.c
index f30fdc69843..6c3851a7f84 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -8,55 +8,55 @@
 #include "utf8.h"
 #include "date.h"
 
-int starts_with(const char *str, const char *prefix)
+bool starts_with(const char *str, const char *prefix)
 {
 	for (; ; str++, prefix++)
 		if (!*prefix)
-			return 1;
+			return true;
 		else if (*str != *prefix)
-			return 0;
+			return false;
 }
 
-int istarts_with(const char *str, const char *prefix)
+bool istarts_with(const char *str, const char *prefix)
 {
 	for (; ; str++, prefix++)
 		if (!*prefix)
-			return 1;
+			return true;
 		else if (tolower(*str) != tolower(*prefix))
-			return 0;
+			return false;
 }
 
-int starts_with_mem(const char *str, size_t len, const char *prefix)
+bool starts_with_mem(const char *str, size_t len, const char *prefix)
 {
 	const char *end = str + len;
 	for (; ; str++, prefix++) {
 		if (!*prefix)
-			return 1;
+			return true;
 		else if (str == end || *str != *prefix)
-			return 0;
+			return false;
 	}
 }
 
-int skip_to_optional_arg_default(const char *str, const char *prefix,
+bool skip_to_optional_arg_default(const char *str, const char *prefix,
 				 const char **arg, const char *def)
 {
 	const char *p;
 
 	if (!skip_prefix(str, prefix, &p))
-		return 0;
+		return false;
 
 	if (!*p) {
 		if (arg)
 			*arg = def;
-		return 1;
+		return true;
 	}
 
 	if (*p != '=')
-		return 0;
+		return false;
 
 	if (arg)
 		*arg = p + 1;
-	return 1;
+	return true;
 }
 
 /*
diff --git a/strbuf.h b/strbuf.h
index 6362777c0a0..a580ac6084b 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -660,9 +660,9 @@ char *xstrvfmt(const char *fmt, va_list ap);
 __attribute__((format (printf, 1, 2)))
 char *xstrfmt(const char *fmt, ...);
 
-int starts_with(const char *str, const char *prefix);
-int istarts_with(const char *str, const char *prefix);
-int starts_with_mem(const char *str, size_t len, const char *prefix);
+bool starts_with(const char *str, const char *prefix);
+bool istarts_with(const char *str, const char *prefix);
+bool starts_with_mem(const char *str, size_t len, const char *prefix);
 
 /*
  * If the string "str" is the same as the string in "prefix", then the "arg"
@@ -678,16 +678,16 @@ int starts_with_mem(const char *str, size_t len, const char *prefix);
  * can be used instead of !strcmp(arg, "--key") and then
  * skip_prefix(arg, "--key=", &arg) to parse such an option.
  */
-int skip_to_optional_arg_default(const char *str, const char *prefix,
+bool skip_to_optional_arg_default(const char *str, const char *prefix,
 				 const char **arg, const char *def);
 
-static inline int skip_to_optional_arg(const char *str, const char *prefix,
+static inline bool skip_to_optional_arg(const char *str, const char *prefix,
 				       const char **arg)
 {
 	return skip_to_optional_arg_default(str, prefix, arg, "");
 }
 
-static inline int ends_with(const char *str, const char *suffix)
+static inline bool ends_with(const char *str, const char *suffix)
 {
 	size_t len;
 	return strip_suffix(str, suffix, &len);
-- 
2.49.0.897.gfad3eb7d210
Phillip Wood· Jul 15, 2025, 13:52 UTC · re: Phillip Wood · lore

[PATCH v2 0/3] C99: declare bool experiment a success

From: Phillip Wood <phillip.wood@dunelm.org.uk>

We've had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.

Thank you to everyone who commented on V1, the only change here is to fix the typos in the commit message for patch 2.

Base-Commit: a30f80fde927d70950b3b4d1820813480968fb0d
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fuse-c99-bool%2Fv2
View-Changes-At: https://github.com/phillipwood/git/compare/a30f80fde...669687147
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/use-c99-bool/v2
Phillip Wood (3):
  CodingGuildlines: allow the use of bool
  git-compat-util: convert string predicates to return bool
  strbuf: convert predicates to return bool
 Documentation/CodingGuidelines |  3 +++
 git-compat-util.h              | 12 ++++++------
 strbuf.c                       | 28 ++++++++++++++--------------
 strbuf.h                       | 12 ++++++------
 4 files changed, 29 insertions(+), 26 deletions(-)
Range-diff against v1:
1:  352f80c49b7 = 1:  352f80c49b7 CodingGuildlines: allow the use of bool
2:  a0f9182aa20 ! 2:  0b2402e11cc git-compat-util: convert string predicates to return bool
    @@ Commit message
         git-compat-util: convert string predicates to return bool
     
         Since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem}
    -    to bool, 2023-12-16) a number of our sting predicates have been
    -    returning bool instead of int. Now we've declared that experiment
    -    a success lets convert the return type the case independent
    +    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
    +    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>
3:  7eaf8042061 = 3:  66968714739 strbuf: convert predicates to return bool
-- 
2.49.0.897.gfad3eb7d210
Phillip Wood· Jul 15, 2025, 13:52 UTC · re: Phillip Wood · lore

[PATCH v2 1/3] CodingGuildlines: allow the use of bool

From: Phillip Wood <phillip.wood@dunelm.org.uk>

We have had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As we've had it over 18 months without any complaints let's declare it a success.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 Documentation/CodingGuidelines | 3 +++
 1 file changed, 3 insertions(+)
Show changes to Documentation/CodingGuidelines +3 −0
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 6350949f2ef..528b42d1dd1 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -298,6 +298,9 @@ For C programs:
    . since late 2021 with 44ba10d6, we have had variables declared in
      the for loop "for (int i = 0; i < 10; i++)".
 
+   . since late 2023 with 8277dbe987 we have been using the bool type
+     from <stdbool.h>.
+
    New C99 features that we cannot use yet:
 
    . %z and %zu as a printf() argument for a size_t (the %z being for
-- 
2.49.0.897.gfad3eb7d210
Jeff King· Jul 16, 2025, 04:38 UTC · re: Phillip Wood · lore

Re: [PATCH v2 1/3] CodingGuildlines: allow the use of bool

On Tue, Jul 15, 2025 at 02:52:50PM +0100, Phillip Wood wrote:
> Subject: Re: [PATCH v2 1/3] CodingGuildlines: allow the use of bool

I was lots of discussion about grammar elsewhere, but nobody seems to have mentioned "Guildlines" instead of "Guidelines". :)

-Peff
Jeff King· Jul 16, 2025, 04:46 UTC · re: Jeff King · lore

Re: [PATCH v2 1/3] CodingGuildlines: allow the use of bool

On Wed, Jul 16, 2025 at 12:38:27AM -0400, Jeff King wrote:
Show 6 quoted lines
> On Tue, Jul 15, 2025 at 02:52:50PM +0100, Phillip Wood wrote:
> 
> > Subject: Re: [PATCH v2 1/3] CodingGuildlines: allow the use of bool
> 
> I was lots of discussion about grammar elsewhere, but nobody seems to
> have mentioned "Guildlines" instead of "Guidelines". :)
s/was/saw/, obviously.

Surely somebody has coined a name for the law that any statement pointing out a typo or grammatical issue is vastly more likely to contain one itself.

-Peff
Elijah Newren· Jul 16, 2025, 05:06 UTC · re: Jeff King · lore

Re: [PATCH v2 1/3] CodingGuildlines: allow the use of bool

On Tue, Jul 15, 2025 at 9:46 PM Jeff King <peff@peff.net> wrote:
Show 11 quoted lines
>
> On Wed, Jul 16, 2025 at 12:38:27AM -0400, Jeff King wrote:
>
> > On Tue, Jul 15, 2025 at 02:52:50PM +0100, Phillip Wood wrote:
> >
> > > Subject: Re: [PATCH v2 1/3] CodingGuildlines: allow the use of bool
> >
> > I was lots of discussion about grammar elsewhere, but nobody seems to
> > have mentioned "Guildlines" instead of "Guidelines". :)
>
> s/was/saw/, obviously.
hehe
> Surely somebody has coined a name for the law that any statement
> pointing out a typo or grammatical issue is vastly more likely to
> contain one itself.
https://en.wikipedia.org/wiki/Muphry%27s_law
Phillip Wood· Jul 15, 2025, 13:52 UTC · re: Phillip Wood · lore

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

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(-)
Show changes to git-compat-util.h +6 −6
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
Phillip Wood· Jul 15, 2025, 13:52 UTC · re: Phillip Wood · lore

[PATCH v2 3/3] strbuf: convert predicates to return bool

From: Phillip Wood <phillip.wood@dunelm.org.uk>

Now that the string predicates defined in git-compat-util.h all return bool let's convert the return type of the string predicates in strbuf.{c,h} to match them.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 strbuf.c | 28 ++++++++++++++--------------
 strbuf.h | 12 ++++++------
 2 files changed, 20 insertions(+), 20 deletions(-)
Show changes to 2 files +20 −20

strbuf.c, strbuf.h

diff --git a/strbuf.c b/strbuf.c
index f30fdc69843..6c3851a7f84 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -8,55 +8,55 @@
 #include "utf8.h"
 #include "date.h"
 
-int starts_with(const char *str, const char *prefix)
+bool starts_with(const char *str, const char *prefix)
 {
 	for (; ; str++, prefix++)
 		if (!*prefix)
-			return 1;
+			return true;
 		else if (*str != *prefix)
-			return 0;
+			return false;
 }
 
-int istarts_with(const char *str, const char *prefix)
+bool istarts_with(const char *str, const char *prefix)
 {
 	for (; ; str++, prefix++)
 		if (!*prefix)
-			return 1;
+			return true;
 		else if (tolower(*str) != tolower(*prefix))
-			return 0;
+			return false;
 }
 
-int starts_with_mem(const char *str, size_t len, const char *prefix)
+bool starts_with_mem(const char *str, size_t len, const char *prefix)
 {
 	const char *end = str + len;
 	for (; ; str++, prefix++) {
 		if (!*prefix)
-			return 1;
+			return true;
 		else if (str == end || *str != *prefix)
-			return 0;
+			return false;
 	}
 }
 
-int skip_to_optional_arg_default(const char *str, const char *prefix,
+bool skip_to_optional_arg_default(const char *str, const char *prefix,
 				 const char **arg, const char *def)
 {
 	const char *p;
 
 	if (!skip_prefix(str, prefix, &p))
-		return 0;
+		return false;
 
 	if (!*p) {
 		if (arg)
 			*arg = def;
-		return 1;
+		return true;
 	}
 
 	if (*p != '=')
-		return 0;
+		return false;
 
 	if (arg)
 		*arg = p + 1;
-	return 1;
+	return true;
 }
 
 /*
diff --git a/strbuf.h b/strbuf.h
index 6362777c0a0..a580ac6084b 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -660,9 +660,9 @@ char *xstrvfmt(const char *fmt, va_list ap);
 __attribute__((format (printf, 1, 2)))
 char *xstrfmt(const char *fmt, ...);
 
-int starts_with(const char *str, const char *prefix);
-int istarts_with(const char *str, const char *prefix);
-int starts_with_mem(const char *str, size_t len, const char *prefix);
+bool starts_with(const char *str, const char *prefix);
+bool istarts_with(const char *str, const char *prefix);
+bool starts_with_mem(const char *str, size_t len, const char *prefix);
 
 /*
  * If the string "str" is the same as the string in "prefix", then the "arg"
@@ -678,16 +678,16 @@ int starts_with_mem(const char *str, size_t len, const char *prefix);
  * can be used instead of !strcmp(arg, "--key") and then
  * skip_prefix(arg, "--key=", &arg) to parse such an option.
  */
-int skip_to_optional_arg_default(const char *str, const char *prefix,
+bool skip_to_optional_arg_default(const char *str, const char *prefix,
 				 const char **arg, const char *def);
 
-static inline int skip_to_optional_arg(const char *str, const char *prefix,
+static inline bool skip_to_optional_arg(const char *str, const char *prefix,
 				       const char **arg)
 {
 	return skip_to_optional_arg_default(str, prefix, arg, "");
 }
 
-static inline int ends_with(const char *str, const char *suffix)
+static inline bool ends_with(const char *str, const char *suffix)
 {
 	size_t len;
 	return strip_suffix(str, suffix, &len);
-- 
2.49.0.897.gfad3eb7d210
Elijah Newren· Jul 15, 2025, 17:19 UTC · re: Phillip Wood · lore

Re: [PATCH v2 0/3] C99: declare bool experiment a success

On Tue, Jul 15, 2025 at 6:53 AM Phillip Wood <phillip.wood123@gmail.com> wrote:
Show 51 quoted lines
>
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> We've had a test balloon for C99's bool type since 8277dbe987
> (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool,
> 2023-12-16). As it has been over 18 months since this was added and
> there have been no complaints let's declare it a success and convert
> the return type our other string predicates to match.
>
> Thank you to everyone who commented on V1, the only change here is
> to fix the typos in the commit message for patch 2.
>
> Base-Commit: a30f80fde927d70950b3b4d1820813480968fb0d
> Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fuse-c99-bool%2Fv2
> View-Changes-At: https://github.com/phillipwood/git/compare/a30f80fde...669687147
> Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/use-c99-bool/v2
>
>
> Phillip Wood (3):
>   CodingGuildlines: allow the use of bool
>   git-compat-util: convert string predicates to return bool
>   strbuf: convert predicates to return bool
>
>  Documentation/CodingGuidelines |  3 +++
>  git-compat-util.h              | 12 ++++++------
>  strbuf.c                       | 28 ++++++++++++++--------------
>  strbuf.h                       | 12 ++++++------
>  4 files changed, 29 insertions(+), 26 deletions(-)
>
> Range-diff against v1:
> 1:  352f80c49b7 = 1:  352f80c49b7 CodingGuildlines: allow the use of bool
> 2:  a0f9182aa20 ! 2:  0b2402e11cc git-compat-util: convert string predicates to return bool
>     @@ Commit message
>          git-compat-util: convert string predicates to return bool
>
>          Since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem}
>     -    to bool, 2023-12-16) a number of our sting predicates have been
>     -    returning bool instead of int. Now we've declared that experiment
>     -    a success lets convert the return type the case independent
>     +    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
>     +    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>
> 3:  7eaf8042061 = 3:  66968714739 strbuf: convert predicates to return bool
> --
> 2.49.0.897.gfad3eb7d210
This version looks good to me, thanks!
rsbecker@nexbridge.com· Jul 15, 2025, 18:23 UTC · re: Elijah Newren · lore

RE: [PATCH v2 0/3] C99: declare bool experiment a success

On July 15, 2025 1:19 PM Elijah Newren wrote:
Show 57 quoted lines
>On Tue, Jul 15, 2025 at 6:53 AM Phillip Wood <phillip.wood123@gmail.com>
>wrote:
>>
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> We've had a test balloon for C99's bool type since 8277dbe987
>> (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool,
>> 2023-12-16). As it has been over 18 months since this was added and
>> there have been no complaints let's declare it a success and convert
>> the return type our other string predicates to match.
>>
>> Thank you to everyone who commented on V1, the only change here is to
>> fix the typos in the commit message for patch 2.
>>
>> Base-Commit: a30f80fde927d70950b3b4d1820813480968fb0d
>> Published-As:
>> https://github.com/phillipwood/git/releases/tag/pw%2Fuse-c99-bool%2Fv2
>> View-Changes-At:
>> https://github.com/phillipwood/git/compare/a30f80fde...669687147
>> Fetch-It-Via: git fetch https://github.com/phillipwood/git
>> pw/use-c99-bool/v2
>>
>>
>> Phillip Wood (3):
>>   CodingGuildlines: allow the use of bool
>>   git-compat-util: convert string predicates to return bool
>>   strbuf: convert predicates to return bool
>>
>>  Documentation/CodingGuidelines |  3 +++
>>  git-compat-util.h              | 12 ++++++------
>>  strbuf.c                       | 28 ++++++++++++++--------------
>>  strbuf.h                       | 12 ++++++------
>>  4 files changed, 29 insertions(+), 26 deletions(-)
>>
>> Range-diff against v1:
>> 1:  352f80c49b7 = 1:  352f80c49b7 CodingGuildlines: allow the use of
>> bool
>> 2:  a0f9182aa20 ! 2:  0b2402e11cc git-compat-util: convert string predicates to
>return bool
>>     @@ Commit message
>>          git-compat-util: convert string predicates to return bool
>>
>>          Since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem}
>>     -    to bool, 2023-12-16) a number of our sting predicates have been
>>     -    returning bool instead of int. Now we've declared that experiment
>>     -    a success lets convert the return type the case independent
>>     +    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
>>     +    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>
>> 3:  7eaf8042061 = 3:  66968714739 strbuf: convert predicates to return
>> bool

bool is not standard in all c99 implementations. I have to #include <stdbool.h> in order to use this type. Please make sure there is a mechanism for that.

Elijah Newren· Jul 15, 2025, 19:35 UTC · re: rsbecker@nexbridge.com · lore

Re: [PATCH v2 0/3] C99: declare bool experiment a success

On Tue, Jul 15, 2025 at 11:23 AM <rsbecker@nexbridge.com> wrote:
Show 13 quoted lines
>
> On July 15, 2025 1:19 PM Elijah Newren wrote:
> >On Tue, Jul 15, 2025 at 6:53 AM Phillip Wood <phillip.wood123@gmail.com>
> >wrote:
> >>
> >> From: Phillip Wood <phillip.wood@dunelm.org.uk>
> >>
> >> We've had a test balloon for C99's bool type since 8277dbe987
> >> (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool,
> >> 2023-12-16). As it has been over 18 months since this was added and
> >> there have been no complaints let's declare it a success and convert
> >> the return type our other string predicates to match.
> >>
[...]
>
> bool is not standard in all c99 implementations. I have to #include <stdbool.h> in order to
> use this type. Please make sure there is a mechanism for that.
From the referenced commit in the commit message:

$ git log --oneline -1 -p 8277dbe987 | head -n 13 8277dbe9872 git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool

Show changes to git-compat-util.h +1 −0
diff --git a/git-compat-util.h b/git-compat-util.h
index 3e7a59b5ff1..603c97e3b3f 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -225,6 +225,7 @@ struct strbuf;
 #include <stddef.h>
 #include <stdlib.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <string.h>
 #ifdef HAVE_STRINGS_H
 #include <strings.h> /* for strcasecmp() */


So, there's not only a mechanism for that, it has already been done
for you 1.5 years ago.  No extra work on your or anyone else's part
needed.  :-)
rsbecker@nexbridge.com· Jul 15, 2025, 20:47 UTC · re: Elijah Newren · lore

RE: [PATCH v2 0/3] C99: declare bool experiment a success

On July 15, 2025 3:35 PM, Elijah Newren wrote:
Show 40 quoted lines
>On Tue, Jul 15, 2025 at 11:23 AM <rsbecker@nexbridge.com> wrote:
>>
>> On July 15, 2025 1:19 PM Elijah Newren wrote:
>> >On Tue, Jul 15, 2025 at 6:53 AM Phillip Wood
>> ><phillip.wood123@gmail.com>
>> >wrote:
>> >>
>> >> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>> >>
>> >> We've had a test balloon for C99's bool type since 8277dbe987
>> >> (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool,
>> >> 2023-12-16). As it has been over 18 months since this was added and
>> >> there have been no complaints let's declare it a success and
>> >> convert the return type our other string predicates to match.
>> >>
>[...]
>>
>> bool is not standard in all c99 implementations. I have to #include
>> <stdbool.h> in order to use this type. Please make sure there is a mechanism for
>that.
>
>>From the referenced commit in the commit message:
>
>$ git log --oneline -1 -p 8277dbe987 | head -n 13
>8277dbe9872 git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool diff --git
>a/git-compat-util.h b/git-compat-util.h index 3e7a59b5ff1..603c97e3b3f 100644
>--- a/git-compat-util.h
>+++ b/git-compat-util.h
>@@ -225,6 +225,7 @@ struct strbuf;
> #include <stddef.h>
> #include <stdlib.h>
> #include <stdarg.h>
>+#include <stdbool.h>
> #include <string.h>
> #ifdef HAVE_STRINGS_H
> #include <strings.h> /* for strcasecmp() */
>
>
>So, there's not only a mechanism for that, it has already been done for you 1.5
>years ago.  No extra work on your or anyone else's part needed.  :-)
Many thanks.
Junio C Hamano· Jul 15, 2025, 21:06 UTC · re: rsbecker@nexbridge.com · lore

Re: [PATCH v2 0/3] C99: declare bool experiment a success

<rsbecker@nexbridge.com> writes:
> bool is not standard in all c99 implementations. I have to #include <stdbool.h> in order to
> use this type. Please make sure there is a mechanism for that.

Given that <git-compat-util.h> unconditionally includes <compat/posix.h> and <compat/posix.h> unconditionally includes <stdbool.h> even in today's code, that should be OK.

Junio C Hamano· Jul 15, 2025, 18:53 UTC · re: Elijah Newren · lore

Re: [PATCH v2 0/3] C99: declare bool experiment a success

Elijah Newren <newren@gmail.com> writes:
Show 18 quoted lines
>>          Since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem}
>>     -    to bool, 2023-12-16) a number of our sting predicates have been
>>     -    returning bool instead of int. Now we've declared that experiment
>>     -    a success lets convert the return type the case independent
>>     +    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
>>     +    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>
>> 3:  7eaf8042061 = 3:  66968714739 strbuf: convert predicates to return bool
>> --
>> 2.49.0.897.gfad3eb7d210
>
> This version looks good to me, thanks!
Thanks, looking good.
brian m. carlson· Jul 15, 2025, 21:48 UTC · re: Phillip Wood · lore

Re: [PATCH v2 0/3] C99: declare bool experiment a success

On 2025-07-15 at 13:52:49, Phillip Wood wrote:
Show 10 quoted lines
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
> 
> We've had a test balloon for C99's bool type since 8277dbe987
> (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool,
> 2023-12-16). As it has been over 18 months since this was added and
> there have been no complaints let's declare it a success and convert
> the return type our other string predicates to match.
> 
> Thank you to everyone who commented on V1, the only change here is
> to fix the typos in the commit message for patch 2.

This series looked good to me. I especially like the fact that we've made it easier for me to figure out whether starts_with and friends are booleans (that is, true if it starts with the value) or our standard zero/negative-one (that is, false if it starts with the value).

-- 
brian m. carlson (they/them)
Toronto, Ontario, CA
Junio C Hamano· Jul 15, 2025, 22:09 UTC · re: brian m. carlson · lore

Re: [PATCH v2 0/3] C99: declare bool experiment a success

"brian m. carlson" <sandals@crustytoothpaste.net> writes:
> This series looked good to me.  I especially like the fact that we've
> made it easier for me to figure out whether starts_with and friends are
> booleans (that is, true if it starts with the value) or our standard
> zero/negative-one (that is, false if it starts with the value).
Hmph, this is a tangent, I've never thought of it that way.

The "0 is success and negative is failure" is exactly about success and failure. We expect such a call to succeed most of the time and failure is a note-worthy event.

Functions like starts_with() and friends, those that Lispers might name with q suffix, are quite different. A predicate is asking "is it, or isn't it?" question and returning "false" from it does not imply a failure in any way.

I wouldn't dream of making them return -1 for "failure", because starts_with(buf.buf, "#") that finds buf.buf does not begin with "#" is no way failing.

Anyway, we may start rewriting our old-fashioned idiom to normalize a "true if non-zero" integers, i.e.

	return !!some_true_if_non_zero_integer_variable;
into 
	return (bool)some_true_if_non_zero_integer_variable;
perhaps ;-).
Phillip Wood· Jul 16, 2025, 09:38 UTC · re: Phillip Wood · lore

[PATCH v3 0/3] C99: declare bool experiment a success

From: Phillip Wood <phillip.wood@dunelm.org.uk>

We've had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As it has been over 18 months since this was added and there have been no complaints let's declare it a success and convert the return type our other string predicates to match.

Thanks to peff for spotting yet another typo - I've updated the commit message for patch 1 accordingly.

Base-Commit: a30f80fde927d70950b3b4d1820813480968fb0d
Published-As: https://github.com/phillipwood/git/releases/tag/pw%2Fuse-c99-bool%2Fv3
View-Changes-At: https://github.com/phillipwood/git/compare/a30f80fde...80e5cd3b9
Fetch-It-Via: git fetch https://github.com/phillipwood/git pw/use-c99-bool/v3
Phillip Wood (3):
  CodingGuidelines: allow the use of bool
  git-compat-util: convert string predicates to return bool
  strbuf: convert predicates to return bool
 Documentation/CodingGuidelines |  3 +++
 git-compat-util.h              | 12 ++++++------
 strbuf.c                       | 28 ++++++++++++++--------------
 strbuf.h                       | 12 ++++++------
 4 files changed, 29 insertions(+), 26 deletions(-)
Range-diff against v2:
1:  352f80c49b7 ! 1:  3ff7ae61f45 CodingGuildlines: allow the use of bool
    @@ Metadata
     Author: Phillip Wood <phillip.wood@dunelm.org.uk>
     
      ## Commit message ##
    -    CodingGuildlines: allow the use of bool
    +    CodingGuidelines: allow the use of bool
     
         We have had a test balloon for C99's bool type since 8277dbe987
         (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool,
2:  0b2402e11cc = 2:  26c3f48ac6c git-compat-util: convert string predicates to return bool
3:  66968714739 = 3:  80e5cd3b9df strbuf: convert predicates to return bool
-- 
2.49.0.897.gfad3eb7d210
Phillip Wood· Jul 16, 2025, 09:38 UTC · re: Phillip Wood · lore

[PATCH v3 1/3] CodingGuidelines: allow the use of bool

From: Phillip Wood <phillip.wood@dunelm.org.uk>

We have had a test balloon for C99's bool type since 8277dbe987 (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool, 2023-12-16). As we've had it over 18 months without any complaints let's declare it a success.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 Documentation/CodingGuidelines | 3 +++
 1 file changed, 3 insertions(+)
Show changes to Documentation/CodingGuidelines +3 −0
diff --git a/Documentation/CodingGuidelines b/Documentation/CodingGuidelines
index 6350949f2ef..528b42d1dd1 100644
--- a/Documentation/CodingGuidelines
+++ b/Documentation/CodingGuidelines
@@ -298,6 +298,9 @@ For C programs:
    . since late 2021 with 44ba10d6, we have had variables declared in
      the for loop "for (int i = 0; i < 10; i++)".
 
+   . since late 2023 with 8277dbe987 we have been using the bool type
+     from <stdbool.h>.
+
    New C99 features that we cannot use yet:
 
    . %z and %zu as a printf() argument for a size_t (the %z being for
-- 
2.49.0.897.gfad3eb7d210
Phillip Wood· Jul 16, 2025, 09:38 UTC · re: Phillip Wood · lore

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

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(-)
Show changes to git-compat-util.h +6 −6
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
Karthik Nayak· Jul 16, 2025, 10:26 UTC · re: Phillip Wood · lore

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

Phillip Wood <phillip.wood123@gmail.com> writes:
Show 48 quoted lines
> 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)
>
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
Show changes to git-compat-util.h +3 −3
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]
Phillip Wood· Jul 16, 2025, 09:38 UTC · re: Phillip Wood · lore

[PATCH v3 3/3] strbuf: convert predicates to return bool

From: Phillip Wood <phillip.wood@dunelm.org.uk>

Now that the string predicates defined in git-compat-util.h all return bool let's convert the return type of the string predicates in strbuf.{c,h} to match them.

Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
---
 strbuf.c | 28 ++++++++++++++--------------
 strbuf.h | 12 ++++++------
 2 files changed, 20 insertions(+), 20 deletions(-)
Show changes to 2 files +20 −20

strbuf.c, strbuf.h

diff --git a/strbuf.c b/strbuf.c
index f30fdc69843..6c3851a7f84 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -8,55 +8,55 @@
 #include "utf8.h"
 #include "date.h"
 
-int starts_with(const char *str, const char *prefix)
+bool starts_with(const char *str, const char *prefix)
 {
 	for (; ; str++, prefix++)
 		if (!*prefix)
-			return 1;
+			return true;
 		else if (*str != *prefix)
-			return 0;
+			return false;
 }
 
-int istarts_with(const char *str, const char *prefix)
+bool istarts_with(const char *str, const char *prefix)
 {
 	for (; ; str++, prefix++)
 		if (!*prefix)
-			return 1;
+			return true;
 		else if (tolower(*str) != tolower(*prefix))
-			return 0;
+			return false;
 }
 
-int starts_with_mem(const char *str, size_t len, const char *prefix)
+bool starts_with_mem(const char *str, size_t len, const char *prefix)
 {
 	const char *end = str + len;
 	for (; ; str++, prefix++) {
 		if (!*prefix)
-			return 1;
+			return true;
 		else if (str == end || *str != *prefix)
-			return 0;
+			return false;
 	}
 }
 
-int skip_to_optional_arg_default(const char *str, const char *prefix,
+bool skip_to_optional_arg_default(const char *str, const char *prefix,
 				 const char **arg, const char *def)
 {
 	const char *p;
 
 	if (!skip_prefix(str, prefix, &p))
-		return 0;
+		return false;
 
 	if (!*p) {
 		if (arg)
 			*arg = def;
-		return 1;
+		return true;
 	}
 
 	if (*p != '=')
-		return 0;
+		return false;
 
 	if (arg)
 		*arg = p + 1;
-	return 1;
+	return true;
 }
 
 /*
diff --git a/strbuf.h b/strbuf.h
index 6362777c0a0..a580ac6084b 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -660,9 +660,9 @@ char *xstrvfmt(const char *fmt, va_list ap);
 __attribute__((format (printf, 1, 2)))
 char *xstrfmt(const char *fmt, ...);
 
-int starts_with(const char *str, const char *prefix);
-int istarts_with(const char *str, const char *prefix);
-int starts_with_mem(const char *str, size_t len, const char *prefix);
+bool starts_with(const char *str, const char *prefix);
+bool istarts_with(const char *str, const char *prefix);
+bool starts_with_mem(const char *str, size_t len, const char *prefix);
 
 /*
  * If the string "str" is the same as the string in "prefix", then the "arg"
@@ -678,16 +678,16 @@ int starts_with_mem(const char *str, size_t len, const char *prefix);
  * can be used instead of !strcmp(arg, "--key") and then
  * skip_prefix(arg, "--key=", &arg) to parse such an option.
  */
-int skip_to_optional_arg_default(const char *str, const char *prefix,
+bool skip_to_optional_arg_default(const char *str, const char *prefix,
 				 const char **arg, const char *def);
 
-static inline int skip_to_optional_arg(const char *str, const char *prefix,
+static inline bool skip_to_optional_arg(const char *str, const char *prefix,
 				       const char **arg)
 {
 	return skip_to_optional_arg_default(str, prefix, arg, "");
 }
 
-static inline int ends_with(const char *str, const char *suffix)
+static inline bool ends_with(const char *str, const char *suffix)
 {
 	size_t len;
 	return strip_suffix(str, suffix, &len);
-- 
2.49.0.897.gfad3eb7d210
Karthik Nayak· Jul 16, 2025, 10:28 UTC · re: Phillip Wood · lore

Re: [PATCH v3 3/3] strbuf: convert predicates to return bool

Phillip Wood <phillip.wood123@gmail.com> writes:
Show 12 quoted lines
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> Now that the string predicates defined in git-compat-util.h all
> return bool let's convert the return type of the string predicates
> in strbuf.{c,h} to match them.
>
> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>
> ---
>  strbuf.c | 28 ++++++++++++++--------------
>  strbuf.h | 12 ++++++------
>  2 files changed, 20 insertions(+), 20 deletions(-)
>
Nit: same here as the previous patch
$ ./ci/run-style-check.sh @~1
Show changes to 2 files +3 −3

strbuf.c, strbuf.h

diff --git a/strbuf.c b/strbuf.c
index 6c3851a7f8..d9e040c13b 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -38,7 +38,7 @@ bool starts_with_mem(const char *str, size_t len,
const char *prefix)
 }

 bool skip_to_optional_arg_default(const char *str, const char *prefix,
-				 const char **arg, const char *def)
+				  const char **arg, const char *def)
 {
 	const char *p;

diff --git a/strbuf.h b/strbuf.h
index a580ac6084..d2ff9839a9 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -679,10 +679,10 @@ bool starts_with_mem(const char *str, size_t
len, const char *prefix);
  * skip_prefix(arg, "--key=", &arg) to parse such an option.
  */
 bool skip_to_optional_arg_default(const char *str, const char *prefix,
-				 const char **arg, const char *def);
+				  const char **arg, const char *def);

 static inline bool skip_to_optional_arg(const char *str, const char *prefix,
-				       const char **arg)
+					const char **arg)
 {
 	return skip_to_optional_arg_default(str, prefix, arg, "");
 }

[snip]
Karthik Nayak· Jul 16, 2025, 10:29 UTC · re: Phillip Wood · lore

Re: [PATCH v3 0/3] C99: declare bool experiment a success

Phillip Wood <phillip.wood123@gmail.com> writes:
Show 8 quoted lines
> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>
> We've had a test balloon for C99's bool type since 8277dbe987
> (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool,
> 2023-12-16). As it has been over 18 months since this was added and
> there have been no complaints let's declare it a success and convert
> the return type our other string predicates to match.
>

Neat, I didn't even know we were running such an experiment. Thanks for getting around to it, I think the patches look great, added some complaints from 'clang-format', feel free to ignore.

Thanks, Karthik

[snip]
Phillip Wood· Jul 17, 2025, 15:21 UTC · re: Karthik Nayak · lore

Re: [PATCH v3 0/3] C99: declare bool experiment a success

Hi Karthik
On 16/07/2025 11:29, Karthik Nayak wrote:
Show 14 quoted lines
> Phillip Wood <phillip.wood123@gmail.com> writes:
> 
>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>
>> We've had a test balloon for C99's bool type since 8277dbe987
>> (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool,
>> 2023-12-16). As it has been over 18 months since this was added and
>> there have been no complaints let's declare it a success and convert
>> the return type our other string predicates to match.
>>
> 
> Neat, I didn't even know we were running such an experiment. Thanks for
> getting around to it, I think the patches look great, added some
> complaints from 'clang-format', feel free to ignore.

Thanks for taking a look. I would have fixed the formatting but this is in next already so I'll leave it as it is if that's ok with you.

Thanks
Phillip
Karthik Nayak· Jul 22, 2025, 08:09 UTC · re: Phillip Wood · lore

Re: [PATCH v3 0/3] C99: declare bool experiment a success

Phillip Wood <phillip.wood123@gmail.com> writes:
Show 21 quoted lines
> Hi Karthik
>
> On 16/07/2025 11:29, Karthik Nayak wrote:
>> Phillip Wood <phillip.wood123@gmail.com> writes:
>>
>>> From: Phillip Wood <phillip.wood@dunelm.org.uk>
>>>
>>> We've had a test balloon for C99's bool type since 8277dbe987
>>> (git-compat-util: convert skip_{prefix,suffix}{,_mem} to bool,
>>> 2023-12-16). As it has been over 18 months since this was added and
>>> there have been no complaints let's declare it a success and convert
>>> the return type our other string predicates to match.
>>>
>>
>> Neat, I didn't even know we were running such an experiment. Thanks for
>> getting around to it, I think the patches look great, added some
>> complaints from 'clang-format', feel free to ignore.
>
> Thanks for taking a look. I would have fixed the formatting but this is
> in next already so I'll leave it as it is if that's ok with you.
>

Of course :) These are small nits. I'm mostly interested in getting clang-format to work without any/many false positives, so I'm trying to test it with different patches that I read and report back!

> Thanks
>
> Phillip

← back to recent threads