From 737496dabd0ec76d747a3a4f2914c2e45fd10712 Mon Sep 17 00:00:00 2001 From: tecc Date: Sun, 17 Aug 2025 19:07:22 +0200 Subject: [PATCH 1/9] feat: Add struct `git_odb_stream` and enum `git_odb_stream_t` Added type definition for struct `libgit2-sys::git_odb_stream`. Previously incorrectly defined as an opaque enum. See git2/odb_backend.h line 196. Added type definition for enum `git_odb_stream_t`. I believe it corresponds to the `mode` field of `git_odb_stream`, but that's just a guess. See git2/odb_backend.h line 182. --- libgit2-sys/lib.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index 7e1ac1e998..599c86ba44 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -87,7 +87,28 @@ pub enum git_reflog_entry {} pub enum git_describe_result {} pub enum git_packbuilder {} pub enum git_odb {} -pub enum git_odb_stream {} + +#[repr(C)] +pub struct git_odb_stream { + pub backend: *mut git_odb_backend, + pub mode: c_uint, + pub hash_ctx: *mut c_void, + pub declared_size: git_object_size_t, + pub received_bytes: git_object_size_t, + pub read: Option c_int>, + pub write: Option c_int>, + pub finalize_write: Option c_int>, + pub free: Option +} + +git_enum! { + pub enum git_odb_stream_t: c_int { + GIT_STREAM_RDONLY = 2, + GIT_STREAM_WRONLY = 4, + GIT_STREAM_RW = 6, + } +} + pub enum git_odb_object {} pub enum git_worktree {} pub enum git_transaction {} From 39509e7cb8770d8b93b0a0cdc4045eb99bd75fdf Mon Sep 17 00:00:00 2001 From: tecc Date: Mon, 18 Aug 2025 01:39:18 +0200 Subject: [PATCH 2/9] feat: Add API from `git2/sys/config.h` Added struct `git_config_backend_entry`. See git2/sys/config.h line 27. Added struct `git_config_iterator`. Previously incorrectly defined as an empty enum. See git2/sys/config.h line 49. Added struct `git_config_backend`. See git2/sys/config.h line 69. Added constant `GIT_CONFIG_BACKEND_VERSION`. See git2/sys/config.h line 103. Added struct `git_config_backend_memory_options`. See git2/sys/config.h line 148. Added constant `GIT_CONFIG_BACKEND_MEMORY_OPTIONS_VERSION`. See git2/sys/config.h line 165. Added function `git_config_add_backend`. See git2/sys/config.h line 140. Added function `git_config_backend_from_string`. See git2/sys/config.h line 181. Added function `git_config_backend_from_values`. See git2/sys/config.h line 197. Added function `git_config_init_backend`. See git2/sys/config.h line 116. --- libgit2-sys/lib.rs | 85 ++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index 599c86ba44..abe74dbfb0 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -55,7 +55,68 @@ pub enum git_branch_iterator {} pub enum git_blame {} pub enum git_commit {} pub enum git_config {} -pub enum git_config_iterator {} + +#[repr(C)] +pub struct git_config_backend_entry { + pub entry: git_config_entry, + pub free: Option, +} + +#[repr(C)] +pub struct git_config_iterator { + pub backend: *mut git_config_backend, + pub flags: c_uint, + pub next: Option< + extern "C" fn(*mut *mut git_config_backend_entry, *mut git_config_iterator) -> c_int, + >, + pub free: Option, +} + +#[repr(C)] +pub struct git_config_backend { + pub version: c_uint, + pub readonly: c_int, + pub cfg: *mut git_config, + pub open: Option< + extern "C" fn(*mut git_config_backend, git_config_level_t, *const git_repository) -> c_int, + >, + pub get: Option< + extern "C" fn( + *mut git_config_backend, + *const c_char, + *mut *mut git_config_backend_entry, + ) -> c_int, + >, + pub set: Option c_int>, + pub set_multivar: Option< + extern "C" fn( + *mut git_config_backend, + *const c_char, + *const c_char, + *const c_char, + ) -> c_int, + >, + pub del: Option c_int>, + pub del_multivar: + Option c_int>, + pub snapshot: + Option c_int>, + pub lock: Option c_int>, + pub unlock: Option c_int>, + pub free: Option, +} + +pub const GIT_CONFIG_BACKEND_VERSION: c_uint = 1; + +#[repr(C)] +pub struct git_config_backend_memory_options { + pub version: c_uint, + pub backend_type: *const c_char, + pub origin_path: *const c_char +} + +pub const GIT_CONFIG_BACKEND_MEMORY_OPTIONS_VERSION: c_uint = 1; + pub enum git_index {} pub enum git_index_conflict_iterator {} pub enum git_object {} @@ -98,7 +159,7 @@ pub struct git_odb_stream { pub read: Option c_int>, pub write: Option c_int>, pub finalize_write: Option c_int>, - pub free: Option + pub free: Option, } git_enum! { @@ -3161,6 +3222,13 @@ extern "C" { ) -> c_int; // config + pub fn git_config_add_backend( + cfg: *mut git_config, + file: *mut git_config_backend, + level: git_config_level_t, + repo: *const git_repository, + force: c_int, + ) -> c_int; pub fn git_config_add_file_ondisk( cfg: *mut git_config, path: *const c_char, @@ -3168,6 +3236,18 @@ extern "C" { repo: *const git_repository, force: c_int, ) -> c_int; + pub fn git_config_backend_backend_from_string( + out: *mut *mut git_config_backend, + cfg: *const c_char, + len: size_t, + opts: *mut git_config_backend_memory_options, + ) -> c_int; + pub fn git_config_backend_backend_from_values( + out: *mut *mut git_config_backend, + values: *mut *const c_char, + len: size_t, + opts: *mut git_config_backend_memory_options, + ) -> c_int; pub fn git_config_delete_entry(cfg: *mut git_config, name: *const c_char) -> c_int; pub fn git_config_delete_multivar( cfg: *mut git_config, @@ -3214,6 +3294,7 @@ extern "C" { cfg: *const git_config, name: *const c_char, ) -> c_int; + pub fn git_config_init_backend(backend: *mut git_config_backend, version: c_uint) -> c_int; pub fn git_config_iterator_free(iter: *mut git_config_iterator); pub fn git_config_iterator_glob_new( out: *mut *mut git_config_iterator, From 0d1e96fc1fc7f6470312fcca7c02889a80bd740a Mon Sep 17 00:00:00 2001 From: tecc Date: Mon, 18 Aug 2025 01:56:05 +0200 Subject: [PATCH 3/9] feat: Add struct `git_reference_iterator` Added struct `git_reference_iterator`. See git2/sys/refdb_backend.h line 35. --- libgit2-sys/lib.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index abe74dbfb0..caca95b75a 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -112,7 +112,7 @@ pub const GIT_CONFIG_BACKEND_VERSION: c_uint = 1; pub struct git_config_backend_memory_options { pub version: c_uint, pub backend_type: *const c_char, - pub origin_path: *const c_char + pub origin_path: *const c_char, } pub const GIT_CONFIG_BACKEND_MEMORY_OPTIONS_VERSION: c_uint = 1; @@ -121,7 +121,15 @@ pub enum git_index {} pub enum git_index_conflict_iterator {} pub enum git_object {} pub enum git_reference {} -pub enum git_reference_iterator {} + +#[repr(C)] +pub struct git_reference_iterator { + pub db: *mut git_refdb, + pub next: Option c_int>, + pub next_name: Option c_int>, + pub free: Option, +} + pub enum git_annotated_commit {} pub enum git_refdb {} pub enum git_refspec {} From b7ce5e626da9234202f0d5e46f5ab3648d43a359 Mon Sep 17 00:00:00 2001 From: tecc Date: Mon, 18 Aug 2025 02:02:56 +0200 Subject: [PATCH 4/9] fix: Rename `git_commit_nth_gen_ancestor`'s first argument `git_commit_nth_gen_ancestor`'s first argument has been changed to `ancestor` from the previous `commit` to bring it closer to the actual definition (git2/commit.h line 282) and because the previous name is also used for the second argument. --- libgit2-sys/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index caca95b75a..e13dfac289 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -2991,7 +2991,7 @@ extern "C" { pub fn git_commit_message_encoding(commit: *const git_commit) -> *const c_char; pub fn git_commit_message_raw(commit: *const git_commit) -> *const c_char; pub fn git_commit_nth_gen_ancestor( - commit: *mut *mut git_commit, + ancestor: *mut *mut git_commit, commit: *const git_commit, n: c_uint, ) -> c_int; From d877928672d489ebb8898bbb6e61aa4b33c04dc1 Mon Sep 17 00:00:00 2001 From: tecc Date: Mon, 18 Aug 2025 02:32:10 +0200 Subject: [PATCH 5/9] fix: Add `git2/sys/config.h` to systest headers, use extern "C" fn --- libgit2-sys/lib.rs | 6 +++--- systest/build.rs | 1 + 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index e13dfac289..bfdb85e333 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -125,9 +125,9 @@ pub enum git_reference {} #[repr(C)] pub struct git_reference_iterator { pub db: *mut git_refdb, - pub next: Option c_int>, - pub next_name: Option c_int>, - pub free: Option, + pub next: Option c_int>, + pub next_name: Option c_int>, + pub free: Option, } pub enum git_annotated_commit {} diff --git a/systest/build.rs b/systest/build.rs index 9503af7e10..eb22065d4f 100644 --- a/systest/build.rs +++ b/systest/build.rs @@ -16,6 +16,7 @@ fn main() { .header("git2/sys/repository.h") .header("git2/sys/cred.h") .header("git2/sys/email.h") + .header("git2/sys/config.h") .header("git2/cred_helpers.h") .type_name(|s, _, _| s.to_string()); cfg.field_name(|_, f| match f { From a5af4764b11e1052067b9530c391597fcb6f58ea Mon Sep 17 00:00:00 2001 From: tecc Date: Mon, 18 Aug 2025 02:34:35 +0200 Subject: [PATCH 6/9] fix: Add missing argument fromm `git_config_backend`, fix function names --- libgit2-sys/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index bfdb85e333..145e25b53c 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -102,7 +102,7 @@ pub struct git_config_backend { pub snapshot: Option c_int>, pub lock: Option c_int>, - pub unlock: Option c_int>, + pub unlock: Option c_int>, pub free: Option, } @@ -3244,13 +3244,13 @@ extern "C" { repo: *const git_repository, force: c_int, ) -> c_int; - pub fn git_config_backend_backend_from_string( + pub fn git_config_backend_from_string( out: *mut *mut git_config_backend, cfg: *const c_char, len: size_t, opts: *mut git_config_backend_memory_options, ) -> c_int; - pub fn git_config_backend_backend_from_values( + pub fn git_config_backend_from_values( out: *mut *mut git_config_backend, values: *mut *const c_char, len: size_t, From 833ed2f94fc0fe2c90d3bc17376c2a2eeb20221d Mon Sep 17 00:00:00 2001 From: tecc Date: Mon, 18 Aug 2025 02:40:26 +0200 Subject: [PATCH 7/9] fix: Add missing `iterator` function to `git_config_backend` --- libgit2-sys/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index 145e25b53c..c30051cf6c 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -99,6 +99,8 @@ pub struct git_config_backend { pub del: Option c_int>, pub del_multivar: Option c_int>, + pub iterator: + Option c_int>, pub snapshot: Option c_int>, pub lock: Option c_int>, From 36aea269eebcaae67e4ade903b53f014af51843b Mon Sep 17 00:00:00 2001 From: tecc Date: Mon, 18 Aug 2025 02:41:29 +0200 Subject: [PATCH 8/9] fix: Make `git_odb_stream_t` unsigned --- libgit2-sys/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index c30051cf6c..deb6e1bbfc 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -173,7 +173,7 @@ pub struct git_odb_stream { } git_enum! { - pub enum git_odb_stream_t: c_int { + pub enum git_odb_stream_t: c_uint { GIT_STREAM_RDONLY = 2, GIT_STREAM_WRONLY = 4, GIT_STREAM_RW = 6, From 60d0dc425037ce2cb07c0ee50013168819384ec1 Mon Sep 17 00:00:00 2001 From: tecc Date: Mon, 18 Aug 2025 13:38:19 +0200 Subject: [PATCH 9/9] fix: Remove int type from `git_odb_stream_t` --- libgit2-sys/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index deb6e1bbfc..a1b640c89a 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -173,7 +173,7 @@ pub struct git_odb_stream { } git_enum! { - pub enum git_odb_stream_t: c_uint { + pub enum git_odb_stream_t { GIT_STREAM_RDONLY = 2, GIT_STREAM_WRONLY = 4, GIT_STREAM_RW = 6,