Unverified Commit 89ddd0fc by Patrick Steinhardt Committed by GitHub

Merge pull request #5533 from pjw91/fix-index-write

Make git_index_write() generate valid v4 index
parents 27cb4e0e 1a899008
......@@ -2744,7 +2744,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
++same_len;
}
path_len -= same_len;
varint_len = git_encode_varint(NULL, 0, same_len);
varint_len = git_encode_varint(NULL, 0, strlen(last) - same_len);
}
disk_size = index_entry_size(path_len, varint_len, entry->flags);
......@@ -2795,7 +2795,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
if (last) {
varint_len = git_encode_varint((unsigned char *) path,
disk_size, same_len);
disk_size, strlen(last) - same_len);
assert(varint_len > 0);
path += varint_len;
disk_size -= varint_len;
......
......@@ -43,6 +43,7 @@ void test_index_version__can_write_v4(void)
"xz",
"xyzzyx"
};
git_repository *repo;
git_index_entry entry;
git_index *index;
size_t i;
......@@ -63,7 +64,8 @@ void test_index_version__can_write_v4(void)
cl_git_pass(git_index_write(index));
git_index_free(index);
cl_git_pass(git_repository_index(&index, g_repo));
cl_git_pass(git_repository_open(&repo, git_repository_path(g_repo)));
cl_git_pass(git_repository_index(&index, repo));
cl_assert(git_index_version(index) == 4);
for (i = 0; i < ARRAY_SIZE(paths); i++) {
......@@ -74,6 +76,7 @@ void test_index_version__can_write_v4(void)
}
git_index_free(index);
git_repository_free(repo);
}
void test_index_version__v4_uses_path_compression(void)
......
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