mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 15:00:04 +00:00
refdb_fs: optionally fsync loose references
This commit is contained in:
parent
5312621bd4
commit
af3dcb0e50
@ -736,7 +736,7 @@ static int reference_path_available(
|
|||||||
|
|
||||||
static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *name)
|
static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *name)
|
||||||
{
|
{
|
||||||
int error;
|
int error, filebuf_flags;
|
||||||
git_buf ref_path = GIT_BUF_INIT;
|
git_buf ref_path = GIT_BUF_INIT;
|
||||||
|
|
||||||
assert(file && backend && name);
|
assert(file && backend && name);
|
||||||
@ -755,7 +755,11 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
|
|||||||
if (git_buf_joinpath(&ref_path, backend->gitpath, name) < 0)
|
if (git_buf_joinpath(&ref_path, backend->gitpath, name) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
error = git_filebuf_open(file, ref_path.ptr, GIT_FILEBUF_FORCE, GIT_REFS_FILE_MODE);
|
filebuf_flags = GIT_FILEBUF_FORCE;
|
||||||
|
if (git_object__synchronized_writing)
|
||||||
|
filebuf_flags |= GIT_FILEBUF_FSYNC;
|
||||||
|
|
||||||
|
error = git_filebuf_open(file, ref_path.ptr, filebuf_flags, GIT_REFS_FILE_MODE);
|
||||||
|
|
||||||
if (error == GIT_EDIRECTORY)
|
if (error == GIT_EDIRECTORY)
|
||||||
giterr_set(GITERR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name);
|
giterr_set(GITERR_REFERENCE, "cannot lock ref '%s', there are refs beneath that folder", name);
|
||||||
@ -1784,7 +1788,7 @@ success:
|
|||||||
/* Append to the reflog, must be called under reference lock */
|
/* Append to the reflog, must be called under reference lock */
|
||||||
static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_oid *old, const git_oid *new, const git_signature *who, const char *message)
|
static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, const git_oid *old, const git_oid *new, const git_signature *who, const char *message)
|
||||||
{
|
{
|
||||||
int error, is_symbolic;
|
int error, is_symbolic, open_flags;
|
||||||
git_oid old_id = {{0}}, new_id = {{0}};
|
git_oid old_id = {{0}}, new_id = {{0}};
|
||||||
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
|
git_buf buf = GIT_BUF_INIT, path = GIT_BUF_INIT;
|
||||||
git_repository *repo = backend->repo;
|
git_repository *repo = backend->repo;
|
||||||
@ -1852,7 +1856,12 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
|
|||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
error = git_futils_writebuffer(&buf, git_buf_cstr(&path), O_WRONLY|O_CREAT|O_APPEND, GIT_REFLOG_FILE_MODE);
|
open_flags = O_WRONLY | O_CREAT | O_APPEND;
|
||||||
|
|
||||||
|
if (git_object__synchronized_writing)
|
||||||
|
open_flags |= O_FSYNC;
|
||||||
|
|
||||||
|
error = git_futils_writebuffer(&buf, git_buf_cstr(&path), open_flags, GIT_REFLOG_FILE_MODE);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
git_buf_free(&buf);
|
git_buf_free(&buf);
|
||||||
|
@ -13,6 +13,7 @@ static git_repository *g_repo;
|
|||||||
void test_refs_create__initialize(void)
|
void test_refs_create__initialize(void)
|
||||||
{
|
{
|
||||||
g_repo = cl_git_sandbox_init("testrepo");
|
g_repo = cl_git_sandbox_init("testrepo");
|
||||||
|
p_fsync__cnt = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_refs_create__cleanup(void)
|
void test_refs_create__cleanup(void)
|
||||||
@ -21,6 +22,7 @@ void test_refs_create__cleanup(void)
|
|||||||
|
|
||||||
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 1));
|
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_OBJECT_CREATION, 1));
|
||||||
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION, 1));
|
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_STRICT_SYMBOLIC_REF_CREATION, 1));
|
||||||
|
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_refs_create__symbolic(void)
|
void test_refs_create__symbolic(void)
|
||||||
@ -297,3 +299,28 @@ void test_refs_create__creating_a_loose_ref_with_invalid_windows_name(void)
|
|||||||
|
|
||||||
test_win32_name("refs/heads/com1");
|
test_win32_name("refs/heads/com1");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test_refs_create__does_not_fsync_by_default(void)
|
||||||
|
{
|
||||||
|
git_reference *ref = NULL;
|
||||||
|
git_oid id;
|
||||||
|
|
||||||
|
git_oid_fromstr(&id, current_master_tip);
|
||||||
|
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/fsync_test", &id, 0, "log message"));
|
||||||
|
git_reference_free(ref);
|
||||||
|
cl_assert_equal_i(0, p_fsync__cnt);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_refs_create__fsyncs_when_requested(void)
|
||||||
|
{
|
||||||
|
git_reference *ref = NULL;
|
||||||
|
git_oid id;
|
||||||
|
|
||||||
|
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION, 1));
|
||||||
|
p_fsync__cnt = 0;
|
||||||
|
|
||||||
|
git_oid_fromstr(&id, current_master_tip);
|
||||||
|
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/fsync_test", &id, 0, "log message"));
|
||||||
|
git_reference_free(ref);
|
||||||
|
cl_assert_equal_i(2, p_fsync__cnt);
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user