mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 15:00:04 +00:00
crlf: tick the index forward to work around racy-git behaviour
In order to avoid racy-git, we zero out the file size for entries with the same timestamp as the index (or during the initial checkout). This is the case in a couple of crlf tests, as the code is fast enough to do everything in the same second. As we know that we do not perform the modification just after writing out the index, which is what this is designed to work around, tick the mtime of the index file such that it doesn't agree with the files anymore, and we do not zero out these entries.
This commit is contained in:
parent
316b820b6f
commit
c4e6ab5f23
@ -26,6 +26,7 @@ typedef int GIT_SOCKET;
|
|||||||
#define p_mkdir(p,m) mkdir(p, m)
|
#define p_mkdir(p,m) mkdir(p, m)
|
||||||
#define p_fsync(fd) fsync(fd)
|
#define p_fsync(fd) fsync(fd)
|
||||||
extern char *p_realpath(const char *, char *);
|
extern char *p_realpath(const char *, char *);
|
||||||
|
#define p_utimensat(fd, path, times, flags) utimensat(fd, path, times, flags)
|
||||||
|
|
||||||
#define p_recv(s,b,l,f) recv(s,b,l,f)
|
#define p_recv(s,b,l,f) recv(s,b,l,f)
|
||||||
#define p_send(s,b,l,f) send(s,b,l,f)
|
#define p_send(s,b,l,f) send(s,b,l,f)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "git2/checkout.h"
|
#include "git2/checkout.h"
|
||||||
#include "repository.h"
|
#include "repository.h"
|
||||||
|
#include "index.h"
|
||||||
#include "posix.h"
|
#include "posix.h"
|
||||||
|
|
||||||
static git_repository *g_repo;
|
static git_repository *g_repo;
|
||||||
@ -31,6 +32,25 @@ void test_checkout_crlf__detect_crlf_autocrlf_false(void)
|
|||||||
check_file_contents("./crlf/all-crlf", ALL_CRLF_TEXT_RAW);
|
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)
|
void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
|
||||||
{
|
{
|
||||||
git_index *index;
|
git_index *index;
|
||||||
@ -40,9 +60,10 @@ void test_checkout_crlf__autocrlf_false_index_size_is_unfiltered_size(void)
|
|||||||
|
|
||||||
cl_repo_set_bool(g_repo, "core.autocrlf", false);
|
cl_repo_set_bool(g_repo, "core.autocrlf", false);
|
||||||
|
|
||||||
git_checkout_head(g_repo, &opts);
|
|
||||||
|
|
||||||
git_repository_index(&index, g_repo);
|
git_repository_index(&index, g_repo);
|
||||||
|
tick_index(index);
|
||||||
|
|
||||||
|
git_checkout_head(g_repo, &opts);
|
||||||
|
|
||||||
cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
|
cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
|
||||||
cl_assert(entry->file_size == strlen(ALL_LF_TEXT_RAW));
|
cl_assert(entry->file_size == strlen(ALL_LF_TEXT_RAW));
|
||||||
@ -140,9 +161,10 @@ void test_checkout_crlf__autocrlf_true_index_size_is_filtered_size(void)
|
|||||||
|
|
||||||
cl_repo_set_bool(g_repo, "core.autocrlf", true);
|
cl_repo_set_bool(g_repo, "core.autocrlf", true);
|
||||||
|
|
||||||
git_checkout_head(g_repo, &opts);
|
|
||||||
|
|
||||||
git_repository_index(&index, g_repo);
|
git_repository_index(&index, g_repo);
|
||||||
|
tick_index(index);
|
||||||
|
|
||||||
|
git_checkout_head(g_repo, &opts);
|
||||||
|
|
||||||
cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
|
cl_assert((entry = git_index_get_bypath(index, "all-lf", 0)) != NULL);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user