Start the 2.48 cycle
[git/gitster.git] / write-or-die.h
blob65a5c42a47ac8659cd75fbf0c962a27bb73693c5
1 #ifndef WRITE_OR_DIE_H
2 #define WRITE_OR_DIE_H
4 void maybe_flush_or_die(FILE *, const char *);
5 __attribute__((format (printf, 2, 3)))
6 void fprintf_or_die(FILE *, const char *fmt, ...);
7 void fwrite_or_die(FILE *f, const void *buf, size_t count);
8 void fflush_or_die(FILE *f);
9 void write_or_die(int fd, const void *buf, size_t count);
12 * These values are used to help identify parts of a repository to fsync.
13 * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the
14 * repository and so shouldn't be fsynced.
16 enum fsync_component {
17 FSYNC_COMPONENT_NONE,
18 FSYNC_COMPONENT_LOOSE_OBJECT = 1 << 0,
19 FSYNC_COMPONENT_PACK = 1 << 1,
20 FSYNC_COMPONENT_PACK_METADATA = 1 << 2,
21 FSYNC_COMPONENT_COMMIT_GRAPH = 1 << 3,
22 FSYNC_COMPONENT_INDEX = 1 << 4,
23 FSYNC_COMPONENT_REFERENCE = 1 << 5,
26 #define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
27 FSYNC_COMPONENT_PACK)
29 #define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \
30 FSYNC_COMPONENT_COMMIT_GRAPH)
32 #define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \
33 FSYNC_COMPONENTS_DERIVED_METADATA) & \
34 ~FSYNC_COMPONENT_LOOSE_OBJECT)
36 #define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
37 FSYNC_COMPONENT_REFERENCE)
39 #define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
40 FSYNC_COMPONENT_INDEX)
42 #define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \
43 FSYNC_COMPONENT_PACK | \
44 FSYNC_COMPONENT_PACK_METADATA | \
45 FSYNC_COMPONENT_COMMIT_GRAPH | \
46 FSYNC_COMPONENT_INDEX | \
47 FSYNC_COMPONENT_REFERENCE)
49 #ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT
50 #define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT
51 #endif
53 /* IO helper functions */
54 void fsync_or_die(int fd, const char *);
55 int fsync_component(enum fsync_component component, int fd);
56 void fsync_component_or_die(enum fsync_component component, int fd, const char *msg);
59 * A bitmask indicating which components of the repo should be fsynced.
61 extern enum fsync_component fsync_components;
62 extern int fsync_object_files;
63 extern int use_fsync;
65 enum fsync_method {
66 FSYNC_METHOD_FSYNC,
67 FSYNC_METHOD_WRITEOUT_ONLY,
68 FSYNC_METHOD_BATCH,
71 extern enum fsync_method fsync_method;
73 static inline int batch_fsync_enabled(enum fsync_component component)
75 return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
78 #endif /* WRITE_OR_DIE_H */