mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-06 07:00:27 +00:00
Merge pull request #3808 from ethomson/read_index_fixes
`git_index_read_index` fixes
This commit is contained in:
commit
f0ee795ccb
14
src/index.c
14
src/index.c
@ -2968,6 +2968,8 @@ int git_index_read_index(
|
||||
*remove_entry = NULL;
|
||||
int diff;
|
||||
|
||||
error = 0;
|
||||
|
||||
if (old_entry && new_entry)
|
||||
diff = git_index_entry_cmp(old_entry, new_entry);
|
||||
else if (!old_entry && new_entry)
|
||||
@ -2985,7 +2987,8 @@ int git_index_read_index(
|
||||
/* Path and stage are equal, if the OID is equal, keep it to
|
||||
* keep the stat cache data.
|
||||
*/
|
||||
if (git_oid_equal(&old_entry->id, &new_entry->id)) {
|
||||
if (git_oid_equal(&old_entry->id, &new_entry->id) &&
|
||||
old_entry->mode == new_entry->mode) {
|
||||
add_entry = (git_index_entry *)old_entry;
|
||||
} else {
|
||||
dup_entry = (git_index_entry *)new_entry;
|
||||
@ -2996,8 +2999,17 @@ int git_index_read_index(
|
||||
if (dup_entry) {
|
||||
if ((error = index_entry_dup_nocache(&add_entry, index, dup_entry)) < 0)
|
||||
goto done;
|
||||
|
||||
index_entry_adjust_namemask(add_entry,
|
||||
((struct entry_internal *)add_entry)->pathlen);
|
||||
}
|
||||
|
||||
/* invalidate this path in the tree cache if this is new (to
|
||||
* invalidate the parent trees)
|
||||
*/
|
||||
if (dup_entry && !remove_entry && index->tree)
|
||||
git_tree_cache_invalidate_path(index->tree, dup_entry->path);
|
||||
|
||||
if (add_entry) {
|
||||
if ((error = git_vector_insert(&new_entries, add_entry)) == 0)
|
||||
INSERT_IN_MAP_EX(index, new_entries_map, add_entry, error);
|
||||
|
@ -71,3 +71,58 @@ void test_index_read_index__maintains_stat_cache(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static bool roundtrip_with_read_index(const char *tree_idstr)
|
||||
{
|
||||
git_oid tree_id, new_tree_id;
|
||||
git_tree *tree;
|
||||
git_index *tree_index;
|
||||
|
||||
cl_git_pass(git_oid_fromstr(&tree_id, tree_idstr));
|
||||
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
|
||||
cl_git_pass(git_index_new(&tree_index));
|
||||
cl_git_pass(git_index_read_tree(tree_index, tree));
|
||||
cl_git_pass(git_index_read_index(_index, tree_index));
|
||||
cl_git_pass(git_index_write_tree(&new_tree_id, _index));
|
||||
|
||||
git_tree_free(tree);
|
||||
git_index_free(tree_index);
|
||||
|
||||
return git_oid_equal(&tree_id, &new_tree_id);
|
||||
}
|
||||
|
||||
void test_index_read_index__produces_treesame_indexes(void)
|
||||
{
|
||||
roundtrip_with_read_index("53fc32d17276939fc79ed05badaef2db09990016");
|
||||
roundtrip_with_read_index("944c0f6e4dfa41595e6eb3ceecdb14f50fe18162");
|
||||
roundtrip_with_read_index("1810dff58d8a660512d4832e740f692884338ccd");
|
||||
roundtrip_with_read_index("d52a8fe84ceedf260afe4f0287bbfca04a117e83");
|
||||
roundtrip_with_read_index("c36d8ea75da8cb510fcb0c408c1d7e53f9a99dbe");
|
||||
roundtrip_with_read_index("7b2417a23b63e1fdde88c80e14b33247c6e5785a");
|
||||
roundtrip_with_read_index("f82a8eb4cb20e88d1030fd10d89286215a715396");
|
||||
roundtrip_with_read_index("fd093bff70906175335656e6ce6ae05783708765");
|
||||
roundtrip_with_read_index("ae90f12eea699729ed24555e40b9fd669da12a12");
|
||||
}
|
||||
|
||||
void test_index_read_index__read_and_writes(void)
|
||||
{
|
||||
git_oid tree_id, new_tree_id;
|
||||
git_tree *tree;
|
||||
git_index *tree_index, *new_index;
|
||||
|
||||
cl_git_pass(git_oid_fromstr(&tree_id, "ae90f12eea699729ed24555e40b9fd669da12a12"));
|
||||
cl_git_pass(git_tree_lookup(&tree, _repo, &tree_id));
|
||||
cl_git_pass(git_index_new(&tree_index));
|
||||
cl_git_pass(git_index_read_tree(tree_index, tree));
|
||||
cl_git_pass(git_index_read_index(_index, tree_index));
|
||||
cl_git_pass(git_index_write(_index));
|
||||
|
||||
cl_git_pass(git_index_open(&new_index, git_index_path(_index)));
|
||||
cl_git_pass(git_index_write_tree_to(&new_tree_id, new_index, _repo));
|
||||
|
||||
cl_assert_equal_oid(&tree_id, &new_tree_id);
|
||||
|
||||
git_tree_free(tree);
|
||||
git_index_free(tree_index);
|
||||
git_index_free(new_index);
|
||||
}
|
||||
|
@ -165,3 +165,46 @@ void test_rebase_inmemory__no_common_ancestor(void)
|
||||
git_reference_free(upstream_ref);
|
||||
git_rebase_free(rebase);
|
||||
}
|
||||
|
||||
void test_rebase_inmemory__with_directories(void)
|
||||
{
|
||||
git_rebase *rebase;
|
||||
git_reference *branch_ref, *upstream_ref;
|
||||
git_annotated_commit *branch_head, *upstream_head;
|
||||
git_rebase_operation *rebase_operation;
|
||||
git_oid commit_id, tree_id;
|
||||
git_commit *commit;
|
||||
git_rebase_options opts = GIT_REBASE_OPTIONS_INIT;
|
||||
|
||||
opts.inmemory = true;
|
||||
|
||||
git_oid_fromstr(&tree_id, "a4d6d9c3d57308fd8e320cf2525bae8f1adafa57");
|
||||
|
||||
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/deep_gravy"));
|
||||
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
|
||||
|
||||
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
|
||||
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
|
||||
|
||||
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, &opts));
|
||||
|
||||
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
|
||||
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
|
||||
NULL, NULL));
|
||||
|
||||
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
|
||||
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
|
||||
NULL, NULL));
|
||||
|
||||
cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
|
||||
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
|
||||
cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit));
|
||||
|
||||
git_commit_free(commit);
|
||||
git_annotated_commit_free(branch_head);
|
||||
git_annotated_commit_free(upstream_head);
|
||||
git_reference_free(branch_ref);
|
||||
git_reference_free(upstream_ref);
|
||||
git_rebase_free(rebase);
|
||||
}
|
||||
|
@ -750,3 +750,42 @@ void test_rebase_merge__custom_merge_options(void)
|
||||
git_rebase_free(rebase);
|
||||
}
|
||||
|
||||
void test_rebase_merge__with_directories(void)
|
||||
{
|
||||
git_rebase *rebase;
|
||||
git_reference *branch_ref, *upstream_ref;
|
||||
git_annotated_commit *branch_head, *upstream_head;
|
||||
git_rebase_operation *rebase_operation;
|
||||
git_oid commit_id, tree_id;
|
||||
git_commit *commit;
|
||||
|
||||
git_oid_fromstr(&tree_id, "a4d6d9c3d57308fd8e320cf2525bae8f1adafa57");
|
||||
|
||||
cl_git_pass(git_reference_lookup(&branch_ref, repo, "refs/heads/deep_gravy"));
|
||||
cl_git_pass(git_reference_lookup(&upstream_ref, repo, "refs/heads/veal"));
|
||||
|
||||
cl_git_pass(git_annotated_commit_from_ref(&branch_head, repo, branch_ref));
|
||||
cl_git_pass(git_annotated_commit_from_ref(&upstream_head, repo, upstream_ref));
|
||||
|
||||
cl_git_pass(git_rebase_init(&rebase, repo, branch_head, upstream_head, NULL, NULL));
|
||||
|
||||
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
|
||||
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
|
||||
NULL, NULL));
|
||||
|
||||
cl_git_pass(git_rebase_next(&rebase_operation, rebase));
|
||||
cl_git_pass(git_rebase_commit(&commit_id, rebase, NULL, signature,
|
||||
NULL, NULL));
|
||||
|
||||
cl_git_fail_with(GIT_ITEROVER, git_rebase_next(&rebase_operation, rebase));
|
||||
|
||||
cl_git_pass(git_commit_lookup(&commit, repo, &commit_id));
|
||||
cl_assert_equal_oid(&tree_id, git_commit_tree_id(commit));
|
||||
|
||||
git_commit_free(commit);
|
||||
git_annotated_commit_free(branch_head);
|
||||
git_annotated_commit_free(upstream_head);
|
||||
git_reference_free(branch_ref);
|
||||
git_reference_free(upstream_ref);
|
||||
git_rebase_free(rebase);
|
||||
}
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
tests/resources/rebase/.gitted/refs/heads/deep_gravy
Normal file
BIN
tests/resources/rebase/.gitted/refs/heads/deep_gravy
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user