Merge pull request #5533 from pjw91/fix-index-write Make git_index_write() generate valid v4 index
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
diff --git a/src/index.c b/src/index.c
index 907bd6d..36a8bdb 100644
--- a/src/index.c
+++ b/src/index.c
@@ -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;
diff --git a/tests/index/version.c b/tests/index/version.c
index 3827df8..b6c0b79 100644
--- a/tests/index/version.c
+++ b/tests/index/version.c
@@ -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)