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

Add bindings to git_indexer #911

Merged
merged 5 commits into from
Feb 27, 2023
Merged

Add bindings to git_indexer #911

merged 5 commits into from
Feb 27, 2023

Conversation

kim
Copy link
Contributor

@kim kim commented Jan 12, 2023

The indexer API is a lower-level interface for storing and indexing pack
files, which, unlike git_odb_write_pack, allows the ouput to be
written to an arbitrary directory. This can be useful when working with
unusual validation requirements or non-standard repository layouts.

@kim
Copy link
Contributor Author

kim commented Jan 12, 2023

Sorry the test does not actually make sense, will amend

@kim kim force-pushed the indexer branch 2 times, most recently from d042e12 to 12a23d2 Compare January 12, 2023 16:52
The indexer API is a lower-level interface for storing and indexing pack
files, which, unlike `git_odb_write_pack`, allows the ouput to be
written to an arbitrary directory. This can be useful when working with
unusual validation requirements or non-standard repository layouts.
@kim
Copy link
Contributor Author

kim commented Jan 13, 2023

Amended to make odb optional

@kim
Copy link
Contributor Author

kim commented Feb 13, 2023

@ehuss any feedback on this?

src/indexer.rs Outdated
let odb = odb.map(Binding::raw).unwrap_or_else(ptr::null_mut);

let mut out = ptr::null_mut();
let progress = MaybeUninit::uninit();
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm having trouble seeing where progress is ever initialized. I see it created here, and then a few calls to as_mut_ptr, but I don't see where it gets initialized before as_mut_ptr is called. Can you help me understand how this works?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure, actually, OdbPackwriter does the same. I assumed it works because MaybeUninit<T> has the same size and alignment as T, so the C side can just write to it (i.e. it is initialized after the first time we pass as_mut_ptr over to libgit2).

I don't know why this would be preferable over deriving Default for git_indexer_progress, and casting to a raw pointer where needed. If I made this change, would you want me to do it for OdbPackwriter as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yea, it looks like OdbPackwriter should also be updated. From what I can tell, the C side is writing to uninitialized memory which is UB to my understanding.

src/indexer.rs Outdated
let res = raw::git_indexer_append(self.raw, ptr, len, self.progress.as_mut_ptr());

if res < 0 {
Err(io::Error::new(io::ErrorKind::Other, "Write error"))
Copy link
Contributor

Choose a reason for hiding this comment

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

This is unfortunate that it erases the libgit2 error. I assume you are just copying this from OdbWriter. I'm curious why this was implemented as io::Write instead of an inherent write method that would expose a native error message.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think io::Write makes sense because we can just io::copy the pack bytes from e.g. a network socket.

That being said, Error::last_error would indeed give the native error here (while it wouldn't for OdbPackwriter), so I'll change that.

src/odb.rs Outdated Show resolved Hide resolved
src/odb.rs Outdated Show resolved Hide resolved
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!

@ehuss ehuss merged commit f08525f into rust-lang:master Feb 27, 2023
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.

2 participants