mirror of
https://git.proxmox.com/git/libgit2
synced 2026-01-06 22:58:58 +00:00
Fix typo setting sorted flag when reloading index
This fixes a typo I made for setting the sorted flag on the index after a reload. That typo didn't actually cause any test failures so I'm also adding a test that explicitly checks that the index is correctly sorted after a reload when ignoring case and when not.
This commit is contained in:
parent
882c774271
commit
43709ca878
@ -1811,8 +1811,10 @@ static int parse_index(git_index *index, const char *buffer, size_t buffer_size)
|
||||
|
||||
#undef seek_forward
|
||||
|
||||
/* Entries are stored case-sensitively on disk. */
|
||||
git_vector_set_sorted(&index->entries, index->ignore_case);
|
||||
/* Entries are stored case-sensitively on disk, so re-sort now if
|
||||
* in-memory index is supposed to be case-insensitive
|
||||
*/
|
||||
git_vector_set_sorted(&index->entries, !index->ignore_case);
|
||||
git_vector_sort(&index->entries);
|
||||
|
||||
return 0;
|
||||
|
||||
@ -543,3 +543,37 @@ void test_index_tests__corrupted_extension(void)
|
||||
|
||||
cl_git_fail_with(git_index_open(&index, TEST_INDEXBAD_PATH), GIT_ERROR);
|
||||
}
|
||||
|
||||
static void assert_index_is_sorted(git_index *index)
|
||||
{
|
||||
git_vector *entries = &index->entries;
|
||||
size_t i;
|
||||
|
||||
cl_assert(git_vector_is_sorted(entries));
|
||||
|
||||
for (i = 1; i < git_vector_length(entries); ++i) {
|
||||
git_index_entry *prev = git_vector_get(entries, i - 1);
|
||||
git_index_entry *curr = git_vector_get(entries, i);
|
||||
cl_assert(index->entries._cmp(prev, curr) <= 0);
|
||||
}
|
||||
}
|
||||
|
||||
void test_index_tests__reload_while_ignoring_case(void)
|
||||
{
|
||||
git_index *index;
|
||||
unsigned int caps;
|
||||
|
||||
cl_git_pass(git_index_open(&index, TEST_INDEX_PATH));
|
||||
assert_index_is_sorted(index);
|
||||
|
||||
caps = git_index_caps(index);
|
||||
cl_git_pass(git_index_set_caps(index, caps &= ~GIT_INDEXCAP_IGNORE_CASE));
|
||||
cl_git_pass(git_index_read(index, true));
|
||||
assert_index_is_sorted(index);
|
||||
|
||||
cl_git_pass(git_index_set_caps(index, caps | GIT_INDEXCAP_IGNORE_CASE));
|
||||
cl_git_pass(git_index_read(index, true));
|
||||
assert_index_is_sorted(index);
|
||||
|
||||
git_index_free(index);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user