Skip to content

Conversation

@cyqsimon
Copy link
Contributor

Previously the documentation did not make it clear the effect of the return value of cb. This PR clarifies that, alongside a minor rewording of existing docs.

Ref:

https://libgit2.org/docs/reference/main/tag/git_tag_foreach_cb.html

/// c callback forwarding to rust callback inside `TagForeachData`
/// see original: <https://libgit2.org/libgit2/#HEAD/group/callback/git_tag_foreach_cb>
pub(crate) extern "C" fn tag_foreach_cb(
name: *const c_char,
oid: *mut git_oid,
payload: *mut c_void,
) -> c_int {
panic::wrap(|| unsafe {
let id: Oid = Binding::from_raw(oid as *const _);
let name = CStr::from_ptr(name);
let name = name.to_bytes();
let payload = &mut *(payload as *mut TagForeachData<'_>);
let cb = &mut payload.cb;
let res = cb(id, name);
if res {
0
} else {
-1
}
})
.unwrap_or(-1)
}

@rustbot rustbot added the S-waiting-on-review Status: Waiting on review label Oct 19, 2025
Copy link
Contributor

@ehuss ehuss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

I notice that it is a little unfortunate that this doesn't do any error handling. Though I suppose an error would probably only happen with a corrupt repo or other catastrophic situation. A callback that panics will also silently drop the panic and just stop iteration.

@ehuss ehuss added this pull request to the merge queue Oct 20, 2025
Merged via the queue into rust-lang:master with commit aa0f63d Oct 20, 2025
7 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Waiting on review label Oct 20, 2025
@cyqsimon cyqsimon deleted the tag-foreach-docs branch October 21, 2025 03:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants