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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

MikeJerred
Copy link

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.

Comment on lines 1373 to 1377
impl Clone for git_merge_file_result {
fn clone(&self) -> git_merge_file_result {
*self
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you say why this is manually implemented instead of being derive?

src/repo.rs Outdated
opts: Option<&mut MergeFileOptions>,
) -> Result<MergeFileResult<'_>, Error> {
let create_raw_entry = |entry: &IndexEntry| -> Result<raw::git_index_entry, Error> {
let path = CString::new(&entry.path[..])?;
Copy link
Contributor

Choose a reason for hiding this comment

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

This does not look correct to me because the CString is freed at the end of the closure, and thus the pointer in the git_index_entry is dangling.

Also, would it be possible to factor this code in some way (either a function or macro) to avoid duplicating it? And preferably in a way that would safely manage the allocation here.

src/repo.rs Outdated
Comment on lines 2559 to 2565
let mut ret = raw::git_merge_file_result {
automergeable: 0,
path: ptr::null_mut(),
mode: 0,
ptr: ptr::null_mut(),
len: 0,
};
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's fine to just use a zeroed struct (at least that's what libgit2 seems to do).

Suggested change
let mut ret = raw::git_merge_file_result {
automergeable: 0,
path: ptr::null_mut(),
mode: 0,
ptr: ptr::null_mut(),
len: 0,
};
let mut ret = unsafe { mem::zeroed() };

src/merge.rs Outdated
}
}

impl<'repo> std::fmt::Display for MergeFileResult<'repo> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can this impl Debug instead of Display?

@MikeJerred MikeJerred requested a review from ehuss November 5, 2024 12:24
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