From 5cc70d20054a2607d9a08e37ca039443a1bc314e Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sat, 24 Feb 2024 11:37:56 -0600 Subject: [PATCH 1/5] WIP Use my libgit2 patch pre-merge --- libgit2-sys/libgit2 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libgit2-sys/libgit2 b/libgit2-sys/libgit2 index a418d9d4ab..4cd2d1798c 160000 --- a/libgit2-sys/libgit2 +++ b/libgit2-sys/libgit2 @@ -1 +1 @@ -Subproject commit a418d9d4ab87bae16b87d8f37143a4687ae0e4b2 +Subproject commit 4cd2d1798ce2af4bff7ce8a76b6e97d702183567 From b49d8b7e3fa7cd64a437ff3d340a15115eccfbd8 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sat, 24 Feb 2024 16:01:53 -0600 Subject: [PATCH 2/5] Add new field for push-options To fix a segfault at [1], adjust to upstream development[2,3] that changed the shape of this struct. This new field is added in the same style as `custom_headers`. [1]: libgit2.git:39669956fb510fb7b13289f6ce959884969dbebd:src/libgit2/remote.c:2987 [2]: libgit2.git:ecc6f2fb8399d84e5b2bf043376dfc51f43f3e90 [3]: libgit2.git:39669956fb510fb7b13289f6ce959884969dbebd --- libgit2-sys/lib.rs | 1 + src/remote.rs | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index 3de6881842..5d997bc059 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -981,6 +981,7 @@ pub struct git_push_options { pub proxy_opts: git_proxy_options, pub follow_redirects: git_remote_redirect_t, pub custom_headers: git_strarray, + pub remote_push_options: git_strarray, } pub type git_tag_foreach_cb = diff --git a/src/remote.rs b/src/remote.rs index a15a095010..3d09d36cf4 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -58,6 +58,8 @@ pub struct PushOptions<'cb> { follow_redirects: RemoteRedirect, custom_headers: Vec, custom_headers_ptrs: Vec<*const c_char>, + remote_push_options: Vec, + remote_push_options_ptrs: Vec<*const c_char>, } /// Holds callbacks for a connection to a `Remote`. Disconnects when dropped @@ -628,6 +630,8 @@ impl<'cb> PushOptions<'cb> { follow_redirects: RemoteRedirect::Initial, custom_headers: Vec::new(), custom_headers_ptrs: Vec::new(), + remote_push_options: Vec::new(), + remote_push_options_ptrs: Vec::new(), } } @@ -673,6 +677,16 @@ impl<'cb> PushOptions<'cb> { self.custom_headers_ptrs = self.custom_headers.iter().map(|s| s.as_ptr()).collect(); self } + + /// Set server-side options for this push operation. + pub fn remote_push_options(&mut self, remote_push_options: &[&str]) -> &mut Self { + self.remote_push_options = remote_push_options + .iter() + .map(|&s| CString::new(s).unwrap()) + .collect(); + self.remote_push_options_ptrs = self.remote_push_options.iter().map(|s| s.as_ptr()).collect(); + self + } } impl<'cb> Binding for PushOptions<'cb> { @@ -700,6 +714,10 @@ impl<'cb> Binding for PushOptions<'cb> { count: self.custom_headers_ptrs.len(), strings: self.custom_headers_ptrs.as_ptr() as *mut _, }, + remote_push_options: git_strarray { + count: self.remote_push_options_ptrs.len(), + strings: self.remote_push_options_ptrs.as_ptr() as *mut _, + }, } } } From 58a78a491b3e5eef0bcd7385af46f622f31e2c59 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sat, 24 Feb 2024 16:04:07 -0600 Subject: [PATCH 3/5] Use new name of GIT_SSH_MEMORY_CREDENTIALS Adjust to upstream development[1] that changed the name of this compiler flag. [1]: libgit2.git:3fccf7468ba7a9a9f764984435db83f4588ec905 --- libgit2-sys/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libgit2-sys/build.rs b/libgit2-sys/build.rs index 88fce00d6e..e1c6eb039f 100644 --- a/libgit2-sys/build.rs +++ b/libgit2-sys/build.rs @@ -180,7 +180,7 @@ The build is now aborting. To disable, unset the variable or use `LIBGIT2_NO_VEN cfg.include(path); } features.push_str("#define GIT_SSH 1\n"); - features.push_str("#define GIT_SSH_MEMORY_CREDENTIALS 1\n"); + features.push_str("#define GIT_SSH_LIBSSH2_MEMORY_CREDENTIALS 1\n"); } if https { features.push_str("#define GIT_HTTPS 1\n"); From e6f02612334352f03e6ff0418061f2931cec0002 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Thu, 3 Mar 2022 05:13:33 -0600 Subject: [PATCH 4/5] Add config level for worktrees Use the new support in libgit2 for the worktree-config extension.[1] [1]: https://git-scm.com/docs/git-worktree/2.35.1#_configuration_file --- libgit2-sys/lib.rs | 3 ++- src/call.rs | 1 + src/lib.rs | 3 +++ tests/add_extensions.rs | 3 ++- tests/get_extensions.rs | 3 ++- tests/remove_extensions.rs | 3 ++- 6 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index 5d997bc059..82fbae09df 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -868,7 +868,8 @@ git_enum! { GIT_CONFIG_LEVEL_XDG = 3, GIT_CONFIG_LEVEL_GLOBAL = 4, GIT_CONFIG_LEVEL_LOCAL = 5, - GIT_CONFIG_LEVEL_APP = 6, + GIT_CONFIG_LEVEL_WORKTREE = 6, + GIT_CONFIG_LEVEL_APP = 7, GIT_CONFIG_HIGHEST_LEVEL = -1, } } diff --git a/src/call.rs b/src/call.rs index 95350d2690..a18f05da91 100644 --- a/src/call.rs +++ b/src/call.rs @@ -166,6 +166,7 @@ mod impls { ConfigLevel::XDG => raw::GIT_CONFIG_LEVEL_XDG, ConfigLevel::Global => raw::GIT_CONFIG_LEVEL_GLOBAL, ConfigLevel::Local => raw::GIT_CONFIG_LEVEL_LOCAL, + ConfigLevel::Worktree => raw::GIT_CONFIG_LEVEL_WORKTREE, ConfigLevel::App => raw::GIT_CONFIG_LEVEL_APP, ConfigLevel::Highest => raw::GIT_CONFIG_HIGHEST_LEVEL, } diff --git a/src/lib.rs b/src/lib.rs index 3dd6fe92ee..e182870c6c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -385,6 +385,8 @@ pub enum ConfigLevel { Global, /// Repository specific config, e.g. $PWD/.git/config Local, + /// Worktree-specific config, e.g. $GIT_DIR/config.worktree + Worktree, /// Application specific configuration file App, /// Highest level available @@ -963,6 +965,7 @@ impl ConfigLevel { raw::GIT_CONFIG_LEVEL_XDG => ConfigLevel::XDG, raw::GIT_CONFIG_LEVEL_GLOBAL => ConfigLevel::Global, raw::GIT_CONFIG_LEVEL_LOCAL => ConfigLevel::Local, + raw::GIT_CONFIG_LEVEL_WORKTREE => ConfigLevel::Worktree, raw::GIT_CONFIG_LEVEL_APP => ConfigLevel::App, raw::GIT_CONFIG_HIGHEST_LEVEL => ConfigLevel::Highest, n => panic!("unknown config level: {}", n), diff --git a/tests/add_extensions.rs b/tests/add_extensions.rs index 57c0eb9762..d90bd07ab5 100644 --- a/tests/add_extensions.rs +++ b/tests/add_extensions.rs @@ -11,11 +11,12 @@ fn test_add_extensions() -> Result<(), Error> { let extensions = unsafe { get_extensions() }?; - assert_eq!(extensions.len(), 3); + assert_eq!(extensions.len(), 4); assert_eq!(extensions.get(0), Some("custom")); // The objectformat extension was added in 1.6 assert_eq!(extensions.get(1), Some("noop")); assert_eq!(extensions.get(2), Some("objectformat")); + assert_eq!(extensions.get(3), Some("worktreeconfig")); Ok(()) } diff --git a/tests/get_extensions.rs b/tests/get_extensions.rs index d8dd55fe0a..cf2c61f75c 100644 --- a/tests/get_extensions.rs +++ b/tests/get_extensions.rs @@ -7,10 +7,11 @@ use git2::Error; fn test_get_extensions() -> Result<(), Error> { let extensions = unsafe { get_extensions() }?; - assert_eq!(extensions.len(), 2); + assert_eq!(extensions.len(), 3); assert_eq!(extensions.get(0), Some("noop")); // The objectformat extension was added in 1.6 assert_eq!(extensions.get(1), Some("objectformat")); + assert_eq!(extensions.get(2), Some("worktreeconfig")); Ok(()) } diff --git a/tests/remove_extensions.rs b/tests/remove_extensions.rs index 5f632a8809..815e2ace2b 100644 --- a/tests/remove_extensions.rs +++ b/tests/remove_extensions.rs @@ -11,9 +11,10 @@ fn test_remove_extensions() -> Result<(), Error> { let extensions = unsafe { get_extensions() }?; - assert_eq!(extensions.len(), 2); + assert_eq!(extensions.len(), 3); assert_eq!(extensions.get(0), Some("custom")); assert_eq!(extensions.get(1), Some("other")); + assert_eq!(extensions.get(2), Some("worktreeconfig")); Ok(()) } From 73ade9679f6956671224220a0a0744cdd5a47a32 Mon Sep 17 00:00:00 2001 From: Sean Allred Date: Sat, 24 Feb 2024 11:38:38 -0600 Subject: [PATCH 5/5] WIP fix word size issue? Is this macOS-specific? --- src/lib.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index e182870c6c..906ff7d220 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -959,7 +959,8 @@ impl fmt::Display for ReferenceType { impl ConfigLevel { /// Converts a raw configuration level to a ConfigLevel pub fn from_raw(raw: raw::git_config_level_t) -> ConfigLevel { - match raw { + match raw >> 12 { + // TODO: why!? raw::GIT_CONFIG_LEVEL_PROGRAMDATA => ConfigLevel::ProgramData, raw::GIT_CONFIG_LEVEL_SYSTEM => ConfigLevel::System, raw::GIT_CONFIG_LEVEL_XDG => ConfigLevel::XDG,