Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2015-11-13 23:32:48 +0300
committerEdward Thomson <ethomson@edwardthomson.com>2015-11-17 06:58:58 +0300
commitd1101263f751a33d70ec585da908bec938f587fd (patch)
treee6680d1f92dc1a17e6d837fe23bbc75bd813d5ef /tests/index
parentcb0ff012d3cb9658b88ad4f752046286ba5ea442 (diff)
index: don't detect raciness in uptodate entries
Keep track of entries that we believe are up-to-date, because we added the index entries since the index was loaded. This prevents us from unnecessarily examining files that we wrote during the cleanup of racy entries (when we smudge racily clean files that have a timestamp newer than or equal to the index's timestamp when we read it). Without keeping track of this, we would examine every file that we just checked out for raciness, since all their timestamps would be newer than the index's timestamp.
Diffstat (limited to 'tests/index')
-rw-r--r--tests/index/racy.c77
1 files changed, 77 insertions, 0 deletions
diff --git a/tests/index/racy.c b/tests/index/racy.c
index df25c851c..6ff12a39a 100644
--- a/tests/index/racy.c
+++ b/tests/index/racy.c
@@ -145,3 +145,80 @@ void test_index_racy__empty_file_after_smudge(void)
git_buf_free(&path);
git_diff_free(diff);
}
+
+static void setup_uptodate_files(void)
+{
+ git_buf path = GIT_BUF_INIT;
+ git_index *index;
+ git_index_entry new_entry = {0};
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ cl_git_pass(git_buf_joinpath(&path, git_repository_workdir(g_repo), "A"));
+ cl_git_mkfile(path.ptr, "A");
+
+ /* Put 'A' into the index */
+ cl_git_pass(git_index_add_bypath(index, "A"));
+
+ /* Put 'B' into the index */
+ new_entry.path = "B";
+ new_entry.mode = GIT_FILEMODE_BLOB;
+ cl_git_pass(git_index_add(index, &new_entry));
+
+ /* Put 'C' into the index */
+ new_entry.path = "C";
+ new_entry.mode = GIT_FILEMODE_BLOB;
+ cl_git_pass(git_index_add_frombuffer(index, &new_entry, "hello!\n", 7));
+
+ git_index_free(index);
+ git_buf_free(&path);
+}
+
+void test_index_racy__adding_to_index_is_uptodate(void)
+{
+ git_index *index;
+ const git_index_entry *entry;
+
+ setup_uptodate_files();
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+
+ /* ensure that they're all uptodate */
+ cl_assert((entry = git_index_get_bypath(index, "A", 0)));
+ cl_assert_equal_i(GIT_IDXENTRY_UPTODATE, (entry->flags_extended & GIT_IDXENTRY_UPTODATE));
+
+ cl_assert((entry = git_index_get_bypath(index, "B", 0)));
+ cl_assert_equal_i(GIT_IDXENTRY_UPTODATE, (entry->flags_extended & GIT_IDXENTRY_UPTODATE));
+
+ cl_assert((entry = git_index_get_bypath(index, "C", 0)));
+ cl_assert_equal_i(GIT_IDXENTRY_UPTODATE, (entry->flags_extended & GIT_IDXENTRY_UPTODATE));
+
+ cl_git_pass(git_index_write(index));
+
+ git_index_free(index);
+}
+
+void test_index_racy__reading_clears_uptodate_bit(void)
+{
+ git_index *index;
+ const git_index_entry *entry;
+
+ setup_uptodate_files();
+
+ cl_git_pass(git_repository_index(&index, g_repo));
+ cl_git_pass(git_index_write(index));
+
+ cl_git_pass(git_index_read(index, true));
+
+ /* ensure that no files are uptodate */
+ cl_assert((entry = git_index_get_bypath(index, "A", 0)));
+ cl_assert_equal_i(0, (entry->flags_extended & GIT_IDXENTRY_UPTODATE));
+
+ cl_assert((entry = git_index_get_bypath(index, "B", 0)));
+ cl_assert_equal_i(0, (entry->flags_extended & GIT_IDXENTRY_UPTODATE));
+
+ cl_assert((entry = git_index_get_bypath(index, "C", 0)));
+ cl_assert_equal_i(0, (entry->flags_extended & GIT_IDXENTRY_UPTODATE));
+
+ git_index_free(index);
+}