Skip to content

Commit eb56ed8

Browse files
author
Edward Thomson
committed
refdb_fs: optionally fsync packed refs
1 parent af3dcb0 commit eb56ed8

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/refdb_fs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -994,15 +994,18 @@ static int packed_write(refdb_fs_backend *backend)
994994
{
995995
git_sortedcache *refcache = backend->refcache;
996996
git_filebuf pack_file = GIT_FILEBUF_INIT;
997-
int error;
997+
int error, open_flags = 0;
998998
size_t i;
999999

10001000
/* lock the cache to updates while we do this */
10011001
if ((error = git_sortedcache_wlock(refcache)) < 0)
10021002
return error;
10031003

1004+
if (git_object__synchronized_writing)
1005+
open_flags = GIT_FILEBUF_FSYNC;
1006+
10041007
/* Open the file! */
1005-
if ((error = git_filebuf_open(&pack_file, git_sortedcache_path(refcache), 0, GIT_PACKEDREFS_FILE_MODE)) < 0)
1008+
if ((error = git_filebuf_open(&pack_file, git_sortedcache_path(refcache), open_flags, GIT_PACKEDREFS_FILE_MODE)) < 0)
10061009
goto fail;
10071010

10081011
/* Packfiles have a header... apparently

tests/refs/create.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -303,17 +303,24 @@ void test_refs_create__creating_a_loose_ref_with_invalid_windows_name(void)
303303
void test_refs_create__does_not_fsync_by_default(void)
304304
{
305305
git_reference *ref = NULL;
306+
git_refdb *refdb;
306307
git_oid id;
307308

308309
git_oid_fromstr(&id, current_master_tip);
309310
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/fsync_test", &id, 0, "log message"));
310311
git_reference_free(ref);
312+
313+
cl_git_pass(git_repository_refdb(&refdb, g_repo));
314+
cl_git_pass(git_refdb_compress(refdb));
315+
git_refdb_free(refdb);
316+
311317
cl_assert_equal_i(0, p_fsync__cnt);
312318
}
313319

314320
void test_refs_create__fsyncs_when_requested(void)
315321
{
316322
git_reference *ref = NULL;
323+
git_refdb *refdb;
317324
git_oid id;
318325

319326
cl_git_pass(git_libgit2_opts(GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION, 1));
@@ -323,4 +330,12 @@ void test_refs_create__fsyncs_when_requested(void)
323330
cl_git_pass(git_reference_create(&ref, g_repo, "refs/heads/fsync_test", &id, 0, "log message"));
324331
git_reference_free(ref);
325332
cl_assert_equal_i(2, p_fsync__cnt);
333+
334+
p_fsync__cnt = 0;
335+
336+
cl_git_pass(git_repository_refdb(&refdb, g_repo));
337+
cl_git_pass(git_refdb_compress(refdb));
338+
git_refdb_free(refdb);
339+
340+
cl_assert_equal_i(1, p_fsync__cnt);
326341
}

0 commit comments

Comments
 (0)