From 3ce2f8728ec6f8613e8e7e699e6af7af402570e2 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sat, 4 Jan 2025 14:26:32 -0800 Subject: [PATCH] Simplify some of the tree_walk changes * I'm pretty sure the fn pointer doesn't need to have `*const`. * No need to move `Convert` around, can just use `as` for an enum (can maybe just remove this impl?). * Verify the actual error in the test. --- libgit2-sys/lib.rs | 2 +- src/call.rs | 11 ----------- src/tree.rs | 19 +++++++++++++++---- 3 files changed, 16 insertions(+), 16 deletions(-) diff --git a/libgit2-sys/lib.rs b/libgit2-sys/lib.rs index 54d384afc9..2cc53bf92d 100644 --- a/libgit2-sys/lib.rs +++ b/libgit2-sys/lib.rs @@ -742,7 +742,7 @@ git_enum! { } pub type git_treewalk_cb = - *const extern "C" fn(*const c_char, *const git_tree_entry, *mut c_void) -> c_int; + extern "C" fn(*const c_char, *const git_tree_entry, *mut c_void) -> c_int; pub type git_treebuilder_filter_cb = Option c_int>; diff --git a/src/call.rs b/src/call.rs index 57aaa26dbd..a18f05da91 100644 --- a/src/call.rs +++ b/src/call.rs @@ -116,17 +116,6 @@ mod impls { } } - impl Convert for crate::TreeWalkMode { - #[cfg(target_env = "msvc")] - fn convert(&self) -> raw::git_treewalk_mode { - *self as i32 - } - #[cfg(not(target_env = "msvc"))] - fn convert(&self) -> raw::git_treewalk_mode { - *self as u32 - } - } - impl Convert for Direction { fn convert(&self) -> raw::git_direction { match *self { diff --git a/src/tree.rs b/src/tree.rs index 376ca9aa2d..3aa2788478 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -61,6 +61,17 @@ impl Into for TreeWalkResult { } } +impl Into for TreeWalkMode { + #[cfg(target_env = "msvc")] + fn into(self) -> raw::git_treewalk_mode { + self as i32 + } + #[cfg(not(target_env = "msvc"))] + fn into(self) -> raw::git_treewalk_mode { + self as u32 + } +} + impl<'repo> Tree<'repo> { /// Get the id (SHA1) of a repository object pub fn id(&self) -> Oid { @@ -118,8 +129,8 @@ impl<'repo> Tree<'repo> { }; try_call!(raw::git_tree_walk( self.raw(), - mode, - treewalk_cb:: as raw::git_treewalk_cb, + mode as raw::git_treewalk_mode, + treewalk_cb::, &mut data as *mut _ as *mut c_void )); Ok(()) @@ -600,7 +611,7 @@ mod tests { let target = head.target().unwrap(); let commit = repo.find_commit(target).unwrap(); let tree = repo.find_tree(commit.tree_id()).unwrap(); - - assert!(tree.walk(TreeWalkMode::PreOrder, |_, _| { -1 }).is_err()); + let e = tree.walk(TreeWalkMode::PreOrder, |_, _| { -1 }).unwrap_err(); + assert_eq!(e.class(), crate::ErrorClass::Callback); } }