Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass byte slice as root to tree walk callback #1034

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 3 additions & 6 deletions src/tree.rs
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