Skip to content

Commit 850c9b9

Browse files
authored
Update the libgit2 submodule to v0.99.0 (#520)
* Update the libgit2 submodule to v0.99.0 Brings in a number of API improvements, security fixes, etc. * rustfmt
1 parent 147c5b4 commit 850c9b9

File tree

11 files changed

+71
-43
lines changed

11 files changed

+71
-43
lines changed

examples/fetch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
107107
}
108108

109109
// Disconnect the underlying connection to prevent from idling.
110-
remote.disconnect();
110+
remote.disconnect()?;
111111

112112
// Update the references in the remote's namespace to point to the right
113113
// commits. This may be needed even if there was no packfile to download,

examples/log.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ fn run(args: &Args) -> Result<(), Error> {
6161
} else {
6262
git2::Sort::NONE
6363
},
64-
);
64+
)?;
6565
for commit in &args.arg_commit {
6666
if commit.starts_with('^') {
6767
let obj = repo.revparse_single(&commit[1..])?;

examples/rev-list.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ fn run(args: &Args) -> Result<(), git2::Error> {
4545
} else {
4646
git2::Sort::NONE
4747
},
48-
);
48+
)?;
4949

5050
let specs = args
5151
.flag_not

libgit2-sys/lib.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,13 +1752,13 @@ extern "C" {
17521752
update_gitlink: c_int,
17531753
) -> c_int;
17541754
pub fn git_repository_index(out: *mut *mut git_index, repo: *mut git_repository) -> c_int;
1755-
pub fn git_repository_set_index(repo: *mut git_repository, index: *mut git_index);
1755+
pub fn git_repository_set_index(repo: *mut git_repository, index: *mut git_index) -> c_int;
17561756

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

17591759
pub fn git_repository_message_remove(repo: *mut git_repository) -> c_int;
17601760
pub fn git_repository_config(out: *mut *mut git_config, repo: *mut git_repository) -> c_int;
1761-
pub fn git_repository_set_config(repo: *mut git_repository, config: *mut git_config);
1761+
pub fn git_repository_set_config(repo: *mut git_repository, config: *mut git_config) -> c_int;
17621762
pub fn git_repository_config_snapshot(
17631763
out: *mut *mut git_config,
17641764
repo: *mut git_repository,
@@ -1769,10 +1769,10 @@ extern "C" {
17691769
across_fs: c_int,
17701770
ceiling_dirs: *const c_char,
17711771
) -> c_int;
1772-
pub fn git_repository_set_odb(repo: *mut git_repository, odb: *mut git_odb);
1772+
pub fn git_repository_set_odb(repo: *mut git_repository, odb: *mut git_odb) -> c_int;
17731773

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

17771777
pub fn git_repository_reinit_filesystem(
17781778
repo: *mut git_repository,
@@ -1826,7 +1826,7 @@ extern "C" {
18261826
pub fn git_object_typeisloose(kind: git_object_t) -> c_int;
18271827

18281828
// oid
1829-
pub fn git_oid_fromraw(out: *mut git_oid, raw: *const c_uchar);
1829+
pub fn git_oid_fromraw(out: *mut git_oid, raw: *const c_uchar) -> c_int;
18301830
pub fn git_oid_fromstrn(out: *mut git_oid, str: *const c_char, len: size_t) -> c_int;
18311831
pub fn git_oid_tostr(out: *mut c_char, n: size_t, id: *const git_oid) -> *mut c_char;
18321832
pub fn git_oid_cmp(a: *const git_oid, b: *const git_oid) -> c_int;
@@ -1837,7 +1837,7 @@ extern "C" {
18371837
// error
18381838
pub fn git_error_last() -> *const git_error;
18391839
pub fn git_error_clear();
1840-
pub fn git_error_set_str(error_class: c_int, string: *const c_char);
1840+
pub fn git_error_set_str(error_class: c_int, string: *const c_char) -> c_int;
18411841

18421842
// remote
18431843
pub fn git_remote_create(
@@ -1877,7 +1877,7 @@ extern "C" {
18771877
custom_headers: *const git_strarray,
18781878
) -> c_int;
18791879
pub fn git_remote_connected(remote: *const git_remote) -> c_int;
1880-
pub fn git_remote_disconnect(remote: *mut git_remote);
1880+
pub fn git_remote_disconnect(remote: *mut git_remote) -> c_int;
18811881
pub fn git_remote_add_fetch(
18821882
repo: *mut git_repository,
18831883
remote: *const c_char,
@@ -1893,7 +1893,7 @@ extern "C" {
18931893
refspecs: *const git_strarray,
18941894
opts: *const git_fetch_options,
18951895
) -> c_int;
1896-
pub fn git_remote_stop(remote: *mut git_remote);
1896+
pub fn git_remote_stop(remote: *mut git_remote) -> c_int;
18971897
pub fn git_remote_dup(dest: *mut *mut git_remote, source: *mut git_remote) -> c_int;
18981898
pub fn git_remote_get_fetch_refspecs(
18991899
array: *mut git_strarray,
@@ -2336,7 +2336,7 @@ extern "C" {
23362336
repo: *mut git_repository,
23372337
source: *const git_tree,
23382338
) -> c_int;
2339-
pub fn git_treebuilder_clear(bld: *mut git_treebuilder);
2339+
pub fn git_treebuilder_clear(bld: *mut git_treebuilder) -> c_int;
23402340
pub fn git_treebuilder_entrycount(bld: *mut git_treebuilder) -> size_t;
23412341
pub fn git_treebuilder_free(bld: *mut git_treebuilder);
23422342
pub fn git_treebuilder_get(
@@ -2355,7 +2355,7 @@ extern "C" {
23552355
bld: *mut git_treebuilder,
23562356
filter: git_treebuilder_filter_cb,
23572357
payload: *mut c_void,
2358-
);
2358+
) -> c_int;
23592359
pub fn git_treebuilder_write(id: *mut git_oid, bld: *mut git_treebuilder) -> c_int;
23602360

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

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

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

29332933
pub fn git_revwalk_push_head(walk: *mut git_revwalk) -> c_int;
29342934
pub fn git_revwalk_push(walk: *mut git_revwalk, oid: *const git_oid) -> c_int;
29352935
pub fn git_revwalk_push_ref(walk: *mut git_revwalk, refname: *const c_char) -> c_int;
29362936
pub fn git_revwalk_push_glob(walk: *mut git_revwalk, glob: *const c_char) -> c_int;
29372937
pub fn git_revwalk_push_range(walk: *mut git_revwalk, range: *const c_char) -> c_int;
2938-
pub fn git_revwalk_simplify_first_parent(walk: *mut git_revwalk);
2938+
pub fn git_revwalk_simplify_first_parent(walk: *mut git_revwalk) -> c_int;
29392939

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

34703470
// mempack
34713471
pub fn git_mempack_new(out: *mut *mut git_odb_backend) -> c_int;
3472-
pub fn git_mempack_reset(backend: *mut git_odb_backend);
3472+
pub fn git_mempack_reset(backend: *mut git_odb_backend) -> c_int;
34733473
pub fn git_mempack_dump(
34743474
pack: *mut git_buf,
34753475
repo: *mut git_repository,

libgit2-sys/libgit2

Submodule libgit2 updated 112 files

src/oid.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ impl Oid {
4949
if bytes.len() != raw::GIT_OID_RAWSZ {
5050
Err(Error::from_str("raw byte array must be 20 bytes"))
5151
} else {
52-
unsafe { raw::git_oid_fromraw(&mut raw, bytes.as_ptr()) }
52+
unsafe {
53+
try_call!(raw::git_oid_fromraw(&mut raw, bytes.as_ptr()));
54+
}
5355
Ok(Oid { raw: raw })
5456
}
5557
}

src/remote.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,11 @@ impl<'repo> Remote<'repo> {
161161
}
162162

163163
/// Disconnect from the remote
164-
pub fn disconnect(&mut self) {
165-
unsafe { raw::git_remote_disconnect(self.raw) }
164+
pub fn disconnect(&mut self) -> Result<(), Error> {
165+
unsafe {
166+
try_call!(raw::git_remote_disconnect(self.raw));
167+
}
168+
Ok(())
166169
}
167170

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

578581
impl<'repo, 'connection, 'cb> Drop for RemoteConnection<'repo, 'connection, 'cb> {
579582
fn drop(&mut self) {
580-
self.remote.disconnect()
583+
drop(self.remote.disconnect());
581584
}
582585
}
583586

@@ -648,12 +651,12 @@ mod tests {
648651

649652
origin.connect(Direction::Push).unwrap();
650653
assert!(origin.connected());
651-
origin.disconnect();
654+
origin.disconnect().unwrap();
652655

653656
origin.connect(Direction::Fetch).unwrap();
654657
assert!(origin.connected());
655658
origin.download(&[] as &[&str], None).unwrap();
656-
origin.disconnect();
659+
origin.disconnect().unwrap();
657660

658661
{
659662
let mut connection = origin.connect_auth(Direction::Push, None, None).unwrap();

src/repo.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,11 @@ impl Repository {
891891
}
892892

893893
/// Set the Index file for this repository.
894-
pub fn set_index(&self, index: &mut Index) {
894+
pub fn set_index(&self, index: &mut Index) -> Result<(), Error> {
895895
unsafe {
896-
raw::git_repository_set_index(self.raw(), index.raw());
896+
try_call!(raw::git_repository_set_index(self.raw(), index.raw()));
897897
}
898+
Ok(())
898899
}
899900

900901
/// Get the configuration file for this repository.

src/revwalk.rs

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,32 @@ impl<'repo> Revwalk<'repo> {
1717
///
1818
/// The revwalk is automatically reset when iteration of its commits
1919
/// completes.
20-
pub fn reset(&mut self) {
21-
unsafe { raw::git_revwalk_reset(self.raw()) }
20+
pub fn reset(&mut self) -> Result<(), Error> {
21+
unsafe {
22+
try_call!(raw::git_revwalk_reset(self.raw()));
23+
}
24+
Ok(())
2225
}
2326

2427
/// Set the order in which commits are visited.
25-
pub fn set_sorting(&mut self, sort_mode: Sort) {
26-
unsafe { raw::git_revwalk_sorting(self.raw(), sort_mode.bits() as c_uint) }
28+
pub fn set_sorting(&mut self, sort_mode: Sort) -> Result<(), Error> {
29+
unsafe {
30+
try_call!(raw::git_revwalk_sorting(
31+
self.raw(),
32+
sort_mode.bits() as c_uint
33+
));
34+
}
35+
Ok(())
2736
}
2837

2938
/// Simplify the history by first-parent
3039
///
3140
/// No parents other than the first for each commit will be enqueued.
32-
pub fn simplify_first_parent(&mut self) {
33-
unsafe { raw::git_revwalk_simplify_first_parent(self.raw) }
41+
pub fn simplify_first_parent(&mut self) -> Result<(), Error> {
42+
unsafe {
43+
try_call!(raw::git_revwalk_simplify_first_parent(self.raw));
44+
}
45+
Ok(())
3446
}
3547

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

198-
walk.reset();
210+
walk.reset().unwrap();
199211
walk.push_head().unwrap();
200212
assert_eq!(walk.by_ref().count(), 1);
201213

202-
walk.reset();
214+
walk.reset().unwrap();
203215
walk.push_head().unwrap();
204216
walk.hide_head().unwrap();
205217
assert_eq!(walk.by_ref().count(), 0);

src/transport.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ extern "C" fn stream_write(
343343

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

349349
// callback used by smart transports to free a `SmartSubtransportStream`

src/treebuilder.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,11 @@ pub struct TreeBuilder<'repo> {
1414

1515
impl<'repo> TreeBuilder<'repo> {
1616
/// Clear all the entries in the builder
17-
pub fn clear(&mut self) {
18-
unsafe { raw::git_treebuilder_clear(self.raw) }
17+
pub fn clear(&mut self) -> Result<(), Error> {
18+
unsafe {
19+
try_call!(raw::git_treebuilder_clear(self.raw));
20+
}
21+
Ok(())
1922
}
2023

2124
/// Get the number of entries
@@ -86,16 +89,21 @@ impl<'repo> TreeBuilder<'repo> {
8689
///
8790
/// Values for which the filter returns `true` will be kept. Note
8891
/// that this behavior is different from the libgit2 C interface.
89-
pub fn filter<F>(&mut self, mut filter: F)
92+
pub fn filter<F>(&mut self, mut filter: F) -> Result<(), Error>
9093
where
9194
F: FnMut(&TreeEntry<'_>) -> bool,
9295
{
9396
let mut cb: &mut FilterCb<'_> = &mut filter;
9497
let ptr = &mut cb as *mut _;
9598
unsafe {
96-
raw::git_treebuilder_filter(self.raw, filter_cb, ptr as *mut _);
99+
try_call!(raw::git_treebuilder_filter(
100+
self.raw,
101+
filter_cb,
102+
ptr as *mut _
103+
));
97104
panic::check();
98105
}
106+
Ok(())
99107
}
100108

101109
/// Write the contents of the TreeBuilder as a Tree object and
@@ -171,7 +179,7 @@ mod tests {
171179
builder.remove("a").unwrap();
172180
assert_eq!(builder.len(), 1);
173181
assert_eq!(builder.get("b").unwrap().unwrap().id(), blob);
174-
builder.clear();
182+
builder.clear().unwrap();
175183
assert_eq!(builder.len(), 0);
176184
}
177185

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

212-
builder.filter(|_| true);
220+
builder.filter(|_| true).unwrap();
213221
assert_eq!(builder.len(), 3);
214-
builder.filter(|e| e.kind().unwrap() != ObjectType::Blob);
222+
builder
223+
.filter(|e| e.kind().unwrap() != ObjectType::Blob)
224+
.unwrap();
215225
assert_eq!(builder.len(), 2);
216-
builder.filter(|_| false);
226+
builder.filter(|_| false).unwrap();
217227
assert_eq!(builder.len(), 0);
218228
}
219229
}

0 commit comments

Comments
 (0)