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

Implement merging of index entries. #503

Merged
merged 1 commit into from Mar 13, 2015
Merged

Implement merging of index entries. #503

merged 1 commit into from Mar 13, 2015

Conversation

pks-t
Copy link
Member

@pks-t pks-t commented Mar 9, 2015

This allows us to generate a textual diff of conflicting files in
bare repositories by first performing a merge, retrieving the
IndexEntries of each conflict and then calling
Index.diff_index_entries(...).

@carlosmn
Copy link
Member

carlosmn commented Mar 9, 2015

The naming here seems odd. This is about merging, rather than diffing. I think this would go better as Repository.merge_file_from_index() (or maybe just merge_file() which we can overload depending on arguments) since it doesn't particularly need to be a method of Index as all we actually need is the repository and the index entries themselves.

We might want to have a convenience method on the index which takes in a path and extracts the three entries and performs the merge, but the basic method should be part of the repo.

ffi.NULL);
check_error(err)

return ffi.string(cmergeresult.ptr)
Copy link
Member

Choose a reason for hiding this comment

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

We need to free the buffer after extracting the string, something like

ret = ffi.string(cmergeresult.ptr)
C.git_buf_free(cmergeresult)

return ret

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed now. This also revealed some kind of bug where the ffi.string would get scrambled at the end when not creating it with cmergeresult.len. Seems as if the string is not correctly NULL-terminated in xdiff. I didn't dive into the issue, though.

Copy link
Member

Choose a reason for hiding this comment

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

That's odd, git_buf is meant to make sure there's always a NUL past the buffer to allow treating it as a C-string

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't have git_buf here, though, but a git_merge_file_result where git_merge_file_result.ptr is filled by xdl_merge in merge_file.c:154.

Copy link
Member

Choose a reason for hiding this comment

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

Oh right, I'm so used to making sure everything's a buf that I didn't notice the .ptr wasn't from that. Yeah, this is purely a ptr+len combination rather than a C string.

@pks-t
Copy link
Member Author

pks-t commented Mar 9, 2015

Agreed. I haven't been comfortable with the naming here, as well. Somehow I had the notion that the index was necessary somewhere, but now I see I've been wrong on that account. Will change that.

@pks-t pks-t changed the title Implement diffing of index entries. Implement merging of index entries. Mar 9, 2015
index = self.repo.merge_commits(c1, c2)
self.assertIsNotNone(index.conflicts)

for (a, t, o) in index.conflicts:
Copy link
Member

Choose a reason for hiding this comment

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

This loop would only ever loop once, and we know which file we want. Possibly asserting len(index.conflicts) and then looking up (a, t, o) = index.conflicts["conflict"] would show better that we're just testing the one file, rather than saying that every file conflict should be this way.

@carlosmn
Copy link
Member

Other than the loop in the test, 👍

This allows us to generate a textual diff of conflicting files in
bare repositories by performing a merge on the index followed by
repo.merge_file_from_index on the resulting index entries.
@jdavid
Copy link
Member

jdavid commented Mar 13, 2015

argh, forget it, I misread the code :/

@jdavid jdavid merged commit 367084e into libgit2:master Mar 13, 2015
@pks-t pks-t deleted the bare-conflicts branch March 17, 2015 09:52
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

3 participants