Commit e44abe16 by Carlos Martín Nieto

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