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

Implementing merge with default options #295

Merged
merged 9 commits into from
Dec 10, 2013
Merged

Conversation

victorgp
Copy link
Contributor

@victorgp victorgp commented Dec 4, 2013

This pull request implements the merge operation based on the default options libgit2 defines.

The merge receives an Oid and returns a MergeResult object.

This MergeResult object is quite similar than the git_merge_result libgit2 implements. it has:

->is_fastforward: boolean field that indicates the merge was fastforward
->is_uptodate: boolean field that indicates the merge was already up to date
->fastforward_oid: python Oid object with the new fastforward Oid to be the new head (only if the merge was fastforward, None otherwise)
->status: dict with the repository status after the merge (if the merge was not fastforward, either there were conflicts or not, an empty dict otherwise)

Some notes:
-The merge, as it name says, only does the merge, it does not perform any commit nor updates the references (ex. in the fastforward case)
-This method does not allow customized parameters for the merge operation, i would like to leave that for a second iteration over this method and let's it work for the moment with the default options defined in the libgit2 constant GIT_MERGE_OPTS_INIT.

The tests i implemented would help to understand this behaviour easily.

Extra: there is also a minor change in the Repository_status method, i removed the args parameter because it wasn't being used anywhere within the method.

@jdavid
Copy link
Member

jdavid commented Dec 5, 2013

Hello Victor, thanks for contributing.

We have the general policy to wrap git structs, so it should be like:

typedef struct {
    PyObject_HEAD
    git_merge_result *result;
} MergeResult;

Note that Repository_status is "expensive" and may fail. Do not keep it.

And please update the documentation docs/merge.rst

@victorgp
Copy link
Contributor Author

victorgp commented Dec 5, 2013

Thanks @jdavid for your comments.

About the MergeResult struct, you are right, i'll implement it in that way.

@victorgp
Copy link
Contributor Author

victorgp commented Dec 9, 2013

Fixes done, please take a look and tell me if you like them.
Thanks

@jdavid
Copy link
Member

jdavid commented Dec 10, 2013

Why do you need MergeResult.index?

merge = repo.merge(...)
merge.index

How that is better than:

merge = repo.merge(...)
repo.index

If MergeResult does not keep a reference to the repository, code would be simpler.

@victorgp
Copy link
Contributor Author

Actually i don't need it but since the git_merge_result struct has an index field, i supposed you also wanted it here.

I'll remove it so it's simpler

@jdavid
Copy link
Member

jdavid commented Dec 10, 2013

Okey, I missed that. Anyway if you don't need it just remove.

@victorgp
Copy link
Contributor Author

Index removed!

@jdavid jdavid merged commit 1938147 into libgit2:master Dec 10, 2013
@alexband
Copy link

alexband commented Jan 9, 2014

@victorgp does merge_result has any attributes to indicate this merge is viable? like will it produce conflicts?

there is 'is_fastforward', 'is_up_to_date', but no other identification for whether the merge is viable, (is it can be merged but not fastforward merge?)

@alexband
Copy link

alexband commented Jan 9, 2014

sorry I found that merge_result has an index object, that explains

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.

4 participants