@@ -736,7 +736,7 @@ static int reference_path_available(
736736
737737static int loose_lock (git_filebuf * file , refdb_fs_backend * backend , const char * name )
738738{
739- int error ;
739+ int error , filebuf_flags ;
740740 git_buf ref_path = GIT_BUF_INIT ;
741741
742742 assert (file && backend && name );
@@ -755,7 +755,11 @@ static int loose_lock(git_filebuf *file, refdb_fs_backend *backend, const char *
755755 if (git_buf_joinpath (& ref_path , backend -> gitpath , name ) < 0 )
756756 return -1 ;
757757
758- error = git_filebuf_open (file , ref_path .ptr , GIT_FILEBUF_FORCE , GIT_REFS_FILE_MODE );
758+ filebuf_flags = GIT_FILEBUF_FORCE ;
759+ if (git_object__synchronized_writing )
760+ filebuf_flags |= GIT_FILEBUF_FSYNC ;
761+
762+ error = git_filebuf_open (file , ref_path .ptr , filebuf_flags , GIT_REFS_FILE_MODE );
759763
760764 if (error == GIT_EDIRECTORY )
761765 giterr_set (GITERR_REFERENCE , "cannot lock ref '%s', there are refs beneath that folder" , name );
@@ -1784,7 +1788,7 @@ static int refdb_reflog_fs__write(git_refdb_backend *_backend, git_reflog *reflo
17841788/* Append to the reflog, must be called under reference lock */
17851789static 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 )
17861790{
1787- int error , is_symbolic ;
1791+ int error , is_symbolic , open_flags ;
17881792 git_oid old_id = {{0 }}, new_id = {{0 }};
17891793 git_buf buf = GIT_BUF_INIT , path = GIT_BUF_INIT ;
17901794 git_repository * repo = backend -> repo ;
@@ -1852,7 +1856,12 @@ static int reflog_append(refdb_fs_backend *backend, const git_reference *ref, co
18521856 goto cleanup ;
18531857 }
18541858
1855- error = git_futils_writebuffer (& buf , git_buf_cstr (& path ), O_WRONLY |O_CREAT |O_APPEND , GIT_REFLOG_FILE_MODE );
1859+ open_flags = O_WRONLY | O_CREAT | O_APPEND ;
1860+
1861+ if (git_object__synchronized_writing )
1862+ open_flags |= O_FSYNC ;
1863+
1864+ error = git_futils_writebuffer (& buf , git_buf_cstr (& path ), open_flags , GIT_REFLOG_FILE_MODE );
18561865
18571866cleanup :
18581867 git_buf_free (& buf );
0 commit comments