diff options
| author | Russell Belfer <rb@github.com> | 2014-02-04 10:33:30 -0800 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2014-02-04 10:33:30 -0800 |
| commit | 43709ca87811efc3c237eb719611f025502f3928 (patch) | |
| tree | 60d959aefc7bee941e8090f45e3ee0e9ef634583 | |
| parent | 882c7742711199f757305687c257ac97262a3a30 (diff) | |
| download | libgit2-43709ca87811efc3c237eb719611f025502f3928.tar.gz | |
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.
| -rw-r--r-- | src/index.c | 6 | ||||
| -rw-r--r-- | tests/index/tests.c | 34 |
2 files changed, 38 insertions, 2 deletions
diff --git a/src/index.c b/src/index.c index 1ab126c87..42eb5fd49 100644 --- a/src/index.c +++ b/src/index.c @@ -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; diff --git a/tests/index/tests.c b/tests/index/tests.c index 55a2f2c51..6e28af1f7 100644 --- a/tests/index/tests.c +++ b/tests/index/tests.c @@ -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); +} |
