Commit 43709ca8 by Russell Belfer

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.
parent 882c7742
......@@ -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);
}
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