@@ -2,11 +2,37 @@
// original symbols can be hidden. Renaming these with a "libgit_" prefix also
// avoid conflicts with other libraries such as libgit2.
+#include "git-compat-util.h"
#include "contrib/cgit-rs/cgit-sys/public_symbol_export.h"
+#include "common-init.h"
+#include "config.h"
+#include "setup.h"
#include "version.h"
+extern struct repository *the_repository;
+
#pragma GCC visibility push(default)
+const char *libgit_setup_git_directory(void)
+{
+ return setup_git_directory();
+}
+
+int libgit_config_get_int(const char *key, int *dest)
+{
+ return repo_config_get_int(the_repository, key, dest);
+}
+
+void libgit_init_git(const char **argv)
+{
+ init_git(argv);
+}
+
+int libgit_parse_maybe_bool(const char *val)
+{
+ return git_parse_maybe_bool(val);
+}
+
const char *libgit_user_agent(void)
{
return git_user_agent();
@@ -1,6 +1,14 @@
#ifndef PUBLIC_SYMBOL_EXPORT_H
#define PUBLIC_SYMBOL_EXPORT_H
+const char *libgit_setup_git_directory(void);
+
+int libgit_config_get_int(const char *key, int *dest);
+
+void libgit_init_git(const char **argv);
+
+int libgit_parse_maybe_bool(const char *val);
+
const char *libgit_user_agent(void);
const char *libgit_user_agent_sanitized(void);
@@ -1,6 +1,17 @@
-use std::ffi::c_char;
+use std::ffi::{c_char, c_int};
extern "C" {
+ pub fn libgit_setup_git_directory() -> *const c_char;
+
+ // From config.c
+ pub fn libgit_config_get_int(key: *const c_char, dest: *mut c_int) -> c_int;
+
+ // From common-init.c
+ pub fn libgit_init_git(argv: *const *const c_char);
+
+ // From parse.c
+ pub fn libgit_parse_maybe_bool(val: *const c_char) -> c_int;
+
// From version.c
pub fn libgit_user_agent() -> *const c_char;
pub fn libgit_user_agent_sanitized() -> *const c_char;
@@ -8,7 +19,7 @@ extern "C" {
#[cfg(test)]
mod tests {
- use std::ffi::CStr;
+ use std::ffi::{CStr, CString};
use super::*;
@@ -37,4 +48,36 @@ mod tests {
agent
);
}
+
+ #[test]
+ fn parse_bools_from_strings() {
+ let arg = CString::new("true").unwrap();
+ assert_eq!(unsafe { libgit_parse_maybe_bool(arg.as_ptr()) }, 1);
+
+ let arg = CString::new("yes").unwrap();
+ assert_eq!(unsafe { libgit_parse_maybe_bool(arg.as_ptr()) }, 1);
+
+ let arg = CString::new("false").unwrap();
+ assert_eq!(unsafe { libgit_parse_maybe_bool(arg.as_ptr()) }, 0);
+
+ let arg = CString::new("no").unwrap();
+ assert_eq!(unsafe { libgit_parse_maybe_bool(arg.as_ptr()) }, 0);
+
+ let arg = CString::new("maybe").unwrap();
+ assert_eq!(unsafe { libgit_parse_maybe_bool(arg.as_ptr()) }, -1);
+ }
+
+ #[test]
+ fn access_configs() {
+ // NEEDSWORK: we need to supply a testdata config
+ let fake_argv = [std::ptr::null::<c_char>()];
+ unsafe {
+ libgit_init_git(fake_argv.as_ptr());
+ libgit_setup_git_directory();
+ }
+ let mut val: c_int = 0;
+ let key = CString::new("trace2.eventNesting").unwrap();
+ unsafe { libgit_config_get_int(key.as_ptr(), &mut val as *mut i32) };
+ assert_eq!(val, 5);
+ }
}