Skip to content

Commit

Permalink
Pass byte slice as root to tree walk callback
Browse files Browse the repository at this point in the history
Fixes #1033.
  • Loading branch information
bsidhom committed Mar 3, 2024
1 parent 3da58f3 commit d3f5ea4
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ impl<'repo> Tree<'repo> {
/// [1]: https://libgit2.org/libgit2/#HEAD/group/tree/git_tree_walk
pub fn walk<C, T>(&self, mode: TreeWalkMode, mut callback: C) -> Result<(), Error>
where
C: FnMut(&str, &TreeEntry<'_>) -> T,
C: FnMut(&[u8], &TreeEntry<'_>) -> T,
T: Into<i32>,
{
unsafe {
Expand Down Expand Up @@ -203,7 +203,7 @@ impl<'repo> Tree<'repo> {
}
}

type TreeWalkCb<'a, T> = dyn FnMut(&str, &TreeEntry<'_>) -> T + 'a;
type TreeWalkCb<'a, T> = dyn FnMut(&[u8], &TreeEntry<'_>) -> T + 'a;

struct TreeWalkCbData<'a, T> {
callback: &'a mut TreeWalkCb<'a, T>,
Expand All @@ -215,10 +215,7 @@ extern "C" fn treewalk_cb<T: Into<i32>>(
payload: *mut c_void,
) -> c_int {
match panic::wrap(|| unsafe {
let root = match CStr::from_ptr(root).to_str() {
Ok(value) => value,
_ => return -1,
};
let root = CStr::from_ptr(root).to_bytes();
let entry = entry_from_raw_const(entry);
let payload = &mut *(payload as *mut TreeWalkCbData<'_, T>);
let callback = &mut payload.callback;
Expand Down

0 comments on commit d3f5ea4

Please sign in to comment.