From f394e093df10f1867d9bb2180b3789ee61124aed Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 21 Mar 2023 06:25:54 +0000 Subject: treewide: be explicit about dependence on gettext.h Dozens of files made use of gettext functions, without explicitly including gettext.h. This made it more difficult to find which files could remove a dependence on cache.h. Make C files explicitly include gettext.h if they are using it. However, while compat/fsmonitor/fsm-ipc-darwin.c should also gain an include of gettext.h, it was left out to avoid conflicting with an in-flight topic. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- wrapper.c | 1 + 1 file changed, 1 insertion(+) (limited to 'wrapper.c') diff --git a/wrapper.c b/wrapper.c index 299d6489a6..0d4ceba6fc 100644 --- a/wrapper.c +++ b/wrapper.c @@ -3,6 +3,7 @@ */ #include "cache.h" #include "config.h" +#include "gettext.h" static intmax_t count_fsync_writeout_only; static intmax_t count_fsync_hardware_flush; -- cgit v1.3-5-g9baa From 0b027f6ca79cafbc14f36ff1741fc7378282f295 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 21 Mar 2023 06:25:58 +0000 Subject: abspath.h: move absolute path functions from cache.h This is another step towards letting us remove the include of cache.h in strbuf.c. It does mean that we also need to add includes of abspath.h in a number of C files. Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- abspath.c | 4 +++- abspath.h | 33 +++++++++++++++++++++++++++++++++ apply.c | 1 + archive.c | 1 + builtin/am.c | 1 + builtin/bugreport.c | 1 + builtin/bundle.c | 1 + builtin/clean.c | 1 + builtin/clone.c | 1 + builtin/config.c | 1 + builtin/credential-cache--daemon.c | 1 + builtin/diagnose.c | 1 + builtin/difftool.c | 1 + builtin/fast-import.c | 1 + builtin/fsmonitor--daemon.c | 1 + builtin/gc.c | 1 + builtin/hash-object.c | 1 + builtin/init-db.c | 1 + builtin/log.c | 1 + builtin/mailinfo.c | 1 + builtin/merge-file.c | 1 + builtin/merge.c | 1 + builtin/multi-pack-index.c | 1 + builtin/mv.c | 1 + builtin/rebase.c | 1 + builtin/receive-pack.c | 1 + builtin/rev-parse.c | 1 + builtin/stash.c | 1 + builtin/submodule--helper.c | 1 + builtin/worktree.c | 1 + cache.h | 27 --------------------------- chdir-notify.c | 1 + compat/disk.h | 1 + compat/mingw.c | 1 + compat/simple-ipc/ipc-win32.c | 1 + config.c | 1 + credential.c | 1 + daemon.c | 1 + diff-no-index.c | 1 + diff.c | 1 + dir.c | 1 + editor.c | 1 + environment.c | 1 + exec-cmd.c | 1 + gettext.c | 1 + lockfile.c | 1 + midx.c | 1 + object-file.c | 1 + parse-options.c | 1 + path.c | 1 + pathspec.c | 1 + remote.c | 1 + repository.c | 1 + rerere.c | 1 + scalar.c | 1 + sequencer.c | 1 + setup.c | 1 + strbuf.c | 1 + submodule.c | 1 + t/helper/test-path-utils.c | 1 + tmp-objdir.c | 1 + trace.c | 1 + trace2/tr2_dst.c | 1 + worktree.c | 1 + wrapper.c | 1 + 65 files changed, 98 insertions(+), 28 deletions(-) create mode 100644 abspath.h (limited to 'wrapper.c') diff --git a/abspath.c b/abspath.c index 9a81c5525b..d032f5dce5 100644 --- a/abspath.c +++ b/abspath.c @@ -1,4 +1,6 @@ -#include "cache.h" +#include "git-compat-util.h" +#include "abspath.h" +#include "strbuf.h" /* * Do not use this for inspecting *tracked* content. When path is a diff --git a/abspath.h b/abspath.h new file mode 100644 index 0000000000..7cd3de5e9d --- /dev/null +++ b/abspath.h @@ -0,0 +1,33 @@ +#ifndef ABSPATH_H +#define ABSPATH_H + +int is_directory(const char *); +char *strbuf_realpath(struct strbuf *resolved, const char *path, + int die_on_error); +char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path, + int die_on_error); +char *real_pathdup(const char *path, int die_on_error); +const char *absolute_path(const char *path); +char *absolute_pathdup(const char *path); + +/* + * Concatenate "prefix" (if len is non-zero) and "path", with no + * connecting characters (so "prefix" should end with a "/"). + * Unlike prefix_path, this should be used if the named file does + * not have to interact with index entry; i.e. name of a random file + * on the filesystem. + * + * The return value is always a newly allocated string (even if the + * prefix was empty). + */ +char *prefix_filename(const char *prefix, const char *path); + +/* Likewise, but path=="-" always yields "-" */ +char *prefix_filename_except_for_dash(const char *prefix, const char *path); + +static inline int is_absolute_path(const char *path) +{ + return is_dir_sep(path[0]) || has_dos_drive_prefix(path); +} + +#endif /* ABSPATH_H */ diff --git a/apply.c b/apply.c index e0bdd43a68..e5e11b8579 100644 --- a/apply.c +++ b/apply.c @@ -8,6 +8,7 @@ */ #include "cache.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "object-store.h" diff --git a/archive.c b/archive.c index 2c3da1cff3..c3c45a5ebe 100644 --- a/archive.c +++ b/archive.c @@ -1,4 +1,5 @@ #include "git-compat-util.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "gettext.h" diff --git a/builtin/am.c b/builtin/am.c index cc1fdf4f75..14347ecf9a 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -5,6 +5,7 @@ */ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "abspath.h" #include "config.h" #include "builtin.h" #include "exec-cmd.h" diff --git a/builtin/bugreport.c b/builtin/bugreport.c index b61cfa9464..b5dfad4e12 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "abspath.h" #include "gettext.h" #include "parse-options.h" #include "strbuf.h" diff --git a/builtin/bundle.c b/builtin/bundle.c index de3898ffa4..9e2aecadf7 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "abspath.h" #include "gettext.h" #include "strvec.h" #include "parse-options.h" diff --git a/builtin/clean.c b/builtin/clean.c index 46c51029ab..fdcf62c5df 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -8,6 +8,7 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "abspath.h" #include "cache.h" #include "config.h" #include "dir.h" diff --git a/builtin/clone.c b/builtin/clone.c index d605fcafa0..b94324ea02 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -10,6 +10,7 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "abspath.h" #include "config.h" #include "gettext.h" #include "hex.h" diff --git a/builtin/config.c b/builtin/config.c index 33b17b40b4..42e6b8d348 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "color.h" diff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c index 0f00ba4d74..62c09a271d 100644 --- a/builtin/credential-cache--daemon.c +++ b/builtin/credential-cache--daemon.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "abspath.h" #include "alloc.h" #include "gettext.h" #include "parse-options.h" diff --git a/builtin/diagnose.c b/builtin/diagnose.c index 5b12d1fb96..0f8b64994c 100644 --- a/builtin/diagnose.c +++ b/builtin/diagnose.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "abspath.h" #include "gettext.h" #include "parse-options.h" #include "diagnose.h" diff --git a/builtin/difftool.c b/builtin/difftool.c index f7380dd1cc..ed06db1208 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -13,6 +13,7 @@ */ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "abspath.h" #include "config.h" #include "builtin.h" #include "run-command.h" diff --git a/builtin/fast-import.c b/builtin/fast-import.c index f3635c7aef..7307c4657f 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "abspath.h" #include "cache.h" #include "gettext.h" #include "hex.h" diff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c index 215e3813d7..4efb141734 100644 --- a/builtin/fsmonitor--daemon.c +++ b/builtin/fsmonitor--daemon.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "gettext.h" diff --git a/builtin/gc.c b/builtin/gc.c index 32cabad7cf..ef063fc828 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -11,6 +11,7 @@ */ #include "builtin.h" +#include "abspath.h" #include "hex.h" #include "repository.h" #include "config.h" diff --git a/builtin/hash-object.c b/builtin/hash-object.c index f233eda759..7651a7a5f5 100644 --- a/builtin/hash-object.c +++ b/builtin/hash-object.c @@ -5,6 +5,7 @@ * Copyright (C) Junio C Hamano, 2005 */ #include "builtin.h" +#include "abspath.h" #include "config.h" #include "gettext.h" #include "hex.h" diff --git a/builtin/init-db.c b/builtin/init-db.c index e182bc7e83..6f724f694f 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -4,6 +4,7 @@ * Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" +#include "abspath.h" #include "config.h" #include "gettext.h" #include "refs.h" diff --git a/builtin/log.c b/builtin/log.c index e702cf126e..b7333b34cc 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -5,6 +5,7 @@ * 2006 Junio Hamano */ #include "git-compat-util.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "gettext.h" diff --git a/builtin/mailinfo.c b/builtin/mailinfo.c index e8bb011cfb..e14f7c0abc 100644 --- a/builtin/mailinfo.c +++ b/builtin/mailinfo.c @@ -3,6 +3,7 @@ * email to figure out authorship and subject */ #include "cache.h" +#include "abspath.h" #include "builtin.h" #include "gettext.h" #include "utf8.h" diff --git a/builtin/merge-file.c b/builtin/merge-file.c index ae45f523b9..c0096ee081 100644 --- a/builtin/merge-file.c +++ b/builtin/merge-file.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "abspath.h" #include "cache.h" #include "config.h" #include "gettext.h" diff --git a/builtin/merge.c b/builtin/merge.c index 2c9da4b23d..38243e55c5 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -8,6 +8,7 @@ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "environment.h" diff --git a/builtin/multi-pack-index.c b/builtin/multi-pack-index.c index e6757a4447..579bc2cac0 100644 --- a/builtin/multi-pack-index.c +++ b/builtin/multi-pack-index.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "abspath.h" #include "cache.h" #include "config.h" #include "gettext.h" diff --git a/builtin/mv.c b/builtin/mv.c index c02dddb72b..0a49bf21b0 100644 --- a/builtin/mv.c +++ b/builtin/mv.c @@ -5,6 +5,7 @@ */ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "gettext.h" diff --git a/builtin/rebase.c b/builtin/rebase.c index a2c68b8ff7..a3f8be8888 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -6,6 +6,7 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "abspath.h" #include "gettext.h" #include "hex.h" #include "run-command.h" diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 006565f851..aec5ee930b 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -1,4 +1,5 @@ #include "builtin.h" +#include "abspath.h" #include "repository.h" #include "config.h" #include "gettext.h" diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c index 5a932a861b..a4c0878bc9 100644 --- a/builtin/rev-parse.c +++ b/builtin/rev-parse.c @@ -5,6 +5,7 @@ */ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "commit.h" diff --git a/builtin/stash.c b/builtin/stash.c index 65817d0b76..52fa892f7e 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -1,5 +1,6 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "abspath.h" #include "config.h" #include "gettext.h" #include "hex.h" diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a4bdd44daa..ff1fd8c87a 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -1,5 +1,6 @@ #define USE_THE_INDEX_VARIABLE #include "builtin.h" +#include "abspath.h" #include "alloc.h" #include "gettext.h" #include "hex.h" diff --git a/builtin/worktree.c b/builtin/worktree.c index ed89b7e972..ed614ffddc 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "checkout.h" #include "config.h" #include "builtin.h" diff --git a/cache.h b/cache.h index e122de6f93..260203c7a6 100644 --- a/cache.h +++ b/cache.h @@ -598,21 +598,6 @@ const char *setup_git_directory(void); char *prefix_path(const char *prefix, int len, const char *path); char *prefix_path_gently(const char *prefix, int len, int *remaining, const char *path); -/* - * Concatenate "prefix" (if len is non-zero) and "path", with no - * connecting characters (so "prefix" should end with a "/"). - * Unlike prefix_path, this should be used if the named file does - * not have to interact with index entry; i.e. name of a random file - * on the filesystem. - * - * The return value is always a newly allocated string (even if the - * prefix was empty). - */ -char *prefix_filename(const char *prefix, const char *path); - -/* Likewise, but path=="-" always yields "-" */ -char *prefix_filename_except_for_dash(const char *prefix, const char *path); - int check_filename(const char *prefix, const char *name); void verify_filename(const char *prefix, const char *name, @@ -1160,18 +1145,6 @@ char *interpolate_path(const char *path, int real_home); /* NEEDSWORK: remove this synonym once in-flight topics have migrated */ #define expand_user_path interpolate_path const char *enter_repo(const char *path, int strict); -static inline int is_absolute_path(const char *path) -{ - return is_dir_sep(path[0]) || has_dos_drive_prefix(path); -} -int is_directory(const char *); -char *strbuf_realpath(struct strbuf *resolved, const char *path, - int die_on_error); -char *strbuf_realpath_forgiving(struct strbuf *resolved, const char *path, - int die_on_error); -char *real_pathdup(const char *path, int die_on_error); -const char *absolute_path(const char *path); -char *absolute_pathdup(const char *path); const char *remove_leading_path(const char *in, const char *prefix); const char *relative_path(const char *in, const char *prefix, struct strbuf *sb); int normalize_path_copy_len(char *dst, const char *src, int *prefix_len); diff --git a/chdir-notify.c b/chdir-notify.c index 5f7f2c2ac2..929ec01b3a 100644 --- a/chdir-notify.c +++ b/chdir-notify.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "chdir-notify.h" #include "list.h" #include "strbuf.h" diff --git a/compat/disk.h b/compat/disk.h index a04a8d294a..6c979c27d8 100644 --- a/compat/disk.h +++ b/compat/disk.h @@ -2,6 +2,7 @@ #define COMPAT_DISK_H #include "git-compat-util.h" +#include "abspath.h" #include "gettext.h" static int get_disk_info(struct strbuf *out) diff --git a/compat/mingw.c b/compat/mingw.c index a9e5570288..cbcd03aea9 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -7,6 +7,7 @@ #include "../strbuf.h" #include "../run-command.h" #include "../cache.h" +#include "../abspath.h" #include "../alloc.h" #include "win32/lazyload.h" #include "../config.h" diff --git a/compat/simple-ipc/ipc-win32.c b/compat/simple-ipc/ipc-win32.c index f011e5cead..997f614434 100644 --- a/compat/simple-ipc/ipc-win32.c +++ b/compat/simple-ipc/ipc-win32.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "gettext.h" #include "simple-ipc.h" #include "strbuf.h" diff --git a/config.c b/config.c index f30a6d8e68..6815919ec3 100644 --- a/config.c +++ b/config.c @@ -6,6 +6,7 @@ * */ #include "cache.h" +#include "abspath.h" #include "alloc.h" #include "date.h" #include "branch.h" diff --git a/credential.c b/credential.c index 5244f3c12c..e6417bf880 100644 --- a/credential.c +++ b/credential.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "config.h" #include "credential.h" #include "gettext.h" diff --git a/daemon.c b/daemon.c index 8908e7f8d2..bb795ca3ca 100644 --- a/daemon.c +++ b/daemon.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "pkt-line.h" diff --git a/diff-no-index.c b/diff-no-index.c index 287a113bad..934a24bee5 100644 --- a/diff-no-index.c +++ b/diff-no-index.c @@ -5,6 +5,7 @@ */ #include "cache.h" +#include "abspath.h" #include "color.h" #include "commit.h" #include "blob.h" diff --git a/diff.c b/diff.c index 00746f2f86..1b0be99c06 100644 --- a/diff.c +++ b/diff.c @@ -2,6 +2,7 @@ * Copyright (C) 2005 Junio C Hamano */ #include "cache.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "gettext.h" diff --git a/dir.c b/dir.c index 46f1bb6e5b..c72481c60e 100644 --- a/dir.c +++ b/dir.c @@ -6,6 +6,7 @@ * Junio Hamano, 2005-2006 */ #include "git-compat-util.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "dir.h" diff --git a/editor.c b/editor.c index 58e790548d..2d3e6be64e 100644 --- a/editor.c +++ b/editor.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "config.h" #include "gettext.h" #include "strbuf.h" diff --git a/environment.c b/environment.c index 82a1fc17d0..c69571f0b2 100644 --- a/environment.c +++ b/environment.c @@ -8,6 +8,7 @@ * are. */ #include "cache.h" +#include "abspath.h" #include "branch.h" #include "environment.h" #include "gettext.h" diff --git a/exec-cmd.c b/exec-cmd.c index 282d95af08..042d9247a5 100644 --- a/exec-cmd.c +++ b/exec-cmd.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "exec-cmd.h" #include "gettext.h" #include "quote.h" diff --git a/gettext.c b/gettext.c index f139008d0a..3e7b3baabc 100644 --- a/gettext.c +++ b/gettext.c @@ -3,6 +3,7 @@ */ #include "cache.h" +#include "abspath.h" #include "exec-cmd.h" #include "gettext.h" #include "strbuf.h" diff --git a/lockfile.c b/lockfile.c index ab6490a391..673c21d17a 100644 --- a/lockfile.c +++ b/lockfile.c @@ -3,6 +3,7 @@ */ #include "cache.h" +#include "abspath.h" #include "gettext.h" #include "lockfile.h" diff --git a/midx.c b/midx.c index e132ef250e..b111665dca 100644 --- a/midx.c +++ b/midx.c @@ -1,4 +1,5 @@ #include "git-compat-util.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "csum-file.h" diff --git a/object-file.c b/object-file.c index 39660d49db..bee41b3047 100644 --- a/object-file.c +++ b/object-file.c @@ -7,6 +7,7 @@ * creation etc. */ #include "git-compat-util.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "gettext.h" diff --git a/parse-options.c b/parse-options.c index 084b4f1062..a577cc85f6 100644 --- a/parse-options.c +++ b/parse-options.c @@ -1,5 +1,6 @@ #include "git-compat-util.h" #include "parse-options.h" +#include "abspath.h" #include "cache.h" #include "config.h" #include "commit.h" diff --git a/path.c b/path.c index 3f2702cbe4..3976c0d7ac 100644 --- a/path.c +++ b/path.c @@ -2,6 +2,7 @@ * Utilities for paths and pathnames */ #include "cache.h" +#include "abspath.h" #include "gettext.h" #include "hex.h" #include "repository.h" diff --git a/pathspec.c b/pathspec.c index 868b4d280c..53763e272f 100644 --- a/pathspec.c +++ b/pathspec.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "config.h" #include "dir.h" #include "gettext.h" diff --git a/remote.c b/remote.c index edb1e07497..2bae247a0a 100644 --- a/remote.c +++ b/remote.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "gettext.h" diff --git a/repository.c b/repository.c index 937fa974b3..4412f63322 100644 --- a/repository.c +++ b/repository.c @@ -4,6 +4,7 @@ */ #define USE_THE_INDEX_VARIABLE #include "cache.h" +#include "abspath.h" #include "repository.h" #include "object-store.h" #include "config.h" diff --git a/rerere.c b/rerere.c index 9428cbca7b..c3258e1390 100644 --- a/rerere.c +++ b/rerere.c @@ -1,4 +1,5 @@ #include "git-compat-util.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "gettext.h" diff --git a/scalar.c b/scalar.c index ca19b95ce4..fe61a3ebdd 100644 --- a/scalar.c +++ b/scalar.c @@ -3,6 +3,7 @@ */ #include "cache.h" +#include "abspath.h" #include "gettext.h" #include "parse-options.h" #include "config.h" diff --git a/sequencer.c b/sequencer.c index 7fa776b061..c61c1fc4d8 100644 --- a/sequencer.c +++ b/sequencer.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "alloc.h" #include "config.h" #include "environment.h" diff --git a/setup.c b/setup.c index 8a4ccee4c2..8f385d9f29 100644 --- a/setup.c +++ b/setup.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "gettext.h" #include "repository.h" #include "config.h" diff --git a/strbuf.c b/strbuf.c index b9cd593b14..9633e37b62 100644 --- a/strbuf.c +++ b/strbuf.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "alloc.h" #include "environment.h" #include "gettext.h" diff --git a/submodule.c b/submodule.c index 8b551e5327..13ff333f68 100644 --- a/submodule.c +++ b/submodule.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "alloc.h" #include "repository.h" #include "config.h" diff --git a/t/helper/test-path-utils.c b/t/helper/test-path-utils.c index f69709d674..d3d00dc34f 100644 --- a/t/helper/test-path-utils.c +++ b/t/helper/test-path-utils.c @@ -1,5 +1,6 @@ #include "test-tool.h" #include "cache.h" +#include "abspath.h" #include "string-list.h" #include "utf8.h" diff --git a/tmp-objdir.c b/tmp-objdir.c index 2a2012eb6d..fff15cb6b5 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -1,5 +1,6 @@ #include "cache.h" #include "tmp-objdir.h" +#include "abspath.h" #include "chdir-notify.h" #include "dir.h" #include "sigchain.h" diff --git a/trace.c b/trace.c index efa4e2d8e0..2b41c683fc 100644 --- a/trace.c +++ b/trace.c @@ -22,6 +22,7 @@ */ #include "cache.h" +#include "abspath.h" #include "quote.h" struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 }; diff --git a/trace2/tr2_dst.c b/trace2/tr2_dst.c index 8a21dd2972..273260e1f1 100644 --- a/trace2/tr2_dst.c +++ b/trace2/tr2_dst.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "sigchain.h" #include "trace2/tr2_dst.h" #include "trace2/tr2_sid.h" diff --git a/worktree.c b/worktree.c index 09eb522e5a..b7bc4c7bb7 100644 --- a/worktree.c +++ b/worktree.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "abspath.h" #include "alloc.h" #include "gettext.h" #include "repository.h" diff --git a/wrapper.c b/wrapper.c index 0d4ceba6fc..df1fa6286d 100644 --- a/wrapper.c +++ b/wrapper.c @@ -2,6 +2,7 @@ * Various trivial helper wrappers around standard functions */ #include "cache.h" +#include "abspath.h" #include "config.h" #include "gettext.h" -- cgit v1.3-5-g9baa From d5ebb50dcb2bae27cf9f233088f7258f21e72be7 Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Tue, 21 Mar 2023 06:26:01 +0000 Subject: wrapper.h: move declarations for wrapper.c functions from cache.h Signed-off-by: Elijah Newren Signed-off-by: Junio C Hamano --- apply.c | 1 + builtin/am.c | 1 + builtin/bisect.c | 1 + builtin/branch.c | 1 + builtin/bugreport.c | 2 +- builtin/config.c | 1 + builtin/credential-cache.c | 1 + builtin/difftool.c | 1 + builtin/fast-import.c | 1 + builtin/fmt-merge-msg.c | 1 + builtin/gc.c | 1 + builtin/get-tar-commit-id.c | 1 + builtin/index-pack.c | 1 + builtin/init-db.c | 1 + builtin/merge.c | 1 + builtin/pack-objects.c | 1 + builtin/rebase.c | 1 + builtin/receive-pack.c | 1 + builtin/rerere.c | 1 + builtin/unpack-file.c | 1 + builtin/worktree.c | 1 + cache.h | 32 -------------------------------- commit-graph.c | 1 + compat/mingw.c | 1 + compat/terminal.c | 1 + config.c | 1 + convert.c | 1 + copy.c | 1 + csum-file.c | 1 + daemon.c | 1 + diff.c | 1 + dir.c | 1 + entry.c | 1 + environment.c | 1 + fetch-pack.c | 1 + gpg-interface.c | 1 + http-backend.c | 1 + imap-send.c | 1 + ll-merge.c | 1 + merge-recursive.c | 1 + notes-merge.c | 1 + object-file.c | 1 + packfile.c | 1 + parallel-checkout.c | 1 + pkt-line.c | 1 + read-cache.c | 1 + rebase-interactive.c | 1 + refs.c | 1 + refs/files-backend.c | 3 ++- rerere.c | 1 + sequencer.c | 1 + server-info.c | 1 + shallow.c | 1 + strbuf.c | 1 + streaming.c | 1 + t/helper/test-delta.c | 1 + t/helper/test-fsmonitor-client.c | 1 + t/helper/test-read-cache.c | 1 + tag.c | 1 + tempfile.c | 1 + trace.c | 1 + transport-helper.c | 1 + transport.c | 1 + usage.c | 1 + worktree.c | 1 + wrapper.c | 1 + wrapper.h | 36 ++++++++++++++++++++++++++++++++++++ write-or-die.c | 1 + 68 files changed, 103 insertions(+), 34 deletions(-) create mode 100644 wrapper.h (limited to 'wrapper.c') diff --git a/apply.c b/apply.c index e5e11b8579..373565a7ba 100644 --- a/apply.c +++ b/apply.c @@ -26,6 +26,7 @@ #include "rerere.h" #include "apply.h" #include "entry.h" +#include "wrapper.h" struct gitdiff_data { struct strbuf *root; diff --git a/builtin/am.c b/builtin/am.c index 14347ecf9a..37f82b3eb4 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -38,6 +38,7 @@ #include "packfile.h" #include "repository.h" #include "pretty.h" +#include "wrapper.h" /** * Returns the length of the first line of msg. diff --git a/builtin/bisect.c b/builtin/bisect.c index 09188e554b..31cc57e45b 100644 --- a/builtin/bisect.c +++ b/builtin/bisect.c @@ -11,6 +11,7 @@ #include "prompt.h" #include "quote.h" #include "revision.h" +#include "wrapper.h" static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS") static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV") diff --git a/builtin/branch.c b/builtin/branch.c index 56dbee97d2..98475ea532 100644 --- a/builtin/branch.c +++ b/builtin/branch.c @@ -26,6 +26,7 @@ #include "worktree.h" #include "help.h" #include "commit-reach.h" +#include "wrapper.h" static const char * const builtin_branch_usage[] = { N_("git branch [] [-r | -a] [--merged] [--no-merged]"), diff --git a/builtin/bugreport.c b/builtin/bugreport.c index b5dfad4e12..160590e4ef 100644 --- a/builtin/bugreport.c +++ b/builtin/bugreport.c @@ -8,7 +8,7 @@ #include "hook.h" #include "hook-list.h" #include "diagnose.h" - +#include "wrapper.h" static void get_system_info(struct strbuf *sys_info) { diff --git a/builtin/config.c b/builtin/config.c index 42e6b8d348..1c1e006ff3 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -9,6 +9,7 @@ #include "urlmatch.h" #include "quote.h" #include "worktree.h" +#include "wrapper.h" static const char *const builtin_config_usage[] = { N_("git config []"), diff --git a/builtin/credential-cache.c b/builtin/credential-cache.c index 25f2f71c21..af56a44923 100644 --- a/builtin/credential-cache.c +++ b/builtin/credential-cache.c @@ -1,6 +1,7 @@ #include "builtin.h" #include "gettext.h" #include "parse-options.h" +#include "wrapper.h" #ifndef NO_UNIX_SOCKETS diff --git a/builtin/difftool.c b/builtin/difftool.c index ed06db1208..59465c39f1 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -27,6 +27,7 @@ #include "object-store.h" #include "dir.h" #include "entry.h" +#include "wrapper.h" static int trust_exit_code; diff --git a/builtin/fast-import.c b/builtin/fast-import.c index 7307c4657f..3300b7f30f 100644 --- a/builtin/fast-import.c +++ b/builtin/fast-import.c @@ -23,6 +23,7 @@ #include "commit-reach.h" #include "khash.h" #include "date.h" +#include "wrapper.h" #define PACK_ID_BITS 16 #define MAX_PACK_ID ((1<] [--log[=] | --no-log] [--file ]"), diff --git a/builtin/gc.c b/builtin/gc.c index ef063fc828..2107e3d1f2 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -35,6 +35,7 @@ #include "exec-cmd.h" #include "gettext.h" #include "hook.h" +#include "wrapper.h" #define FAILED_RUN "failed to run %s" diff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c index 491af9202d..6745796998 100644 --- a/builtin/get-tar-commit-id.c +++ b/builtin/get-tar-commit-id.c @@ -6,6 +6,7 @@ #include "tar.h" #include "builtin.h" #include "quote.h" +#include "wrapper.h" static const char builtin_get_tar_commit_id_usage[] = "git get-tar-commit-id"; diff --git a/builtin/index-pack.c b/builtin/index-pack.c index bae5b05403..2393897cb8 100644 --- a/builtin/index-pack.c +++ b/builtin/index-pack.c @@ -19,6 +19,7 @@ #include "object-store.h" #include "replace-object.h" #include "promisor-remote.h" +#include "wrapper.h" static const char index_pack_usage[] = "git index-pack [-v] [-o ] [--keep | --keep=] [--[no-]rev-index] [--verify] [--strict] ( | --stdin [--fix-thin] [])"; diff --git a/builtin/init-db.c b/builtin/init-db.c index 6f724f694f..a5d4f5c8ec 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -12,6 +12,7 @@ #include "exec-cmd.h" #include "parse-options.h" #include "worktree.h" +#include "wrapper.h" #ifndef DEFAULT_GIT_TEMPLATE_DIR #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates" diff --git a/builtin/merge.c b/builtin/merge.c index 38243e55c5..f4f4a220f3 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -49,6 +49,7 @@ #include "commit-reach.h" #include "wt-status.h" #include "commit-graph.h" +#include "wrapper.h" #define DEFAULT_TWOHEAD (1<<0) #define DEFAULT_OCTOPUS (1<<1) diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 1ca800c7c5..8b55a088a7 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -40,6 +40,7 @@ #include "shallow.h" #include "promisor-remote.h" #include "pack-mtimes.h" +#include "wrapper.h" /* * Objects we are going to pack are collected in the `to_pack` structure. diff --git a/builtin/rebase.c b/builtin/rebase.c index a3f8be8888..d2f8f703d6 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -32,6 +32,7 @@ #include "rebase-interactive.h" #include "reset.h" #include "hook.h" +#include "wrapper.h" static char const * const builtin_rebase_usage[] = { N_("git rebase [-i] [options] [--exec ] " diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index aec5ee930b..ae49ea8c2a 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -33,6 +33,7 @@ #include "commit-reach.h" #include "worktree.h" #include "shallow.h" +#include "wrapper.h" static const char * const receive_pack_usage[] = { N_("git receive-pack "), diff --git a/builtin/rerere.c b/builtin/rerere.c index 24c7875572..d4a03707b1 100644 --- a/builtin/rerere.c +++ b/builtin/rerere.c @@ -6,6 +6,7 @@ #include "parse-options.h" #include "string-list.h" #include "rerere.h" +#include "wrapper.h" #include "xdiff/xdiff.h" #include "xdiff-interface.h" #include "pathspec.h" diff --git a/builtin/unpack-file.c b/builtin/unpack-file.c index e9b105a539..4cbb403929 100644 --- a/builtin/unpack-file.c +++ b/builtin/unpack-file.c @@ -2,6 +2,7 @@ #include "config.h" #include "hex.h" #include "object-store.h" +#include "wrapper.h" static char *create_temp_file(struct object_id *oid) { diff --git a/builtin/worktree.c b/builtin/worktree.c index ed614ffddc..1533b4ab43 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -16,6 +16,7 @@ #include "submodule.h" #include "utf8.h" #include "worktree.h" +#include "wrapper.h" #include "quote.h" #define BUILTIN_WORKTREE_ADD_USAGE \ diff --git a/cache.h b/cache.h index 705c41992b..31c722533f 100644 --- a/cache.h +++ b/cache.h @@ -1085,10 +1085,6 @@ const char *repo_find_unique_abbrev(struct repository *r, const struct object_id int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len); #define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len) -/* set default permissions by passing mode arguments to open(2) */ -int git_mkstemps_mode(char *pattern, int suffix_len, int mode); -int git_mkstemp_mode(char *pattern, int mode); - /* * NOTE NOTE NOTE!! * @@ -1423,31 +1419,6 @@ static inline int batch_fsync_enabled(enum fsync_component component) return (fsync_components & component) && (fsync_method == FSYNC_METHOD_BATCH); } -ssize_t read_in_full(int fd, void *buf, size_t count); -ssize_t write_in_full(int fd, const void *buf, size_t count); -ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset); - -static inline ssize_t write_str_in_full(int fd, const char *str) -{ - return write_in_full(fd, str, strlen(str)); -} - -/** - * Open (and truncate) the file at path, write the contents of buf to it, - * and close it. Dies if any errors are encountered. - */ -void write_file_buf(const char *path, const char *buf, size_t len); - -/** - * Like write_file_buf(), but format the contents into a buffer first. - * Additionally, write_file() will append a newline if one is not already - * present, making it convenient to write text files: - * - * write_file(path, "counter: %d", ctr); - */ -__attribute__((format (printf, 2, 3))) -void write_file(const char *path, const char *fmt, ...); - /* pager.c */ void setup_pager(void); int pager_in_use(void); @@ -1571,7 +1542,4 @@ int versioncmp(const char *s1, const char *s2); */ int print_sha1_ellipsis(void); -/* Return 1 if the file is empty or does not exists, 0 otherwise. */ -int is_empty_or_missing_file(const char *filename); - #endif /* CACHE_H */ diff --git a/commit-graph.c b/commit-graph.c index 8f21a0a0c2..5481736c76 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -22,6 +22,7 @@ #include "json-writer.h" #include "trace2.h" #include "chunk-format.h" +#include "wrapper.h" void git_test_write_commit_graph_or_die(void) { diff --git a/compat/mingw.c b/compat/mingw.c index cbcd03aea9..d48899bf7b 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -11,6 +11,7 @@ #include "../alloc.h" #include "win32/lazyload.h" #include "../config.h" +#include "../wrapper.h" #include "dir.h" #include "gettext.h" #define SECURITY_WIN32 diff --git a/compat/terminal.c b/compat/terminal.c index afebe6b249..ed2b30b38f 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -6,6 +6,7 @@ #include "run-command.h" #include "string-list.h" #include "hashmap.h" +#include "wrapper.h" #if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE) diff --git a/config.c b/config.c index 6815919ec3..5b1a5d5205 100644 --- a/config.c +++ b/config.c @@ -28,6 +28,7 @@ #include "replace-object.h" #include "refs.h" #include "worktree.h" +#include "wrapper.h" struct config_source { struct config_source *prev; diff --git a/convert.c b/convert.c index 2bd54244b5..da06e2f51c 100644 --- a/convert.c +++ b/convert.c @@ -11,6 +11,7 @@ #include "sub-process.h" #include "utf8.h" #include "ll-merge.h" +#include "wrapper.h" /* * convert.c - convert a file when checking it out and checking it in. diff --git a/copy.c b/copy.c index 4de6a110f0..c3250f0822 100644 --- a/copy.c +++ b/copy.c @@ -1,4 +1,5 @@ #include "cache.h" +#include "wrapper.h" int copy_fd(int ifd, int ofd) { diff --git a/csum-file.c b/csum-file.c index cce13c0f04..2d22f80d90 100644 --- a/csum-file.c +++ b/csum-file.c @@ -10,6 +10,7 @@ #include "cache.h" #include "progress.h" #include "csum-file.h" +#include "wrapper.h" static void verify_buffer_or_die(struct hashfile *f, const void *buf, diff --git a/daemon.c b/daemon.c index bb795ca3ca..e35604e194 100644 --- a/daemon.c +++ b/daemon.c @@ -6,6 +6,7 @@ #include "run-command.h" #include "strbuf.h" #include "string-list.h" +#include "wrapper.h" #ifdef NO_INITGROUPS #define initgroups(x, y) (0) /* nothing */ diff --git a/diff.c b/diff.c index 1b0be99c06..1b0b24c21c 100644 --- a/diff.c +++ b/diff.c @@ -33,6 +33,7 @@ #include "promisor-remote.h" #include "dir.h" #include "strmap.h" +#include "wrapper.h" #ifdef NO_FAST_WORKING_DIRECTORY #define FAST_WORKING_DIRECTORY 0 diff --git a/dir.c b/dir.c index c72481c60e..b57c770e68 100644 --- a/dir.c +++ b/dir.c @@ -21,6 +21,7 @@ #include "ewah/ewok.h" #include "fsmonitor.h" #include "submodule-config.h" +#include "wrapper.h" /* * Tells read_directory_recursive how a file or directory should be treated. diff --git a/entry.c b/entry.c index acb76a61ac..70212af260 100644 --- a/entry.c +++ b/entry.c @@ -10,6 +10,7 @@ #include "fsmonitor.h" #include "entry.h" #include "parallel-checkout.h" +#include "wrapper.h" static void create_directories(const char *path, int path_len, const struct checkout *state) diff --git a/environment.c b/environment.c index c69571f0b2..bf02f3cf48 100644 --- a/environment.c +++ b/environment.c @@ -23,6 +23,7 @@ #include "tmp-objdir.h" #include "chdir-notify.h" #include "shallow.h" +#include "wrapper.h" int trust_executable_bit = 1; int trust_ctime = 1; diff --git a/fetch-pack.c b/fetch-pack.c index 359dce6afe..c119080140 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -30,6 +30,7 @@ #include "commit-graph.h" #include "sigchain.h" #include "mergesort.h" +#include "wrapper.h" static int transfer_unpack_limit = -1; static int fetch_unpack_limit = -1; diff --git a/gpg-interface.c b/gpg-interface.c index f9c5b6c3f5..6644701fda 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -10,6 +10,7 @@ #include "sigchain.h" #include "tempfile.h" #include "alias.h" +#include "wrapper.h" static int git_gpg_config(const char *, const char *, void *); diff --git a/http-backend.c b/http-backend.c index 7e7c19e66b..42e6c2596e 100644 --- a/http-backend.c +++ b/http-backend.c @@ -16,6 +16,7 @@ #include "object-store.h" #include "protocol.h" #include "date.h" +#include "wrapper.h" static const char content_type[] = "Content-Type"; static const char content_length[] = "Content-Length"; diff --git a/imap-send.c b/imap-send.c index c65a27219c..aa5b2f252d 100644 --- a/imap-send.c +++ b/imap-send.c @@ -28,6 +28,7 @@ #include "gettext.h" #include "run-command.h" #include "parse-options.h" +#include "wrapper.h" #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG) typedef void *SSL; #endif diff --git a/ll-merge.c b/ll-merge.c index 130d26501c..8be38d3bd4 100644 --- a/ll-merge.c +++ b/ll-merge.c @@ -11,6 +11,7 @@ #include "run-command.h" #include "ll-merge.h" #include "quote.h" +#include "wrapper.h" struct ll_merge_driver; diff --git a/merge-recursive.c b/merge-recursive.c index 0b0255ebc8..f918cea4c6 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -30,6 +30,7 @@ #include "tag.h" #include "tree-walk.h" #include "unpack-trees.h" +#include "wrapper.h" #include "xdiff-interface.h" struct merge_options_internal { diff --git a/notes-merge.c b/notes-merge.c index c8d0020b1a..ba2970f070 100644 --- a/notes-merge.c +++ b/notes-merge.c @@ -15,6 +15,7 @@ #include "strbuf.h" #include "notes-utils.h" #include "commit-reach.h" +#include "wrapper.h" struct notes_merge_pair { struct object_id obj, base, local, remote; diff --git a/object-file.c b/object-file.c index bee41b3047..bdf68763a5 100644 --- a/object-file.c +++ b/object-file.c @@ -38,6 +38,7 @@ #include "promisor-remote.h" #include "submodule.h" #include "fsck.h" +#include "wrapper.h" /* The maximum size for an object header. */ #define MAX_HEADER_LEN 32 diff --git a/packfile.c b/packfile.c index 3290fde15a..8c117ccee2 100644 --- a/packfile.c +++ b/packfile.c @@ -20,6 +20,7 @@ #include "midx.h" #include "commit-graph.h" #include "promisor-remote.h" +#include "wrapper.h" char *odb_pack_name(struct strbuf *buf, const unsigned char *hash, diff --git a/parallel-checkout.c b/parallel-checkout.c index 38c4dc665d..50fd7fe31e 100644 --- a/parallel-checkout.c +++ b/parallel-checkout.c @@ -12,6 +12,7 @@ #include "streaming.h" #include "thread-utils.h" #include "trace2.h" +#include "wrapper.h" struct pc_worker { struct child_process cp; diff --git a/pkt-line.c b/pkt-line.c index c8b90b2242..30469eb4d8 100644 --- a/pkt-line.c +++ b/pkt-line.c @@ -3,6 +3,7 @@ #include "gettext.h" #include "hex.h" #include "run-command.h" +#include "wrapper.h" char packet_buffer[LARGE_PACKET_MAX]; static const char *packet_trace_prefix = "git"; diff --git a/read-cache.c b/read-cache.c index 63789ea5e2..9a8d5fe97e 100644 --- a/read-cache.c +++ b/read-cache.c @@ -32,6 +32,7 @@ #include "csum-file.h" #include "promisor-remote.h" #include "hook.h" +#include "wrapper.h" /* Mask for the name length in ce_flags in the on-disk index */ diff --git a/rebase-interactive.c b/rebase-interactive.c index 649c94e69a..7c885c35bf 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -7,6 +7,7 @@ #include "commit-slab.h" #include "config.h" #include "dir.h" +#include "wrapper.h" static const char edit_todo_list_advice[] = N_("You can fix this with 'git rebase --edit-todo' " diff --git a/refs.c b/refs.c index 8684f4610f..385051752f 100644 --- a/refs.c +++ b/refs.c @@ -24,6 +24,7 @@ #include "sigchain.h" #include "date.h" #include "commit.h" +#include "wrapper.h" /* * List of all available backends diff --git a/refs/files-backend.c b/refs/files-backend.c index de3628ff3f..eb14d124e3 100644 --- a/refs/files-backend.c +++ b/refs/files-backend.c @@ -13,7 +13,8 @@ #include "../object.h" #include "../dir.h" #include "../chdir-notify.h" -#include "worktree.h" +#include "../worktree.h" +#include "../wrapper.h" /* * This backend uses the following flags in `ref_update::flags` for diff --git a/rerere.c b/rerere.c index c3258e1390..b5ccbecdcd 100644 --- a/rerere.c +++ b/rerere.c @@ -16,6 +16,7 @@ #include "object-store.h" #include "hash-lookup.h" #include "strmap.h" +#include "wrapper.h" #define RESOLVED 0 #define PUNTED 1 diff --git a/sequencer.c b/sequencer.c index c61c1fc4d8..aa7983f5b4 100644 --- a/sequencer.c +++ b/sequencer.c @@ -41,6 +41,7 @@ #include "rebase-interactive.h" #include "reset.h" #include "branch.h" +#include "wrapper.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION" diff --git a/server-info.c b/server-info.c index 7864337705..ae96d784e5 100644 --- a/server-info.c +++ b/server-info.c @@ -10,6 +10,7 @@ #include "packfile.h" #include "object-store.h" #include "strbuf.h" +#include "wrapper.h" struct update_info_ctx { FILE *cur_fp; diff --git a/shallow.c b/shallow.c index c5433a4fd3..7fcba5f6d0 100644 --- a/shallow.c +++ b/shallow.c @@ -17,6 +17,7 @@ #include "list-objects.h" #include "commit-reach.h" #include "shallow.h" +#include "wrapper.h" void set_alternate_shallow_file(struct repository *r, const char *path, int override) { diff --git a/strbuf.c b/strbuf.c index 9633e37b62..70a83e7980 100644 --- a/strbuf.c +++ b/strbuf.c @@ -8,6 +8,7 @@ #include "string-list.h" #include "utf8.h" #include "date.h" +#include "wrapper.h" int starts_with(const char *str, const char *prefix) { diff --git a/streaming.c b/streaming.c index 27841dc1d9..6c69f59504 100644 --- a/streaming.c +++ b/streaming.c @@ -7,6 +7,7 @@ #include "object-store.h" #include "replace-object.h" #include "packfile.h" +#include "wrapper.h" typedef int (*open_istream_fn)(struct git_istream *, struct repository *, diff --git a/t/helper/test-delta.c b/t/helper/test-delta.c index b15481ea59..6609fcbc12 100644 --- a/t/helper/test-delta.c +++ b/t/helper/test-delta.c @@ -12,6 +12,7 @@ #include "git-compat-util.h" #include "delta.h" #include "cache.h" +#include "wrapper.h" static const char usage_str[] = "test-tool delta (-d|-p) "; diff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c index 54a4856c48..c43fc976b8 100644 --- a/t/helper/test-fsmonitor-client.c +++ b/t/helper/test-fsmonitor-client.c @@ -9,6 +9,7 @@ #include "fsmonitor-ipc.h" #include "thread-utils.h" #include "trace2.h" +#include "wrapper.h" #ifndef HAVE_FSMONITOR_DAEMON_BACKEND int cmd__fsmonitor_client(int argc, const char **argv) diff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c index 23e9e27109..84818363d5 100644 --- a/t/helper/test-read-cache.c +++ b/t/helper/test-read-cache.c @@ -2,6 +2,7 @@ #include "test-tool.h" #include "cache.h" #include "config.h" +#include "wrapper.h" int cmd__read_cache(int argc, const char **argv) { diff --git a/tag.c b/tag.c index 18b718cca6..3408bb9433 100644 --- a/tag.c +++ b/tag.c @@ -8,6 +8,7 @@ #include "gpg-interface.h" #include "hex.h" #include "packfile.h" +#include "wrapper.h" const char *tag_type = "tag"; diff --git a/tempfile.c b/tempfile.c index e27048f970..cdd2cab3ba 100644 --- a/tempfile.c +++ b/tempfile.c @@ -45,6 +45,7 @@ #include "cache.h" #include "tempfile.h" #include "sigchain.h" +#include "wrapper.h" static VOLATILE_LIST_HEAD(tempfile_list); diff --git a/trace.c b/trace.c index 2b41c683fc..de004f6298 100644 --- a/trace.c +++ b/trace.c @@ -24,6 +24,7 @@ #include "cache.h" #include "abspath.h" #include "quote.h" +#include "wrapper.h" struct trace_key trace_default_key = { "GIT_TRACE", 0, 0, 0 }; struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE); diff --git a/transport-helper.c b/transport-helper.c index 105bb801c2..09048eab48 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -16,6 +16,7 @@ #include "refspec.h" #include "transport-internal.h" #include "protocol.h" +#include "wrapper.h" static int debug; diff --git a/transport.c b/transport.c index 80059124c0..c6179b801e 100644 --- a/transport.c +++ b/transport.c @@ -26,6 +26,7 @@ #include "object-store.h" #include "color.h" #include "bundle-uri.h" +#include "wrapper.h" static int transport_use_color = -1; static char transport_colors[][COLOR_MAXLEN] = { diff --git a/usage.c b/usage.c index 40a1c5a433..b53c99dbe5 100644 --- a/usage.c +++ b/usage.c @@ -5,6 +5,7 @@ */ #include "cache.h" #include "gettext.h" +#include "wrapper.h" static void vreportf(const char *prefix, const char *err, va_list params) { diff --git a/worktree.c b/worktree.c index b7bc4c7bb7..fe4345012c 100644 --- a/worktree.c +++ b/worktree.c @@ -9,6 +9,7 @@ #include "dir.h" #include "wt-status.h" #include "config.h" +#include "wrapper.h" void free_worktrees(struct worktree **worktrees) { diff --git a/wrapper.c b/wrapper.c index df1fa6286d..ee83757590 100644 --- a/wrapper.c +++ b/wrapper.c @@ -5,6 +5,7 @@ #include "abspath.h" #include "config.h" #include "gettext.h" +#include "wrapper.h" static intmax_t count_fsync_writeout_only; static intmax_t count_fsync_hardware_flush; diff --git a/wrapper.h b/wrapper.h new file mode 100644 index 0000000000..f0c7d0616d --- /dev/null +++ b/wrapper.h @@ -0,0 +1,36 @@ +#ifndef WRAPPER_H +#define WRAPPER_H + +/* set default permissions by passing mode arguments to open(2) */ +int git_mkstemps_mode(char *pattern, int suffix_len, int mode); +int git_mkstemp_mode(char *pattern, int mode); + +ssize_t read_in_full(int fd, void *buf, size_t count); +ssize_t write_in_full(int fd, const void *buf, size_t count); +ssize_t pread_in_full(int fd, void *buf, size_t count, off_t offset); + +static inline ssize_t write_str_in_full(int fd, const char *str) +{ + return write_in_full(fd, str, strlen(str)); +} + +/** + * Open (and truncate) the file at path, write the contents of buf to it, + * and close it. Dies if any errors are encountered. + */ +void write_file_buf(const char *path, const char *buf, size_t len); + +/** + * Like write_file_buf(), but format the contents into a buffer first. + * Additionally, write_file() will append a newline if one is not already + * present, making it convenient to write text files: + * + * write_file(path, "counter: %d", ctr); + */ +__attribute__((format (printf, 2, 3))) +void write_file(const char *path, const char *fmt, ...); + +/* Return 1 if the file is empty or does not exists, 0 otherwise. */ +int is_empty_or_missing_file(const char *filename); + +#endif /* WRAPPER_H */ diff --git a/write-or-die.c b/write-or-die.c index aaa0318e82..a7afc303db 100644 --- a/write-or-die.c +++ b/write-or-die.c @@ -1,6 +1,7 @@ #include "cache.h" #include "config.h" #include "run-command.h" +#include "wrapper.h" /* * Some cases use stdio, but want to flush after the write -- cgit v1.3-5-g9baa