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 function: git_merge_file_from_index #1062

Merged
merged 9 commits into from
Mar 17, 2025
Merged

Conversation

MikeJerred
Copy link
Contributor

Some overlap with #635 but that PR has been open for years.

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.

Sorry for the long delay on review.

@MikeJerred MikeJerred requested a review from ehuss November 5, 2024 12:24
src/merge.rs Outdated
Comment on lines 394 to 395
fn raw(&self) -> raw::git_merge_file_result {
self.raw
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This generally doesn't look correct to me, or at least looks concerning. I don't think git_merge_file_result should be copy/clone, since this looks like it is erasing the lifetime.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The raw func is required to impl Binding? Not sure what you mean here

Copy link
Contributor

Choose a reason for hiding this comment

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

I went ahead and removed the Copy/Clone. My concern is that it could make it a little too easy to copy the struct, which is definitely not something you want to do (since these need to be manually freed, and you don't want to have two copies lying around). It's fine to mark this as unimplemented.

In general, I'm not always certain when it is best to implement Binding versus just making associated functions of the struct itself. Probably would be good to document that someday.

src/merge.rs Outdated
/// Information about file-level merging.
pub struct MergeFileResult<'repo> {
raw: raw::git_merge_file_result,
_marker: marker::PhantomData<&'repo str>,
Copy link
Contributor

Choose a reason for hiding this comment

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

Why does this have a PhantomData?

From what I can tell, the struct owns its own pointers (which are freed with git_merge_file_result_free).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might be unnecessary, see comment below.

src/merge.rs Outdated
}

/// Acquire a pointer to the underlying raw options.
pub unsafe fn raw(&mut self) -> *const raw::git_merge_file_options {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this need to be pub?

Also, it seems like this could be done as a Binding impl. Is there any reason that was not done that way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, there could well be cargo cult issues going on here - I believe I copied this from MergeOptions. I'm not clear on the difference with implementing Binding, but it does need to be pub, since it is used in the merge_commits func in repo.rs. If impl Binding is the preferred way of doing this I can change over to use that?

More generally, I think the reasoning in my head was that structs like AnnotatedCommit or MergeFileResult are returned via libgit2 functions, and could be linked to the repository and should have a lifetime as such. Structs like MergeOptions or MergeFileOptions are created manually and consumed by the libgit2 functions, and as such would not have those same lifetime requirements.
I could be wrong, I am not all that familiar with how things work, but that is why I have copied from AnnotatedCommit to write MergeFileResult, and from MergeOptions to write MergeFileOptions.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hm, yea. I'm comfortable not including the lifetime here, so I pushed an update to drop it. git_merge_file_result seems to own its data, and I'm not too worried about it gaining internal references in the future.

@MikeJerred MikeJerred requested a review from ehuss January 5, 2025 10:27
MikeJerred and others added 9 commits March 17, 2025 13:53
For now I feel more comfortable not exposing this unless it is needed.
I don't feel comfortable making this copy, since it could accidentally
lead to creating multiple copies, which could then be confused as the
memory of these needs to be managed.
I feel comfortable not tying the lifetime here, since libgit2 fairly
clearly keeps only owned data in git_merge_file_result, without any
pointers to anything outside of it.
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 enabled auto-merge March 17, 2025 21:36
@ehuss ehuss added this pull request to the merge queue Mar 17, 2025
Merged via the queue into rust-lang:master with commit 258d3b6 Mar 17, 2025
7 checks passed
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.

None yet

2 participants