From: Phillip Wood <phillip.wood123@gmail.com>
To: ionnss via GitGitGadget <gitgitgadget@gmail.com>, git@vger.kernel.org
Cc: Chris Torek <chris.torek@gmail.com>, ions <zara.leonardo@gmail.com>
Subject: Re: [PATCH v3 2/3] libgit-rs: add get_bool() method to ConfigSet
Date: Mon, 29 Sep 2025 14:23:48 +0100 [thread overview]
Message-ID: <a3febed5-22aa-41cb-a602-39eae148c131@gmail.com> (raw)
In-Reply-To: <479c263bc19aa5cdfe9d990b2521f88b1620759c.1758945111.git.gitgitgadget@gmail.com>
On 27/09/2025 04:51, ionnss via GitGitGadget wrote:
> From: ionnss <zara.leonardo@gmail.com>
>
> Add support for parsing boolean configuration values using Git's
> git_configset_get_bool() C function. This ensures consistent behavior
> with Git's native boolean parsing logic.
>
> The method handles all Git boolean formats (true/false, yes/no, on/off,
> 1/0) and edge cases like "00" and "100" correctly.
>
> Includes comprehensive tests for various boolean formats and edge cases.
Unfortunately when I try to run those tests with
make INCLUDE_LIBGIT_RS=1 && cd contrib/libgit-rs && cargo test
I see
= note: /usr/bin/ld:
/home/phil/src/git/update-ref-date/contrib/libgit-rs/target/debug/deps/libgit-8c021564b9d1ec26.9j3smxv8a5f6u8czhaxq401mn.rcgu.o:
in function `libgit::config::ConfigSet::get_bool':
/home/phil/src/git/update-ref-date/contrib/libgit-rs/src/config.rs:78:
undefined reference to `libgit_configset_get_bool'
collect2: error: ld returned 1 exit status
This happens because libgit_configset_get_bool() is not defined in
contrib/libgit-sys/public_symbol_export.[ch]. You need to wrap
configset_get_bool() in the some way that configset_get_int() is.
Thanks
Phillip
> Signed-off-by: ionnss <zara.leonardo@gmail.com>
> ---
> contrib/libgit-rs/src/config.rs | 26 ++++++++++++++++++++++++++
> contrib/libgit-rs/testdata/config3 | 2 +-
> contrib/libgit-rs/testdata/config4 | 9 +++++++++
> contrib/libgit-sys/src/lib.rs | 6 ++++++
> 4 files changed, 42 insertions(+), 1 deletion(-)
> create mode 100644 contrib/libgit-rs/testdata/config4
>
> diff --git a/contrib/libgit-rs/src/config.rs b/contrib/libgit-rs/src/config.rs
> index 6bf04845c8..72ee88801b 100644
> --- a/contrib/libgit-rs/src/config.rs
> +++ b/contrib/libgit-rs/src/config.rs
> @@ -68,6 +68,20 @@ impl ConfigSet {
> Some(owned_str)
> }
> }
> +
> + /// Load the value for the given key and attempt to parse it as a boolean. Dies with a fatal error
> + /// if the value cannot be parsed. Returns None if the key is not present.
> + pub fn get_bool(&mut self, key: &str) -> Option<bool> {
> + let key = CString::new(key).expect("config key should be valid CString");
> + let mut val: c_int = 0;
> + unsafe {
> + if libgit_configset_get_bool(self.0, key.as_ptr(), &mut val as *mut c_int) != 0 {
> + return None;
> + }
> + }
> +
> + Some(val != 0)
> + }
> }
>
> impl Default for ConfigSet {
> @@ -95,6 +109,7 @@ mod tests {
> Path::new("testdata/config1"),
> Path::new("testdata/config2"),
> Path::new("testdata/config3"),
> + Path::new("testdata/config4"),
> ]);
> // ConfigSet retrieves correct value
> assert_eq!(cs.get_int("trace2.eventTarget"), Some(1));
> @@ -102,5 +117,16 @@ mod tests {
> assert_eq!(cs.get_int("trace2.eventNesting"), Some(3));
> // ConfigSet returns None for missing key
> assert_eq!(cs.get_string("foo.bar"), None);
> + // Test boolean parsing - comprehensive tests
> + assert_eq!(cs.get_bool("test.boolTrue"), Some(true));
> + assert_eq!(cs.get_bool("test.boolFalse"), Some(false));
> + assert_eq!(cs.get_bool("test.boolYes"), Some(true));
> + assert_eq!(cs.get_bool("test.boolNo"), Some(false));
> + assert_eq!(cs.get_bool("test.boolOne"), Some(true));
> + assert_eq!(cs.get_bool("test.boolZero"), Some(false));
> + assert_eq!(cs.get_bool("test.boolZeroZero"), Some(false)); // "00" → false
> + assert_eq!(cs.get_bool("test.boolHundred"), Some(true)); // "100" → true
> + // Test missing boolean key
> + assert_eq!(cs.get_bool("missing.boolean"), None);
> }
> }
> diff --git a/contrib/libgit-rs/testdata/config3 b/contrib/libgit-rs/testdata/config3
> index ca7b9a7c38..3ea5b96f12 100644
> --- a/contrib/libgit-rs/testdata/config3
> +++ b/contrib/libgit-rs/testdata/config3
> @@ -1,2 +1,2 @@
> [trace2]
> - eventNesting = 3
> + eventNesting = 3
> \ No newline at end of file
> diff --git a/contrib/libgit-rs/testdata/config4 b/contrib/libgit-rs/testdata/config4
> new file mode 100644
> index 0000000000..c0755a32be
> --- /dev/null
> +++ b/contrib/libgit-rs/testdata/config4
> @@ -0,0 +1,9 @@
> +[test]
> + boolTrue = true
> + boolFalse = false
> + boolYes = yes
> + boolNo = no
> + boolOne = 1
> + boolZero = 0
> + boolZeroZero = 00
> + boolHundred = 100
> diff --git a/contrib/libgit-sys/src/lib.rs b/contrib/libgit-sys/src/lib.rs
> index 4bfc650450..b104fda8f6 100644
> --- a/contrib/libgit-sys/src/lib.rs
> +++ b/contrib/libgit-sys/src/lib.rs
> @@ -43,6 +43,12 @@ extern "C" {
> dest: *mut *mut c_char,
> ) -> c_int;
>
> + pub fn libgit_configset_get_bool(
> + cs: *mut libgit_config_set,
> + key: *const c_char,
> + dest: *mut c_int,
> + ) -> c_int;
> +
> }
>
> #[cfg(test)]
next prev parent reply other threads:[~2025-09-29 13:23 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-25 11:44 [PATCH 0/2] libgit-rs: add get_bool() method to ConfigSet ions via GitGitGadget
2025-09-25 11:44 ` [PATCH 1/2] po: fix escaped underscores in README.md ionnss via GitGitGadget
2025-09-25 11:44 ` [PATCH 2/2] libgit-rs: add get_bool() method to ConfigSet ionnss via GitGitGadget
2025-09-26 6:43 ` Chris Torek
2025-09-26 9:58 ` Phillip Wood
2025-09-26 17:15 ` Junio C Hamano
2025-09-27 0:07 ` [PATCH v2 0/3] " ions via GitGitGadget
2025-09-27 0:07 ` [PATCH v2 1/3] po: fix escaped underscores in README.md ionnss via GitGitGadget
2025-09-27 0:07 ` [PATCH v2 2/3] libgit-rs: add get_bool() method to ConfigSet ionnss via GitGitGadget
2025-09-27 0:07 ` [PATCH v2 3/3] libgit-rs: address review feedback for get_bool() ionnss via GitGitGadget
2025-09-27 2:01 ` [PATCH v2 0/3] libgit-rs: add get_bool() method to ConfigSet Junio C Hamano
2025-09-27 3:51 ` [PATCH v3 " ions via GitGitGadget
2025-09-27 3:51 ` [PATCH v3 1/3] po: fix escaped underscores in README.md ionnss via GitGitGadget
2025-09-29 13:26 ` Phillip Wood
2025-09-27 3:51 ` [PATCH v3 2/3] libgit-rs: add get_bool() method to ConfigSet ionnss via GitGitGadget
2025-09-29 13:23 ` Phillip Wood [this message]
2025-09-27 3:51 ` [PATCH v3 3/3] libgit-rs: add get_ulong() and get_pathname() methods ionnss via GitGitGadget
2025-09-29 13:23 ` Phillip Wood
2025-09-30 8:46 ` [PATCH v4] libgit-rs: add get_bool(), get_ulong(), " ions via GitGitGadget
2025-10-01 10:15 ` Phillip Wood
2025-10-06 21:20 ` brian m. carlson
2025-10-08 13:36 ` Phillip Wood
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=a3febed5-22aa-41cb-a602-39eae148c131@gmail.com \
--to=phillip.wood123@gmail.com \
--cc=chris.torek@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=zara.leonardo@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.