Skip to content

Commit

Permalink
libgit2: Update struct representation for git_push_options
Browse files Browse the repository at this point in the history
  • Loading branch information
bnjmnt4n committed Mar 2, 2024
1 parent 765c09b commit 43cad8d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
22 changes: 22 additions & 0 deletions src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ pub struct PushOptions<'cb> {
follow_redirects: RemoteRedirect,
custom_headers: Vec<CString>,
custom_headers_ptrs: Vec<*const c_char>,
remote_push_options: Vec<CString>,
remote_push_options_ptrs: Vec<*const c_char>,
}

/// Holds callbacks for a connection to a `Remote`. Disconnects when dropped
Expand Down Expand Up @@ -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(),
}
}

Expand Down Expand Up @@ -673,6 +677,20 @@ impl<'cb> PushOptions<'cb> {
self.custom_headers_ptrs = self.custom_headers.iter().map(|s| s.as_ptr()).collect();
self
}

/// Set "push options" to deliver to the remote.
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> {
Expand Down Expand Up @@ -700,6 +718,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.len(),
strings: self.remote_push_options_ptrs.as_ptr() as *mut _,
},
}
}
}
Expand Down

0 comments on commit 43cad8d

Please sign in to comment.