Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Merge trees #1389

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

Merged
merged 3 commits into from
May 1, 2013
Merged

Merge trees #1389

merged 3 commits into from
May 1, 2013

Conversation

ethomson
Copy link
Member

@ethomson ethomson commented Mar 4, 2013

I'm trying to break that big nasty merge PR into smaller, more manageable PRs. These two commits will take 2 trees and an optional common ancestor tree, and produce a git_merge_index that represents the changes.

A git_merge_index is remarkably similar to a git_index, however conflicts are tracked differently. A git_index records conflicts by filename only, which makes determining what happened during a rename conflict impossible. A git_merge_index, in contrast, keeps track of the files as they were renamed.

Consider that there exists some file where file A1 is renamed to B1 in one side and C1 in the other, while the file A2 is renamed to A2 and A3. The resultant git_index will contain the following entries:

100644 1bdef746acfcabf0c1229b6afa34164bf8f3ce7b 1   A1
100644 8c4bc39a4ee424d8a5d550c73f471dafbc5023e0 1   A2
100644 1bdef746acfcabf0c1229b6afa34164bf8f3ce7b 3   B1
100644 8c4bc39a4ee424d8a5d550c73f471dafbc5023e0 3   B2
100644 1bdef746acfcabf0c1229b6afa34164bf8f3ce7b 2   C1
100644 8c4bc39a4ee424d8a5d550c73f471dafbc5023e0 2   C2

A git_merge_index, however, contains conflict grouped by the conflict instead of by the filename. For example:

{
    100644 1bdef746acfcabf0c1229b6afa34164bf8f3ce7b    A1
    100644 1bdef746acfcabf0c1229b6afa34164bf8f3ce7b    B1
    100644 1bdef746acfcabf0c1229b6afa34164bf8f3ce7b    C1
},
{
    100644 8c4bc39a4ee424d8a5d550c73f471dafbc5023e0    A2
    100644 8c4bc39a4ee424d8a5d550c73f471dafbc5023e0    B2
    100644 8c4bc39a4ee424d8a5d550c73f471dafbc5023e0    C2
},

This has additional data above a git_merge_index and is trivially convertable to a git_index that would represent the merged output or - like an index - into a git_tree.

Looking only at the above example, one could make an argument that we could somehow tie the conflict entries back together using the same algorithm that determined that they were rename conflicts in the first place. Even if you wanted to take the computational hit of recomputing the similarity each time you reload the index (and you probably don't), it's not deterministic.

In a rename 2 -> 1 conflict, for example, the ancestors of the conflict isn't even recorded. Consider files A and B both renamed to C in the two branches. The resultant conflicts only show the two sides - presumably as a result of these being treated like add/add conflicts:

100644 bcf3dc80800397ab485dd453c822a437c03662e6 2   C
100644 9141c522b4f783453452c318d190288383b8c5d5 3   C

Further, since core git treats these conflicts as separate between the ours and theirs side, once you began resolving these sides independently, it's still more difficult to pair these sides back up.

Thus, I think it makes more sense to track conflicts as conflicts and not track the conflicts by filename.

const git_merge_tree_opts *opts);

/**
* Produces a `git_index` from the given `git_merge_index`
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add a sentence explaining that the merge index is a superset of what can be stored in the index and this flattens the in-memory merge index data when it's time to write the merge results into the actual index? Just thinking about someone who is coming new to this trying to make out how to use the API.

@ethomson
Copy link
Member Author

Removed git_merge_index in favor of git_index. The rename conflicts (in 04c7d73) now use an optional extension (NAME) as discussed on the core git mailing list.

I propose we not take 04c7d73 without further coordination with git proper. However it is included for completeness since we removed rename detection in merge with the removal of git_merge_index.

@ethomson
Copy link
Member Author

@arrbee by removing git_merge_index, this should address your comments about the lack of documentation of such. :) The in-memory representation of a merge diff is now internal (git_merge_diff).

* will track renames.
*
* The returned merge_index must be freed explicitly with
* `git_merge_index_free`.
Copy link
Member

Choose a reason for hiding this comment

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

Outta date.

Edward Thomson and others added 2 commits April 30, 2013 15:31
@ethomson
Copy link
Member Author

@vmg thanks - I cleaned up that documentation comment as well as some other names that were still sort of sloppily referring to the late, not-so-great "merge index". Also rebased on latest development.

char *ancestor;
char *ours;
char *theirs;
} git_index_name_entry;
Copy link
Member

Choose a reason for hiding this comment

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

Some nitpicking: I'd like to have _name and _reuc functions under the sys/ namespace, since they are not supposed to be used by normal index consumers. Can you move them? :)

Copy link
Member Author

Choose a reason for hiding this comment

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

@vmg you know I love the picking of nits. They have been moved.

vmg pushed a commit that referenced this pull request May 1, 2013
@vmg vmg merged commit 758e50c into libgit2:development May 1, 2013
@vmg
Copy link
Member

vmg commented May 1, 2013

lolshipped

conflict->their_status == GIT_DELTA_RENAMED)
return 0;

ancestor_empty = !GIT_MERGE_INDEX_ENTRY_EXISTS(conflict->ancestor_entry);
Copy link
Member

Choose a reason for hiding this comment

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

@ethomson: This variable is set but not used anywhere. Can you double-check please?

@nulltoken nulltoken mentioned this pull request Jul 30, 2013
phatblat pushed a commit to phatblat/libgit2 that referenced this pull request Sep 13, 2014
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.

3 participants