Commit 0972c592 by Edward Thomson

Two-phase index merging

When three-way merging indexes, we previously changed each path
as we read them, which would lead to us adding an index entry for
'foo', then removing an index entry for 'foo/file'.  With the new
index requirements, this is not allowed.  Removing entries in the
merged index, then adding them, resolves this.  In the previous
example, we now remove 'foo/file' before adding 'foo'.
parent b747eb14
...@@ -2398,12 +2398,21 @@ int git_merge__indexes(git_repository *repo, git_index *index_new) ...@@ -2398,12 +2398,21 @@ int git_merge__indexes(git_repository *repo, git_index *index_new)
goto done; goto done;
} }
/* Update the new index */ /* Remove removed items from the index */
git_vector_foreach(&paths, i, path) { git_vector_foreach(&paths, i, path) {
if ((e = git_index_get_bypath(index_new, path, 0)) != NULL) if ((e = git_index_get_bypath(index_new, path, 0)) == NULL) {
error = git_index_add(index_repo, e); if ((error = git_index_remove(index_repo, path, 0)) < 0 &&
else error != GIT_ENOTFOUND)
error = git_index_remove(index_repo, path, 0); goto done;
}
}
/* Add updated items to the index */
git_vector_foreach(&paths, i, path) {
if ((e = git_index_get_bypath(index_new, path, 0)) != NULL) {
if ((error = git_index_add(index_repo, e)) < 0)
goto done;
}
} }
/* Add conflicts */ /* Add conflicts */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment