Skip to content

Commit

Permalink
Simplify some of the tree_walk changes
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
ehuss committed Jan 4, 2025
1 parent 41d8e06 commit 3ce2f87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion libgit2-sys/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<extern "C" fn(*const git_tree_entry, *mut c_void) -> c_int>;

Expand Down
11 changes: 0 additions & 11 deletions src/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,6 @@ mod impls {
}
}

impl Convert<raw::git_treewalk_mode> 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<raw::git_direction> for Direction {
fn convert(&self) -> raw::git_direction {
match *self {
Expand Down
19 changes: 15 additions & 4 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ impl Into<i32> for TreeWalkResult {
}
}

impl Into<raw::git_treewalk_mode> 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 {
Expand Down Expand Up @@ -118,8 +129,8 @@ impl<'repo> Tree<'repo> {
};
try_call!(raw::git_tree_walk(
self.raw(),
mode,
treewalk_cb::<T> as raw::git_treewalk_cb,
mode as raw::git_treewalk_mode,
treewalk_cb::<T>,
&mut data as *mut _ as *mut c_void
));
Ok(())
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 3ce2f87

Please sign in to comment.