]> git.ipfire.org Git - thirdparty/git.git/commitdiff
write-or-die.h: move declarations for write-or-die.c functions from cache.h
authorElijah Newren <newren@gmail.com>
Tue, 21 Mar 2023 06:26:07 +0000 (06:26 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Mar 2023 17:56:54 +0000 (10:56 -0700)
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
35 files changed:
archive-tar.c
archive-zip.c
builtin/blame.c
builtin/cat-file.c
builtin/check-attr.c
builtin/check-ignore.c
builtin/check-mailmap.c
builtin/credential-cache.c
builtin/credential-store.c
builtin/grep.c
builtin/hash-object.c
builtin/log.c
builtin/notes.c
builtin/send-pack.c
builtin/stripspace.c
builtin/tag.c
builtin/update-index.c
bundle.c
cache.h
config.c
csum-file.h
diagnose.c
environment.c
http-backend.c
log-tree.c
pkt-line.c
refs/files-backend.c
refs/packed-backend.c
remote-curl.c
send-pack.c
sideband.c
t/helper/test-pkt-line.c
upload-pack.c
write-or-die.c
write-or-die.h [new file with mode: 0644]

index 16ee133bbf57fd573caf636bf7a0cac371ac4403..497dad0b3af4adac513ee70d5eb72f9cc1517179 100644 (file)
@@ -11,6 +11,7 @@
 #include "object-store.h"
 #include "streaming.h"
 #include "run-command.h"
+#include "write-or-die.h"
 
 #define RECORDSIZE     (512)
 #define BLOCKSIZE      (RECORDSIZE * 20)
index c02dc33e4066a39121425e275ed6f3173a6b440a..e6f5c10a14f20a105de81224aae0144610f5a312 100644 (file)
@@ -10,6 +10,7 @@
 #include "utf8.h"
 #include "object-store.h"
 #include "userdiff.h"
+#include "write-or-die.h"
 #include "xdiff-interface.h"
 #include "date.h"
 
index fb271bae70ef03340ea4e384baf0215680e6bcd1..0a3cc019059a20f3c09610dd663ee23613c11da9 100644 (file)
@@ -33,6 +33,7 @@
 #include "refs.h"
 #include "setup.h"
 #include "tag.h"
+#include "write-or-die.h"
 
 static char blame_usage[] = N_("git blame [<options>] [<rev-opts>] [<rev>] [--] <file>");
 static char annotate_usage[] = N_("git annotate [<options>] [<rev-opts>] [<rev>] [--] <file>");
index 365d9234bdb630fca34e8e4d5648390c2ac7b1a9..cf73d1879124a1dbc4bedeb94f5f20eb1f317396 100644 (file)
@@ -23,6 +23,7 @@
 #include "replace-object.h"
 #include "promisor-remote.h"
 #include "mailmap.h"
+#include "write-or-die.h"
 
 enum batch_mode {
        BATCH_MODE_CONTENTS,
index ec37b8164af15abb6e6baed266eb7e67ed2ede08..1dbe9d6ca887811134b77df04c8bc6ff453d3625 100644 (file)
@@ -8,6 +8,7 @@
 #include "quote.h"
 #include "setup.h"
 #include "parse-options.h"
+#include "write-or-die.h"
 
 static int all_attrs;
 static int cached_attrs;
index a45d001e3536673305b50833c603d99b389faf8b..9401dad0070c025af4592eb1fd2b34f601c2fba1 100644 (file)
@@ -8,6 +8,7 @@
 #include "pathspec.h"
 #include "parse-options.h"
 #include "submodule.h"
+#include "write-or-die.h"
 
 static int quiet, verbose, stdin_paths, show_non_matching, no_index;
 static const char * const check_ignore_usage[] = {
index fa86fd9423d895974afbcf968e772297d6986630..002d2941e931034f9426c8e3dbda28310fc2776a 100644 (file)
@@ -5,6 +5,7 @@
 #include "mailmap.h"
 #include "parse-options.h"
 #include "string-list.h"
+#include "write-or-die.h"
 
 static int use_stdin;
 static const char * const check_mailmap_usage[] = {
index af56a44923d689f4dbd8f182ec6a6911da170b57..508da4c6e4d4b42d0b6e159ed01211d9d02f168c 100644 (file)
@@ -2,6 +2,7 @@
 #include "gettext.h"
 #include "parse-options.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 #ifndef NO_UNIX_SOCKETS
 
index da32cfd89e29f988393c71f8cc1cf98790c91ccb..8977604eb9dc0b206474282e6e34afe36aeeb35f 100644 (file)
@@ -5,6 +5,7 @@
 #include "credential.h"
 #include "string-list.h"
 #include "parse-options.h"
+#include "write-or-die.h"
 
 static struct lock_file credential_lock;
 
index b8ebf014f403de391084d96c85041b729a6ae861..d858bf0bea642027809bb7ed6d9faa671067561c 100644 (file)
@@ -28,6 +28,7 @@
 #include "submodule-config.h"
 #include "object-store.h"
 #include "packfile.h"
+#include "write-or-die.h"
 
 static const char *grep_prefix;
 
index a2e160db0265ba3102606637e060587f4aa603b0..a15fe4fd3f4f96b9f82535c224956eb957e93b49 100644 (file)
@@ -15,6 +15,7 @@
 #include "parse-options.h"
 #include "exec-cmd.h"
 #include "setup.h"
+#include "write-or-die.h"
 
 /*
  * This is to create corrupt objects for debugging and as such it
index 1b92dee196e5102debb94e3e1ffafd6d63937ea1..b28a24c309322746d3a8f13e33951ae13e0be50b 100644 (file)
@@ -40,6 +40,7 @@
 #include "commit-reach.h"
 #include "range-diff.h"
 #include "tmp-objdir.h"
+#include "write-or-die.h"
 
 #define MAIL_DEFAULT_WRAP 72
 #define COVER_FROM_AUTO_MAX_SUBJECT_LEN 100
index 8e9be33ddbba69dd80794e852997362f4787c0ba..26cbb564a8ee5cb43742bb4ccd902de7879fb7d0 100644 (file)
@@ -25,6 +25,7 @@
 #include "notes-merge.h"
 #include "notes-utils.h"
 #include "worktree.h"
+#include "write-or-die.h"
 
 static const char * const git_notes_usage[] = {
        N_("git notes [--ref <notes-ref>] [list [<object>]]"),
index fb5b2bad2cc8e51e1ee83629a0cead31b1d4714e..2b360fee426faf0ed9eeb0dd1cb5d3f3b707cbd0 100644 (file)
@@ -16,6 +16,7 @@
 #include "gpg-interface.h"
 #include "gettext.h"
 #include "protocol.h"
+#include "write-or-die.h"
 
 static const char * const send_pack_usage[] = {
        N_("git send-pack [--mirror] [--dry-run] [--force]\n"
index 53930458ffa9af41ad097e6dec3173a3cbf404a9..9451eb69ff4771931118e948669114e9f3d4e63d 100644 (file)
@@ -5,6 +5,7 @@
 #include "parse-options.h"
 #include "setup.h"
 #include "strbuf.h"
+#include "write-or-die.h"
 
 static void comment_lines(struct strbuf *buf)
 {
index 0611b3bd600199f8d496c90d736a10362336bfa5..531631a36c204095b320aa63430811ba570a23fb 100644 (file)
@@ -24,6 +24,7 @@
 #include "column.h"
 #include "ref-filter.h"
 #include "date.h"
+#include "write-or-die.h"
 
 static const char * const git_tag_usage[] = {
        N_("git tag [-a | -s | -u <key-id>] [-f] [-m <msg> | -F <file>] [-e]\n"
index f97f8d4c9d5fcfd92c58c049810847be3c8a7d02..03cda5e60d2bd17c6de251c815d9c2bdd319429b 100644 (file)
@@ -23,6 +23,7 @@
 #include "setup.h"
 #include "split-index.h"
 #include "fsmonitor.h"
+#include "write-or-die.h"
 
 /*
  * Default to not allowing changes to the list of files. The
index efeaf6f71515af29819fb65cd66a563f795f67e4..dac82e2f2d92a242f3d1901e8495d3f2ec05c9f5 100644 (file)
--- a/bundle.c
+++ b/bundle.c
@@ -16,6 +16,7 @@
 #include "strvec.h"
 #include "list-objects-filter-options.h"
 #include "connected.h"
+#include "write-or-die.h"
 
 static const char v2_bundle_signature[] = "# v2 git bundle\n";
 static const char v3_bundle_signature[] = "# v3 git bundle\n";
diff --git a/cache.h b/cache.h
index bffedd240e71d16a40adb61d18ebac9c127f10a6..c43051d7928e823588bf033c69704d24d31c3d48 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -686,63 +686,6 @@ extern int verify_ce_order;
 
 extern int quote_path_fully;
 
-/*
- * These values are used to help identify parts of a repository to fsync.
- * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the
- * repository and so shouldn't be fsynced.
- */
-enum fsync_component {
-       FSYNC_COMPONENT_NONE,
-       FSYNC_COMPONENT_LOOSE_OBJECT            = 1 << 0,
-       FSYNC_COMPONENT_PACK                    = 1 << 1,
-       FSYNC_COMPONENT_PACK_METADATA           = 1 << 2,
-       FSYNC_COMPONENT_COMMIT_GRAPH            = 1 << 3,
-       FSYNC_COMPONENT_INDEX                   = 1 << 4,
-       FSYNC_COMPONENT_REFERENCE               = 1 << 5,
-};
-
-#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
-                                 FSYNC_COMPONENT_PACK)
-
-#define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \
-                                          FSYNC_COMPONENT_COMMIT_GRAPH)
-
-#define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \
-                                  FSYNC_COMPONENTS_DERIVED_METADATA) & \
-                                 ~FSYNC_COMPONENT_LOOSE_OBJECT)
-
-#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
-                                   FSYNC_COMPONENT_REFERENCE)
-
-#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
-                               FSYNC_COMPONENT_INDEX)
-
-#define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \
-                             FSYNC_COMPONENT_PACK | \
-                             FSYNC_COMPONENT_PACK_METADATA | \
-                             FSYNC_COMPONENT_COMMIT_GRAPH | \
-                             FSYNC_COMPONENT_INDEX | \
-                             FSYNC_COMPONENT_REFERENCE)
-
-#ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT
-#define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT
-#endif
-
-/*
- * A bitmask indicating which components of the repo should be fsynced.
- */
-extern enum fsync_component fsync_components;
-extern int fsync_object_files;
-extern int use_fsync;
-
-enum fsync_method {
-       FSYNC_METHOD_FSYNC,
-       FSYNC_METHOD_WRITEOUT_ONLY,
-       FSYNC_METHOD_BATCH,
-};
-
-extern enum fsync_method fsync_method;
-
 #define MTIME_CHANGED  0x0001
 #define CTIME_CHANGED  0x0002
 #define OWNER_CHANGED  0x0004
@@ -1045,29 +988,12 @@ int update_server_info(int);
 extern const char *git_mailmap_file;
 extern const char *git_mailmap_blob;
 
-/* IO helper functions */
-void maybe_flush_or_die(FILE *, const char *);
-__attribute__((format (printf, 2, 3)))
-void fprintf_or_die(FILE *, const char *fmt, ...);
-void fwrite_or_die(FILE *f, const void *buf, size_t count);
-void fflush_or_die(FILE *f);
-
 #define COPY_READ_ERROR (-2)
 #define COPY_WRITE_ERROR (-3)
 int copy_fd(int ifd, int ofd);
 int copy_file(const char *dst, const char *src, int mode);
 int copy_file_with_time(const char *dst, const char *src, int mode);
 
-void write_or_die(int fd, const void *buf, size_t count);
-void fsync_or_die(int fd, const char *);
-int fsync_component(enum fsync_component component, int fd);
-void fsync_component_or_die(enum fsync_component component, int fd, const char *msg);
-
-static inline int batch_fsync_enabled(enum fsync_component component)
-{
-       return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
-}
-
 /* pager.c */
 void setup_pager(void);
 int pager_in_use(void);
index 03a4fcaba5ba789513a885e43ca283b76e4f692e..5ad9ae914366f68e092c60c4b2ff86d14b6fea27 100644 (file)
--- a/config.c
+++ b/config.c
@@ -30,6 +30,7 @@
 #include "setup.h"
 #include "worktree.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 struct config_source {
        struct config_source *prev;
index 793a59da12b6e6bc23c0542e83f33dcfdc8509fe..4cd9014e367ed6959dfc7393975dc5d9c6ba7960 100644 (file)
@@ -3,6 +3,7 @@
 
 #include "cache.h"
 #include "hash.h"
+#include "write-or-die.h"
 
 struct progress;
 
index 169a55407fd4936ce85b09be25761574d788d6b3..f9a2496c7ff07db8367a0b6db1e5e0496403c253 100644 (file)
@@ -9,6 +9,7 @@
 #include "strvec.h"
 #include "object-store.h"
 #include "packfile.h"
+#include "write-or-die.h"
 
 struct archive_dir {
        const char *path;
index 649d16ac27c49556689f0a05de5fb94abdc7ba70..63c697e7e97cca35e52df3847bb017713f6940ef 100644 (file)
@@ -25,6 +25,7 @@
 #include "setup.h"
 #include "shallow.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 int trust_executable_bit = 1;
 int trust_ctime = 1;
index 042ccf12e8ccfbb4e05e07cf7efa61a5f1a4dc80..89aad1b42c7f1e14868fb28d963c20979fe452ad 100644 (file)
@@ -18,6 +18,7 @@
 #include "protocol.h"
 #include "date.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 static const char content_type[] = "Content-Type";
 static const char content_length[] = "Content-Length";
index e2bf8d6df75da73172c7e95c279b6b10da82aa74..ba7b885984f67492421952171aaee572896b496a 100644 (file)
@@ -23,6 +23,7 @@
 #include "help.h"
 #include "range-diff.h"
 #include "strmap.h"
+#include "write-or-die.h"
 
 static struct decoration name_decoration = { "object names" };
 static int decoration_loaded;
index 30469eb4d8d36866b7ba0ea303332bf61962ba4c..36ae0fea4a3c6ba06899d6248fb2c2a7578b378d 100644 (file)
@@ -4,6 +4,7 @@
 #include "hex.h"
 #include "run-command.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 char packet_buffer[LARGE_PACKET_MAX];
 static const char *packet_trace_prefix = "git";
index d2b8925ebd0fa882fc11b40a9b6fd024468edd77..e6a6971381e09a5f153b25d29b69bb5b1c1d6270 100644 (file)
@@ -17,6 +17,7 @@
 #include "../setup.h"
 #include "../worktree.h"
 #include "../wrapper.h"
+#include "../write-or-die.h"
 
 /*
  * This backend uses the following flags in `ref_update::flags` for
index 3334c07003c76e8b8776418e635ec63f7fcfe948..1eba1015dd5aa8378bf722b50a2b466774b43f0d 100644 (file)
@@ -9,6 +9,7 @@
 #include "../iterator.h"
 #include "../lockfile.h"
 #include "../chdir-notify.h"
+#include "../write-or-die.h"
 
 enum mmap_strategy {
        /*
index 260ea200bb091f71f1b5d25ee28b17f8042719e7..0f2410da8e7eed233117034c2d2f5fc7ccf54304 100644 (file)
@@ -22,6 +22,7 @@
 #include "protocol.h"
 #include "quote.h"
 #include "transport.h"
+#include "write-or-die.h"
 
 static struct remote *remote;
 /* always ends with a trailing slash */
index f531cb482121378f31c668603c7d163e9c8f8642..11f41a8d81e541efa956ba1e114eae0a37284742 100644 (file)
@@ -16,8 +16,9 @@
 #include "version.h"
 #include "oid-array.h"
 #include "gpg-interface.h"
-#include "cache.h"
 #include "shallow.h"
+#include "trace2.h"
+#include "write-or-die.h"
 
 int option_parse_push_signed(const struct option *opt,
                             const char *arg, int unset)
index 4905cf9b32afbb8437d8cfacb2a7e9eaf3958b5d..0af582858bf4175e8c3047cffc10eb156661a631 100644 (file)
@@ -5,6 +5,7 @@
 #include "sideband.h"
 #include "help.h"
 #include "pkt-line.h"
+#include "write-or-die.h"
 
 struct keyword_entry {
        /*
index c5e052e537805075682f16204f1ab16991a8e0fe..f4d134a145214f3964e781db949c05cf51f32fc5 100644 (file)
@@ -1,6 +1,7 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "test-tool.h"
 #include "pkt-line.h"
+#include "write-or-die.h"
 
 static void pack_line(const char *line)
 {
index 1155f795382c23e3209922b3a9a9e24b4e444d90..eb3d0b3fa36799617f4b1a03f356519dac1a7924 100644 (file)
@@ -30,6 +30,7 @@
 #include "commit-graph.h"
 #include "commit-reach.h"
 #include "shallow.h"
+#include "write-or-die.h"
 
 /* Remember to update object flag allocation in object.h */
 #define THEY_HAVE      (1u << 11)
index a7afc303db2dc02108cbafc091fe82cbc0739500..cc9e0787a1de50e9032a06d4036835bc9d1b35b9 100644 (file)
@@ -1,7 +1,8 @@
-#include "cache.h"
+#include "git-compat-util.h"
 #include "config.h"
 #include "run-command.h"
 #include "wrapper.h"
+#include "write-or-die.h"
 
 /*
  * Some cases use stdio, but want to flush after the write
diff --git a/write-or-die.h b/write-or-die.h
new file mode 100644 (file)
index 0000000..65a5c42
--- /dev/null
@@ -0,0 +1,78 @@
+#ifndef WRITE_OR_DIE_H
+#define WRITE_OR_DIE_H
+
+void maybe_flush_or_die(FILE *, const char *);
+__attribute__((format (printf, 2, 3)))
+void fprintf_or_die(FILE *, const char *fmt, ...);
+void fwrite_or_die(FILE *f, const void *buf, size_t count);
+void fflush_or_die(FILE *f);
+void write_or_die(int fd, const void *buf, size_t count);
+
+/*
+ * These values are used to help identify parts of a repository to fsync.
+ * FSYNC_COMPONENT_NONE identifies data that will not be a persistent part of the
+ * repository and so shouldn't be fsynced.
+ */
+enum fsync_component {
+       FSYNC_COMPONENT_NONE,
+       FSYNC_COMPONENT_LOOSE_OBJECT            = 1 << 0,
+       FSYNC_COMPONENT_PACK                    = 1 << 1,
+       FSYNC_COMPONENT_PACK_METADATA           = 1 << 2,
+       FSYNC_COMPONENT_COMMIT_GRAPH            = 1 << 3,
+       FSYNC_COMPONENT_INDEX                   = 1 << 4,
+       FSYNC_COMPONENT_REFERENCE               = 1 << 5,
+};
+
+#define FSYNC_COMPONENTS_OBJECTS (FSYNC_COMPONENT_LOOSE_OBJECT | \
+                                 FSYNC_COMPONENT_PACK)
+
+#define FSYNC_COMPONENTS_DERIVED_METADATA (FSYNC_COMPONENT_PACK_METADATA | \
+                                          FSYNC_COMPONENT_COMMIT_GRAPH)
+
+#define FSYNC_COMPONENTS_DEFAULT ((FSYNC_COMPONENTS_OBJECTS | \
+                                  FSYNC_COMPONENTS_DERIVED_METADATA) & \
+                                 ~FSYNC_COMPONENT_LOOSE_OBJECT)
+
+#define FSYNC_COMPONENTS_COMMITTED (FSYNC_COMPONENTS_OBJECTS | \
+                                   FSYNC_COMPONENT_REFERENCE)
+
+#define FSYNC_COMPONENTS_ADDED (FSYNC_COMPONENTS_COMMITTED | \
+                               FSYNC_COMPONENT_INDEX)
+
+#define FSYNC_COMPONENTS_ALL (FSYNC_COMPONENT_LOOSE_OBJECT | \
+                             FSYNC_COMPONENT_PACK | \
+                             FSYNC_COMPONENT_PACK_METADATA | \
+                             FSYNC_COMPONENT_COMMIT_GRAPH | \
+                             FSYNC_COMPONENT_INDEX | \
+                             FSYNC_COMPONENT_REFERENCE)
+
+#ifndef FSYNC_COMPONENTS_PLATFORM_DEFAULT
+#define FSYNC_COMPONENTS_PLATFORM_DEFAULT FSYNC_COMPONENTS_DEFAULT
+#endif
+
+/* IO helper functions */
+void fsync_or_die(int fd, const char *);
+int fsync_component(enum fsync_component component, int fd);
+void fsync_component_or_die(enum fsync_component component, int fd, const char *msg);
+
+/*
+ * A bitmask indicating which components of the repo should be fsynced.
+ */
+extern enum fsync_component fsync_components;
+extern int fsync_object_files;
+extern int use_fsync;
+
+enum fsync_method {
+       FSYNC_METHOD_FSYNC,
+       FSYNC_METHOD_WRITEOUT_ONLY,
+       FSYNC_METHOD_BATCH,
+};
+
+extern enum fsync_method fsync_method;
+
+static inline int batch_fsync_enabled(enum fsync_component component)
+{
+       return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH);
+}
+
+#endif /* WRITE_OR_DIE_H */