Skip to content

Commit

Permalink
(Breaking Change) remove unnecessary Option wrapper on `Error::last…
Browse files Browse the repository at this point in the history
…_error`.
  • Loading branch information
vcfxb committed Jul 22, 2024
1 parent 7be7525 commit fa33a26
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 15 deletions.
4 changes: 1 addition & 3 deletions src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ pub fn c_try(ret: libc::c_int) -> Result<libc::c_int, Error> {
}

pub fn last_error(code: libc::c_int) -> Error {
// nowadays this unwrap is safe as `Error::last_error` always returns
// `Some`.
Error::last_error(code).unwrap()
Error::last_error(code)
}

mod impls {
Expand Down
9 changes: 2 additions & 7 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,7 @@ impl Error {
///
/// The `code` argument typically comes from the return value of a function
/// call. This code will later be returned from the `code` function.
///
/// Historically this function returned `Some` or `None` based on the return
/// value of `git_error_last` but nowadays it always returns `Some` so it's
/// safe to unwrap the return value. This API will change in the next major
/// version.
pub fn last_error(code: c_int) -> Option<Error> {
pub fn last_error(code: c_int) -> Error {
crate::init();
unsafe {
// Note that whenever libgit2 returns an error any negative value
Expand All @@ -64,7 +59,7 @@ impl Error {
Error::from_raw(code, ptr)
};
raw::git_error_clear();
Some(err)
err
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ impl io::Write for Indexer<'_> {
if res < 0 {
Err(io::Error::new(
io::ErrorKind::Other,
Error::last_error(res).unwrap(),
Error::last_error(res),
))
} else {
Ok(buf.len())
Expand Down
2 changes: 1 addition & 1 deletion src/odb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ impl<'repo> OdbPackwriter<'repo> {
};

if res < 0 {
Err(Error::last_error(res).unwrap())
Err(Error::last_error(res))
} else {
Ok(res)
}
Expand Down
2 changes: 1 addition & 1 deletion src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -848,7 +848,7 @@ impl Repository {
match value {
0 => Ok(false),
1 => Ok(true),
_ => Err(Error::last_error(value).unwrap()),
_ => Err(Error::last_error(value)),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/tracing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ pub fn trace_set(level: TraceLevel, cb: TracingCb) -> Result<(), Error> {
let return_code: c_int = unsafe { raw::git_trace_set(level.raw(), Some(tracing_cb_c)) };

if return_code != 0 {
// Unwrap here is fine since `Error::last_error` always returns `Some`.
Err(Error::last_error(return_code).unwrap())
Err(Error::last_error(return_code))
} else {
Ok(())
}
Expand Down

0 comments on commit fa33a26

Please sign in to comment.