diff options
author | Edward Thomson <ethomson@microsoft.com> | 2015-11-17 02:06:52 +0300 |
---|---|---|
committer | Edward Thomson <ethomson@edwardthomson.com> | 2015-11-17 06:59:02 +0300 |
commit | 5f32c50683cefaf51fa4f8825abfe533f36fe6f3 (patch) | |
tree | fa31ad3589a7044e0c31757943600a9e1fcdfe4c /tests/index | |
parent | c30051f0d0fd6ff74d6e2fbe0fc5b0209ecf8b85 (diff) |
racy: make git_index_read_index handle raciness
Ensure that `git_index_read_index` clears the uptodate bit on
files that it modifies.
Further, do not propagate the cache from an on-disk index into
another on-disk index. Although this should not be done, as
`git_index_read_index` is used to bring an in-memory index into
another index (that may or may not be on-disk), ensure that we do
not accidentally bring in these bits when misused.
Diffstat (limited to 'tests/index')
-rw-r--r-- | tests/index/racy.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/tests/index/racy.c b/tests/index/racy.c index ce395316f..f7440c3af 100644 --- a/tests/index/racy.c +++ b/tests/index/racy.c @@ -278,3 +278,51 @@ void test_index_racy__read_tree_clears_uptodate_bit(void) git_tree_free(tree); git_index_free(index); } + +void test_index_racy__read_index_smudges(void) +{ + git_index *index, *newindex; + const git_index_entry *entry; + + /* if we are reading an index into our new index, ensure that any + * racy entries in the index that we're reading are smudged so that + * we don't propagate their timestamps without further investigation. + */ + setup_race(); + + cl_git_pass(git_repository_index(&index, g_repo)); + cl_git_pass(git_index_new(&newindex)); + cl_git_pass(git_index_read_index(newindex, index)); + + cl_assert(entry = git_index_get_bypath(newindex, "A", 0)); + cl_assert_equal_i(0, entry->file_size); + + git_index_free(index); + git_index_free(newindex); +} + +void test_index_racy__read_index_clears_uptodate_bit(void) +{ + git_index *index, *newindex; + const git_index_entry *entry; + git_oid id; + + setup_uptodate_files(); + + cl_git_pass(git_repository_index(&index, g_repo)); + cl_git_pass(git_index_new(&newindex)); + cl_git_pass(git_index_read_index(newindex, index)); + + /* ensure that files brought in from the other index are not uptodate */ + cl_assert((entry = git_index_get_bypath(newindex, "A", 0))); + cl_assert_equal_i(0, (entry->flags_extended & GIT_IDXENTRY_UPTODATE)); + + cl_assert((entry = git_index_get_bypath(newindex, "B", 0))); + cl_assert_equal_i(0, (entry->flags_extended & GIT_IDXENTRY_UPTODATE)); + + cl_assert((entry = git_index_get_bypath(newindex, "C", 0))); + cl_assert_equal_i(0, (entry->flags_extended & GIT_IDXENTRY_UPTODATE)); + + git_index_free(index); + git_index_free(newindex); +} |