Skip to content

Update the libgit2 submodule to v0.99.0 #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
}

// Disconnect the underlying connection to prevent from idling.
remote.disconnect();
remote.disconnect()?;

// Update the references in the remote's namespace to point to the right
// commits. This may be needed even if there was no packfile to download,
Expand Down
2 changes: 1 addition & 1 deletion examples/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ fn run(args: &Args) -> Result<(), Error> {
} else {
git2::Sort::NONE
},
);
)?;
for commit in &args.arg_commit {
if commit.starts_with('^') {
let obj = repo.revparse_single(&commit[1..])?;
Expand Down
2 changes: 1 addition & 1 deletion examples/rev-list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
} else {
git2::Sort::NONE
},
);
)?;

let specs = args
.flag_not
Expand Down
28 changes: 14 additions & 14 deletions libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1752,13 +1752,13 @@ extern "C" {
update_gitlink: c_int,
) -> c_int;
pub fn git_repository_index(out: *mut *mut git_index, repo: *mut git_repository) -> c_int;
pub fn git_repository_set_index(repo: *mut git_repository, index: *mut git_index);
pub fn git_repository_set_index(repo: *mut git_repository, index: *mut git_index) -> c_int;

pub fn git_repository_message(buf: *mut git_buf, repo: *mut git_repository) -> c_int;

pub fn git_repository_message_remove(repo: *mut git_repository) -> c_int;
pub fn git_repository_config(out: *mut *mut git_config, repo: *mut git_repository) -> c_int;
pub fn git_repository_set_config(repo: *mut git_repository, config: *mut git_config);
pub fn git_repository_set_config(repo: *mut git_repository, config: *mut git_config) -> c_int;
pub fn git_repository_config_snapshot(
out: *mut *mut git_config,
repo: *mut git_repository,
Expand All @@ -1769,10 +1769,10 @@ extern "C" {
across_fs: c_int,
ceiling_dirs: *const c_char,
) -> c_int;
pub fn git_repository_set_odb(repo: *mut git_repository, odb: *mut git_odb);
pub fn git_repository_set_odb(repo: *mut git_repository, odb: *mut git_odb) -> c_int;

pub fn git_repository_refdb(out: *mut *mut git_refdb, repo: *mut git_repository) -> c_int;
pub fn git_repository_set_refdb(repo: *mut git_repository, refdb: *mut git_refdb);
pub fn git_repository_set_refdb(repo: *mut git_repository, refdb: *mut git_refdb) -> c_int;

pub fn git_repository_reinit_filesystem(
repo: *mut git_repository,
Expand Down Expand Up @@ -1826,7 +1826,7 @@ extern "C" {
pub fn git_object_typeisloose(kind: git_object_t) -> c_int;

// oid
pub fn git_oid_fromraw(out: *mut git_oid, raw: *const c_uchar);
pub fn git_oid_fromraw(out: *mut git_oid, raw: *const c_uchar) -> c_int;
pub fn git_oid_fromstrn(out: *mut git_oid, str: *const c_char, len: size_t) -> c_int;
pub fn git_oid_tostr(out: *mut c_char, n: size_t, id: *const git_oid) -> *mut c_char;
pub fn git_oid_cmp(a: *const git_oid, b: *const git_oid) -> c_int;
Expand All @@ -1837,7 +1837,7 @@ extern "C" {
// error
pub fn git_error_last() -> *const git_error;
pub fn git_error_clear();
pub fn git_error_set_str(error_class: c_int, string: *const c_char);
pub fn git_error_set_str(error_class: c_int, string: *const c_char) -> c_int;

// remote
pub fn git_remote_create(
Expand Down Expand Up @@ -1877,7 +1877,7 @@ extern "C" {
custom_headers: *const git_strarray,
) -> c_int;
pub fn git_remote_connected(remote: *const git_remote) -> c_int;
pub fn git_remote_disconnect(remote: *mut git_remote);
pub fn git_remote_disconnect(remote: *mut git_remote) -> c_int;
pub fn git_remote_add_fetch(
repo: *mut git_repository,
remote: *const c_char,
Expand All @@ -1893,7 +1893,7 @@ extern "C" {
refspecs: *const git_strarray,
opts: *const git_fetch_options,
) -> c_int;
pub fn git_remote_stop(remote: *mut git_remote);
pub fn git_remote_stop(remote: *mut git_remote) -> c_int;
pub fn git_remote_dup(dest: *mut *mut git_remote, source: *mut git_remote) -> c_int;
pub fn git_remote_get_fetch_refspecs(
array: *mut git_strarray,
Expand Down Expand Up @@ -2336,7 +2336,7 @@ extern "C" {
repo: *mut git_repository,
source: *const git_tree,
) -> c_int;
pub fn git_treebuilder_clear(bld: *mut git_treebuilder);
pub fn git_treebuilder_clear(bld: *mut git_treebuilder) -> c_int;
pub fn git_treebuilder_entrycount(bld: *mut git_treebuilder) -> size_t;
pub fn git_treebuilder_free(bld: *mut git_treebuilder);
pub fn git_treebuilder_get(
Expand All @@ -2355,7 +2355,7 @@ extern "C" {
bld: *mut git_treebuilder,
filter: git_treebuilder_filter_cb,
payload: *mut c_void,
);
) -> c_int;
pub fn git_treebuilder_write(id: *mut git_oid, bld: *mut git_treebuilder) -> c_int;

// buf
Expand Down Expand Up @@ -2926,16 +2926,16 @@ extern "C" {
pub fn git_revwalk_new(out: *mut *mut git_revwalk, repo: *mut git_repository) -> c_int;
pub fn git_revwalk_free(walk: *mut git_revwalk);

pub fn git_revwalk_reset(walk: *mut git_revwalk);
pub fn git_revwalk_reset(walk: *mut git_revwalk) -> c_int;

pub fn git_revwalk_sorting(walk: *mut git_revwalk, sort_mode: c_uint);
pub fn git_revwalk_sorting(walk: *mut git_revwalk, sort_mode: c_uint) -> c_int;

pub fn git_revwalk_push_head(walk: *mut git_revwalk) -> c_int;
pub fn git_revwalk_push(walk: *mut git_revwalk, oid: *const git_oid) -> c_int;
pub fn git_revwalk_push_ref(walk: *mut git_revwalk, refname: *const c_char) -> c_int;
pub fn git_revwalk_push_glob(walk: *mut git_revwalk, glob: *const c_char) -> c_int;
pub fn git_revwalk_push_range(walk: *mut git_revwalk, range: *const c_char) -> c_int;
pub fn git_revwalk_simplify_first_parent(walk: *mut git_revwalk);
pub fn git_revwalk_simplify_first_parent(walk: *mut git_revwalk) -> c_int;

pub fn git_revwalk_hide_head(walk: *mut git_revwalk) -> c_int;
pub fn git_revwalk_hide(walk: *mut git_revwalk, oid: *const git_oid) -> c_int;
Expand Down Expand Up @@ -3469,7 +3469,7 @@ extern "C" {

// mempack
pub fn git_mempack_new(out: *mut *mut git_odb_backend) -> c_int;
pub fn git_mempack_reset(backend: *mut git_odb_backend);
pub fn git_mempack_reset(backend: *mut git_odb_backend) -> c_int;
pub fn git_mempack_dump(
pack: *mut git_buf,
repo: *mut git_repository,
Expand Down
2 changes: 1 addition & 1 deletion libgit2-sys/libgit2
Submodule libgit2 updated 112 files
4 changes: 3 additions & 1 deletion src/oid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ impl Oid {
if bytes.len() != raw::GIT_OID_RAWSZ {
Err(Error::from_str("raw byte array must be 20 bytes"))
} else {
unsafe { raw::git_oid_fromraw(&mut raw, bytes.as_ptr()) }
unsafe {
try_call!(raw::git_oid_fromraw(&mut raw, bytes.as_ptr()));
}
Ok(Oid { raw: raw })
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/remote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,11 @@ impl<'repo> Remote<'repo> {
}

/// Disconnect from the remote
pub fn disconnect(&mut self) {
unsafe { raw::git_remote_disconnect(self.raw) }
pub fn disconnect(&mut self) -> Result<(), Error> {
unsafe {
try_call!(raw::git_remote_disconnect(self.raw));
}
Ok(())
}

/// Download and index the packfile
Expand Down Expand Up @@ -577,7 +580,7 @@ impl<'repo, 'connection, 'cb> RemoteConnection<'repo, 'connection, 'cb> {

impl<'repo, 'connection, 'cb> Drop for RemoteConnection<'repo, 'connection, 'cb> {
fn drop(&mut self) {
self.remote.disconnect()
drop(self.remote.disconnect());
}
}

Expand Down Expand Up @@ -648,12 +651,12 @@ mod tests {

origin.connect(Direction::Push).unwrap();
assert!(origin.connected());
origin.disconnect();
origin.disconnect().unwrap();

origin.connect(Direction::Fetch).unwrap();
assert!(origin.connected());
origin.download(&[] as &[&str], None).unwrap();
origin.disconnect();
origin.disconnect().unwrap();

{
let mut connection = origin.connect_auth(Direction::Push, None, None).unwrap();
Expand Down
5 changes: 3 additions & 2 deletions src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -891,10 +891,11 @@ impl Repository {
}

/// Set the Index file for this repository.
pub fn set_index(&self, index: &mut Index) {
pub fn set_index(&self, index: &mut Index) -> Result<(), Error> {
unsafe {
raw::git_repository_set_index(self.raw(), index.raw());
try_call!(raw::git_repository_set_index(self.raw(), index.raw()));
}
Ok(())
}

/// Get the configuration file for this repository.
Expand Down
28 changes: 20 additions & 8 deletions src/revwalk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,32 @@ impl<'repo> Revwalk<'repo> {
///
/// The revwalk is automatically reset when iteration of its commits
/// completes.
pub fn reset(&mut self) {
unsafe { raw::git_revwalk_reset(self.raw()) }
pub fn reset(&mut self) -> Result<(), Error> {
unsafe {
try_call!(raw::git_revwalk_reset(self.raw()));
}
Ok(())
}

/// Set the order in which commits are visited.
pub fn set_sorting(&mut self, sort_mode: Sort) {
unsafe { raw::git_revwalk_sorting(self.raw(), sort_mode.bits() as c_uint) }
pub fn set_sorting(&mut self, sort_mode: Sort) -> Result<(), Error> {
unsafe {
try_call!(raw::git_revwalk_sorting(
self.raw(),
sort_mode.bits() as c_uint
));
}
Ok(())
}

/// Simplify the history by first-parent
///
/// No parents other than the first for each commit will be enqueued.
pub fn simplify_first_parent(&mut self) {
unsafe { raw::git_revwalk_simplify_first_parent(self.raw) }
pub fn simplify_first_parent(&mut self) -> Result<(), Error> {
unsafe {
try_call!(raw::git_revwalk_simplify_first_parent(self.raw));
}
Ok(())
}

/// Mark a commit to start traversal from.
Expand Down Expand Up @@ -195,11 +207,11 @@ mod tests {
assert_eq!(oids.len(), 1);
assert_eq!(oids[0], target);

walk.reset();
walk.reset().unwrap();
walk.push_head().unwrap();
assert_eq!(walk.by_ref().count(), 1);

walk.reset();
walk.reset().unwrap();
walk.push_head().unwrap();
walk.hide_head().unwrap();
assert_eq!(walk.by_ref().count(), 0);
Expand Down
2 changes: 1 addition & 1 deletion src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ extern "C" fn stream_write(

unsafe fn set_err(e: &io::Error) {
let s = CString::new(e.to_string()).unwrap();
raw::git_error_set_str(raw::GIT_ERROR_NET as c_int, s.as_ptr())
raw::git_error_set_str(raw::GIT_ERROR_NET as c_int, s.as_ptr());
}

// callback used by smart transports to free a `SmartSubtransportStream`
Expand Down
26 changes: 18 additions & 8 deletions src/treebuilder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,11 @@ pub struct TreeBuilder<'repo> {

impl<'repo> TreeBuilder<'repo> {
/// Clear all the entries in the builder
pub fn clear(&mut self) {
unsafe { raw::git_treebuilder_clear(self.raw) }
pub fn clear(&mut self) -> Result<(), Error> {
unsafe {
try_call!(raw::git_treebuilder_clear(self.raw));
}
Ok(())
}

/// Get the number of entries
Expand Down Expand Up @@ -86,16 +89,21 @@ impl<'repo> TreeBuilder<'repo> {
///
/// Values for which the filter returns `true` will be kept. Note
/// that this behavior is different from the libgit2 C interface.
pub fn filter<F>(&mut self, mut filter: F)
pub fn filter<F>(&mut self, mut filter: F) -> Result<(), Error>
where
F: FnMut(&TreeEntry<'_>) -> bool,
{
let mut cb: &mut FilterCb<'_> = &mut filter;
let ptr = &mut cb as *mut _;
unsafe {
raw::git_treebuilder_filter(self.raw, filter_cb, ptr as *mut _);
try_call!(raw::git_treebuilder_filter(
self.raw,
filter_cb,
ptr as *mut _
));
panic::check();
}
Ok(())
}

/// Write the contents of the TreeBuilder as a Tree object and
Expand Down Expand Up @@ -171,7 +179,7 @@ mod tests {
builder.remove("a").unwrap();
assert_eq!(builder.len(), 1);
assert_eq!(builder.get("b").unwrap().unwrap().id(), blob);
builder.clear();
builder.clear().unwrap();
assert_eq!(builder.len(), 0);
}

Expand Down Expand Up @@ -209,11 +217,13 @@ mod tests {
builder.insert("dir", tree, 0o040000).unwrap();
builder.insert("dir2", tree, 0o040000).unwrap();

builder.filter(|_| true);
builder.filter(|_| true).unwrap();
assert_eq!(builder.len(), 3);
builder.filter(|e| e.kind().unwrap() != ObjectType::Blob);
builder
.filter(|e| e.kind().unwrap() != ObjectType::Blob)
.unwrap();
assert_eq!(builder.len(), 2);
builder.filter(|_| false);
builder.filter(|_| false).unwrap();
assert_eq!(builder.len(), 0);
}
}