···1515#include "parse-options.h"
1616#include "exec-cmd.h"
1717#include "setup.h"
1818+#include "write-or-die.h"
18191920/*
2021 * This is to create corrupt objects for debugging and as such it
···2323#include "setup.h"
2424#include "split-index.h"
2525#include "fsmonitor.h"
2626+#include "write-or-die.h"
26272728/*
2829 * Default to not allowing changes to the list of files. The
···1717#include "../setup.h"
1818#include "../worktree.h"
1919#include "../wrapper.h"
2020+#include "../write-or-die.h"
20212122/*
2223 * This backend uses the following flags in `ref_update::flags` for
···3030#include "commit-graph.h"
3131#include "commit-reach.h"
3232#include "shallow.h"
3333+#include "write-or-die.h"
33343435/* Remember to update object flag allocation in object.h */
3536#define THEY_HAVE (1u << 11)
+2-1
write-or-die.c
···11-#include "cache.h"
11+#include "git-compat-util.h"
22#include "config.h"
33#include "run-command.h"
44#include "wrapper.h"
55+#include "write-or-die.h"
5667/*
78 * Some cases use stdio, but want to flush after the write
+78
write-or-die.h
···11+#ifndef WRITE_OR_DIE_H
22+#define WRITE_OR_DIE_H
33+44+void maybe_flush_or_die(FILE *, const char *);
55+__attribute__((format (printf, 2, 3)))
66+void fprintf_or_die(FILE *, const char *fmt, ...);
77+void fwrite_or_die(FILE *f, const void *buf, size_t count);
88+void fflush_or_die(FILE *f);
99+void write_or_die(int fd, const void *buf, size_t count);
1010+1111+/*
1212+ * These values are used to help identify parts of a repository to fsync.
1313+ * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the
1414+ * repository and so shouldn't be fsynced.
1515+ */
1616+enum fsync_component {
1717+ FSYNC_COMPONENT_NONE,
1818+ FSYNC_COMPONENT_LOOSE_OBJECT = 1 << 0,
1919+ FSYNC_COMPONENT_PACK = 1 << 1,
2020+ FSYNC_COMPONENT_PACK_METADATA = 1 << 2,
2121+ FSYNC_COMPONENT_COMMIT_GRAPH = 1 << 3,
2222+ FSYNC_COMPONENT_INDEX = 1 << 4,
2323+ FSYNC_COMPONENT_REFERENCE = 1 << 5,
2424+};
2525+2626+#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
2727+ FSYNC_COMPONENT_PACK)
2828+2929+#define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \
3030+ FSYNC_COMPONENT_COMMIT_GRAPH)
3131+3232+#define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \
3333+ FSYNC_COMPONENTS_DERIVED_METADATA) & \
3434+ ~FSYNC_COMPONENT_LOOSE_OBJECT)
3535+3636+#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
3737+ FSYNC_COMPONENT_REFERENCE)
3838+3939+#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
4040+ FSYNC_COMPONENT_INDEX)
4141+4242+#define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \
4343+ FSYNC_COMPONENT_PACK | \
4444+ FSYNC_COMPONENT_PACK_METADATA | \
4545+ FSYNC_COMPONENT_COMMIT_GRAPH | \
4646+ FSYNC_COMPONENT_INDEX | \
4747+ FSYNC_COMPONENT_REFERENCE)
4848+4949+#ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT
5050+#define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT
5151+#endif
5252+5353+/* IO helper functions */
5454+void fsync_or_die(int fd, const char *);
5555+int fsync_component(enum fsync_component component, int fd);
5656+void fsync_component_or_die(enum fsync_component component, int fd, const char *msg);
5757+5858+/*
5959+ * A bitmask indicating which components of the repo should be fsynced.
6060+ */
6161+extern enum fsync_component fsync_components;
6262+extern int fsync_object_files;
6363+extern int use_fsync;
6464+6565+enum fsync_method {
6666+ FSYNC_METHOD_FSYNC,
6767+ FSYNC_METHOD_WRITEOUT_ONLY,
6868+ FSYNC_METHOD_BATCH,
6969+};
7070+7171+extern enum fsync_method fsync_method;
7272+7373+static inline int batch_fsync_enabled(enum fsync_component component)
7474+{
7575+ return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
7676+}
7777+7878+#endif /* WRITE_OR_DIE_H */