interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / write-or-die.h

81 lines · 2592 bytes Raw Blame History
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);
10void writev_or_die(int fd, struct iovec *iov, int iovlen);
11
12/*
13 * These values are used to help identify parts of a repository to fsync.
14 * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the
15 * repository and so shouldn't be fsynced.
16 */
17enum fsync_component {
18 FSYNC_COMPONENT_NONE,
19 FSYNC_COMPONENT_LOOSE_OBJECT = 1 << 0,
20 FSYNC_COMPONENT_PACK = 1 << 1,
21 FSYNC_COMPONENT_PACK_METADATA = 1 << 2,
22 FSYNC_COMPONENT_COMMIT_GRAPH = 1 << 3,
23 FSYNC_COMPONENT_INDEX = 1 << 4,
24 FSYNC_COMPONENT_REFERENCE = 1 << 5,
25 FSYNC_COMPONENT_OBJECT_MAP = 1 << 6,
26};
27
28#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
29 FSYNC_COMPONENT_PACK)
30
31#define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \
32 FSYNC_COMPONENT_COMMIT_GRAPH)
33
34#define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \
35 FSYNC_COMPONENTS_DERIVED_METADATA) & \
36 ~FSYNC_COMPONENT_LOOSE_OBJECT)
37
38#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
39 FSYNC_COMPONENT_REFERENCE)
40
41#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
42 FSYNC_COMPONENT_INDEX)
43
44#define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \
45 FSYNC_COMPONENT_PACK | \
46 FSYNC_COMPONENT_PACK_METADATA | \
47 FSYNC_COMPONENT_COMMIT_GRAPH | \
48 FSYNC_COMPONENT_INDEX | \
49 FSYNC_COMPONENT_REFERENCE | \
50 FSYNC_COMPONENT_OBJECT_MAP)
51
52#ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT
53#define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT
54#endif
55
56/* IO helper functions */
57void fsync_or_die(int fd, const char *);
58int fsync_component(enum fsync_component component, int fd);
59void fsync_component_or_die(enum fsync_component component, int fd, const char *msg);
60
61/*
62 * A bitmask indicating which components of the repo should be fsynced.
63 */
64extern enum fsync_component fsync_components;
65extern int fsync_object_files;
66extern int use_fsync;
67
68enum fsync_method {
69 FSYNC_METHOD_FSYNC,
70 FSYNC_METHOD_WRITEOUT_ONLY,
71 FSYNC_METHOD_BATCH,
72};
73
74extern enum fsync_method fsync_method;
75
76static inline int batch_fsync_enabled(enum fsync_component component)
77{
78 return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
79}
80
81#endif /* WRITE_OR_DIE_H */