]> git.ipfire.org Git - thirdparty/git.git/blame - write-or-die.h
Start the 2.46 cycle
[thirdparty/git.git] / write-or-die.h
CommitLineData
d48be35c
EN
1#ifndef WRITE_OR_DIE_H
2#define WRITE_OR_DIE_H
3
4void maybe_flush_or_die(FILE *, const char *);
5__attribute__((format (printf, 2, 3)))
6void fprintf_or_die(FILE *, const char *fmt, ...);
7void fwrite_or_die(FILE *f, const void *buf, size_t count);
8void fflush_or_die(FILE *f);
9void write_or_die(int fd, const void *buf, size_t count);
10
11/*
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.
15 */
16enum 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,
24};
25
26#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
27 FSYNC_COMPONENT_PACK)
28
29#define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \
30 FSYNC_COMPONENT_COMMIT_GRAPH)
31
32#define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \
33 FSYNC_COMPONENTS_DERIVED_METADATA) & \
34 ~FSYNC_COMPONENT_LOOSE_OBJECT)
35
36#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
37 FSYNC_COMPONENT_REFERENCE)
38
39#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
40 FSYNC_COMPONENT_INDEX)
41
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)
48
49#ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT
50#define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT
51#endif
52
53/* IO helper functions */
54void fsync_or_die(int fd, const char *);
55int fsync_component(enum fsync_component component, int fd);
56void fsync_component_or_die(enum fsync_component component, int fd, const char *msg);
57
58/*
59 * A bitmask indicating which components of the repo should be fsynced.
60 */
61extern enum fsync_component fsync_components;
62extern int fsync_object_files;
63extern int use_fsync;
64
65enum fsync_method {
66 FSYNC_METHOD_FSYNC,
67 FSYNC_METHOD_WRITEOUT_ONLY,
68 FSYNC_METHOD_BATCH,
69};
70
71extern enum fsync_method fsync_method;
72
73static inline int batch_fsync_enabled(enum fsync_component component)
74{
75 return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
76}
77
78#endif /* WRITE_OR_DIE_H */