Skip to content

Commit 89ddd0f

Browse files
authored
Merge pull request libgit2#5533 from pjw91/fix-index-write
Make git_index_write() generate valid v4 index
2 parents 27cb4e0 + 1a89900 commit 89ddd0f

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

src/index.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2744,7 +2744,7 @@ static int write_disk_entry(git_filebuf *file, git_index_entry *entry, const cha
27442744
++same_len;
27452745
}
27462746
path_len -= same_len;
2747-
varint_len = git_encode_varint(NULL, 0, same_len);
2747+
varint_len = git_encode_varint(NULL, 0, strlen(last) - same_len);
27482748
}
27492749

27502750
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
27952795

27962796
if (last) {
27972797
varint_len = git_encode_varint((unsigned char *) path,
2798-
disk_size, same_len);
2798+
disk_size, strlen(last) - same_len);
27992799
assert(varint_len > 0);
28002800
path += varint_len;
28012801
disk_size -= varint_len;

tests/index/version.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void test_index_version__can_write_v4(void)
4343
"xz",
4444
"xyzzyx"
4545
};
46+
git_repository *repo;
4647
git_index_entry entry;
4748
git_index *index;
4849
size_t i;
@@ -63,7 +64,8 @@ void test_index_version__can_write_v4(void)
6364
cl_git_pass(git_index_write(index));
6465
git_index_free(index);
6566

66-
cl_git_pass(git_repository_index(&index, g_repo));
67+
cl_git_pass(git_repository_open(&repo, git_repository_path(g_repo)));
68+
cl_git_pass(git_repository_index(&index, repo));
6769
cl_assert(git_index_version(index) == 4);
6870

6971
for (i = 0; i < ARRAY_SIZE(paths); i++) {
@@ -74,6 +76,7 @@ void test_index_version__can_write_v4(void)
7476
}
7577

7678
git_index_free(index);
79+
git_repository_free(repo);
7780
}
7881

7982
void test_index_version__v4_uses_path_compression(void)

0 commit comments

Comments
 (0)