Skip to content

Commit 6d3ad7e

Browse files
author
Edward Thomson
committed
Add ENABLE_SYNCHRONIZED_OBJECT_CREATION option
Allow users to enable `SYNCHRONIZED_OBJECT_CREATION` with a setting.
1 parent fc27fe2 commit 6d3ad7e

File tree

5 files changed

+16
-1
lines changed

5 files changed

+16
-1
lines changed

include/git2/common.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,7 @@ typedef enum {
179179
GIT_OPT_SET_SSL_CIPHERS,
180180
GIT_OPT_GET_USER_AGENT,
181181
GIT_OPT_ENABLE_OFS_DELTA,
182+
GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION,
182183
} git_libgit2_opt_t;
183184

184185
/**
@@ -316,6 +317,13 @@ typedef enum {
316317
* > Packfiles containing offset deltas can still be read.
317318
* > This defaults to enabled.
318319
*
320+
* * opts(GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION, int enabled)
321+
*
322+
* > Enable synchronized writes of new objects using `fsync`
323+
* > (or the platform equivalent) to ensure that new object data
324+
* > is written to permanent storage, not simply cached. This
325+
* > defaults to disabled.
326+
*
319327
* @param option Option key
320328
* @param ... value to set the option
321329
* @return 0 on success, <0 on failure

src/object.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include "tag.h"
1717

1818
bool git_object__strict_input_validation = true;
19+
bool git_object__synchronized_writing = false;
1920

2021
typedef struct {
2122
const char *str; /* type name string */

src/object.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#include "repository.h"
1111

1212
extern bool git_object__strict_input_validation;
13+
extern bool git_object__synchronized_writing;
1314

1415
/** Base git object for inheritance */
1516
struct git_object {

src/odb_loose.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "odb.h"
1515
#include "delta.h"
1616
#include "filebuf.h"
17+
#include "object.h"
1718

1819
#include "git2/odb_backend.h"
1920
#include "git2/types.h"
@@ -843,7 +844,7 @@ static int filebuf_flags(loose_backend *backend)
843844
int flags = GIT_FILEBUF_TEMPORARY |
844845
(backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT);
845846

846-
if (backend->fsync_object_files)
847+
if (backend->fsync_object_files || git_object__synchronized_writing)
847848
flags |= GIT_FILEBUF_FSYNC;
848849

849850
return flags;

src/settings.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ int git_libgit2_opts(int key, ...)
227227
git_smart__ofs_delta_enabled = (va_arg(ap, int) != 0);
228228
break;
229229

230+
case GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION:
231+
git_object__synchronized_writing = (va_arg(ap, int) != 0);
232+
break;
233+
230234
default:
231235
giterr_set(GITERR_INVALID, "invalid option key");
232236
error = -1;

0 commit comments

Comments
 (0)