Skip to content

[RFC] Repository: get all values from git_merge_file_from_index #1376

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eantoranz
Copy link
Contributor

In Repository.merge_file_from_index, pygit2 is only returning the resulting content out of the merge, however other values might be relevant like the filemode.

Add an optional flag to make it possible to get all the values coming out of git_merge_file_from_index instead of just the file content.

@eantoranz
Copy link
Contributor Author

I know right from the get go that this is not very elegant but I wanted to start the conversation somewhere.

I am working on a simplified rebasing tool. I am dealing with 3way-merges of blobs and I did not find that git_merge_file is mapped in pygit2 so I went the easy but hackish way and I am using Repository.merge_trees(), you can take a look over here. I don't like it because it means I need to write tree objects just to be able to merge the blobs which I think is an overkill, but at least it works.

I noticed that I could use Repository.merge_file_from_index() however I noticed that it is not giving up any of the values coming out of git_merge_file_from_index() except for the content of the file. At least for my use-case, I need to get the filemode as it is relevant for the merges I am attempting to make.

So I added the additional flag to be able to get all the values without breaking the implementation of existing users of the method.

Let me know what you think, if you don't mind.

Thanks!

@eantoranz eantoranz force-pushed the 3way-merge-blobs-rename-- branch from a60a7bf to 8cdac54 Compare June 10, 2025 20:44
In Repository.merge_file_from_index, pygit2 is only returning
the resulting content out of the merge, however other values might be
relevant like the filemode.

Add an optional flag to make it possible to get all the values
coming out of git_merge_file_from_index instead of just
the file content.
@eantoranz eantoranz force-pushed the 3way-merge-blobs-rename-- branch from 8cdac54 to a8e75e2 Compare June 10, 2025 20:51
C.git_merge_file_result_free(cmergeresult)

return ret
if not return_full:
return content
Copy link
Member

Choose a reason for hiding this comment

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

Could you add a deprecation warning?

if not return_full:
return content

return automergeable, content, filemode, path
Copy link
Member

Choose a reason for hiding this comment

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

Could you return a smarter object, like a dataclass? With the name MergeFileResult, and using "contents" instead of "content" (as is written in the libgit2 reference documentation).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep... will do both things. Thanks for the feedback.

Copy link
Member

Choose a reason for hiding this comment

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

Unit tests too please. Thanks!

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