Commit e44abe16bd20512c76331e6889f390e35993153a

Carlos Martín Nieto 2015-06-16T08:51:45

tests: tick the index when we count OID calculations These tests want to test that we don't recalculate entries which match the index already. This is however something we force when truncating racily-clean entries. Tick the index forward as we know that we don't perform the modifications which the racily-clean code is trying to avoid.

diff --git a/tests/checkout/checkout_helpers.c b/tests/checkout/checkout_helpers.c
index 06b4e06..c2e65b8 100644
--- a/tests/checkout/checkout_helpers.c
+++ b/tests/checkout/checkout_helpers.c
@@ -2,6 +2,7 @@
 #include "checkout_helpers.h"
 #include "refs.h"
 #include "fileops.h"
+#include "index.h"
 
 void assert_on_branch(git_repository *repo, const char *branch)
 {
@@ -128,3 +129,22 @@ int checkout_count_callback(
 
 	return 0;
 }
+
+void tick_index(git_index *index)
+{
+	git_time_t ts;
+	struct timespec times[2];
+
+	cl_assert(index->on_disk);
+	cl_assert(git_index_path(index));
+
+	cl_git_pass(git_index_read(index, true));
+	ts = index->stamp.mtime;
+
+	times[0].tv_sec  = UTIME_OMIT; /* dont' change the atime */
+	times[0].tv_nsec = UTIME_OMIT; /* dont' change the atime */
+	times[1].tv_sec  = ts + 1;
+	times[1].tv_nsec = 0;
+	cl_git_pass(p_utimensat(AT_FDCWD, git_index_path(index), times, 0));
+	cl_git_pass(git_index_read(index, true));
+}
diff --git a/tests/checkout/checkout_helpers.h b/tests/checkout/checkout_helpers.h
index 705ee90..6058a19 100644
--- a/tests/checkout/checkout_helpers.h
+++ b/tests/checkout/checkout_helpers.h
@@ -27,3 +27,5 @@ extern int checkout_count_callback(
 	const git_diff_file *target,
 	const git_diff_file *workdir,
 	void *payload);
+
+extern void tick_index(git_index *index);
diff --git a/tests/checkout/crlf.c b/tests/checkout/crlf.c
index e0d94e7..61459b3 100644
--- a/tests/checkout/crlf.c
+++ b/tests/checkout/crlf.c
@@ -32,25 +32,6 @@ void test_checkout_crlf__detect_crlf_autocrlf_false(void)
 	check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
 }
 
-static void tick_index(git_index *index)
-{
-	git_time_t ts;
-	struct timespec times[2];
-
-	cl_assert(index->on_disk);
-	cl_assert(git_index_path(index));
-
-	cl_git_pass(git_index_read(index, true));
-	ts = index->stamp.mtime;
-
-	times[0].tv_sec  = UTIME_OMIT; /* dont' change the atime */
-	times[0].tv_nsec = UTIME_OMIT; /* dont' change the atime */
-	times[1].tv_sec  = ts + 1;
-	times[1].tv_nsec = 0;
-	cl_git_pass(p_utimensat(AT_FDCWD, git_index_path(index), times, 0));
-	cl_git_pass(git_index_read(index, true));
-}
-
 void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
 {
 	git_index *index;
diff --git a/tests/diff/workdir.c b/tests/diff/workdir.c
index 5d6ebed..6b72f32 100644
--- a/tests/diff/workdir.c
+++ b/tests/diff/workdir.c
@@ -2,6 +2,7 @@
 #include "diff_helpers.h"
 #include "repository.h"
 #include "git2/sys/diff.h"
+#include "../checkout/checkout_helpers.h"
 
 static git_repository *g_repo = NULL;
 
@@ -1583,6 +1584,7 @@ void test_diff_workdir__can_update_index(void)
 	git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
 	git_diff *diff = NULL;
 	git_diff_perfdata perf = GIT_DIFF_PERFDATA_INIT;
+	git_index *index;
 
 	g_repo = cl_git_sandbox_init("status");
 
@@ -1607,6 +1609,10 @@ void test_diff_workdir__can_update_index(void)
 	/* now allow diff to update stat cache */
 	opts.flags |= GIT_DIFF_UPDATE_INDEX;
 
+	/* advance a tick for the index so we don't re-calculate racily-clean entries */
+	cl_git_pass(git_repository_index__weakptr(&index, g_repo));
+	tick_index(index);
+
 	basic_diff_status(&diff, &opts);
 
 	cl_git_pass(git_diff_get_perfdata(&perf, diff));
diff --git a/tests/status/worktree.c b/tests/status/worktree.c
index 3b18ae6..f8d1f7f 100644
--- a/tests/status/worktree.c
+++ b/tests/status/worktree.c
@@ -6,6 +6,7 @@
 #include "util.h"
 #include "path.h"
 #include "../diff/diff_helpers.h"
+#include "../checkout/checkout_helpers.h"
 #include "git2/sys/diff.h"
 
 /**
@@ -956,6 +957,7 @@ void test_status_worktree__update_stat_cache_0(void)
 	git_status_options opts = GIT_STATUS_OPTIONS_INIT;
 	git_status_list *status;
 	git_diff_perfdata perf = GIT_DIFF_PERFDATA_INIT;
+	git_index *index;
 
 	opts.flags = GIT_STATUS_OPT_DEFAULTS;
 
@@ -967,6 +969,10 @@ void test_status_worktree__update_stat_cache_0(void)
 
 	git_status_list_free(status);
 
+	/* tick the index so we avoid recalculating racily-clean entries */
+	cl_git_pass(git_repository_index__weakptr(&index, repo));
+	tick_index(index);
+
 	opts.flags |= GIT_STATUS_OPT_UPDATE_INDEX;
 
 	cl_git_pass(git_status_list_new(&status, repo, &opts));