libgit-sys: also export some config_set functions
In preparation for implementing a higher-level Rust API for accessing Git configs, export some of the upstream configset API via libgitpub and libgit-sys. Since this will be exercised as part of the higher-level API in the next commit, no tests have been added for libgit-sys. While we're at it, add git_configset_alloc() and git_configset_free() functions in libgitpub so that callers can manage config_set structs on the heap. This also allows non-C external consumers to treat config_sets as opaque structs. Co-authored-by: Calvin Wan <calvinwan@google.com> Signed-off-by: Calvin Wan <calvinwan@google.com> Signed-off-by: Josh Steadmon <steadmon@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
e7f8bf125c
commit
d76eb0dccc
@ -5,11 +5,47 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "git-compat-util.h"
|
#include "git-compat-util.h"
|
||||||
|
#include "config.h"
|
||||||
#include "contrib/libgit-sys/public_symbol_export.h"
|
#include "contrib/libgit-sys/public_symbol_export.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
|
|
||||||
#pragma GCC visibility push(default)
|
#pragma GCC visibility push(default)
|
||||||
|
|
||||||
|
struct libgit_config_set {
|
||||||
|
struct config_set cs;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct libgit_config_set *libgit_configset_alloc(void)
|
||||||
|
{
|
||||||
|
struct libgit_config_set *cs =
|
||||||
|
xmalloc(sizeof(struct libgit_config_set));
|
||||||
|
git_configset_init(&cs->cs);
|
||||||
|
return cs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void libgit_configset_free(struct libgit_config_set *cs)
|
||||||
|
{
|
||||||
|
git_configset_clear(&cs->cs);
|
||||||
|
free(cs);
|
||||||
|
}
|
||||||
|
|
||||||
|
int libgit_configset_add_file(struct libgit_config_set *cs, const char *filename)
|
||||||
|
{
|
||||||
|
return git_configset_add_file(&cs->cs, filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
int libgit_configset_get_int(struct libgit_config_set *cs, const char *key,
|
||||||
|
int *dest)
|
||||||
|
{
|
||||||
|
return git_configset_get_int(&cs->cs, key, dest);
|
||||||
|
}
|
||||||
|
|
||||||
|
int libgit_configset_get_string(struct libgit_config_set *cs, const char *key,
|
||||||
|
char **dest)
|
||||||
|
{
|
||||||
|
return git_configset_get_string(&cs->cs, key, dest);
|
||||||
|
}
|
||||||
|
|
||||||
const char *libgit_user_agent(void)
|
const char *libgit_user_agent(void)
|
||||||
{
|
{
|
||||||
return git_user_agent();
|
return git_user_agent();
|
||||||
|
@ -1,6 +1,16 @@
|
|||||||
#ifndef PUBLIC_SYMBOL_EXPORT_H
|
#ifndef PUBLIC_SYMBOL_EXPORT_H
|
||||||
#define PUBLIC_SYMBOL_EXPORT_H
|
#define PUBLIC_SYMBOL_EXPORT_H
|
||||||
|
|
||||||
|
struct libgit_config_set *libgit_configset_alloc(void);
|
||||||
|
|
||||||
|
void libgit_configset_free(struct libgit_config_set *cs);
|
||||||
|
|
||||||
|
int libgit_configset_add_file(struct libgit_config_set *cs, const char *filename);
|
||||||
|
|
||||||
|
int libgit_configset_get_int(struct libgit_config_set *cs, const char *key, int *dest);
|
||||||
|
|
||||||
|
int libgit_configset_get_string(struct libgit_config_set *cs, const char *key, char **dest);
|
||||||
|
|
||||||
const char *libgit_user_agent(void);
|
const char *libgit_user_agent(void);
|
||||||
|
|
||||||
const char *libgit_user_agent_sanitized(void);
|
const char *libgit_user_agent_sanitized(void);
|
||||||
|
@ -1,15 +1,44 @@
|
|||||||
#[cfg(has_std__ffi__c_char)]
|
#[cfg(has_std__ffi__c_char)]
|
||||||
use std::ffi::c_char;
|
use std::ffi::{c_char, c_int};
|
||||||
|
|
||||||
#[cfg(not(has_std__ffi__c_char))]
|
#[cfg(not(has_std__ffi__c_char))]
|
||||||
#[allow(non_camel_case_types)]
|
#[allow(non_camel_case_types)]
|
||||||
pub type c_char = i8;
|
pub type c_char = i8;
|
||||||
|
|
||||||
|
#[cfg(not(has_std__ffi__c_char))]
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
pub type c_int = i32;
|
||||||
|
|
||||||
extern crate libz_sys;
|
extern crate libz_sys;
|
||||||
|
|
||||||
|
#[allow(non_camel_case_types)]
|
||||||
|
#[repr(C)]
|
||||||
|
pub struct libgit_config_set {
|
||||||
|
_data: [u8; 0],
|
||||||
|
_marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
pub fn libgit_user_agent() -> *const c_char;
|
pub fn libgit_user_agent() -> *const c_char;
|
||||||
pub fn libgit_user_agent_sanitized() -> *const c_char;
|
pub fn libgit_user_agent_sanitized() -> *const c_char;
|
||||||
|
|
||||||
|
pub fn libgit_configset_alloc() -> *mut libgit_config_set;
|
||||||
|
pub fn libgit_configset_free(cs: *mut libgit_config_set);
|
||||||
|
|
||||||
|
pub fn libgit_configset_add_file(cs: *mut libgit_config_set, filename: *const c_char) -> c_int;
|
||||||
|
|
||||||
|
pub fn libgit_configset_get_int(
|
||||||
|
cs: *mut libgit_config_set,
|
||||||
|
key: *const c_char,
|
||||||
|
int: *mut c_int,
|
||||||
|
) -> c_int;
|
||||||
|
|
||||||
|
pub fn libgit_configset_get_string(
|
||||||
|
cs: *mut libgit_config_set,
|
||||||
|
key: *const c_char,
|
||||||
|
dest: *mut *mut c_char,
|
||||||
|
) -> c_int;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
Reference in New Issue
Block a user