From aa081abf2c7456c6355340abc7b67d2da234e63d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 19 Feb 2020 06:57:46 -0800 Subject: [PATCH 1/2] Update the libgit2 submodule to v0.99.0 Brings in a number of API improvements, security fixes, etc. --- examples/fetch.rs | 2 +- examples/log.rs | 2 +- examples/rev-list.rs | 2 +- libgit2-sys/lib.rs | 28 ++++++++++++++-------------- libgit2-sys/libgit2 | 2 +- src/oid.rs | 4 +++- src/remote.rs | 13 ++++++++----- src/repo.rs | 5 +++-- src/revwalk.rs | 28 ++++++++++++++++++++-------- src/transport.rs | 2 +- src/treebuilder.rs | 24 ++++++++++++++++-------- 11 files changed, 69 insertions(+), 43 deletions(-) diff --git a/examples/fetch.rs b/examples/fetch.rs index 6ede3c9ab5..212f934da4 100644 --- a/examples/fetch.rs +++ b/examples/fetch.rs @@ -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, diff --git a/examples/log.rs b/examples/log.rs index 94066f385a..d7f7711186 100644 --- a/examples/log.rs +++ b/examples/log.rs @@ -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..])?; diff --git a/examples/rev-list.rs b/examples/rev-list.rs index 84c0adcedb..de72102671 100644 --- a/examples/rev-list.rs +++ b/examples/rev-list.rs @@ -45,7 +45,7 @@ fn run(args: &Args) -> Result<(), git2::Error> { } else { git2::Sort::NONE }, - ); + )?; let specs = args .flag_not diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index a5998af84c..b6ad79ab4c 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -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, @@ -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, @@ -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; @@ -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( @@ -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, @@ -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, @@ -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( @@ -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 @@ -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; @@ -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, diff --git a/libgit2-sys/libgit2 b/libgit2-sys/libgit2 index cc4f4cbea4..172239021f 160000 --- a/libgit2-sys/libgit2 +++ b/libgit2-sys/libgit2 @@ -1 +1 @@ -Subproject commit cc4f4cbea48ac00a5edec1b3570ac3d2ef10fe77 +Subproject commit 172239021f7ba04fe7327647b213799853a9eb89 diff --git a/src/oid.rs b/src/oid.rs index 4f69bec8ef..59f2a7ffa2 100644 --- a/src/oid.rs +++ b/src/oid.rs @@ -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 }) } } diff --git a/src/remote.rs b/src/remote.rs index ded0387fb2..b00f7e1c84 100644 --- a/src/remote.rs +++ b/src/remote.rs @@ -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 @@ -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()); } } @@ -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(); diff --git a/src/repo.rs b/src/repo.rs index 77694df008..29ca2b37f9 100644 --- a/src/repo.rs +++ b/src/repo.rs @@ -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. diff --git a/src/revwalk.rs b/src/revwalk.rs index 4afd36ed9f..00152a2e32 100644 --- a/src/revwalk.rs +++ b/src/revwalk.rs @@ -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. @@ -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); diff --git a/src/transport.rs b/src/transport.rs index 0543c39779..e7b398ce6b 100644 --- a/src/transport.rs +++ b/src/transport.rs @@ -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` diff --git a/src/treebuilder.rs b/src/treebuilder.rs index 4eec55c10b..20ad22220c 100644 --- a/src/treebuilder.rs +++ b/src/treebuilder.rs @@ -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 @@ -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(&mut self, mut filter: F) + pub fn filter(&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 @@ -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); } @@ -209,11 +217,11 @@ 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); } } From 89ce58ad89da34b4e376b9c6c4f2993c6eb74c03 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 19 Feb 2020 07:16:17 -0800 Subject: [PATCH 2/2] rustfmt --- src/treebuilder.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/treebuilder.rs b/src/treebuilder.rs index 20ad22220c..e14d96319b 100644 --- a/src/treebuilder.rs +++ b/src/treebuilder.rs @@ -219,7 +219,9 @@ mod tests { builder.filter(|_| true).unwrap(); assert_eq!(builder.len(), 3); - builder.filter(|e| e.kind().unwrap() != ObjectType::Blob).unwrap(); + builder + .filter(|e| e.kind().unwrap() != ObjectType::Blob) + .unwrap(); assert_eq!(builder.len(), 2); builder.filter(|_| false).unwrap(); assert_eq!(builder.len(), 0);