write-or-die.h: move declarations for write-or-die.c functions from cache.h

Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Mar 21, 2023 at 06:26 UTC d48be35ca6f62e1ddd0161f9bbb4c893ee498bfe
35 files changed +114 -77
archive-tar.c
+1
@@ -11,6 +11,7 @@
11 #include "object-store.h"
12 #include "streaming.h"
13 #include "run-command.h"
14 +#include "write-or-die.h"
15
16 #define RECORDSIZE (512)
17 #define BLOCKSIZE (RECORDSIZE * 20)
archive-zip.c
+1
@@ -10,6 +10,7 @@
10 #include "utf8.h"
11 #include "object-store.h"
12 #include "userdiff.h"
13 +#include "write-or-die.h"
14 #include "xdiff-interface.h"
15 #include "date.h"
16
builtin/blame.c
+1
@@ -33,6 +33,7 @@
33 #include "refs.h"
34 #include "setup.h"
35 #include "tag.h"
36 +#include "write-or-die.h"
37
38 static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>");
39 static char annotate_usage[] = N_("git annotate [<options>] [<rev-opts>] [<rev>] [--] <file>");
builtin/cat-file.c
+1
@@ -23,6 +23,7 @@
23 #include "replace-object.h"
24 #include "promisor-remote.h"
25 #include "mailmap.h"
26 +#include "write-or-die.h"
27
28 enum batch_mode {
29 BATCH_MODE_CONTENTS,
builtin/check-attr.c
+1
@@ -8,6 +8,7 @@
8 #include "quote.h"
9 #include "setup.h"
10 #include "parse-options.h"
11 +#include "write-or-die.h"
12
13 static int all_attrs;
14 static int cached_attrs;
builtin/check-ignore.c
+1
@@ -8,6 +8,7 @@
8 #include "pathspec.h"
9 #include "parse-options.h"
10 #include "submodule.h"
11 +#include "write-or-die.h"
12
13 static int quiet, verbose, stdin_paths, show_non_matching, no_index;
14 static const char * const check_ignore_usage[] = {
builtin/check-mailmap.c
+1
@@ -5,6 +5,7 @@
5 #include "mailmap.h"
6 #include "parse-options.h"
7 #include "string-list.h"
8 +#include "write-or-die.h"
9
10 static int use_stdin;
11 static const char * const check_mailmap_usage[] = {
builtin/credential-cache.c
+1
@@ -2,6 +2,7 @@
2 #include "gettext.h"
3 #include "parse-options.h"
4 #include "wrapper.h"
5 +#include "write-or-die.h"
6
7 #ifndef NO_UNIX_SOCKETS
8
builtin/credential-store.c
+1
@@ -5,6 +5,7 @@
5 #include "credential.h"
6 #include "string-list.h"
7 #include "parse-options.h"
8 +#include "write-or-die.h"
9
10 static struct lock_file credential_lock;
11
builtin/grep.c
+1
@@ -28,6 +28,7 @@
28 #include "submodule-config.h"
29 #include "object-store.h"
30 #include "packfile.h"
31 +#include "write-or-die.h"
32
33 static const char *grep_prefix;
34
builtin/hash-object.c
+1
@@ -15,6 +15,7 @@
15 #include "parse-options.h"
16 #include "exec-cmd.h"
17 #include "setup.h"
18 +#include "write-or-die.h"
19
20 /*
21 * This is to create corrupt objects for debugging and as such it
builtin/log.c
+1
@@ -40,6 +40,7 @@
40 #include "commit-reach.h"
41 #include "range-diff.h"
42 #include "tmp-objdir.h"
43 +#include "write-or-die.h"
44
45 #define MAIL_DEFAULT_WRAP 72
46 #define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100
builtin/notes.c
+1
@@ -25,6 +25,7 @@
25 #include "notes-merge.h"
26 #include "notes-utils.h"
27 #include "worktree.h"
28 +#include "write-or-die.h"
29
30 static const char * const git_notes_usage[] = {
31 N_("git notes [--ref <notes-ref>] [list [<object>]]"),
builtin/send-pack.c
+1
@@ -16,6 +16,7 @@
16 #include "gpg-interface.h"
17 #include "gettext.h"
18 #include "protocol.h"
19 +#include "write-or-die.h"
20
21 static const char * const send_pack_usage[] = {
22 N_("git send-pack [--mirror] [--dry-run] [--force]\n"
builtin/stripspace.c
+1
@@ -5,6 +5,7 @@
5 #include "parse-options.h"
6 #include "setup.h"
7 #include "strbuf.h"
8 +#include "write-or-die.h"
9
10 static void comment_lines(struct strbuf *buf)
11 {
builtin/tag.c
+1
@@ -24,6 +24,7 @@
24 #include "column.h"
25 #include "ref-filter.h"
26 #include "date.h"
27 +#include "write-or-die.h"
28
29 static const char * const git_tag_usage[] = {
30 N_("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] [-e]\n"
builtin/update-index.c
+1
@@ -23,6 +23,7 @@
23 #include "setup.h"
24 #include "split-index.h"
25 #include "fsmonitor.h"
26 +#include "write-or-die.h"
27
28 /*
29 * Default to not allowing changes to the list of files. The
bundle.c
+1
@@ -16,6 +16,7 @@
16 #include "strvec.h"
17 #include "list-objects-filter-options.h"
18 #include "connected.h"
19 +#include "write-or-die.h"
20
21 static const char v2_bundle_signature[] = "# v2 git bundle\n";
22 static const char v3_bundle_signature[] = "# v3 git bundle\n";
cache.h
-74
@@ -686,63 +686,6 @@ extern int verify_ce_order;
686
687 extern int quote_path_fully;
688
689 -/*
690 - * These values are used to help identify parts of a repository to fsync.
691 - * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the
692 - * repository and so shouldn't be fsynced.
693 - */
694 -enum fsync_component {
695 - FSYNC_COMPONENT_NONE,
696 - FSYNC_COMPONENT_LOOSE_OBJECT = 1 << 0,
697 - FSYNC_COMPONENT_PACK = 1 << 1,
698 - FSYNC_COMPONENT_PACK_METADATA = 1 << 2,
699 - FSYNC_COMPONENT_COMMIT_GRAPH = 1 << 3,
700 - FSYNC_COMPONENT_INDEX = 1 << 4,
701 - FSYNC_COMPONENT_REFERENCE = 1 << 5,
702 -};
703 -
704 -#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
705 - FSYNC_COMPONENT_PACK)
706 -
707 -#define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \
708 - FSYNC_COMPONENT_COMMIT_GRAPH)
709 -
710 -#define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \
711 - FSYNC_COMPONENTS_DERIVED_METADATA) & \
712 - ~FSYNC_COMPONENT_LOOSE_OBJECT)
713 -
714 -#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
715 - FSYNC_COMPONENT_REFERENCE)
716 -
717 -#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
718 - FSYNC_COMPONENT_INDEX)
719 -
720 -#define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \
721 - FSYNC_COMPONENT_PACK | \
722 - FSYNC_COMPONENT_PACK_METADATA | \
723 - FSYNC_COMPONENT_COMMIT_GRAPH | \
724 - FSYNC_COMPONENT_INDEX | \
725 - FSYNC_COMPONENT_REFERENCE)
726 -
727 -#ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT
728 -#define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT
729 -#endif
730 -
731 -/*
732 - * A bitmask indicating which components of the repo should be fsynced.
733 - */
734 -extern enum fsync_component fsync_components;
735 -extern int fsync_object_files;
736 -extern int use_fsync;
737 -
738 -enum fsync_method {
739 - FSYNC_METHOD_FSYNC,
740 - FSYNC_METHOD_WRITEOUT_ONLY,
741 - FSYNC_METHOD_BATCH,
742 -};
743 -
744 -extern enum fsync_method fsync_method;
745 -
689 #define MTIME_CHANGED 0x0001
690 #define CTIME_CHANGED 0x0002
691 #define OWNER_CHANGED 0x0004
@@ -1045,29 +988,12 @@ int update_server_info(int);
988 extern const char *git_mailmap_file;
989 extern const char *git_mailmap_blob;
990
1048 -/* IO helper functions */
1049 -void maybe_flush_or_die(FILE *, const char *);
1050 -__attribute__((format (printf, 2, 3)))
1051 -void fprintf_or_die(FILE *, const char *fmt, ...);
1052 -void fwrite_or_die(FILE *f, const void *buf, size_t count);
1053 -void fflush_or_die(FILE *f);
1054 -
991 #define COPY_READ_ERROR (-2)
992 #define COPY_WRITE_ERROR (-3)
993 int copy_fd(int ifd, int ofd);
994 int copy_file(const char *dst, const char *src, int mode);
995 int copy_file_with_time(const char *dst, const char *src, int mode);
996
1061 -void write_or_die(int fd, const void *buf, size_t count);
1062 -void fsync_or_die(int fd, const char *);
1063 -int fsync_component(enum fsync_component component, int fd);
1064 -void fsync_component_or_die(enum fsync_component component, int fd, const char *msg);
1065 -
1066 -static inline int batch_fsync_enabled(enum fsync_component component)
1067 -{
1068 - return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
1069 -}
1070 -
997 /* pager.c */
998 void setup_pager(void);
999 int pager_in_use(void);
config.c
+1
@@ -30,6 +30,7 @@
30 #include "setup.h"
31 #include "worktree.h"
32 #include "wrapper.h"
33 +#include "write-or-die.h"
34
35 struct config_source {
36 struct config_source *prev;
csum-file.h
+1
@@ -3,6 +3,7 @@
3
4 #include "cache.h"
5 #include "hash.h"
6 +#include "write-or-die.h"
7
8 struct progress;
9
diagnose.c
+1
@@ -9,6 +9,7 @@
9 #include "strvec.h"
10 #include "object-store.h"
11 #include "packfile.h"
12 +#include "write-or-die.h"
13
14 struct archive_dir {
15 const char *path;
environment.c
+1
@@ -25,6 +25,7 @@
25 #include "setup.h"
26 #include "shallow.h"
27 #include "wrapper.h"
28 +#include "write-or-die.h"
29
30 int trust_executable_bit = 1;
31 int trust_ctime = 1;
http-backend.c
+1
@@ -18,6 +18,7 @@
18 #include "protocol.h"
19 #include "date.h"
20 #include "wrapper.h"
21 +#include "write-or-die.h"
22
23 static const char content_type[] = "Content-Type";
24 static const char content_length[] = "Content-Length";
log-tree.c
+1
@@ -23,6 +23,7 @@
23 #include "help.h"
24 #include "range-diff.h"
25 #include "strmap.h"
26 +#include "write-or-die.h"
27
28 static struct decoration name_decoration = { "object names" };
29 static int decoration_loaded;
pkt-line.c
+1
@@ -4,6 +4,7 @@
4 #include "hex.h"
5 #include "run-command.h"
6 #include "wrapper.h"
7 +#include "write-or-die.h"
8
9 char packet_buffer[LARGE_PACKET_MAX];
10 static const char *packet_trace_prefix = "git";
refs/files-backend.c
+1
@@ -17,6 +17,7 @@
17 #include "../setup.h"
18 #include "../worktree.h"
19 #include "../wrapper.h"
20 +#include "../write-or-die.h"
21
22 /*
23 * This backend uses the following flags in `ref_update::flags` for
refs/packed-backend.c
+1
@@ -9,6 +9,7 @@
9 #include "../iterator.h"
10 #include "../lockfile.h"
11 #include "../chdir-notify.h"
12 +#include "../write-or-die.h"
13
14 enum mmap_strategy {
15 /*
remote-curl.c
+1
@@ -22,6 +22,7 @@
22 #include "protocol.h"
23 #include "quote.h"
24 #include "transport.h"
25 +#include "write-or-die.h"
26
27 static struct remote *remote;
28 /* always ends with a trailing slash */
send-pack.c
+2 -1
@@ -16,8 +16,9 @@
16 #include "version.h"
17 #include "oid-array.h"
18 #include "gpg-interface.h"
19 -#include "cache.h"
19 #include "shallow.h"
20 +#include "trace2.h"
21 +#include "write-or-die.h"
22
23 int option_parse_push_signed(const struct option *opt,
24 const char *arg, int unset)
sideband.c
+1
@@ -5,6 +5,7 @@
5 #include "sideband.h"
6 #include "help.h"
7 #include "pkt-line.h"
8 +#include "write-or-die.h"
9
10 struct keyword_entry {
11 /*
t/helper/test-pkt-line.c
+2 -1
@@ -1,6 +1,7 @@
1 -#include "cache.h"
1 +#include "git-compat-util.h"
2 #include "test-tool.h"
3 #include "pkt-line.h"
4 +#include "write-or-die.h"
5
6 static void pack_line(const char *line)
7 {
upload-pack.c
+1
@@ -30,6 +30,7 @@
30 #include "commit-graph.h"
31 #include "commit-reach.h"
32 #include "shallow.h"
33 +#include "write-or-die.h"
34
35 /* Remember to update object flag allocation in object.h */
36 #define THEY_HAVE (1u << 11)
write-or-die.c
+2 -1
@@ -1,7 +1,8 @@
1 -#include "cache.h"
1 +#include "git-compat-util.h"
2 #include "config.h"
3 #include "run-command.h"
4 #include "wrapper.h"
5 +#include "write-or-die.h"
6
7 /*
8 * Some cases use stdio, but want to flush after the write
write-or-die.h new
+78
@@ -0,0 +1,78 @@
1 +#ifndef WRITE_OR_DIE_H
2 +#define WRITE_OR_DIE_H
3 +
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);
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 + */
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,
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 */
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);
57 +
58 +/*
59 + * A bitmask indicating which components of the repo should be fsynced.
60 + */
61 +extern enum fsync_component fsync_components;
62 +extern int fsync_object_files;
63 +extern int use_fsync;
64 +
65 +enum fsync_method {
66 + FSYNC_METHOD_FSYNC,
67 + FSYNC_METHOD_WRITEOUT_ONLY,
68 + FSYNC_METHOD_BATCH,
69 +};
70 +
71 +extern enum fsync_method fsync_method;
72 +
73 +static 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 */