Skip to content

Tree walk: bugfix #352

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

Merged
merged 2 commits into from
Sep 12, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,14 @@ pub enum TreeWalkMode {
}

/// Possible return codes for tree walking callback functions.
#[allow(dead_code)]
#[repr(i32)]
pub enum TreeWalkResult {
/// Continue with the traversal as normal.
Ok = 0,
/// Skip the current node (in pre-order mode).
Skip = 1,
/// Completely stop the traversal.
Abort = -1,
Abort = raw::GIT_EUSER,
}

impl Into<i32> for TreeWalkResult {
Expand Down Expand Up @@ -127,7 +127,7 @@ impl<'repo> Tree<'repo> {
raw::git_tree_walk(
self.raw(),
mode.into(),
treewalk_cb,
treewalk_cb::<T>,
&mut data as *mut _ as *mut c_void,
);
Ok(())
Expand Down Expand Up @@ -201,15 +201,15 @@ impl<'repo> Tree<'repo> {

type TreeWalkCb<'a, T> = FnMut(&str, &TreeEntry) -> T + 'a;

extern fn treewalk_cb(root: *const c_char, entry: *const raw::git_tree_entry, payload: *mut c_void) -> c_int {
extern fn treewalk_cb<T: Into<i32>>(root: *const c_char, entry: *const raw::git_tree_entry, 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 entry = entry_from_raw_const(entry);
let payload = payload as *mut &mut TreeWalkCb<_>;
(*payload)(root, &entry)
let payload = payload as *mut &mut TreeWalkCb<T>;
(*payload)(root, &entry).into()
}) {
Some(value) => value,
None => -1,
Expand Down Expand Up @@ -520,7 +520,7 @@ mod tests {
0
}).unwrap();
assert_eq!(ct, 1);

let mut ct = 0;
tree.walk(TreeWalkMode::PreOrder, |_, entry| {
assert_eq!(entry.name(), Some("foo"));
Expand Down