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

Re: [PATCH 2/2] libgit-rs: add get_bool() method to ConfigSet

From
PWPhillip Wood <phillip.wood123@gmail.com>
Date
Sep 26, 2025, 09:58 UTC
Message-ID
<9e53f617-1b17-4d36-9c35-fc86c0ddfb19@gmail.com>
In-Reply-To
<a5904a2ac00ea6de142344272b45f6b4697b4f98.1758800669.git.gitgitgadget@gmail.com>
On 25/09/2025 12:44, ionnss via GitGitGadget wrote:
Show 8 quoted lines
> From: ionnss <zara.leonardo@gmail.com>
> 
> Add support for parsing boolean configuration values in the Rust
> ConfigSet API. The method follows Git's standard boolean parsing
> rules, accepting true/yes/on/1 as true and false/no/off/0 as false.
> 
> The implementation reuses the existing get_string() infrastructure
> and adds case-insensitive boolean parsing logic.

It's nice to know that someone is using the rust bindings. The code in contrib/libgit-rs is intended to be safe wrappers around the unsafe functions in contrib/libgit-sys which wrap git's C code. I think what we need to do here is add a binding for git_configset_get_bool() to libgit-sys and then wrap that in libgit-rs. We don't want to start implementing the parsing separately as they'll inevitably end up behaving differently to git. For example what you have here parses "00" or "100" differently to git.

Thanks
Phillip
Show 56 quoted lines
> Signed-off-by: ionnss <zara.leonardo@gmail.com>
> ---
>   contrib/libgit-rs/src/config.rs    | 24 ++++++++++++++++++++++++
>   contrib/libgit-rs/testdata/config3 |  2 ++
>   2 files changed, 26 insertions(+)
> 
> diff --git a/contrib/libgit-rs/src/config.rs b/contrib/libgit-rs/src/config.rs
> index 6bf04845c8..3f4a32c72d 100644
> --- a/contrib/libgit-rs/src/config.rs
> +++ b/contrib/libgit-rs/src/config.rs
> @@ -68,6 +68,26 @@ impl ConfigSet {
>               Some(owned_str)
>           }
>       }
> +
> +    pub fn get_bool(&mut self, key: &str) -> Option<bool> {
> +        let key = CString::new(key).expect("Couldn't convert key to CString");
> +        let mut val: *mut c_char = std::ptr::null_mut();
> +        unsafe {
> +            if libgit_configset_get_string(self.0, key.as_ptr(), &mut val as *mut *mut c_char) != 0
> +            {
> +                return None;
> +            }
> +            let borrowed_str = CStr::from_ptr(val);
> +            let owned_str =
> +                String::from(borrowed_str.to_str().expect("Couldn't convert val to str"));
> +            free(val as *mut c_void); // Free the xstrdup()ed pointer from the C side
> +            match owned_str.to_lowercase().as_str() {
> +                "true" | "yes" | "on" | "1" => Some(true),
> +                "false" | "no" | "off" | "0" => Some(false),
> +                _ => None,
> +            }
> +        }
> +    }
>   }
>   
>   impl Default for ConfigSet {
> @@ -102,5 +122,9 @@ 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
> +        assert_eq!(cs.get_bool("test.booleanValue"), Some(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..83a474ccef 100644
> --- a/contrib/libgit-rs/testdata/config3
> +++ b/contrib/libgit-rs/testdata/config3
> @@ -1,2 +1,4 @@
>   [trace2]
>   	eventNesting = 3
> +[test]
> +	booleanValue = true
Previous: Chris TorekNext: Junio C Hamano
Message 5 of 22 in “libgit-rs: add get_bool() method to ConfigSet”
  1. 0/2 libgit-rs: add get_bool() method to ConfigSetions via GitGitGadget, Sep 25, 2025
  2. 1/2 po: fix escaped underscores in README.mdionnss via GitGitGadget, Sep 25, 2025
  3. 2/2 libgit-rs: add get_bool() method to ConfigSetionnss via GitGitGadget, Sep 25, 2025
  4. Chris TorekSep 26, 2025
  5. Phillip WoodSep 26, 2025
  6. Junio C HamanoSep 26, 2025
  7. 0/3 libgit-rs: add get_bool() method to ConfigSetions via GitGitGadget, Sep 27, 2025
  8. 1/3 po: fix escaped underscores in README.mdionnss via GitGitGadget, Sep 27, 2025
  9. 2/3 libgit-rs: add get_bool() method to ConfigSetionnss via GitGitGadget, Sep 27, 2025
  10. 3/3 libgit-rs: address review feedback for get_bool()ionnss via GitGitGadget, Sep 27, 2025
  11. Junio C HamanoSep 27, 2025
  12. 0/3 libgit-rs: add get_bool() method to ConfigSetions via GitGitGadget, Sep 27, 2025
  13. 1/3 po: fix escaped underscores in README.mdionnss via GitGitGadget, Sep 27, 2025
  14. Phillip WoodSep 29, 2025
  15. 2/3 libgit-rs: add get_bool() method to ConfigSetionnss via GitGitGadget, Sep 27, 2025
  16. Phillip WoodSep 29, 2025
  17. 3/3 libgit-rs: add get_ulong() and get_pathname() methodsionnss via GitGitGadget, Sep 27, 2025
  18. Phillip WoodSep 29, 2025
  19. libgit-rs: add get_bool(), get_ulong(), and get_pathname() methodsions via GitGitGadget, Sep 30, 2025
  20. Phillip WoodOct 1, 2025
  21. brian m. carlsonOct 6, 2025
  22. Phillip WoodOct 8, 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.