Skip to content

Commit 36af476

Browse files
committed
Libgit2 1.4.0 fixes
1 parent ab158dd commit 36af476

File tree

7 files changed

+145
-40
lines changed

7 files changed

+145
-40
lines changed

libgit2-sys/lib.rs

+51-34
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,7 @@ pub struct git_fetch_options {
383383
pub update_fetchhead: c_int,
384384
pub download_tags: git_remote_autotag_option_t,
385385
pub proxy_opts: git_proxy_options,
386+
pub follow_redirects: git_remote_redirect_t,
386387
pub custom_headers: git_strarray,
387388
}
388389

@@ -609,6 +610,7 @@ pub struct git_status_options {
609610
pub flags: c_uint,
610611
pub pathspec: git_strarray,
611612
pub baseline: *mut git_tree,
613+
pub rename_threshold: u16,
612614
}
613615

614616
#[repr(C)]
@@ -728,7 +730,7 @@ pub struct git_tree_update {
728730
#[derive(Copy, Clone)]
729731
pub struct git_buf {
730732
pub ptr: *mut c_char,
731-
pub asize: size_t,
733+
pub reserved: size_t,
732734
pub size: size_t,
733735
}
734736

@@ -951,6 +953,7 @@ pub struct git_push_options {
951953
pub pb_parallelism: c_uint,
952954
pub callbacks: git_remote_callbacks,
953955
pub proxy_opts: git_proxy_options,
956+
pub follow_redirects: git_remote_redirect_t,
954957
pub custom_headers: git_strarray,
955958
}
956959

@@ -1356,55 +1359,66 @@ pub type git_transport_cb = Option<
13561359
#[repr(C)]
13571360
pub struct git_transport {
13581361
pub version: c_uint,
1359-
pub set_callbacks: Option<
1362+
pub connect: Option<
13601363
extern "C" fn(
1361-
*mut git_transport,
1362-
git_transport_message_cb,
1363-
git_transport_message_cb,
1364-
git_transport_certificate_check_cb,
1365-
*mut c_void,
1364+
transport: *mut git_transport,
1365+
url: *const c_char,
1366+
direction: c_int,
1367+
connect_opts: *const git_remote_connect_options,
13661368
) -> c_int,
13671369
>,
1368-
pub set_custom_headers: Option<extern "C" fn(*mut git_transport, *const git_strarray) -> c_int>,
1369-
pub connect: Option<
1370+
pub set_connect_opts: Option<
13701371
extern "C" fn(
1371-
*mut git_transport,
1372-
*const c_char,
1373-
git_cred_acquire_cb,
1374-
*mut c_void,
1375-
*const git_proxy_options,
1376-
c_int,
1377-
c_int,
1372+
transport: *mut git_transport,
1373+
connect_opts: *const git_remote_connect_options,
13781374
) -> c_int,
13791375
>,
1376+
pub capabilities:
1377+
Option<extern "C" fn(capabilities: *mut c_uint, transport: *mut git_transport) -> c_int>,
13801378
pub ls: Option<
1381-
extern "C" fn(*mut *mut *const git_remote_head, *mut size_t, *mut git_transport) -> c_int,
1382-
>,
1383-
pub push: Option<
1384-
extern "C" fn(*mut git_transport, *mut git_push, *const git_remote_callbacks) -> c_int,
1379+
extern "C" fn(
1380+
out: *mut *mut *const git_remote_head,
1381+
size: *mut size_t,
1382+
transport: *mut git_transport,
1383+
) -> c_int,
13851384
>,
1385+
pub push: Option<extern "C" fn(transport: *mut git_transport, push: *mut git_push) -> c_int>,
13861386
pub negotiate_fetch: Option<
13871387
extern "C" fn(
1388-
*mut git_transport,
1389-
*mut git_repository,
1390-
*const *const git_remote_head,
1391-
size_t,
1388+
transport: *mut git_transport,
1389+
repo: *mut git_repository,
1390+
refs: *const *const git_remote_head,
1391+
count: size_t,
13921392
) -> c_int,
13931393
>,
13941394
pub download_pack: Option<
13951395
extern "C" fn(
1396-
*mut git_transport,
1397-
*mut git_repository,
1398-
*mut git_indexer_progress,
1399-
git_indexer_progress_cb,
1400-
*mut c_void,
1396+
transport: *mut git_transport,
1397+
repo: *mut git_repository,
1398+
stats: *mut git_indexer_progress,
14011399
) -> c_int,
14021400
>,
1403-
pub is_connected: Option<extern "C" fn(*mut git_transport) -> c_int>,
1404-
pub read_flags: Option<extern "C" fn(*mut git_transport, *mut c_int) -> c_int>,
1405-
pub cancel: Option<extern "C" fn(*mut git_transport)>,
1406-
pub close: Option<extern "C" fn(*mut git_transport) -> c_int>,
1407-
pub free: Option<extern "C" fn(*mut git_transport)>,
1401+
pub is_connected: Option<extern "C" fn(transport: *mut git_transport) -> c_int>,
1402+
pub cancel: Option<extern "C" fn(transport: *mut git_transport)>,
1403+
pub close: Option<extern "C" fn(transport: *mut git_transport) -> c_int>,
1404+
pub free: Option<extern "C" fn(transport: *mut git_transport)>,
1405+
}
1406+
1407+
#[repr(C)]
1408+
pub struct git_remote_connect_options {
1409+
pub version: c_uint,
1410+
pub callbacks: git_remote_callbacks,
1411+
pub proxy_opts: git_proxy_options,
1412+
pub follow_redirects: git_remote_redirect_t,
1413+
pub custom_headers: git_strarray,
1414+
}
1415+
1416+
git_enum! {
1417+
pub enum git_remote_redirect_t {
1418+
GIT_REMOTE_REDIRECT_NONE = 1 << 0,
1419+
GIT_REMOTE_REDIRECT_INITIAL = 1 << 1,
1420+
GIT_REMOTE_REDIRECT_ALL = 1 << 2,
1421+
}
14081422
}
14091423

14101424
#[repr(C)]
@@ -1891,6 +1905,7 @@ pub struct git_worktree_add_options {
18911905
pub version: c_uint,
18921906
pub lock: c_int,
18931907
pub reference: *mut git_reference,
1908+
pub checkout_options: git_checkout_options,
18941909
}
18951910

18961911
pub const GIT_WORKTREE_ADD_OPTIONS_VERSION: c_uint = 1;
@@ -3727,7 +3742,9 @@ extern "C" {
37273742
progress_cb: git_indexer_progress_cb,
37283743
progress_cb_payload: *mut c_void,
37293744
) -> c_int;
3745+
#[deprecated = "use `git_packbuilder_name` to retrieve the filename"]
37303746
pub fn git_packbuilder_hash(pb: *mut git_packbuilder) -> *const git_oid;
3747+
pub fn git_packbuilder_name(pb: *mut git_packbuilder) -> *const c_char;
37313748
pub fn git_packbuilder_foreach(
37323749
pb: *mut git_packbuilder,
37333750
cb: git_packbuilder_foreach_cb,

src/buf.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl Buf {
2828
Binding::from_raw(&mut raw::git_buf {
2929
ptr: ptr::null_mut(),
3030
size: 0,
31-
asize: 0,
31+
reserved: 0,
3232
} as *mut _)
3333
}
3434
}

src/index.rs

-3
Original file line numberDiff line numberDiff line change
@@ -849,9 +849,6 @@ mod tests {
849849

850850
#[test]
851851
fn add_then_read() {
852-
let mut index = Index::new().unwrap();
853-
assert!(index.add(&entry()).is_err());
854-
855852
let mut index = Index::new().unwrap();
856853
let mut e = entry();
857854
e.path = b"foobar".to_vec();

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub use crate::reference::{Reference, ReferenceNames, References};
120120
pub use crate::reflog::{Reflog, ReflogEntry, ReflogIter};
121121
pub use crate::refspec::Refspec;
122122
pub use crate::remote::{
123-
FetchOptions, PushOptions, Refspecs, Remote, RemoteConnection, RemoteHead,
123+
FetchOptions, PushOptions, Refspecs, Remote, RemoteConnection, RemoteHead, RemoteRedirect,
124124
};
125125
pub use crate::remote_callbacks::{Credentials, RemoteCallbacks};
126126
pub use crate::remote_callbacks::{TransportMessage, UpdateTips};

src/packbuilder.rs

+27-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use libc::{c_int, c_uint, c_void, size_t};
22
use std::marker;
33
use std::ptr;
44
use std::slice;
5+
use std::str;
56

67
use crate::util::Binding;
78
use crate::{panic, raw, Buf, Error, Oid, Repository, Revwalk};
@@ -160,13 +161,34 @@ impl<'repo> PackBuilder<'repo> {
160161
/// Get the packfile's hash. A packfile's name is derived from the sorted
161162
/// hashing of all object names. This is only correct after the packfile
162163
/// has been written.
164+
#[deprecated = "use `name()` to retrieve the filename"]
165+
#[allow(deprecated)]
163166
pub fn hash(&self) -> Option<Oid> {
164167
if self.object_count() == 0 {
165168
unsafe { Some(Binding::from_raw(raw::git_packbuilder_hash(self.raw))) }
166169
} else {
167170
None
168171
}
169172
}
173+
174+
/// Get the unique name for the resulting packfile.
175+
///
176+
/// The packfile's name is derived from the packfile's content. This is only
177+
/// correct after the packfile has been written.
178+
///
179+
/// Returns `None` if the packfile has not been written or if the name is
180+
/// not valid utf-8.
181+
pub fn name(&self) -> Option<&str> {
182+
self.name_bytes().and_then(|s| str::from_utf8(s).ok())
183+
}
184+
185+
/// Get the unique name for the resulting packfile, in bytes.
186+
///
187+
/// The packfile's name is derived from the packfile's content. This is only
188+
/// correct after the packfile has been written.
189+
pub fn name_bytes(&self) -> Option<&[u8]> {
190+
unsafe { crate::opt_bytes(self, raw::git_packbuilder_name(self.raw)) }
191+
}
170192
}
171193

172194
impl<'repo> Binding for PackBuilder<'repo> {
@@ -284,7 +306,11 @@ mod tests {
284306
let mut builder = t!(repo.packbuilder());
285307
let mut buf = Buf::new();
286308
t!(builder.write_buf(&mut buf));
287-
assert!(builder.hash().unwrap().is_zero());
309+
#[allow(deprecated)]
310+
{
311+
assert!(builder.hash().unwrap().is_zero());
312+
}
313+
assert!(builder.name().is_none());
288314
assert_eq!(&*buf, &*empty_pack_header());
289315
}
290316

src/remote.rs

+57
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ pub struct FetchOptions<'cb> {
4444
prune: FetchPrune,
4545
update_fetchhead: bool,
4646
download_tags: AutotagOption,
47+
follow_redirects: RemoteRedirect,
4748
custom_headers: Vec<CString>,
4849
custom_headers_ptrs: Vec<*const c_char>,
4950
}
@@ -53,6 +54,7 @@ pub struct PushOptions<'cb> {
5354
callbacks: Option<RemoteCallbacks<'cb>>,
5455
proxy: Option<ProxyOptions<'cb>>,
5556
pb_parallelism: u32,
57+
follow_redirects: RemoteRedirect,
5658
custom_headers: Vec<CString>,
5759
custom_headers_ptrs: Vec<*const c_char>,
5860
}
@@ -64,6 +66,21 @@ pub struct RemoteConnection<'repo, 'connection, 'cb> {
6466
remote: &'connection mut Remote<'repo>,
6567
}
6668

69+
/// Remote redirection settings; whether redirects to another host are
70+
/// permitted.
71+
///
72+
/// By default, git will follow a redirect on the initial request
73+
/// (`/info/refs`), but not subsequent requests.
74+
pub enum RemoteRedirect {
75+
/// Do not follow any off-site redirects at any stage of the fetch or push.
76+
None,
77+
/// Allow off-site redirects only upon the initial request. This is the
78+
/// default.
79+
Initial,
80+
/// Allow redirects at any stage in the fetch or push.
81+
All,
82+
}
83+
6784
pub fn remote_into_raw(remote: Remote<'_>) -> *mut raw::git_remote {
6885
let ret = remote.raw;
6986
mem::forget(remote);
@@ -479,6 +496,7 @@ impl<'cb> FetchOptions<'cb> {
479496
prune: FetchPrune::Unspecified,
480497
update_fetchhead: true,
481498
download_tags: AutotagOption::Unspecified,
499+
follow_redirects: RemoteRedirect::Initial,
482500
custom_headers: Vec::new(),
483501
custom_headers_ptrs: Vec::new(),
484502
}
@@ -519,6 +537,16 @@ impl<'cb> FetchOptions<'cb> {
519537
self
520538
}
521539

540+
/// Set remote redirection settings; whether redirects to another host are
541+
/// permitted.
542+
///
543+
/// By default, git will follow a redirect on the initial request
544+
/// (`/info/refs`), but not subsequent requests.
545+
pub fn follow_redirects(&mut self, redirect: RemoteRedirect) -> &mut Self {
546+
self.follow_redirects = redirect;
547+
self
548+
}
549+
522550
/// Set extra headers for this fetch operation.
523551
pub fn custom_headers(&mut self, custom_headers: &[&str]) -> &mut Self {
524552
self.custom_headers = custom_headers
@@ -552,6 +580,7 @@ impl<'cb> Binding for FetchOptions<'cb> {
552580
prune: crate::call::convert(&self.prune),
553581
update_fetchhead: crate::call::convert(&self.update_fetchhead),
554582
download_tags: crate::call::convert(&self.download_tags),
583+
follow_redirects: self.follow_redirects.raw(),
555584
custom_headers: git_strarray {
556585
count: self.custom_headers_ptrs.len(),
557586
strings: self.custom_headers_ptrs.as_ptr() as *mut _,
@@ -573,6 +602,7 @@ impl<'cb> PushOptions<'cb> {
573602
callbacks: None,
574603
proxy: None,
575604
pb_parallelism: 1,
605+
follow_redirects: RemoteRedirect::Initial,
576606
custom_headers: Vec::new(),
577607
custom_headers_ptrs: Vec::new(),
578608
}
@@ -601,6 +631,16 @@ impl<'cb> PushOptions<'cb> {
601631
self
602632
}
603633

634+
/// Set remote redirection settings; whether redirects to another host are
635+
/// permitted.
636+
///
637+
/// By default, git will follow a redirect on the initial request
638+
/// (`/info/refs`), but not subsequent requests.
639+
pub fn follow_redirects(&mut self, redirect: RemoteRedirect) -> &mut Self {
640+
self.follow_redirects = redirect;
641+
self
642+
}
643+
604644
/// Set extra headers for this push operation.
605645
pub fn custom_headers(&mut self, custom_headers: &[&str]) -> &mut Self {
606646
self.custom_headers = custom_headers
@@ -632,6 +672,7 @@ impl<'cb> Binding for PushOptions<'cb> {
632672
.map(|m| m.raw())
633673
.unwrap_or_else(|| ProxyOptions::new().raw()),
634674
pb_parallelism: self.pb_parallelism as libc::c_uint,
675+
follow_redirects: self.follow_redirects.raw(),
635676
custom_headers: git_strarray {
636677
count: self.custom_headers_ptrs.len(),
637678
strings: self.custom_headers_ptrs.as_ptr() as *mut _,
@@ -674,6 +715,22 @@ impl<'repo, 'connection, 'cb> Drop for RemoteConnection<'repo, 'connection, 'cb>
674715
}
675716
}
676717

718+
impl Default for RemoteRedirect {
719+
fn default() -> Self {
720+
RemoteRedirect::Initial
721+
}
722+
}
723+
724+
impl RemoteRedirect {
725+
fn raw(&self) -> raw::git_remote_redirect_t {
726+
match self {
727+
RemoteRedirect::None => raw::GIT_REMOTE_REDIRECT_NONE,
728+
RemoteRedirect::Initial => raw::GIT_REMOTE_REDIRECT_INITIAL,
729+
RemoteRedirect::All => raw::GIT_REMOTE_REDIRECT_ALL,
730+
}
731+
}
732+
}
733+
677734
#[cfg(test)]
678735
mod tests {
679736
use crate::{AutotagOption, PushOptions};

src/status.rs

+8
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,14 @@ impl StatusOptions {
216216
self.flag(raw::GIT_STATUS_OPT_INCLUDE_UNREADABLE_AS_UNTRACKED, include)
217217
}
218218

219+
/// Set threshold above which similar files will be considered renames.
220+
///
221+
/// This is equivalent to the `-M` option. Defaults to 50.
222+
pub fn rename_threshold(&mut self, threshold: u16) -> &mut StatusOptions {
223+
self.raw.rename_threshold = threshold;
224+
self
225+
}
226+
219227
/// Get a pointer to the inner list of status options.
220228
///
221229
/// This function is unsafe as the returned structure has interior pointers

0 commit comments

Comments
 (0)