Skip to content

Commit

Permalink
Libgit2 1.4.0 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Feb 15, 2022
1 parent ab158dd commit 10d9423
Show file tree
Hide file tree
Showing 5 changed files with 116 additions and 36 deletions.
83 changes: 49 additions & 34 deletions libgit2-sys/lib.rs
Expand Up @@ -383,6 +383,7 @@ pub struct git_fetch_options {
pub update_fetchhead: c_int,
pub download_tags: git_remote_autotag_option_t,
pub proxy_opts: git_proxy_options,
pub follow_redirects: git_remote_redirect_t,
pub custom_headers: git_strarray,
}

Expand Down Expand Up @@ -609,6 +610,7 @@ pub struct git_status_options {
pub flags: c_uint,
pub pathspec: git_strarray,
pub baseline: *mut git_tree,
pub rename_threshold: u16,
}

#[repr(C)]
Expand Down Expand Up @@ -728,7 +730,7 @@ pub struct git_tree_update {
#[derive(Copy, Clone)]
pub struct git_buf {
pub ptr: *mut c_char,
pub asize: size_t,
pub reserved: size_t,
pub size: size_t,
}

Expand Down Expand Up @@ -951,6 +953,7 @@ pub struct git_push_options {
pub pb_parallelism: c_uint,
pub callbacks: git_remote_callbacks,
pub proxy_opts: git_proxy_options,
pub follow_redirects: git_remote_redirect_t,
pub custom_headers: git_strarray,
}

Expand Down Expand Up @@ -1356,55 +1359,66 @@ pub type git_transport_cb = Option<
#[repr(C)]
pub struct git_transport {
pub version: c_uint,
pub set_callbacks: Option<
pub connect: Option<
extern "C" fn(
*mut git_transport,
git_transport_message_cb,
git_transport_message_cb,
git_transport_certificate_check_cb,
*mut c_void,
transport: *mut git_transport,
url: *const c_char,
direction: c_int,
connect_opts: *const git_remote_connect_options,
) -> c_int,
>,
pub set_custom_headers: Option<extern "C" fn(*mut git_transport, *const git_strarray) -> c_int>,
pub connect: Option<
pub set_connect_opts: Option<
extern "C" fn(
*mut git_transport,
*const c_char,
git_cred_acquire_cb,
*mut c_void,
*const git_proxy_options,
c_int,
c_int,
transport: *mut git_transport,
connect_opts: *const git_remote_connect_options,
) -> c_int,
>,
pub capabilities:
Option<extern "C" fn(capabilities: *mut c_uint, transport: *mut git_transport) -> c_int>,
pub ls: Option<
extern "C" fn(*mut *mut *const git_remote_head, *mut size_t, *mut git_transport) -> c_int,
>,
pub push: Option<
extern "C" fn(*mut git_transport, *mut git_push, *const git_remote_callbacks) -> c_int,
extern "C" fn(
out: *mut *mut *const git_remote_head,
size: *mut size_t,
transport: *mut git_transport,
) -> c_int,
>,
pub push: Option<extern "C" fn(transport: *mut git_transport, push: *mut git_push) -> c_int>,
pub negotiate_fetch: Option<
extern "C" fn(
*mut git_transport,
*mut git_repository,
*const *const git_remote_head,
size_t,
transport: *mut git_transport,
repo: *mut git_repository,
refs: *const *const git_remote_head,
count: size_t,
) -> c_int,
>,
pub download_pack: Option<
extern "C" fn(
*mut git_transport,
*mut git_repository,
*mut git_indexer_progress,
git_indexer_progress_cb,
*mut c_void,
transport: *mut git_transport,
repo: *mut git_repository,
stats: *mut git_indexer_progress,
) -> c_int,
>,
pub is_connected: Option<extern "C" fn(*mut git_transport) -> c_int>,
pub read_flags: Option<extern "C" fn(*mut git_transport, *mut c_int) -> c_int>,
pub cancel: Option<extern "C" fn(*mut git_transport)>,
pub close: Option<extern "C" fn(*mut git_transport) -> c_int>,
pub free: Option<extern "C" fn(*mut git_transport)>,
pub is_connected: Option<extern "C" fn(transport: *mut git_transport) -> c_int>,
pub cancel: Option<extern "C" fn(transport: *mut git_transport)>,
pub close: Option<extern "C" fn(transport: *mut git_transport) -> c_int>,
pub free: Option<extern "C" fn(transport: *mut git_transport)>,
}

#[repr(C)]
pub struct git_remote_connect_options {
pub version: c_uint,
pub callbacks: git_remote_callbacks,
pub proxy_opts: git_proxy_options,
pub follow_redirects: git_remote_redirect_t,
pub custom_headers: git_strarray,
}

git_enum! {
pub enum git_remote_redirect_t {
GIT_REMOTE_REDIRECT_NONE = 1 << 0,
GIT_REMOTE_REDIRECT_INITIAL = 1 << 1,
GIT_REMOTE_REDIRECT_ALL = 1 << 2,
}
}

#[repr(C)]
Expand Down Expand Up @@ -1891,6 +1905,7 @@ pub struct git_worktree_add_options {
pub version: c_uint,
pub lock: c_int,
pub reference: *mut git_reference,
pub checkout_options: git_checkout_options,
}

pub const GIT_WORKTREE_ADD_OPTIONS_VERSION: c_uint = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/buf.rs
Expand Up @@ -28,7 +28,7 @@ impl Buf {
Binding::from_raw(&mut raw::git_buf {
ptr: ptr::null_mut(),
size: 0,
asize: 0,
reserved: 0,
} as *mut _)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Expand Up @@ -120,7 +120,7 @@ pub use crate::reference::{Reference, ReferenceNames, References};
pub use crate::reflog::{Reflog, ReflogEntry, ReflogIter};
pub use crate::refspec::Refspec;
pub use crate::remote::{
FetchOptions, PushOptions, Refspecs, Remote, RemoteConnection, RemoteHead,
FetchOptions, PushOptions, Refspecs, Remote, RemoteConnection, RemoteHead, RemoteRedirect,
};
pub use crate::remote_callbacks::{Credentials, RemoteCallbacks};
pub use crate::remote_callbacks::{TransportMessage, UpdateTips};
Expand Down
57 changes: 57 additions & 0 deletions src/remote.rs
Expand Up @@ -44,6 +44,7 @@ pub struct FetchOptions<'cb> {
prune: FetchPrune,
update_fetchhead: bool,
download_tags: AutotagOption,
follow_redirects: RemoteRedirect,
custom_headers: Vec<CString>,
custom_headers_ptrs: Vec<*const c_char>,
}
Expand All @@ -53,6 +54,7 @@ pub struct PushOptions<'cb> {
callbacks: Option<RemoteCallbacks<'cb>>,
proxy: Option<ProxyOptions<'cb>>,
pb_parallelism: u32,
follow_redirects: RemoteRedirect,
custom_headers: Vec<CString>,
custom_headers_ptrs: Vec<*const c_char>,
}
Expand All @@ -64,6 +66,21 @@ pub struct RemoteConnection<'repo, 'connection, 'cb> {
remote: &'connection mut Remote<'repo>,
}

/// Remote redirection settings; whether redirects to another host are
/// permitted.
///
/// By default, git will follow a redirect on the initial request
/// (`/info/refs`), but not subsequent requests.
pub enum RemoteRedirect {
/// Do not follow any off-site redirects at any stage of the fetch or push.
None,
/// Allow off-site redirects only upon the initial request. This is the
/// default.
Initial,
/// Allow redirects at any stage in the fetch or push.
All,
}

pub fn remote_into_raw(remote: Remote<'_>) -> *mut raw::git_remote {
let ret = remote.raw;
mem::forget(remote);
Expand Down Expand Up @@ -479,6 +496,7 @@ impl<'cb> FetchOptions<'cb> {
prune: FetchPrune::Unspecified,
update_fetchhead: true,
download_tags: AutotagOption::Unspecified,
follow_redirects: RemoteRedirect::Initial,
custom_headers: Vec::new(),
custom_headers_ptrs: Vec::new(),
}
Expand Down Expand Up @@ -519,6 +537,16 @@ impl<'cb> FetchOptions<'cb> {
self
}

/// Set remote redirection settings; whether redirects to another host are
/// permitted.
///
/// By default, git will follow a redirect on the initial request
/// (`/info/refs`), but not subsequent requests.
pub fn follow_redirects(&mut self, redirect: RemoteRedirect) -> &mut Self {
self.follow_redirects = redirect;
self
}

/// Set extra headers for this fetch operation.
pub fn custom_headers(&mut self, custom_headers: &[&str]) -> &mut Self {
self.custom_headers = custom_headers
Expand Down Expand Up @@ -552,6 +580,7 @@ impl<'cb> Binding for FetchOptions<'cb> {
prune: crate::call::convert(&self.prune),
update_fetchhead: crate::call::convert(&self.update_fetchhead),
download_tags: crate::call::convert(&self.download_tags),
follow_redirects: self.follow_redirects.raw(),
custom_headers: git_strarray {
count: self.custom_headers_ptrs.len(),
strings: self.custom_headers_ptrs.as_ptr() as *mut _,
Expand All @@ -573,6 +602,7 @@ impl<'cb> PushOptions<'cb> {
callbacks: None,
proxy: None,
pb_parallelism: 1,
follow_redirects: RemoteRedirect::Initial,
custom_headers: Vec::new(),
custom_headers_ptrs: Vec::new(),
}
Expand Down Expand Up @@ -601,6 +631,16 @@ impl<'cb> PushOptions<'cb> {
self
}

/// Set remote redirection settings; whether redirects to another host are
/// permitted.
///
/// By default, git will follow a redirect on the initial request
/// (`/info/refs`), but not subsequent requests.
pub fn follow_redirects(&mut self, redirect: RemoteRedirect) -> &mut Self {
self.follow_redirects = redirect;
self
}

/// Set extra headers for this push operation.
pub fn custom_headers(&mut self, custom_headers: &[&str]) -> &mut Self {
self.custom_headers = custom_headers
Expand Down Expand Up @@ -632,6 +672,7 @@ impl<'cb> Binding for PushOptions<'cb> {
.map(|m| m.raw())
.unwrap_or_else(|| ProxyOptions::new().raw()),
pb_parallelism: self.pb_parallelism as libc::c_uint,
follow_redirects: self.follow_redirects.raw(),
custom_headers: git_strarray {
count: self.custom_headers_ptrs.len(),
strings: self.custom_headers_ptrs.as_ptr() as *mut _,
Expand Down Expand Up @@ -674,6 +715,22 @@ impl<'repo, 'connection, 'cb> Drop for RemoteConnection<'repo, 'connection, 'cb>
}
}

impl Default for RemoteRedirect {
fn default() -> Self {
RemoteRedirect::Initial
}
}

impl RemoteRedirect {
fn raw(&self) -> raw::git_remote_redirect_t {
match self {
RemoteRedirect::None => raw::GIT_REMOTE_REDIRECT_NONE,
RemoteRedirect::Initial => raw::GIT_REMOTE_REDIRECT_INITIAL,
RemoteRedirect::All => raw::GIT_REMOTE_REDIRECT_ALL,
}
}
}

#[cfg(test)]
mod tests {
use crate::{AutotagOption, PushOptions};
Expand Down
8 changes: 8 additions & 0 deletions src/status.rs
Expand Up @@ -216,6 +216,14 @@ impl StatusOptions {
self.flag(raw::GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED, include)
}

/// Set threshold above which similar files will be considered renames.
///
/// This is equivalent to the `-M` option. Defaults to 50.
pub fn rename_threshold(&mut self, threshold: u16) -> &mut StatusOptions {
self.raw.rename_threshold = threshold;
self
}

/// Get a pointer to the inner list of status options.
///
/// This function is unsafe as the returned structure has interior pointers
Expand Down

0 comments on commit 10d9423

Please sign in to comment.