-
Notifications
You must be signed in to change notification settings - Fork 413
Adding tree walk #343
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
Adding tree walk #343
Conversation
Thanks for the PR! Looks like tests on MSVC may be failing though? Could a bitflags type be used instead perhaps? Other than that with a small test this should be good to go! |
What should the callback function return? I actually only put bool cuz the filter function I referenced did but doesn't really make sense in this context. |
According to libgit2:
Could errors translate to -1 and the boolean be used to skip/not skip? |
Libgit2 exposes a specific error number for such cases (stopping an iteration): |
How about using a custom enum type that's kind of like Option but also includes an option to stop? Seems like there's three kinds of actions that could take place here: enum TreeWalkResult {
Ok,
Skip,
Stop,
} Not sure about the exact naming but then we could implement either Thoughts? |
@alexcrichton what are your thoughts on this implementation? |
src/tree.rs
Outdated
|
||
extern fn treewalk_cb(root: *const c_char, entry: *const raw::git_tree_entry, payload: *mut c_void) -> c_int { | ||
match panic::wrap(|| unsafe { | ||
if panic::panicked() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this shouldn't be necessary in that panic::wrap
already checks it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok 👍
Looks good to me! Could some documentation be added to the function to mention the enum types as well? |
Thanks! |
I'm seeing some strange behaviour with this feature. I have a callback which returns |
That's not good! I'll take a look after classes today.
…On Mon, Sep 10, 2018, 10:32 Alex Sayers ***@***.***> wrote:
I'm seeing some strange behaviour with this feature. I have a callback
which returns TreeWalkResult::Ok unconditionally, and I expect every node
in the tree to be visited. Instead I see a subset of the top-level nodes
only, and this subset is not deterministic across runs! Looks like
something nasty is happening. Returning 0 from the callback instead gives
the expected behaviour.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<https://github.com/alexcrichton/git2-rs/pull/343#issuecomment-419956222>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABnx-sfN6A5NY0zrujht65AvfQuDcZ4Xks5uZoYEgaJpZM4V3mia>
.
|
Also, reading libgit2/libgit2#4703 makes it seem like we should be passing EDIT: Just noticed that @neithernut pointed out the same thing. |
Just wanted to get some code down and start some discussion. I haven't worked much with bindings before so I'd appreciate some tips.
#267