Add `ENABLE_SYNCHRONIZED_OBJECT_CREATION` option Allow users to enable `SYNCHRONIZED_OBJECT_CREATION` with a setting.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
diff --git a/include/git2/common.h b/include/git2/common.h
index f13dfd5..f5d37ed 100644
--- a/include/git2/common.h
+++ b/include/git2/common.h
@@ -179,6 +179,7 @@ typedef enum {
GIT_OPT_SET_SSL_CIPHERS,
GIT_OPT_GET_USER_AGENT,
GIT_OPT_ENABLE_OFS_DELTA,
+ GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION,
} git_libgit2_opt_t;
/**
@@ -316,6 +317,13 @@ typedef enum {
* > Packfiles containing offset deltas can still be read.
* > This defaults to enabled.
*
+ * * opts(GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION, int enabled)
+ *
+ * > Enable synchronized writes of new objects using `fsync`
+ * > (or the platform equivalent) to ensure that new object data
+ * > is written to permanent storage, not simply cached. This
+ * > defaults to disabled.
+ *
* @param option Option key
* @param ... value to set the option
* @return 0 on success, <0 on failure
diff --git a/src/object.c b/src/object.c
index 2da36a2..c92adbb 100644
--- a/src/object.c
+++ b/src/object.c
@@ -16,6 +16,7 @@
#include "tag.h"
bool git_object__strict_input_validation = true;
+bool git_object__synchronized_writing = false;
typedef struct {
const char *str; /* type name string */
diff --git a/src/object.h b/src/object.h
index dd227d1..7d94d8b 100644
--- a/src/object.h
+++ b/src/object.h
@@ -10,6 +10,7 @@
#include "repository.h"
extern bool git_object__strict_input_validation;
+extern bool git_object__synchronized_writing;
/** Base git object for inheritance */
struct git_object {
diff --git a/src/odb_loose.c b/src/odb_loose.c
index 8796f4b..5a80b7a 100644
--- a/src/odb_loose.c
+++ b/src/odb_loose.c
@@ -14,6 +14,7 @@
#include "odb.h"
#include "delta.h"
#include "filebuf.h"
+#include "object.h"
#include "git2/odb_backend.h"
#include "git2/types.h"
@@ -843,7 +844,7 @@ static int filebuf_flags(loose_backend *backend)
int flags = GIT_FILEBUF_TEMPORARY |
(backend->object_zlib_level << GIT_FILEBUF_DEFLATE_SHIFT);
- if (backend->fsync_object_files)
+ if (backend->fsync_object_files || git_object__synchronized_writing)
flags |= GIT_FILEBUF_FSYNC;
return flags;
diff --git a/src/settings.c b/src/settings.c
index 2158567..f3120ff 100644
--- a/src/settings.c
+++ b/src/settings.c
@@ -227,6 +227,10 @@ int git_libgit2_opts(int key, ...)
git_smart__ofs_delta_enabled = (va_arg(ap, int) != 0);
break;
+ case GIT_OPT_ENABLE_SYNCHRONIZED_OBJECT_CREATION:
+ git_object__synchronized_writing = (va_arg(ap, int) != 0);
+ break;
+
default:
giterr_set(GITERR_INVALID, "invalid option key");
error = -1;