{"thread":{"id":"59752","subject":"[PATCH 0/6] git-compat-util cleanups","startedAt":"2023-05-16T17:09:54Z","lastAt":"2023-07-05T17:58:42Z","messageCount":56,"participants":["Calvin Wan","Junio C Hamano","Jonathan Tan","Phillip Wood","Ramsay Jones"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"477388","messageId":"20230516170932.1358685-1-calvinwan@google.com","threadId":"59752","inReplyTo":null,"subject":"[PATCH 0/6] git-compat-util cleanups","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-16T17:09:25Z","receivedAt":"2023-05-16T17:09:54Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"This series focuses on cleaning up and reducing the scope of\ngit-compat-util.h by moving headers to their respective files and\nseparating out functionality from git-compat-util.h to a new file,\ncommon.h. I go into more detail in patch 3 as to why I believe this\nseparation is useful. \n\nBy the end of this series, git-compat-util.h includes common.h which\nincludes wrapper.h and usage.h. Since virtually every file includes\ngit-compat-util.h and the large majority of files use functions defined\nin common.h, wrapper.h, and usage.h, I believe it makes sense that those\nare also automatically included with git-compat-util.h.\n\nWhile this series does not intend to draw clearer boundaries for\ncommon.h, I am open to ideas for how it can be cleaned up more and if\nthere is a better name for the file. \n\nCalvin Wan (6):\n  strbuf.h: move declarations for strbuf.c functions from\n    git-compat-util.h\n  wrapper.h: move declarations for wrapper.c functions from\n    git-compat-util.h\n  common.h: move non-compat specific macros and functions from\n    git-compat-util.h\n  usage.h: move declarations for usage.c functions from\n    git-compat-util.h\n  treewide: remove unnecessary includes for wrapper.h\n  common: move alloc macros to common.h\n\n add-patch.c                        |   1 -\n alias.c                            |   1 -\n alloc.h                            |  75 ----\n apply.c                            |   2 -\n archive-tar.c                      |   1 -\n archive.c                          |   1 -\n attr.c                             |   1 -\n builtin/am.c                       |   1 -\n builtin/bisect.c                   |   1 -\n builtin/blame.c                    |   1 -\n builtin/branch.c                   |   1 -\n builtin/bugreport.c                |   1 -\n builtin/cat-file.c                 |   1 -\n builtin/checkout--worker.c         |   1 -\n builtin/clone.c                    |   1 -\n builtin/config.c                   |   2 -\n builtin/credential-cache--daemon.c |   1 -\n builtin/credential-cache.c         |   1 -\n builtin/difftool.c                 |   1 -\n builtin/fast-import.c              |   1 -\n builtin/fetch-pack.c               |   1 -\n builtin/fmt-merge-msg.c            |   1 -\n builtin/fsmonitor--daemon.c        |   1 -\n builtin/gc.c                       |   1 -\n builtin/get-tar-commit-id.c        |   1 -\n builtin/grep.c                     |   1 -\n builtin/index-pack.c               |   2 -\n builtin/init-db.c                  |   1 -\n builtin/log.c                      |   1 -\n builtin/merge.c                    |   2 -\n builtin/mktree.c                   |   1 -\n builtin/mv.c                       |   1 -\n builtin/name-rev.c                 |   1 -\n builtin/pack-objects.c             |   2 -\n builtin/rebase.c                   |   1 -\n builtin/receive-pack.c             |   1 -\n builtin/repack.c                   |   1 -\n builtin/rerere.c                   |   1 -\n builtin/rev-parse.c                |   1 -\n builtin/revert.c                   |   1 -\n builtin/rm.c                       |   1 -\n builtin/submodule--helper.c        |   1 -\n builtin/unpack-file.c              |   1 -\n builtin/worktree.c                 |   1 -\n bulk-checkin.c                     |   2 -\n cache-tree.c                       |   1 -\n chunk-format.c                     |   1 -\n combine-diff.c                     |   1 -\n commit-graph.c                     |   1 -\n commit-reach.c                     |   1 -\n common.h                           | 551 ++++++++++++++++++++++++\n compat/terminal.c                  |   1 -\n config.c                           |   2 -\n convert.c                          |   1 -\n copy.c                             |   1 -\n csum-file.c                        |   1 -\n daemon.c                           |   2 -\n delta-islands.c                    |   1 -\n diff.c                             |   2 -\n diffcore-rename.c                  |   1 -\n dir-iterator.c                     |   1 -\n dir.c                              |   2 -\n editor.c                           |   1 -\n entry.c                            |   1 -\n environment.c                      |   1 -\n ewah/bitmap.c                      |   1 -\n ewah/ewah_bitmap.c                 |   1 -\n fetch-pack.c                       |   2 -\n fmt-merge-msg.c                    |   1 -\n fsck.c                             |   1 -\n git-compat-util.h                  | 664 +----------------------------\n gpg-interface.c                    |   1 -\n grep.c                             |   1 -\n help.c                             |   1 -\n http-backend.c                     |   2 -\n imap-send.c                        |   1 -\n line-log.c                         |   1 -\n list-objects-filter-options.c      |   1 -\n list-objects-filter.c              |   1 -\n ll-merge.c                         |   1 -\n merge-recursive.c                  |   1 -\n midx.c                             |   1 -\n notes-merge.c                      |   1 -\n object-file.c                      |   2 -\n oid-array.c                        |   1 -\n oidtree.c                          |   1 -\n pack-bitmap-write.c                |   1 -\n pack-bitmap.c                      |   1 -\n pack-objects.c                     |   1 -\n pack-write.c                       |   1 -\n packfile.c                         |   2 -\n parallel-checkout.c                |   2 -\n path.c                             |   1 -\n pkt-line.c                         |   1 -\n pretty.c                           |   1 -\n prio-queue.c                       |   1 -\n quote.c                            |   1 -\n read-cache.c                       |   2 -\n rebase-interactive.c               |   1 -\n ref-filter.c                       |   1 -\n reflog-walk.c                      |   1 -\n refs.c                             |   2 -\n refspec.c                          |   1 -\n remote-curl.c                      |   1 -\n remote.c                           |   1 -\n rerere.c                           |   2 -\n revision.c                         |   1 -\n send-pack.c                        |   1 -\n sequencer.c                        |   2 -\n server-info.c                      |   2 -\n setup.c                            |   1 -\n shallow.c                          |   2 -\n sigchain.c                         |   1 -\n sparse-index.c                     |   1 -\n split-index.c                      |   1 -\n strbuf.c                           |   2 -\n strbuf.h                           |  32 ++\n streaming.c                        |   1 -\n string-list.c                      |   1 -\n strvec.c                           |   1 -\n submodule-config.c                 |   1 -\n submodule.c                        |   1 -\n t/helper/test-delta.c              |   1 -\n t/helper/test-fsmonitor-client.c   |   1 -\n t/helper/test-reach.c              |   1 -\n t/helper/test-read-cache.c         |   1 -\n tag.c                              |   1 -\n tempfile.c                         |   1 -\n trace.c                            |   1 -\n trace2/tr2_tls.c                   |   1 -\n trailer.c                          |   1 -\n transport-helper.c                 |   1 -\n transport.c                        |   2 -\n tree-walk.c                        |   1 -\n upload-pack.c                      |   1 -\n usage.c                            |   1 -\n usage.h                            |  60 +++\n userdiff.c                         |   1 -\n worktree.c                         |   2 -\n wrapper.c                          |   1 -\n wrapper.h                          | 111 +++++\n write-or-die.c                     |   1 -\n 142 files changed, 756 insertions(+), 897 deletions(-)\n create mode 100644 common.h\n create mode 100644 usage.h\n\n-- \n2.40.1.606.ga4b1b128d6-goog\n\n"},{"id":"477389","messageId":"20230516170932.1358685-2-calvinwan@google.com","threadId":"59752","inReplyTo":"20230516170932.1358685-1-calvinwan@google.com","subject":"[PATCH 1/6] strbuf.h: move declarations for strbuf.c functions from git-compat-util.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-16T17:09:26Z","receivedAt":"2023-05-16T17:09:56Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"While functions like starts_with() probably should not belong in the\nboundaries of the strbuf library, this commit focuses on first splitting\nout headers from git-compat-util.h.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n git-compat-util.h | 32 --------------------------------\n strbuf.h          | 32 ++++++++++++++++++++++++++++++++\n 2 files changed, 32 insertions(+), 32 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 5b2b99c17c..51af0a53aa 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -679,9 +679,6 @@ void set_warn_routine(report_fn routine);\n report_fn get_warn_routine(void);\n void set_die_is_recursing_routine(int (*routine)(void));\n \n-int starts_with(const char *str, const char *prefix);\n-int istarts_with(const char *str, const char *prefix);\n-\n /*\n  * If the string \"str\" begins with the string found in \"prefix\", return 1.\n  * The \"out\" parameter is set to \"str + strlen(prefix)\" (i.e., to the point in\n@@ -710,29 +707,6 @@ static inline int skip_prefix(const char *str, const char *prefix,\n \treturn 0;\n }\n \n-/*\n- * If the string \"str\" is the same as the string in \"prefix\", then the \"arg\"\n- * parameter is set to the \"def\" parameter and 1 is returned.\n- * If the string \"str\" begins with the string found in \"prefix\" and then a\n- * \"=\" sign, then the \"arg\" parameter is set to \"str + strlen(prefix) + 1\"\n- * (i.e., to the point in the string right after the prefix and the \"=\" sign),\n- * and 1 is returned.\n- *\n- * Otherwise, return 0 and leave \"arg\" untouched.\n- *\n- * When we accept both a \"--key\" and a \"--key=<val>\" option, this function\n- * can be used instead of !strcmp(arg, \"--key\") and then\n- * skip_prefix(arg, \"--key=\", &arg) to parse such an option.\n- */\n-int skip_to_optional_arg_default(const char *str, const char *prefix,\n-\t\t\t\t const char **arg, const char *def);\n-\n-static inline int skip_to_optional_arg(const char *str, const char *prefix,\n-\t\t\t\t       const char **arg)\n-{\n-\treturn skip_to_optional_arg_default(str, prefix, arg, \"\");\n-}\n-\n /*\n  * Like skip_prefix, but promises never to read past \"len\" bytes of the input\n  * buffer, and returns the remaining number of bytes in \"out\" via \"outlen\".\n@@ -777,12 +751,6 @@ static inline int strip_suffix(const char *str, const char *suffix, size_t *len)\n \treturn strip_suffix_mem(str, len, suffix);\n }\n \n-static inline int ends_with(const char *str, const char *suffix)\n-{\n-\tsize_t len;\n-\treturn strip_suffix(str, suffix, &len);\n-}\n-\n #define SWAP(a, b) do {\t\t\t\t\t\t\\\n \tvoid *_swap_a_ptr = &(a);\t\t\t\t\\\n \tvoid *_swap_b_ptr = &(b);\t\t\t\t\\\ndiff --git a/strbuf.h b/strbuf.h\nindex 3dfeadb44c..5e6f7f3d8e 100644\n--- a/strbuf.h\n+++ b/strbuf.h\n@@ -727,4 +727,36 @@ char *xstrvfmt(const char *fmt, va_list ap);\n __attribute__((format (printf, 1, 2)))\n char *xstrfmt(const char *fmt, ...);\n \n+int starts_with(const char *str, const char *prefix);\n+int istarts_with(const char *str, const char *prefix);\n+\n+/*\n+ * If the string \"str\" is the same as the string in \"prefix\", then the \"arg\"\n+ * parameter is set to the \"def\" parameter and 1 is returned.\n+ * If the string \"str\" begins with the string found in \"prefix\" and then a\n+ * \"=\" sign, then the \"arg\" parameter is set to \"str + strlen(prefix) + 1\"\n+ * (i.e., to the point in the string right after the prefix and the \"=\" sign),\n+ * and 1 is returned.\n+ *\n+ * Otherwise, return 0 and leave \"arg\" untouched.\n+ *\n+ * When we accept both a \"--key\" and a \"--key=<val>\" option, this function\n+ * can be used instead of !strcmp(arg, \"--key\") and then\n+ * skip_prefix(arg, \"--key=\", &arg) to parse such an option.\n+ */\n+int skip_to_optional_arg_default(const char *str, const char *prefix,\n+\t\t\t\t const char **arg, const char *def);\n+\n+static inline int skip_to_optional_arg(const char *str, const char *prefix,\n+\t\t\t\t       const char **arg)\n+{\n+\treturn skip_to_optional_arg_default(str, prefix, arg, \"\");\n+}\n+\n+static inline int ends_with(const char *str, const char *suffix)\n+{\n+\tsize_t len;\n+\treturn strip_suffix(str, suffix, &len);\n+}\n+\n #endif /* STRBUF_H */\n-- \n2.40.1.606.ga4b1b128d6-goog\n\n"},{"id":"477390","messageId":"20230516170932.1358685-3-calvinwan@google.com","threadId":"59752","inReplyTo":"20230516170932.1358685-1-calvinwan@google.com","subject":"[PATCH 2/6] wrapper.h: move declarations for wrapper.c functions from git-compat-util.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-16T17:09:27Z","receivedAt":"2023-05-16T17:10:00Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Since the functions in wrapper.c are widely used across the codebase,\ninclude it by default in git-compat-util.h. A future patch will remove\nnow unnecessary inclusions of wrapper.h from other files.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n git-compat-util.h | 113 +---------------------------------------------\n wrapper.h         | 111 +++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 112 insertions(+), 112 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 51af0a53aa..9898fe9374 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -626,8 +626,7 @@ static inline int git_has_dir_sep(const char *path)\n #include \"compat/bswap.h\"\n \n #include \"wildmatch.h\"\n-\n-struct strbuf;\n+#include \"wrapper.h\"\n \n /* General helper functions */\n NORETURN void usage(const char *err);\n@@ -1047,36 +1046,6 @@ static inline int cast_size_t_to_int(size_t a)\n # define xalloca(size)      (xmalloc(size))\n # define xalloca_free(p)    (free(p))\n #endif\n-char *xstrdup(const char *str);\n-void *xmalloc(size_t size);\n-void *xmallocz(size_t size);\n-void *xmallocz_gently(size_t size);\n-void *xmemdupz(const void *data, size_t len);\n-char *xstrndup(const char *str, size_t len);\n-void *xrealloc(void *ptr, size_t size);\n-void *xcalloc(size_t nmemb, size_t size);\n-void xsetenv(const char *name, const char *value, int overwrite);\n-void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n-const char *mmap_os_err(void);\n-void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n-int xopen(const char *path, int flags, ...);\n-ssize_t xread(int fd, void *buf, size_t len);\n-ssize_t xwrite(int fd, const void *buf, size_t len);\n-ssize_t xpread(int fd, void *buf, size_t len, off_t offset);\n-int xdup(int fd);\n-FILE *xfopen(const char *path, const char *mode);\n-FILE *xfdopen(int fd, const char *mode);\n-int xmkstemp(char *temp_filename);\n-int xmkstemp_mode(char *temp_filename, int mode);\n-char *xgetcwd(void);\n-FILE *fopen_for_writing(const char *path);\n-FILE *fopen_or_warn(const char *path, const char *mode);\n-\n-/*\n- * Like strncmp, but only return zero if s is NUL-terminated and exactly len\n- * characters long.  If it is not, consider it greater than t.\n- */\n-int xstrncmpz(const char *s, const char *t, size_t len);\n \n /*\n  * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note\n@@ -1178,15 +1147,10 @@ static inline size_t xsize_t(off_t len)\n \treturn (size_t) len;\n }\n \n-__attribute__((format (printf, 3, 4)))\n-int xsnprintf(char *dst, size_t max, const char *fmt, ...);\n-\n #ifndef HOST_NAME_MAX\n #define HOST_NAME_MAX 256\n #endif\n \n-int xgethostname(char *buf, size_t len);\n-\n /* in ctype.c, for kwset users */\n extern const unsigned char tolower_trans_tbl[256];\n \n@@ -1427,72 +1391,6 @@ void bug_fl(const char *file, int line, const char *fmt, ...);\n #endif\n #endif\n \n-enum fsync_action {\n-\tFSYNC_WRITEOUT_ONLY,\n-\tFSYNC_HARDWARE_FLUSH\n-};\n-\n-/*\n- * Issues an fsync against the specified file according to the specified mode.\n- *\n- * FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating\n- * systems to flush the OS cache without issuing a flush command to the storage\n- * controller. If those interfaces are unavailable, the function fails with\n- * ENOSYS.\n- *\n- * FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that\n- * changes are durable. It is not expected to fail.\n- */\n-int git_fsync(int fd, enum fsync_action action);\n-\n-/*\n- * Writes out trace statistics for fsync using the trace2 API.\n- */\n-void trace_git_fsync_stats(void);\n-\n-/*\n- * Preserves errno, prints a message, but gives no warning for ENOENT.\n- * Returns 0 on success, which includes trying to unlink an object that does\n- * not exist.\n- */\n-int unlink_or_warn(const char *path);\n- /*\n-  * Tries to unlink file.  Returns 0 if unlink succeeded\n-  * or the file already didn't exist.  Returns -1 and\n-  * appends a message to err suitable for\n-  * 'error(\"%s\", err->buf)' on error.\n-  */\n-int unlink_or_msg(const char *file, struct strbuf *err);\n-/*\n- * Preserves errno, prints a message, but gives no warning for ENOENT.\n- * Returns 0 on success, which includes trying to remove a directory that does\n- * not exist.\n- */\n-int rmdir_or_warn(const char *path);\n-/*\n- * Calls the correct function out of {unlink,rmdir}_or_warn based on\n- * the supplied file mode.\n- */\n-int remove_or_warn(unsigned int mode, const char *path);\n-\n-/*\n- * Call access(2), but warn for any error except \"missing file\"\n- * (ENOENT or ENOTDIR).\n- */\n-#define ACCESS_EACCES_OK (1U << 0)\n-int access_or_warn(const char *path, int mode, unsigned flag);\n-int access_or_die(const char *path, int mode, unsigned flag);\n-\n-/* Warn on an inaccessible file if errno indicates this is an error */\n-int warn_on_fopen_errors(const char *path);\n-\n-/*\n- * Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent\n- * may be racy. Do not use this as protection against an attacker who can\n- * simultaneously create paths.\n- */\n-int open_nofollow(const char *path, int flags);\n-\n #ifndef SHELL_PATH\n # define SHELL_PATH \"/bin/sh\"\n #endif\n@@ -1632,13 +1530,4 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset)\n \t((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))\n #endif /* !__GNUC__ */\n \n-void sleep_millisec(int millisec);\n-\n-/*\n- * Generate len bytes from the system cryptographically secure PRNG.\n- * Returns 0 on success and -1 on error, setting errno.  The inability to\n- * satisfy the full request is an error.\n- */\n-int csprng_bytes(void *buf, size_t len);\n-\n #endif\ndiff --git a/wrapper.h b/wrapper.h\nindex f0c7d0616d..c85b1328d1 100644\n--- a/wrapper.h\n+++ b/wrapper.h\n@@ -1,6 +1,42 @@\n #ifndef WRAPPER_H\n #define WRAPPER_H\n \n+char *xstrdup(const char *str);\n+void *xmalloc(size_t size);\n+void *xmallocz(size_t size);\n+void *xmallocz_gently(size_t size);\n+void *xmemdupz(const void *data, size_t len);\n+char *xstrndup(const char *str, size_t len);\n+void *xrealloc(void *ptr, size_t size);\n+void *xcalloc(size_t nmemb, size_t size);\n+void xsetenv(const char *name, const char *value, int overwrite);\n+void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n+const char *mmap_os_err(void);\n+void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n+int xopen(const char *path, int flags, ...);\n+ssize_t xread(int fd, void *buf, size_t len);\n+ssize_t xwrite(int fd, const void *buf, size_t len);\n+ssize_t xpread(int fd, void *buf, size_t len, off_t offset);\n+int xdup(int fd);\n+FILE *xfopen(const char *path, const char *mode);\n+FILE *xfdopen(int fd, const char *mode);\n+int xmkstemp(char *temp_filename);\n+int xmkstemp_mode(char *temp_filename, int mode);\n+char *xgetcwd(void);\n+FILE *fopen_for_writing(const char *path);\n+FILE *fopen_or_warn(const char *path, const char *mode);\n+\n+/*\n+ * Like strncmp, but only return zero if s is NUL-terminated and exactly len\n+ * characters long.  If it is not, consider it greater than t.\n+ */\n+int xstrncmpz(const char *s, const char *t, size_t len);\n+\n+__attribute__((format (printf, 3, 4)))\n+int xsnprintf(char *dst, size_t max, const char *fmt, ...);\n+\n+int xgethostname(char *buf, size_t len);\n+\n /* set default permissions by passing mode arguments to open(2) */\n int git_mkstemps_mode(char *pattern, int suffix_len, int mode);\n int git_mkstemp_mode(char *pattern, int mode);\n@@ -33,4 +69,79 @@ void write_file(const char *path, const char *fmt, ...);\n /* Return 1 if the file is empty or does not exists, 0 otherwise. */\n int is_empty_or_missing_file(const char *filename);\n \n+enum fsync_action {\n+\tFSYNC_WRITEOUT_ONLY,\n+\tFSYNC_HARDWARE_FLUSH\n+};\n+\n+/*\n+ * Issues an fsync against the specified file according to the specified mode.\n+ *\n+ * FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating\n+ * systems to flush the OS cache without issuing a flush command to the storage\n+ * controller. If those interfaces are unavailable, the function fails with\n+ * ENOSYS.\n+ *\n+ * FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that\n+ * changes are durable. It is not expected to fail.\n+ */\n+int git_fsync(int fd, enum fsync_action action);\n+\n+/*\n+ * Writes out trace statistics for fsync using the trace2 API.\n+ */\n+void trace_git_fsync_stats(void);\n+\n+/*\n+ * Preserves errno, prints a message, but gives no warning for ENOENT.\n+ * Returns 0 on success, which includes trying to unlink an object that does\n+ * not exist.\n+ */\n+int unlink_or_warn(const char *path);\n+ /*\n+  * Tries to unlink file.  Returns 0 if unlink succeeded\n+  * or the file already didn't exist.  Returns -1 and\n+  * appends a message to err suitable for\n+  * 'error(\"%s\", err->buf)' on error.\n+  */\n+int unlink_or_msg(const char *file, struct strbuf *err);\n+/*\n+ * Preserves errno, prints a message, but gives no warning for ENOENT.\n+ * Returns 0 on success, which includes trying to remove a directory that does\n+ * not exist.\n+ */\n+int rmdir_or_warn(const char *path);\n+/*\n+ * Calls the correct function out of {unlink,rmdir}_or_warn based on\n+ * the supplied file mode.\n+ */\n+int remove_or_warn(unsigned int mode, const char *path);\n+\n+/*\n+ * Call access(2), but warn for any error except \"missing file\"\n+ * (ENOENT or ENOTDIR).\n+ */\n+#define ACCESS_EACCES_OK (1U << 0)\n+int access_or_warn(const char *path, int mode, unsigned flag);\n+int access_or_die(const char *path, int mode, unsigned flag);\n+\n+/* Warn on an inaccessible file if errno indicates this is an error */\n+int warn_on_fopen_errors(const char *path);\n+\n+/*\n+ * Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent\n+ * may be racy. Do not use this as protection against an attacker who can\n+ * simultaneously create paths.\n+ */\n+int open_nofollow(const char *path, int flags);\n+\n+void sleep_millisec(int millisec);\n+\n+/*\n+ * Generate len bytes from the system cryptographically secure PRNG.\n+ * Returns 0 on success and -1 on error, setting errno.  The inability to\n+ * satisfy the full request is an error.\n+ */\n+int csprng_bytes(void *buf, size_t len);\n+\n #endif /* WRAPPER_H */\n-- \n2.40.1.606.ga4b1b128d6-goog\n\n"},{"id":"477392","messageId":"20230516170932.1358685-4-calvinwan@google.com","threadId":"59752","inReplyTo":"20230516170932.1358685-1-calvinwan@google.com","subject":"[PATCH 3/6] common.h: move non-compat specific macros and functions from git-compat-util.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-16T17:09:28Z","receivedAt":"2023-05-16T17:10:06Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"git-compat-util.h has grown to a large and difficult to read file partly\nbecause its set of functionality is overloaded. Besides being a\ncompatibility file that ensures Git's operation across different\noperating systems, it has also become a dumping ground for commonly used\nmacros and static inline functions.\n\nThis commit separates out macros and static inline functions that are\ncompatible across operating systems into common.h. common.h is\nreincluded back into git-compat-util.h so that other files do not also\nhave to include it. The eventual goal is for common.h to be separated\nout into more reasonable boundaries, but for now this should be a good\nfirst step towards that goal.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n common.h          | 475 ++++++++++++++++++++++++++++++++++++++++++++++\n git-compat-util.h | 467 +--------------------------------------------\n 2 files changed, 477 insertions(+), 465 deletions(-)\n create mode 100644 common.h\n\ndiff --git a/common.h b/common.h\nnew file mode 100644\nindex 0000000000..c0fdc5eb98\n--- /dev/null\n+++ b/common.h\n@@ -0,0 +1,475 @@\n+#ifndef COMMON_H\n+#define COMMON_H\n+\n+#include \"git-compat-util.h\"\n+#include \"wrapper.h\"\n+\n+/*\n+ * ARRAY_SIZE - get the number of elements in a visible array\n+ * @x: the array whose size you want.\n+ *\n+ * This does not work on pointers, or arrays declared as [], or\n+ * function parameters.  With correct compiler support, such usage\n+ * will cause a build error (see the build_assert_or_zero macro).\n+ */\n+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + BARF_UNLESS_AN_ARRAY(x))\n+\n+#define bitsizeof(x)  (CHAR_BIT * sizeof(x))\n+\n+#define maximum_signed_value_of_type(a) \\\n+    (INTMAX_MAX >> (bitsizeof(intmax_t) - bitsizeof(a)))\n+\n+#define maximum_unsigned_value_of_type(a) \\\n+    (UINTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a)))\n+\n+/*\n+ * Signed integer overflow is undefined in C, so here's a helper macro\n+ * to detect if the sum of two integers will overflow.\n+ *\n+ * Requires: a >= 0, typeof(a) equals typeof(b)\n+ */\n+#define signed_add_overflows(a, b) \\\n+    ((b) > maximum_signed_value_of_type(a) - (a))\n+\n+#define unsigned_add_overflows(a, b) \\\n+    ((b) > maximum_unsigned_value_of_type(a) - (a))\n+\n+/*\n+ * Returns true if the multiplication of \"a\" and \"b\" will\n+ * overflow. The types of \"a\" and \"b\" must match and must be unsigned.\n+ * Note that this macro evaluates \"a\" twice!\n+ */\n+#define unsigned_mult_overflows(a, b) \\\n+    ((a) && (b) > maximum_unsigned_value_of_type(a) / (a))\n+\n+/*\n+ * Returns true if the left shift of \"a\" by \"shift\" bits will\n+ * overflow. The type of \"a\" must be unsigned.\n+ */\n+#define unsigned_left_shift_overflows(a, shift) \\\n+    ((shift) < bitsizeof(a) && \\\n+     (a) > maximum_unsigned_value_of_type(a) >> (shift))\n+\n+#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))\n+#define HAS_MULTI_BITS(i)  ((i) & ((i) - 1))  /* checks if an integer has more than 1 bit set */\n+\n+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))\n+\n+/* Approximation of the length of the decimal representation of this type. */\n+#define decimal_length(x)\t((int)(sizeof(x) * 2.56 + 0.5) + 1)\n+\n+/*\n+ * If the string \"str\" begins with the string found in \"prefix\", return 1.\n+ * The \"out\" parameter is set to \"str + strlen(prefix)\" (i.e., to the point in\n+ * the string right after the prefix).\n+ *\n+ * Otherwise, return 0 and leave \"out\" untouched.\n+ *\n+ * Examples:\n+ *\n+ *   [extract branch name, fail if not a branch]\n+ *   if (!skip_prefix(ref, \"refs/heads/\", &branch)\n+ *\treturn -1;\n+ *\n+ *   [skip prefix if present, otherwise use whole string]\n+ *   skip_prefix(name, \"refs/heads/\", &name);\n+ */\n+static inline int skip_prefix(const char *str, const char *prefix,\n+\t\t\t      const char **out)\n+{\n+\tdo {\n+\t\tif (!*prefix) {\n+\t\t\t*out = str;\n+\t\t\treturn 1;\n+\t\t}\n+\t} while (*str++ == *prefix++);\n+\treturn 0;\n+}\n+\n+/*\n+ * Like skip_prefix, but promises never to read past \"len\" bytes of the input\n+ * buffer, and returns the remaining number of bytes in \"out\" via \"outlen\".\n+ */\n+static inline int skip_prefix_mem(const char *buf, size_t len,\n+\t\t\t\t  const char *prefix,\n+\t\t\t\t  const char **out, size_t *outlen)\n+{\n+\tsize_t prefix_len = strlen(prefix);\n+\tif (prefix_len <= len && !memcmp(buf, prefix, prefix_len)) {\n+\t\t*out = buf + prefix_len;\n+\t\t*outlen = len - prefix_len;\n+\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+/*\n+ * If buf ends with suffix, return 1 and subtract the length of the suffix\n+ * from *len. Otherwise, return 0 and leave *len untouched.\n+ */\n+static inline int strip_suffix_mem(const char *buf, size_t *len,\n+\t\t\t\t   const char *suffix)\n+{\n+\tsize_t suflen = strlen(suffix);\n+\tif (*len < suflen || memcmp(buf + (*len - suflen), suffix, suflen))\n+\t\treturn 0;\n+\t*len -= suflen;\n+\treturn 1;\n+}\n+\n+/*\n+ * If str ends with suffix, return 1 and set *len to the size of the string\n+ * without the suffix. Otherwise, return 0 and set *len to the size of the\n+ * string.\n+ *\n+ * Note that we do _not_ NUL-terminate str to the new length.\n+ */\n+static inline int strip_suffix(const char *str, const char *suffix, size_t *len)\n+{\n+\t*len = strlen(str);\n+\treturn strip_suffix_mem(str, len, suffix);\n+}\n+\n+#define SWAP(a, b) do {\t\t\t\t\t\t\\\n+\tvoid *_swap_a_ptr = &(a);\t\t\t\t\\\n+\tvoid *_swap_b_ptr = &(b);\t\t\t\t\\\n+\tunsigned char _swap_buffer[sizeof(a)];\t\t\t\\\n+\tmemcpy(_swap_buffer, _swap_a_ptr, sizeof(a));\t\t\\\n+\tmemcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a) +\t\t\\\n+\t       BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b)));\t\\\n+\tmemcpy(_swap_b_ptr, _swap_buffer, sizeof(a));\t\t\\\n+} while (0)\n+\n+static inline size_t st_add(size_t a, size_t b)\n+{\n+\tif (unsigned_add_overflows(a, b))\n+\t\tdie(\"size_t overflow: %\"PRIuMAX\" + %\"PRIuMAX,\n+\t\t    (uintmax_t)a, (uintmax_t)b);\n+\treturn a + b;\n+}\n+#define st_add3(a,b,c)   st_add(st_add((a),(b)),(c))\n+#define st_add4(a,b,c,d) st_add(st_add3((a),(b),(c)),(d))\n+\n+static inline size_t st_mult(size_t a, size_t b)\n+{\n+\tif (unsigned_mult_overflows(a, b))\n+\t\tdie(\"size_t overflow: %\"PRIuMAX\" * %\"PRIuMAX,\n+\t\t    (uintmax_t)a, (uintmax_t)b);\n+\treturn a * b;\n+}\n+\n+static inline size_t st_sub(size_t a, size_t b)\n+{\n+\tif (a < b)\n+\t\tdie(\"size_t underflow: %\"PRIuMAX\" - %\"PRIuMAX,\n+\t\t    (uintmax_t)a, (uintmax_t)b);\n+\treturn a - b;\n+}\n+\n+static inline size_t st_left_shift(size_t a, unsigned shift)\n+{\n+\tif (unsigned_left_shift_overflows(a, shift))\n+\t\tdie(\"size_t overflow: %\"PRIuMAX\" << %u\",\n+\t\t    (uintmax_t)a, shift);\n+\treturn a << shift;\n+}\n+\n+static inline unsigned long cast_size_t_to_ulong(size_t a)\n+{\n+\tif (a != (unsigned long)a)\n+\t\tdie(\"object too large to read on this platform: %\"\n+\t\t    PRIuMAX\" is cut off to %lu\",\n+\t\t    (uintmax_t)a, (unsigned long)a);\n+\treturn (unsigned long)a;\n+}\n+\n+static inline int cast_size_t_to_int(size_t a)\n+{\n+\tif (a > INT_MAX)\n+\t\tdie(\"number too large to represent as int on this platform: %\"PRIuMAX,\n+\t\t    (uintmax_t)a);\n+\treturn (int)a;\n+}\n+\n+\n+/*\n+ * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note\n+ * that ptr is used twice, so don't pass e.g. ptr++.\n+ */\n+#define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)\n+\n+#define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))\n+#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))\n+#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))\n+\n+#define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \\\n+\tBARF_UNLESS_COPYABLE((dst), (src)))\n+static inline void copy_array(void *dst, const void *src, size_t n, size_t size)\n+{\n+\tif (n)\n+\t\tmemcpy(dst, src, st_mult(size, n));\n+}\n+\n+#define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \\\n+\tBARF_UNLESS_COPYABLE((dst), (src)))\n+static inline void move_array(void *dst, const void *src, size_t n, size_t size)\n+{\n+\tif (n)\n+\t\tmemmove(dst, src, st_mult(size, n));\n+}\n+\n+#define DUP_ARRAY(dst, src, n) do { \\\n+\tsize_t dup_array_n_ = (n); \\\n+\tCOPY_ARRAY(ALLOC_ARRAY((dst), dup_array_n_), (src), dup_array_n_); \\\n+} while (0)\n+\n+/*\n+ * These functions help you allocate structs with flex arrays, and copy\n+ * the data directly into the array. For example, if you had:\n+ *\n+ *   struct foo {\n+ *     int bar;\n+ *     char name[FLEX_ARRAY];\n+ *   };\n+ *\n+ * you can do:\n+ *\n+ *   struct foo *f;\n+ *   FLEX_ALLOC_MEM(f, name, src, len);\n+ *\n+ * to allocate a \"foo\" with the contents of \"src\" in the \"name\" field.\n+ * The resulting struct is automatically zero'd, and the flex-array field\n+ * is NUL-terminated (whether the incoming src buffer was or not).\n+ *\n+ * The FLEXPTR_* variants operate on structs that don't use flex-arrays,\n+ * but do want to store a pointer to some extra data in the same allocated\n+ * block. For example, if you have:\n+ *\n+ *   struct foo {\n+ *     char *name;\n+ *     int bar;\n+ *   };\n+ *\n+ * you can do:\n+ *\n+ *   struct foo *f;\n+ *   FLEXPTR_ALLOC_STR(f, name, src);\n+ *\n+ * and \"name\" will point to a block of memory after the struct, which will be\n+ * freed along with the struct (but the pointer can be repointed anywhere).\n+ *\n+ * The *_STR variants accept a string parameter rather than a ptr/len\n+ * combination.\n+ *\n+ * Note that these macros will evaluate the first parameter multiple\n+ * times, and it must be assignable as an lvalue.\n+ */\n+#define FLEX_ALLOC_MEM(x, flexname, buf, len) do { \\\n+\tsize_t flex_array_len_ = (len); \\\n+\t(x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \\\n+\tmemcpy((void *)(x)->flexname, (buf), flex_array_len_); \\\n+} while (0)\n+#define FLEXPTR_ALLOC_MEM(x, ptrname, buf, len) do { \\\n+\tsize_t flex_array_len_ = (len); \\\n+\t(x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \\\n+\tmemcpy((x) + 1, (buf), flex_array_len_); \\\n+\t(x)->ptrname = (void *)((x)+1); \\\n+} while(0)\n+#define FLEX_ALLOC_STR(x, flexname, str) \\\n+\tFLEX_ALLOC_MEM((x), flexname, (str), strlen(str))\n+#define FLEXPTR_ALLOC_STR(x, ptrname, str) \\\n+\tFLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))\n+\n+static inline char *xstrdup_or_null(const char *str)\n+{\n+\treturn str ? xstrdup(str) : NULL;\n+}\n+\n+static inline size_t xsize_t(off_t len)\n+{\n+\tif (len < 0 || (uintmax_t) len > SIZE_MAX)\n+\t\tdie(\"Cannot handle files this big\");\n+\treturn (size_t) len;\n+}\n+\n+/* in ctype.c, for kwset users */\n+extern const unsigned char tolower_trans_tbl[256];\n+\n+/* Sane ctype - no locale, and works with signed chars */\n+#undef isascii\n+#undef isspace\n+#undef isdigit\n+#undef isalpha\n+#undef isalnum\n+#undef isprint\n+#undef islower\n+#undef isupper\n+#undef tolower\n+#undef toupper\n+#undef iscntrl\n+#undef ispunct\n+#undef isxdigit\n+\n+extern const unsigned char sane_ctype[256];\n+extern const signed char hexval_table[256];\n+#define GIT_SPACE 0x01\n+#define GIT_DIGIT 0x02\n+#define GIT_ALPHA 0x04\n+#define GIT_GLOB_SPECIAL 0x08\n+#define GIT_REGEX_SPECIAL 0x10\n+#define GIT_PATHSPEC_MAGIC 0x20\n+#define GIT_CNTRL 0x40\n+#define GIT_PUNCT 0x80\n+#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n+#define isascii(x) (((x) & ~0x7f) == 0)\n+#define isspace(x) sane_istest(x,GIT_SPACE)\n+#define isdigit(x) sane_istest(x,GIT_DIGIT)\n+#define isalpha(x) sane_istest(x,GIT_ALPHA)\n+#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)\n+#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)\n+#define islower(x) sane_iscase(x, 1)\n+#define isupper(x) sane_iscase(x, 0)\n+#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)\n+#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)\n+#define iscntrl(x) (sane_istest(x,GIT_CNTRL))\n+#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \\\n+\t\tGIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)\n+#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n+#define tolower(x) sane_case((unsigned char)(x), 0x20)\n+#define toupper(x) sane_case((unsigned char)(x), 0)\n+#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)\n+\n+static inline int sane_case(int x, int high)\n+{\n+\tif (sane_istest(x, GIT_ALPHA))\n+\t\tx = (x & ~0x20) | high;\n+\treturn x;\n+}\n+\n+static inline int sane_iscase(int x, int is_lower)\n+{\n+\tif (!sane_istest(x, GIT_ALPHA))\n+\t\treturn 0;\n+\n+\tif (is_lower)\n+\t\treturn (x & 0x20) != 0;\n+\telse\n+\t\treturn (x & 0x20) == 0;\n+}\n+\n+/*\n+ * Like skip_prefix, but compare case-insensitively. Note that the comparison\n+ * is done via tolower(), so it is strictly ASCII (no multi-byte characters or\n+ * locale-specific conversions).\n+ */\n+static inline int skip_iprefix(const char *str, const char *prefix,\n+\t\t\t       const char **out)\n+{\n+\tdo {\n+\t\tif (!*prefix) {\n+\t\t\t*out = str;\n+\t\t\treturn 1;\n+\t\t}\n+\t} while (tolower(*str++) == tolower(*prefix++));\n+\treturn 0;\n+}\n+\n+/*\n+ * Like skip_prefix_mem, but compare case-insensitively. Note that the\n+ * comparison is done via tolower(), so it is strictly ASCII (no multi-byte\n+ * characters or locale-specific conversions).\n+ */\n+static inline int skip_iprefix_mem(const char *buf, size_t len,\n+\t\t\t\t   const char *prefix,\n+\t\t\t\t   const char **out, size_t *outlen)\n+{\n+\tdo {\n+\t\tif (!*prefix) {\n+\t\t\t*out = buf;\n+\t\t\t*outlen = len;\n+\t\t\treturn 1;\n+\t\t}\n+\t} while (len-- > 0 && tolower(*buf++) == tolower(*prefix++));\n+\treturn 0;\n+}\n+\n+static inline int strtoul_ui(char const *s, int base, unsigned int *result)\n+{\n+\tunsigned long ul;\n+\tchar *p;\n+\n+\terrno = 0;\n+\t/* negative values would be accepted by strtoul */\n+\tif (strchr(s, '-'))\n+\t\treturn -1;\n+\tul = strtoul(s, &p, base);\n+\tif (errno || *p || p == s || (unsigned int) ul != ul)\n+\t\treturn -1;\n+\t*result = ul;\n+\treturn 0;\n+}\n+\n+static inline int strtol_i(char const *s, int base, int *result)\n+{\n+\tlong ul;\n+\tchar *p;\n+\n+\terrno = 0;\n+\tul = strtol(s, &p, base);\n+\tif (errno || *p || p == s || (int) ul != ul)\n+\t\treturn -1;\n+\t*result = ul;\n+\treturn 0;\n+}\n+\n+static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,\n+\t\t\t      size_t nmatch, regmatch_t pmatch[], int eflags)\n+{\n+\tassert(nmatch > 0 && pmatch);\n+\tpmatch[0].rm_so = 0;\n+\tpmatch[0].rm_eo = size;\n+\treturn regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);\n+}\n+\n+/*\n+ * Our code often opens a path to an optional file, to work on its\n+ * contents when we can successfully open it.  We can ignore a failure\n+ * to open if such an optional file does not exist, but we do want to\n+ * report a failure in opening for other reasons (e.g. we got an I/O\n+ * error, or the file is there, but we lack the permission to open).\n+ *\n+ * Call this function after seeing an error from open() or fopen() to\n+ * see if the errno indicates a missing file that we can safely ignore.\n+ */\n+static inline int is_missing_file_error(int errno_)\n+{\n+\treturn (errno_ == ENOENT || errno_ == ENOTDIR);\n+}\n+\n+/*\n+ * container_of - Get the address of an object containing a field.\n+ *\n+ * @ptr: pointer to the field.\n+ * @type: type of the object.\n+ * @member: name of the field within the object.\n+ */\n+#define container_of(ptr, type, member) \\\n+\t((type *) ((char *)(ptr) - offsetof(type, member)))\n+\n+/*\n+ * helper function for `container_of_or_null' to avoid multiple\n+ * evaluation of @ptr\n+ */\n+static inline void *container_of_or_null_offset(void *ptr, size_t offset)\n+{\n+\treturn ptr ? (char *)ptr - offset : NULL;\n+}\n+\n+/*\n+ * like `container_of', but allows returned value to be NULL\n+ */\n+#define container_of_or_null(ptr, type, member) \\\n+\t(type *)container_of_or_null_offset(ptr, offsetof(type, member))\n+\n+\n+#endif\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 9898fe9374..c2b92a3033 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -106,51 +106,6 @@ struct strbuf;\n \tBUILD_ASSERT_OR_ZERO(0 ? ((*(dst) = *(src)), 0) : \\\n \t\t\t\t sizeof(*(dst)) == sizeof(*(src)))\n #endif\n-/*\n- * ARRAY_SIZE - get the number of elements in a visible array\n- * @x: the array whose size you want.\n- *\n- * This does not work on pointers, or arrays declared as [], or\n- * function parameters.  With correct compiler support, such usage\n- * will cause a build error (see the build_assert_or_zero macro).\n- */\n-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + BARF_UNLESS_AN_ARRAY(x))\n-\n-#define bitsizeof(x)  (CHAR_BIT * sizeof(x))\n-\n-#define maximum_signed_value_of_type(a) \\\n-    (INTMAX_MAX >> (bitsizeof(intmax_t) - bitsizeof(a)))\n-\n-#define maximum_unsigned_value_of_type(a) \\\n-    (UINTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a)))\n-\n-/*\n- * Signed integer overflow is undefined in C, so here's a helper macro\n- * to detect if the sum of two integers will overflow.\n- *\n- * Requires: a >= 0, typeof(a) equals typeof(b)\n- */\n-#define signed_add_overflows(a, b) \\\n-    ((b) > maximum_signed_value_of_type(a) - (a))\n-\n-#define unsigned_add_overflows(a, b) \\\n-    ((b) > maximum_unsigned_value_of_type(a) - (a))\n-\n-/*\n- * Returns true if the multiplication of \"a\" and \"b\" will\n- * overflow. The types of \"a\" and \"b\" must match and must be unsigned.\n- * Note that this macro evaluates \"a\" twice!\n- */\n-#define unsigned_mult_overflows(a, b) \\\n-    ((a) && (b) > maximum_unsigned_value_of_type(a) / (a))\n-\n-/*\n- * Returns true if the left shift of \"a\" by \"shift\" bits will\n- * overflow. The type of \"a\" must be unsigned.\n- */\n-#define unsigned_left_shift_overflows(a, shift) \\\n-    ((shift) < bitsizeof(a) && \\\n-     (a) > maximum_unsigned_value_of_type(a) >> (shift))\n \n #ifdef __GNUC__\n #define TYPEOF(x) (__typeof__(x))\n@@ -158,14 +113,6 @@ struct strbuf;\n #define TYPEOF(x)\n #endif\n \n-#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))\n-#define HAS_MULTI_BITS(i)  ((i) & ((i) - 1))  /* checks if an integer has more than 1 bit set */\n-\n-#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))\n-\n-/* Approximation of the length of the decimal representation of this type. */\n-#define decimal_length(x)\t((int)(sizeof(x) * 2.56 + 0.5) + 1)\n-\n #ifdef __MINGW64__\n #define _POSIX_C_SOURCE 1\n #elif defined(__sun__)\n@@ -678,88 +625,6 @@ void set_warn_routine(report_fn routine);\n report_fn get_warn_routine(void);\n void set_die_is_recursing_routine(int (*routine)(void));\n \n-/*\n- * If the string \"str\" begins with the string found in \"prefix\", return 1.\n- * The \"out\" parameter is set to \"str + strlen(prefix)\" (i.e., to the point in\n- * the string right after the prefix).\n- *\n- * Otherwise, return 0 and leave \"out\" untouched.\n- *\n- * Examples:\n- *\n- *   [extract branch name, fail if not a branch]\n- *   if (!skip_prefix(ref, \"refs/heads/\", &branch)\n- *\treturn -1;\n- *\n- *   [skip prefix if present, otherwise use whole string]\n- *   skip_prefix(name, \"refs/heads/\", &name);\n- */\n-static inline int skip_prefix(const char *str, const char *prefix,\n-\t\t\t      const char **out)\n-{\n-\tdo {\n-\t\tif (!*prefix) {\n-\t\t\t*out = str;\n-\t\t\treturn 1;\n-\t\t}\n-\t} while (*str++ == *prefix++);\n-\treturn 0;\n-}\n-\n-/*\n- * Like skip_prefix, but promises never to read past \"len\" bytes of the input\n- * buffer, and returns the remaining number of bytes in \"out\" via \"outlen\".\n- */\n-static inline int skip_prefix_mem(const char *buf, size_t len,\n-\t\t\t\t  const char *prefix,\n-\t\t\t\t  const char **out, size_t *outlen)\n-{\n-\tsize_t prefix_len = strlen(prefix);\n-\tif (prefix_len <= len && !memcmp(buf, prefix, prefix_len)) {\n-\t\t*out = buf + prefix_len;\n-\t\t*outlen = len - prefix_len;\n-\t\treturn 1;\n-\t}\n-\treturn 0;\n-}\n-\n-/*\n- * If buf ends with suffix, return 1 and subtract the length of the suffix\n- * from *len. Otherwise, return 0 and leave *len untouched.\n- */\n-static inline int strip_suffix_mem(const char *buf, size_t *len,\n-\t\t\t\t   const char *suffix)\n-{\n-\tsize_t suflen = strlen(suffix);\n-\tif (*len < suflen || memcmp(buf + (*len - suflen), suffix, suflen))\n-\t\treturn 0;\n-\t*len -= suflen;\n-\treturn 1;\n-}\n-\n-/*\n- * If str ends with suffix, return 1 and set *len to the size of the string\n- * without the suffix. Otherwise, return 0 and set *len to the size of the\n- * string.\n- *\n- * Note that we do _not_ NUL-terminate str to the new length.\n- */\n-static inline int strip_suffix(const char *str, const char *suffix, size_t *len)\n-{\n-\t*len = strlen(str);\n-\treturn strip_suffix_mem(str, len, suffix);\n-}\n-\n-#define SWAP(a, b) do {\t\t\t\t\t\t\\\n-\tvoid *_swap_a_ptr = &(a);\t\t\t\t\\\n-\tvoid *_swap_b_ptr = &(b);\t\t\t\t\\\n-\tunsigned char _swap_buffer[sizeof(a)];\t\t\t\\\n-\tmemcpy(_swap_buffer, _swap_a_ptr, sizeof(a));\t\t\\\n-\tmemcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a) +\t\t\\\n-\t       BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b)));\t\\\n-\tmemcpy(_swap_b_ptr, _swap_buffer, sizeof(a));\t\t\\\n-} while (0)\n-\n #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)\n \n #ifndef PROT_READ\n@@ -965,57 +830,6 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size);\n int git_atexit(void (*handler)(void));\n #endif\n \n-static inline size_t st_add(size_t a, size_t b)\n-{\n-\tif (unsigned_add_overflows(a, b))\n-\t\tdie(\"size_t overflow: %\"PRIuMAX\" + %\"PRIuMAX,\n-\t\t    (uintmax_t)a, (uintmax_t)b);\n-\treturn a + b;\n-}\n-#define st_add3(a,b,c)   st_add(st_add((a),(b)),(c))\n-#define st_add4(a,b,c,d) st_add(st_add3((a),(b),(c)),(d))\n-\n-static inline size_t st_mult(size_t a, size_t b)\n-{\n-\tif (unsigned_mult_overflows(a, b))\n-\t\tdie(\"size_t overflow: %\"PRIuMAX\" * %\"PRIuMAX,\n-\t\t    (uintmax_t)a, (uintmax_t)b);\n-\treturn a * b;\n-}\n-\n-static inline size_t st_sub(size_t a, size_t b)\n-{\n-\tif (a < b)\n-\t\tdie(\"size_t underflow: %\"PRIuMAX\" - %\"PRIuMAX,\n-\t\t    (uintmax_t)a, (uintmax_t)b);\n-\treturn a - b;\n-}\n-\n-static inline size_t st_left_shift(size_t a, unsigned shift)\n-{\n-\tif (unsigned_left_shift_overflows(a, shift))\n-\t\tdie(\"size_t overflow: %\"PRIuMAX\" << %u\",\n-\t\t    (uintmax_t)a, shift);\n-\treturn a << shift;\n-}\n-\n-static inline unsigned long cast_size_t_to_ulong(size_t a)\n-{\n-\tif (a != (unsigned long)a)\n-\t\tdie(\"object too large to read on this platform: %\"\n-\t\t    PRIuMAX\" is cut off to %lu\",\n-\t\t    (uintmax_t)a, (unsigned long)a);\n-\treturn (unsigned long)a;\n-}\n-\n-static inline int cast_size_t_to_int(size_t a)\n-{\n-\tif (a > INT_MAX)\n-\t\tdie(\"number too large to represent as int on this platform: %\"PRIuMAX,\n-\t\t    (uintmax_t)a);\n-\treturn (int)a;\n-}\n-\n /*\n  * Limit size of IO chunks, because huge chunks only cause pain.  OS X\n  * 64-bit is buggy, returning EINVAL if len >= INT_MAX; and even in\n@@ -1047,240 +861,10 @@ static inline int cast_size_t_to_int(size_t a)\n # define xalloca_free(p)    (free(p))\n #endif\n \n-/*\n- * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note\n- * that ptr is used twice, so don't pass e.g. ptr++.\n- */\n-#define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)\n-\n-#define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))\n-#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))\n-#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))\n-\n-#define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \\\n-\tBARF_UNLESS_COPYABLE((dst), (src)))\n-static inline void copy_array(void *dst, const void *src, size_t n, size_t size)\n-{\n-\tif (n)\n-\t\tmemcpy(dst, src, st_mult(size, n));\n-}\n-\n-#define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \\\n-\tBARF_UNLESS_COPYABLE((dst), (src)))\n-static inline void move_array(void *dst, const void *src, size_t n, size_t size)\n-{\n-\tif (n)\n-\t\tmemmove(dst, src, st_mult(size, n));\n-}\n-\n-#define DUP_ARRAY(dst, src, n) do { \\\n-\tsize_t dup_array_n_ = (n); \\\n-\tCOPY_ARRAY(ALLOC_ARRAY((dst), dup_array_n_), (src), dup_array_n_); \\\n-} while (0)\n-\n-/*\n- * These functions help you allocate structs with flex arrays, and copy\n- * the data directly into the array. For example, if you had:\n- *\n- *   struct foo {\n- *     int bar;\n- *     char name[FLEX_ARRAY];\n- *   };\n- *\n- * you can do:\n- *\n- *   struct foo *f;\n- *   FLEX_ALLOC_MEM(f, name, src, len);\n- *\n- * to allocate a \"foo\" with the contents of \"src\" in the \"name\" field.\n- * The resulting struct is automatically zero'd, and the flex-array field\n- * is NUL-terminated (whether the incoming src buffer was or not).\n- *\n- * The FLEXPTR_* variants operate on structs that don't use flex-arrays,\n- * but do want to store a pointer to some extra data in the same allocated\n- * block. For example, if you have:\n- *\n- *   struct foo {\n- *     char *name;\n- *     int bar;\n- *   };\n- *\n- * you can do:\n- *\n- *   struct foo *f;\n- *   FLEXPTR_ALLOC_STR(f, name, src);\n- *\n- * and \"name\" will point to a block of memory after the struct, which will be\n- * freed along with the struct (but the pointer can be repointed anywhere).\n- *\n- * The *_STR variants accept a string parameter rather than a ptr/len\n- * combination.\n- *\n- * Note that these macros will evaluate the first parameter multiple\n- * times, and it must be assignable as an lvalue.\n- */\n-#define FLEX_ALLOC_MEM(x, flexname, buf, len) do { \\\n-\tsize_t flex_array_len_ = (len); \\\n-\t(x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \\\n-\tmemcpy((void *)(x)->flexname, (buf), flex_array_len_); \\\n-} while (0)\n-#define FLEXPTR_ALLOC_MEM(x, ptrname, buf, len) do { \\\n-\tsize_t flex_array_len_ = (len); \\\n-\t(x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \\\n-\tmemcpy((x) + 1, (buf), flex_array_len_); \\\n-\t(x)->ptrname = (void *)((x)+1); \\\n-} while(0)\n-#define FLEX_ALLOC_STR(x, flexname, str) \\\n-\tFLEX_ALLOC_MEM((x), flexname, (str), strlen(str))\n-#define FLEXPTR_ALLOC_STR(x, ptrname, str) \\\n-\tFLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))\n-\n-static inline char *xstrdup_or_null(const char *str)\n-{\n-\treturn str ? xstrdup(str) : NULL;\n-}\n-\n-static inline size_t xsize_t(off_t len)\n-{\n-\tif (len < 0 || (uintmax_t) len > SIZE_MAX)\n-\t\tdie(\"Cannot handle files this big\");\n-\treturn (size_t) len;\n-}\n-\n #ifndef HOST_NAME_MAX\n #define HOST_NAME_MAX 256\n #endif\n \n-/* in ctype.c, for kwset users */\n-extern const unsigned char tolower_trans_tbl[256];\n-\n-/* Sane ctype - no locale, and works with signed chars */\n-#undef isascii\n-#undef isspace\n-#undef isdigit\n-#undef isalpha\n-#undef isalnum\n-#undef isprint\n-#undef islower\n-#undef isupper\n-#undef tolower\n-#undef toupper\n-#undef iscntrl\n-#undef ispunct\n-#undef isxdigit\n-\n-extern const unsigned char sane_ctype[256];\n-extern const signed char hexval_table[256];\n-#define GIT_SPACE 0x01\n-#define GIT_DIGIT 0x02\n-#define GIT_ALPHA 0x04\n-#define GIT_GLOB_SPECIAL 0x08\n-#define GIT_REGEX_SPECIAL 0x10\n-#define GIT_PATHSPEC_MAGIC 0x20\n-#define GIT_CNTRL 0x40\n-#define GIT_PUNCT 0x80\n-#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n-#define isascii(x) (((x) & ~0x7f) == 0)\n-#define isspace(x) sane_istest(x,GIT_SPACE)\n-#define isdigit(x) sane_istest(x,GIT_DIGIT)\n-#define isalpha(x) sane_istest(x,GIT_ALPHA)\n-#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)\n-#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)\n-#define islower(x) sane_iscase(x, 1)\n-#define isupper(x) sane_iscase(x, 0)\n-#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)\n-#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)\n-#define iscntrl(x) (sane_istest(x,GIT_CNTRL))\n-#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \\\n-\t\tGIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)\n-#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n-#define tolower(x) sane_case((unsigned char)(x), 0x20)\n-#define toupper(x) sane_case((unsigned char)(x), 0)\n-#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)\n-\n-static inline int sane_case(int x, int high)\n-{\n-\tif (sane_istest(x, GIT_ALPHA))\n-\t\tx = (x & ~0x20) | high;\n-\treturn x;\n-}\n-\n-static inline int sane_iscase(int x, int is_lower)\n-{\n-\tif (!sane_istest(x, GIT_ALPHA))\n-\t\treturn 0;\n-\n-\tif (is_lower)\n-\t\treturn (x & 0x20) != 0;\n-\telse\n-\t\treturn (x & 0x20) == 0;\n-}\n-\n-/*\n- * Like skip_prefix, but compare case-insensitively. Note that the comparison\n- * is done via tolower(), so it is strictly ASCII (no multi-byte characters or\n- * locale-specific conversions).\n- */\n-static inline int skip_iprefix(const char *str, const char *prefix,\n-\t\t\t       const char **out)\n-{\n-\tdo {\n-\t\tif (!*prefix) {\n-\t\t\t*out = str;\n-\t\t\treturn 1;\n-\t\t}\n-\t} while (tolower(*str++) == tolower(*prefix++));\n-\treturn 0;\n-}\n-\n-/*\n- * Like skip_prefix_mem, but compare case-insensitively. Note that the\n- * comparison is done via tolower(), so it is strictly ASCII (no multi-byte\n- * characters or locale-specific conversions).\n- */\n-static inline int skip_iprefix_mem(const char *buf, size_t len,\n-\t\t\t\t   const char *prefix,\n-\t\t\t\t   const char **out, size_t *outlen)\n-{\n-\tdo {\n-\t\tif (!*prefix) {\n-\t\t\t*out = buf;\n-\t\t\t*outlen = len;\n-\t\t\treturn 1;\n-\t\t}\n-\t} while (len-- > 0 && tolower(*buf++) == tolower(*prefix++));\n-\treturn 0;\n-}\n-\n-static inline int strtoul_ui(char const *s, int base, unsigned int *result)\n-{\n-\tunsigned long ul;\n-\tchar *p;\n-\n-\terrno = 0;\n-\t/* negative values would be accepted by strtoul */\n-\tif (strchr(s, '-'))\n-\t\treturn -1;\n-\tul = strtoul(s, &p, base);\n-\tif (errno || *p || p == s || (unsigned int) ul != ul)\n-\t\treturn -1;\n-\t*result = ul;\n-\treturn 0;\n-}\n-\n-static inline int strtol_i(char const *s, int base, int *result)\n-{\n-\tlong ul;\n-\tchar *p;\n-\n-\terrno = 0;\n-\tul = strtol(s, &p, base);\n-\tif (errno || *p || p == s || (int) ul != ul)\n-\t\treturn -1;\n-\t*result = ul;\n-\treturn 0;\n-}\n-\n void git_stable_qsort(void *base, size_t nmemb, size_t size,\n \t\t      int(*compar)(const void *, const void *));\n #ifdef INTERNAL_QSORT\n@@ -1313,15 +897,6 @@ int git_qsort_s(void *base, size_t nmemb, size_t size,\n #error \"Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd\"\n #endif\n \n-static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,\n-\t\t\t      size_t nmatch, regmatch_t pmatch[], int eflags)\n-{\n-\tassert(nmatch > 0 && pmatch);\n-\tpmatch[0].rm_so = 0;\n-\tpmatch[0].rm_eo = size;\n-\treturn regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);\n-}\n-\n #ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS\n int git_regcomp(regex_t *preg, const char *pattern, int cflags);\n #define regcomp git_regcomp\n@@ -1430,21 +1005,6 @@ int git_access(const char *path, int mode);\n # endif\n #endif\n \n-/*\n- * Our code often opens a path to an optional file, to work on its\n- * contents when we can successfully open it.  We can ignore a failure\n- * to open if such an optional file does not exist, but we do want to\n- * report a failure in opening for other reasons (e.g. we got an I/O\n- * error, or the file is there, but we lack the permission to open).\n- *\n- * Call this function after seeing an error from open() or fopen() to\n- * see if the errno indicates a missing file that we can safely ignore.\n- */\n-static inline int is_missing_file_error(int errno_)\n-{\n-\treturn (errno_ == ENOENT || errno_ == ENOTDIR);\n-}\n-\n int cmd_main(int, const char **);\n \n /*\n@@ -1486,37 +1046,14 @@ int uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,\n \t\tuLong *sourceLen);\n #endif\n \n+#include \"common.h\"\n+\n /*\n  * This include must come after system headers, since it introduces macros that\n  * replace system names.\n  */\n #include \"banned.h\"\n \n-/*\n- * container_of - Get the address of an object containing a field.\n- *\n- * @ptr: pointer to the field.\n- * @type: type of the object.\n- * @member: name of the field within the object.\n- */\n-#define container_of(ptr, type, member) \\\n-\t((type *) ((char *)(ptr) - offsetof(type, member)))\n-\n-/*\n- * helper function for `container_of_or_null' to avoid multiple\n- * evaluation of @ptr\n- */\n-static inline void *container_of_or_null_offset(void *ptr, size_t offset)\n-{\n-\treturn ptr ? (char *)ptr - offset : NULL;\n-}\n-\n-/*\n- * like `container_of', but allows returned value to be NULL\n- */\n-#define container_of_or_null(ptr, type, member) \\\n-\t(type *)container_of_or_null_offset(ptr, offsetof(type, member))\n-\n /*\n  * like offsetof(), but takes a pointer to a variable of type which\n  * contains @member, instead of a specified type.\n-- \n2.40.1.606.ga4b1b128d6-goog\n\n"},{"id":"477391","messageId":"20230516170932.1358685-5-calvinwan@google.com","threadId":"59752","inReplyTo":"20230516170932.1358685-1-calvinwan@google.com","subject":"[PATCH 4/6] usage.h: move declarations for usage.c functions from git-compat-util.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-16T17:09:29Z","receivedAt":"2023-05-16T17:10:07Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Signed-off-by: Calvin Wan <calvinwan@google.com>\n---\n common.h          |  1 +\n git-compat-util.h | 54 ------------------------------------------\n usage.h           | 60 +++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 61 insertions(+), 54 deletions(-)\n create mode 100644 usage.h\n\ndiff --git a/common.h b/common.h\nindex c0fdc5eb98..4aa99bc98b 100644\n--- a/common.h\n+++ b/common.h\n@@ -3,6 +3,7 @@\n \n #include \"git-compat-util.h\"\n #include \"wrapper.h\"\n+#include \"usage.h\"\n \n /*\n  * ARRAY_SIZE - get the number of elements in a visible array\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex c2b92a3033..bc543baa66 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -573,19 +573,6 @@ static inline int git_has_dir_sep(const char *path)\n #include \"compat/bswap.h\"\n \n #include \"wildmatch.h\"\n-#include \"wrapper.h\"\n-\n-/* General helper functions */\n-NORETURN void usage(const char *err);\n-NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-int die_message(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-int die_message_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-int error(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n \n #ifndef NO_OPENSSL\n #ifdef APPLE_COMMON_CRYPTO\n@@ -601,30 +588,6 @@ void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n #include <openssl/rand.h>\n #endif\n \n-/*\n- * Let callers be aware of the constant return value; this can help\n- * gcc with -Wuninitialized analysis. We restrict this trick to gcc, though,\n- * because other compilers may be confused by this.\n- */\n-#if defined(__GNUC__)\n-static inline int const_error(void)\n-{\n-\treturn -1;\n-}\n-#define error(...) (error(__VA_ARGS__), const_error())\n-#define error_errno(...) (error_errno(__VA_ARGS__), const_error())\n-#endif\n-\n-typedef void (*report_fn)(const char *, va_list params);\n-\n-void set_die_routine(NORETURN_PTR report_fn routine);\n-report_fn get_die_message_routine(void);\n-void set_error_routine(report_fn routine);\n-report_fn get_error_routine(void);\n-void set_warn_routine(report_fn routine);\n-report_fn get_warn_routine(void);\n-void set_die_is_recursing_routine(int (*routine)(void));\n-\n #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)\n \n #ifndef PROT_READ\n@@ -941,23 +904,6 @@ int git_regcomp(regex_t *preg, const char *pattern, int cflags);\n #endif\n #endif\n \n-/* usage.c: only to be used for testing BUG() implementation (see test-tool) */\n-extern int BUG_exit_code;\n-\n-/* usage.c: if bug() is called we should have a BUG_if_bug() afterwards */\n-extern int bug_called_must_BUG;\n-\n-__attribute__((format (printf, 3, 4))) NORETURN\n-void BUG_fl(const char *file, int line, const char *fmt, ...);\n-#define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__)\n-__attribute__((format (printf, 3, 4)))\n-void bug_fl(const char *file, int line, const char *fmt, ...);\n-#define bug(...) bug_fl(__FILE__, __LINE__, __VA_ARGS__)\n-#define BUG_if_bug(...) do { \\\n-\tif (bug_called_must_BUG) \\\n-\t\tBUG_fl(__FILE__, __LINE__, __VA_ARGS__); \\\n-} while (0)\n-\n #ifndef FSYNC_METHOD_DEFAULT\n #ifdef __APPLE__\n #define FSYNC_METHOD_DEFAULT FSYNC_METHOD_WRITEOUT_ONLY\ndiff --git a/usage.h b/usage.h\nnew file mode 100644\nindex 0000000000..770076e684\n--- /dev/null\n+++ b/usage.h\n@@ -0,0 +1,60 @@\n+#ifndef USAGE_H\n+#define USAGE_H\n+\n+#include \"git-compat-util.h\"\n+\n+/* General helper functions */\n+NORETURN void usage(const char *err);\n+NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+int error(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+int die_message(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+int die_message_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+\n+void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+\n+/*\n+ * Let callers be aware of the constant return value; this can help\n+ * gcc with -Wuninitialized analysis. We restrict this trick to gcc, though,\n+ * because other compilers may be confused by this.\n+ */\n+#if defined(__GNUC__)\n+static inline int const_error(void)\n+{\n+\treturn -1;\n+}\n+#define error(...) (error(__VA_ARGS__), const_error())\n+#define error_errno(...) (error_errno(__VA_ARGS__), const_error())\n+#endif\n+\n+typedef void (*report_fn)(const char *, va_list params);\n+\n+void set_die_routine(NORETURN_PTR report_fn routine);\n+report_fn get_die_message_routine(void);\n+void set_error_routine(report_fn routine);\n+report_fn get_error_routine(void);\n+void set_warn_routine(report_fn routine);\n+report_fn get_warn_routine(void);\n+void set_die_is_recursing_routine(int (*routine)(void));\n+\n+/* usage.c: only to be used for testing BUG() implementation (see test-tool) */\n+extern int BUG_exit_code;\n+\n+/* usage.c: if bug() is called we should have a BUG_if_bug() afterwards */\n+extern int bug_called_must_BUG;\n+\n+__attribute__((format (printf, 3, 4))) NORETURN\n+void BUG_fl(const char *file, int line, const char *fmt, ...);\n+#define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__)\n+__attribute__((format (printf, 3, 4)))\n+void bug_fl(const char *file, int line, const char *fmt, ...);\n+#define bug(...) bug_fl(__FILE__, __LINE__, __VA_ARGS__)\n+#define BUG_if_bug(...) do { \\\n+\tif (bug_called_must_BUG) \\\n+\t\tBUG_fl(__FILE__, __LINE__, __VA_ARGS__); \\\n+} while (0)\n+\n+#endif /* USAGE_H */\n-- \n2.40.1.606.ga4b1b128d6-goog\n\n"},{"id":"477393","messageId":"20230516170932.1358685-6-calvinwan@google.com","threadId":"59752","inReplyTo":"20230516170932.1358685-1-calvinwan@google.com","subject":"[PATCH 5/6] treewide: remove unnecessary includes for wrapper.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-16T17:09:30Z","receivedAt":"2023-05-16T17:10:09Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Signed-off-by: Calvin Wan <calvinwan@google.com>\n---\n apply.c                          | 1 -\n builtin/am.c                     | 1 -\n builtin/bisect.c                 | 1 -\n builtin/branch.c                 | 1 -\n builtin/bugreport.c              | 1 -\n builtin/clone.c                  | 1 -\n builtin/config.c                 | 1 -\n builtin/credential-cache.c       | 1 -\n builtin/difftool.c               | 1 -\n builtin/fast-import.c            | 1 -\n builtin/fmt-merge-msg.c          | 1 -\n builtin/gc.c                     | 1 -\n builtin/get-tar-commit-id.c      | 1 -\n builtin/index-pack.c             | 1 -\n builtin/init-db.c                | 1 -\n builtin/merge.c                  | 1 -\n builtin/pack-objects.c           | 1 -\n builtin/rebase.c                 | 1 -\n builtin/receive-pack.c           | 1 -\n builtin/rerere.c                 | 1 -\n builtin/unpack-file.c            | 1 -\n builtin/worktree.c               | 1 -\n bulk-checkin.c                   | 1 -\n combine-diff.c                   | 1 -\n commit-graph.c                   | 1 -\n compat/terminal.c                | 1 -\n config.c                         | 1 -\n convert.c                        | 1 -\n copy.c                           | 1 -\n csum-file.c                      | 1 -\n daemon.c                         | 1 -\n diff.c                           | 1 -\n dir.c                            | 1 -\n editor.c                         | 1 -\n entry.c                          | 1 -\n environment.c                    | 1 -\n fetch-pack.c                     | 1 -\n gpg-interface.c                  | 1 -\n grep.c                           | 1 -\n http-backend.c                   | 1 -\n imap-send.c                      | 1 -\n ll-merge.c                       | 1 -\n merge-recursive.c                | 1 -\n notes-merge.c                    | 1 -\n object-file.c                    | 1 -\n pack-write.c                     | 1 -\n packfile.c                       | 1 -\n parallel-checkout.c              | 1 -\n path.c                           | 1 -\n pkt-line.c                       | 1 -\n read-cache.c                     | 1 -\n rebase-interactive.c             | 1 -\n refs.c                           | 1 -\n rerere.c                         | 1 -\n send-pack.c                      | 1 -\n sequencer.c                      | 1 -\n server-info.c                    | 1 -\n setup.c                          | 1 -\n shallow.c                        | 1 -\n strbuf.c                         | 1 -\n streaming.c                      | 1 -\n t/helper/test-delta.c            | 1 -\n t/helper/test-fsmonitor-client.c | 1 -\n t/helper/test-read-cache.c       | 1 -\n tag.c                            | 1 -\n tempfile.c                       | 1 -\n trace.c                          | 1 -\n transport-helper.c               | 1 -\n transport.c                      | 1 -\n upload-pack.c                    | 1 -\n usage.c                          | 1 -\n worktree.c                       | 1 -\n wrapper.c                        | 1 -\n write-or-die.c                   | 1 -\n 74 files changed, 74 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 3636bc14c2..ef6020b18f 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -30,7 +30,6 @@\n #include \"apply.h\"\n #include \"entry.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n struct gitdiff_data {\n \tstruct strbuf *root;\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 5c83f2e003..5689ed44c4 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -43,7 +43,6 @@\n #include \"pager.h\"\n #include \"repository.h\"\n #include \"pretty.h\"\n-#include \"wrapper.h\"\n \n /**\n  * Returns the length of the first line of msg.\ndiff --git a/builtin/bisect.c b/builtin/bisect.c\nindex 4b2143d455..dc3bd0c3a0 100644\n--- a/builtin/bisect.c\n+++ b/builtin/bisect.c\n@@ -14,7 +14,6 @@\n #include \"prompt.h\"\n #include \"quote.h\"\n #include \"revision.h\"\n-#include \"wrapper.h\"\n \n static GIT_PATH_FUNC(git_path_bisect_terms, \"BISECT_TERMS\")\n static GIT_PATH_FUNC(git_path_bisect_expected_rev, \"BISECT_EXPECTED_REV\")\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 501c47657c..728931f011 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -28,7 +28,6 @@\n #include \"worktree.h\"\n #include \"help.h\"\n #include \"commit-reach.h\"\n-#include \"wrapper.h\"\n \n static const char * const builtin_branch_usage[] = {\n \tN_(\"git branch [<options>] [-r | -a] [--merged] [--no-merged]\"),\ndiff --git a/builtin/bugreport.c b/builtin/bugreport.c\nindex daf6c23657..d2ae5c305d 100644\n--- a/builtin/bugreport.c\n+++ b/builtin/bugreport.c\n@@ -11,7 +11,6 @@\n #include \"diagnose.h\"\n #include \"object-file.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n static void get_system_info(struct strbuf *sys_info)\n {\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 186845ef0b..c632ad4a9a 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -42,7 +42,6 @@\n #include \"hook.h\"\n #include \"bundle.h\"\n #include \"bundle-uri.h\"\n-#include \"wrapper.h\"\n \n /*\n  * Overall FIXMEs:\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 9401f1e5e3..71bb376fb3 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -12,7 +12,6 @@\n #include \"quote.h\"\n #include \"setup.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n \n static const char *const builtin_config_usage[] = {\n \tN_(\"git config [<options>]\"),\ndiff --git a/builtin/credential-cache.c b/builtin/credential-cache.c\nindex 508da4c6e4..c84920a3c1 100644\n--- a/builtin/credential-cache.c\n+++ b/builtin/credential-cache.c\n@@ -1,7 +1,6 @@\n #include \"builtin.h\"\n #include \"gettext.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n #ifndef NO_UNIX_SOCKETS\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex f09d24d37f..785105c61c 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -30,7 +30,6 @@\n #include \"dir.h\"\n #include \"entry.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n static int trust_exit_code;\n \ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex bbd9b2b3e7..7473f3a42e 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -26,7 +26,6 @@\n #include \"commit-reach.h\"\n #include \"khash.h\"\n #include \"date.h\"\n-#include \"wrapper.h\"\n \n #define PACK_ID_BITS 16\n #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex cc81241642..0f9855b680 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -3,7 +3,6 @@\n #include \"fmt-merge-msg.h\"\n #include \"gettext.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n \n static const char * const fmt_merge_msg_usage[] = {\n \tN_(\"git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]\"),\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex c9f8557335..15b60273fc 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -39,7 +39,6 @@\n #include \"hook.h\"\n #include \"setup.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n #define FAILED_RUN \"failed to run %s\"\n \ndiff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c\nindex 564cfcac4f..a458a925f1 100644\n--- a/builtin/get-tar-commit-id.c\n+++ b/builtin/get-tar-commit-id.c\n@@ -6,7 +6,6 @@\n #include \"tar.h\"\n #include \"builtin.h\"\n #include \"quote.h\"\n-#include \"wrapper.h\"\n \n static const char builtin_get_tar_commit_id_usage[] =\n \"git get-tar-commit-id\";\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex bb67e16655..1e065e9ce3 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -24,7 +24,6 @@\n #include \"replace-object.h\"\n #include \"promisor-remote.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n static const char index_pack_usage[] =\n \"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])\";\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 6183f3fb3f..81da7fcd75 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -15,7 +15,6 @@\n #include \"parse-options.h\"\n #include \"setup.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n \n #ifndef DEFAULT_GIT_TEMPLATE_DIR\n #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates\"\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 8da3e46abb..b800d4e189 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -52,7 +52,6 @@\n #include \"commit-reach.h\"\n #include \"wt-status.h\"\n #include \"commit-graph.h\"\n-#include \"wrapper.h\"\n \n #define DEFAULT_TWOHEAD (1<<0)\n #define DEFAULT_OCTOPUS (1<<1)\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex a5b466839b..79f3a2f300 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -43,7 +43,6 @@\n #include \"promisor-remote.h\"\n #include \"pack-mtimes.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n \n /*\n  * Objects we are going to pack are collected in the `to_pack` structure.\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex ace1d5e8d1..e28e24b4fd 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -36,7 +36,6 @@\n #include \"reset.h\"\n #include \"trace2.h\"\n #include \"hook.h\"\n-#include \"wrapper.h\"\n \n static char const * const builtin_rebase_usage[] = {\n \tN_(\"git rebase [-i] [options] [--exec <cmd>] \"\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex d22180435c..a548424c93 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -38,7 +38,6 @@\n #include \"worktree.h\"\n #include \"shallow.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n \n static const char * const receive_pack_usage[] = {\n \tN_(\"git receive-pack <git-dir>\"),\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex d4a03707b1..24c7875572 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -6,7 +6,6 @@\n #include \"parse-options.h\"\n #include \"string-list.h\"\n #include \"rerere.h\"\n-#include \"wrapper.h\"\n #include \"xdiff/xdiff.h\"\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\ndiff --git a/builtin/unpack-file.c b/builtin/unpack-file.c\nindex b35a4b9dfe..3b8b8da5f6 100644\n--- a/builtin/unpack-file.c\n+++ b/builtin/unpack-file.c\n@@ -3,7 +3,6 @@\n #include \"hex.h\"\n #include \"object-name.h\"\n #include \"object-store.h\"\n-#include \"wrapper.h\"\n \n static char *create_temp_file(struct object_id *oid)\n {\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex a61bc32189..dce9106757 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -19,7 +19,6 @@\n #include \"submodule.h\"\n #include \"utf8.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n #include \"quote.h\"\n \n #define BUILTIN_WORKTREE_ADD_USAGE \\\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex d843279715..9192298db6 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -17,7 +17,6 @@\n #include \"packfile.h\"\n #include \"object-file.h\"\n #include \"object-store.h\"\n-#include \"wrapper.h\"\n \n static int odb_transaction_nesting;\n \ndiff --git a/combine-diff.c b/combine-diff.c\nindex f7e9fb5747..cd5f39f22f 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -16,7 +16,6 @@\n #include \"userdiff.h\"\n #include \"oid-array.h\"\n #include \"revision.h\"\n-#include \"wrapper.h\"\n \n static int compare_paths(const struct combine_diff_path *one,\n \t\t\t  const struct diff_filespec *two)\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 43558b4d9b..b07e22ce66 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -24,7 +24,6 @@\n #include \"json-writer.h\"\n #include \"trace2.h\"\n #include \"chunk-format.h\"\n-#include \"wrapper.h\"\n \n void git_test_write_commit_graph_or_die(void)\n {\ndiff --git a/compat/terminal.c b/compat/terminal.c\nindex d87e321189..83d95e8656 100644\n--- a/compat/terminal.c\n+++ b/compat/terminal.c\n@@ -6,7 +6,6 @@\n #include \"run-command.h\"\n #include \"string-list.h\"\n #include \"hashmap.h\"\n-#include \"wrapper.h\"\n \n #if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE)\n \ndiff --git a/config.c b/config.c\nindex 43b0d3fb57..b7cccbe245 100644\n--- a/config.c\n+++ b/config.c\n@@ -35,7 +35,6 @@\n #include \"setup.h\"\n #include \"trace2.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n struct config_source {\ndiff --git a/convert.c b/convert.c\nindex 5a2ea5308d..93e9ebe6d8 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -14,7 +14,6 @@\n #include \"trace.h\"\n #include \"utf8.h\"\n #include \"ll-merge.h\"\n-#include \"wrapper.h\"\n \n /*\n  * convert.c - convert a file when checking it out and checking it in.\ndiff --git a/copy.c b/copy.c\nindex c3250f0822..4de6a110f0 100644\n--- a/copy.c\n+++ b/copy.c\n@@ -1,5 +1,4 @@\n #include \"cache.h\"\n-#include \"wrapper.h\"\n \n int copy_fd(int ifd, int ofd)\n {\ndiff --git a/csum-file.c b/csum-file.c\nindex 82ae2973d3..ddfc685d52 100644\n--- a/csum-file.c\n+++ b/csum-file.c\n@@ -10,7 +10,6 @@\n #include \"git-compat-util.h\"\n #include \"progress.h\"\n #include \"csum-file.h\"\n-#include \"wrapper.h\"\n \n static void verify_buffer_or_die(struct hashfile *f,\n \t\t\t\t const void *buf,\ndiff --git a/daemon.c b/daemon.c\nindex 75c3c06457..4047b0cf27 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -9,7 +9,6 @@\n #include \"setup.h\"\n #include \"strbuf.h\"\n #include \"string-list.h\"\n-#include \"wrapper.h\"\n \n #ifdef NO_INITGROUPS\n #define initgroups(x, y) (0) /* nothing */\ndiff --git a/diff.c b/diff.c\nindex 067846b13c..4033358cf4 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -40,7 +40,6 @@\n #include \"object-name.h\"\n #include \"setup.h\"\n #include \"strmap.h\"\n-#include \"wrapper.h\"\n \n #ifdef NO_FAST_WORKING_DIRECTORY\n #define FAST_WORKING_DIRECTORY 0\ndiff --git a/dir.c b/dir.c\nindex aa840995c4..f235df015e 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -26,7 +26,6 @@\n #include \"setup.h\"\n #include \"submodule-config.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n /*\n  * Tells read_directory_recursive how a file or directory should be treated.\ndiff --git a/editor.c b/editor.c\nindex b34e10606d..d6c00f2b6d 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -10,7 +10,6 @@\n #include \"strvec.h\"\n #include \"run-command.h\"\n #include \"sigchain.h\"\n-#include \"wrapper.h\"\n \n #ifndef DEFAULT_EDITOR\n #define DEFAULT_EDITOR \"vi\"\ndiff --git a/entry.c b/entry.c\nindex d89e61fa64..eaee78a526 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -11,7 +11,6 @@\n #include \"fsmonitor.h\"\n #include \"entry.h\"\n #include \"parallel-checkout.h\"\n-#include \"wrapper.h\"\n \n static void create_directories(const char *path, int path_len,\n \t\t\t       const struct checkout *state)\ndiff --git a/environment.c b/environment.c\nindex 8a96997539..330277ff43 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -27,7 +27,6 @@\n #include \"setup.h\"\n #include \"shallow.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n int trust_executable_bit = 1;\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 6fa6e8af9a..5e3e875670 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -32,7 +32,6 @@\n #include \"commit-graph.h\"\n #include \"sigchain.h\"\n #include \"mergesort.h\"\n-#include \"wrapper.h\"\n \n static int transfer_unpack_limit = -1;\n static int fetch_unpack_limit = -1;\ndiff --git a/gpg-interface.c b/gpg-interface.c\nindex f3ac5acdd9..75ce234ddf 100644\n--- a/gpg-interface.c\n+++ b/gpg-interface.c\n@@ -10,7 +10,6 @@\n #include \"sigchain.h\"\n #include \"tempfile.h\"\n #include \"alias.h\"\n-#include \"wrapper.h\"\n \n static int git_gpg_config(const char *, const char *, void *);\n \ndiff --git a/grep.c b/grep.c\nindex 073559f2cd..b86462a12a 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -11,7 +11,6 @@\n #include \"commit.h\"\n #include \"quote.h\"\n #include \"help.h\"\n-#include \"wrapper.h\"\n \n static int grep_source_load(struct grep_source *gs);\n static int grep_source_is_binary(struct grep_source *gs,\ndiff --git a/http-backend.c b/http-backend.c\nindex ac146d85c5..4491cdee39 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -18,7 +18,6 @@\n #include \"object-store.h\"\n #include \"protocol.h\"\n #include \"date.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n static const char content_type[] = \"Content-Type\";\ndiff --git a/imap-send.c b/imap-send.c\nindex a62424e90a..ad5474643c 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -29,7 +29,6 @@\n #include \"run-command.h\"\n #include \"parse-options.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)\n typedef void *SSL;\n #endif\ndiff --git a/ll-merge.c b/ll-merge.c\nindex 28bc94c45d..f0763f7016 100644\n--- a/ll-merge.c\n+++ b/ll-merge.c\n@@ -12,7 +12,6 @@\n #include \"run-command.h\"\n #include \"ll-merge.h\"\n #include \"quote.h\"\n-#include \"wrapper.h\"\n \n struct ll_merge_driver;\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 9875bdb11c..8bf84c9339 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -33,7 +33,6 @@\n #include \"tag.h\"\n #include \"tree-walk.h\"\n #include \"unpack-trees.h\"\n-#include \"wrapper.h\"\n #include \"xdiff-interface.h\"\n \n struct merge_options_internal {\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 233e49e319..434090634e 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -19,7 +19,6 @@\n #include \"trace.h\"\n #include \"notes-utils.h\"\n #include \"commit-reach.h\"\n-#include \"wrapper.h\"\n \n struct notes_merge_pair {\n \tstruct object_id obj, base, local, remote;\ndiff --git a/object-file.c b/object-file.c\nindex af18e38527..43c1585aa7 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -42,7 +42,6 @@\n #include \"setup.h\"\n #include \"submodule.h\"\n #include \"fsck.h\"\n-#include \"wrapper.h\"\n \n /* The maximum size for an object header. */\n #define MAX_HEADER_LEN 32\ndiff --git a/pack-write.c b/pack-write.c\nindex 3b3ce89de6..7dd8882830 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -10,7 +10,6 @@\n #include \"oidmap.h\"\n #include \"pack-objects.h\"\n #include \"pack-revindex.h\"\n-#include \"wrapper.h\"\n \n void reset_pack_idx_option(struct pack_idx_option *opts)\n {\ndiff --git a/packfile.c b/packfile.c\nindex 57df0c1956..96727e63a8 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -24,7 +24,6 @@\n #include \"commit-graph.h\"\n #include \"pack-revindex.h\"\n #include \"promisor-remote.h\"\n-#include \"wrapper.h\"\n \n char *odb_pack_name(struct strbuf *buf,\n \t\t    const unsigned char *hash,\ndiff --git a/parallel-checkout.c b/parallel-checkout.c\nindex 50fd7fe31e..38c4dc665d 100644\n--- a/parallel-checkout.c\n+++ b/parallel-checkout.c\n@@ -12,7 +12,6 @@\n #include \"streaming.h\"\n #include \"thread-utils.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n struct pc_worker {\n \tstruct child_process cp;\ndiff --git a/path.c b/path.c\nindex 7c1cd8182a..dff215ac69 100644\n--- a/path.c\n+++ b/path.c\n@@ -18,7 +18,6 @@\n #include \"object-store.h\"\n #include \"lockfile.h\"\n #include \"exec-cmd.h\"\n-#include \"wrapper.h\"\n \n static int get_st_mode_bits(const char *path, int *mode)\n {\ndiff --git a/pkt-line.c b/pkt-line.c\nindex 3561d85358..9cf6f12c4e 100644\n--- a/pkt-line.c\n+++ b/pkt-line.c\n@@ -4,7 +4,6 @@\n #include \"hex.h\"\n #include \"run-command.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n char packet_buffer[LARGE_PACKET_MAX];\ndiff --git a/read-cache.c b/read-cache.c\nindex e919af3c77..7fa89c684d 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -38,7 +38,6 @@\n #include \"csum-file.h\"\n #include \"promisor-remote.h\"\n #include \"hook.h\"\n-#include \"wrapper.h\"\n \n /* Mask for the name length in ce_flags in the on-disk index */\n \ndiff --git a/rebase-interactive.c b/rebase-interactive.c\nindex 789f407361..8c52d2170a 100644\n--- a/rebase-interactive.c\n+++ b/rebase-interactive.c\n@@ -10,7 +10,6 @@\n #include \"config.h\"\n #include \"dir.h\"\n #include \"object-name.h\"\n-#include \"wrapper.h\"\n \n static const char edit_todo_list_advice[] =\n N_(\"You can fix this with 'git rebase --edit-todo' \"\ndiff --git a/refs.c b/refs.c\nindex d2a98e1c21..379217b03e 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -28,7 +28,6 @@\n #include \"sigchain.h\"\n #include \"date.h\"\n #include \"commit.h\"\n-#include \"wrapper.h\"\n \n /*\n  * List of all available backends\ndiff --git a/rerere.c b/rerere.c\nindex 7abc94bf44..7ed2493891 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -17,7 +17,6 @@\n #include \"object-store.h\"\n #include \"hash-lookup.h\"\n #include \"strmap.h\"\n-#include \"wrapper.h\"\n \n #define RESOLVED 0\n #define PUNTED 1\ndiff --git a/send-pack.c b/send-pack.c\nindex 2089143555..97344b629e 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -14,7 +14,6 @@\n #include \"quote.h\"\n #include \"transport.h\"\n #include \"version.h\"\n-#include \"wrapper.h\"\n #include \"oid-array.h\"\n #include \"gpg-interface.h\"\n #include \"shallow.h\"\ndiff --git a/sequencer.c b/sequencer.c\nindex c88d1d9553..e773b4999b 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -45,7 +45,6 @@\n #include \"rebase-interactive.h\"\n #include \"reset.h\"\n #include \"branch.h\"\n-#include \"wrapper.h\"\n \n #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n \ndiff --git a/server-info.c b/server-info.c\nindex 68098ddd1a..67ce4ad529 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -12,7 +12,6 @@\n #include \"object-file.h\"\n #include \"object-store.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n struct update_info_ctx {\n \tFILE *cur_fp;\ndiff --git a/setup.c b/setup.c\nindex 59abc16ba6..a546da755f 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -12,7 +12,6 @@\n #include \"promisor-remote.h\"\n #include \"quote.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n static int inside_git_dir = -1;\n static int inside_work_tree = -1;\ndiff --git a/shallow.c b/shallow.c\nindex 128f56179e..9ff8923ccf 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -18,7 +18,6 @@\n #include \"commit-reach.h\"\n #include \"shallow.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n \n void set_alternate_shallow_file(struct repository *r, const char *path, int override)\n {\ndiff --git a/strbuf.c b/strbuf.c\nindex 729378ec82..d486189303 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -9,7 +9,6 @@\n #include \"string-list.h\"\n #include \"utf8.h\"\n #include \"date.h\"\n-#include \"wrapper.h\"\n \n int starts_with(const char *str, const char *prefix)\n {\ndiff --git a/streaming.c b/streaming.c\nindex 21e39585e8..83b1530419 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -10,7 +10,6 @@\n #include \"object-store.h\"\n #include \"replace-object.h\"\n #include \"packfile.h\"\n-#include \"wrapper.h\"\n \n typedef int (*open_istream_fn)(struct git_istream *,\n \t\t\t       struct repository *,\ndiff --git a/t/helper/test-delta.c b/t/helper/test-delta.c\nindex e7d134ec25..6bc787a474 100644\n--- a/t/helper/test-delta.c\n+++ b/t/helper/test-delta.c\n@@ -11,7 +11,6 @@\n #include \"test-tool.h\"\n #include \"git-compat-util.h\"\n #include \"delta.h\"\n-#include \"wrapper.h\"\n \n static const char usage_str[] =\n \t\"test-tool delta (-d|-p) <from_file> <data_file> <out_file>\";\ndiff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c\nindex 14522b4c47..a3427e048b 100644\n--- a/t/helper/test-fsmonitor-client.c\n+++ b/t/helper/test-fsmonitor-client.c\n@@ -10,7 +10,6 @@\n #include \"setup.h\"\n #include \"thread-utils.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n #ifndef HAVE_FSMONITOR_DAEMON_BACKEND\n int cmd__fsmonitor_client(int argc UNUSED, const char **argv UNUSED)\ndiff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c\nindex a4c24d0e42..e4c3e8f01c 100644\n--- a/t/helper/test-read-cache.c\n+++ b/t/helper/test-read-cache.c\n@@ -3,7 +3,6 @@\n #include \"cache.h\"\n #include \"config.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n int cmd__read_cache(int argc, const char **argv)\n {\ndiff --git a/tag.c b/tag.c\nindex 96dbd5b2d5..fb0eaa5595 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -10,7 +10,6 @@\n #include \"gpg-interface.h\"\n #include \"hex.h\"\n #include \"packfile.h\"\n-#include \"wrapper.h\"\n \n const char *tag_type = \"tag\";\n \ndiff --git a/tempfile.c b/tempfile.c\nindex 50c377134c..423266e4c7 100644\n--- a/tempfile.c\n+++ b/tempfile.c\n@@ -46,7 +46,6 @@\n #include \"path.h\"\n #include \"tempfile.h\"\n #include \"sigchain.h\"\n-#include \"wrapper.h\"\n \n static VOLATILE_LIST_HEAD(tempfile_list);\n \ndiff --git a/trace.c b/trace.c\nindex 592c141d78..971a68abe8 100644\n--- a/trace.c\n+++ b/trace.c\n@@ -27,7 +27,6 @@\n #include \"quote.h\"\n #include \"setup.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n \n struct trace_key trace_default_key = { \"GIT_TRACE\", 0, 0, 0 };\n struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE);\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 6b816940dc..28a0309e06 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -18,7 +18,6 @@\n #include \"refspec.h\"\n #include \"transport-internal.h\"\n #include \"protocol.h\"\n-#include \"wrapper.h\"\n \n static int debug;\n \ndiff --git a/transport.c b/transport.c\nindex 67afdae57c..cd4b7f5528 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -30,7 +30,6 @@\n #include \"object-store.h\"\n #include \"color.h\"\n #include \"bundle-uri.h\"\n-#include \"wrapper.h\"\n \n static int transport_use_color = -1;\n static char transport_colors[][COLOR_MAXLEN] = {\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 08633dc121..7990a2037c 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -32,7 +32,6 @@\n #include \"commit-graph.h\"\n #include \"commit-reach.h\"\n #include \"shallow.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n /* Remember to update object flag allocation in object.h */\ndiff --git a/usage.c b/usage.c\nindex 46d99f8bd4..09f0ed509b 100644\n--- a/usage.c\n+++ b/usage.c\n@@ -6,7 +6,6 @@\n #include \"git-compat-util.h\"\n #include \"gettext.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n static void vreportf(const char *prefix, const char *err, va_list params)\n {\ndiff --git a/worktree.c b/worktree.c\nindex b5ee71c5eb..7afeaf49fe 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -11,7 +11,6 @@\n #include \"dir.h\"\n #include \"wt-status.h\"\n #include \"config.h\"\n-#include \"wrapper.h\"\n \n void free_worktrees(struct worktree **worktrees)\n {\ndiff --git a/wrapper.c b/wrapper.c\nindex c130d7518b..98321531ec 100644\n--- a/wrapper.c\n+++ b/wrapper.c\n@@ -6,7 +6,6 @@\n #include \"config.h\"\n #include \"gettext.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n static intmax_t count_fsync_writeout_only;\n static intmax_t count_fsync_hardware_flush;\ndiff --git a/write-or-die.c b/write-or-die.c\nindex cc9e0787a1..d8355c0c3e 100644\n--- a/write-or-die.c\n+++ b/write-or-die.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"config.h\"\n #include \"run-command.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n /*\n-- \n2.40.1.606.ga4b1b128d6-goog\n\n"},{"id":"477394","messageId":"20230516170932.1358685-7-calvinwan@google.com","threadId":"59752","inReplyTo":"20230516170932.1358685-1-calvinwan@google.com","subject":"[PATCH 6/6] common: move alloc macros to common.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-16T17:09:31Z","receivedAt":"2023-05-16T17:10:24Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"alloc_nr, ALLOC_GROW, and ALLOC_GROW_BY are commonly used macros for\ndynamic array allocation. Moving these macros to common.h focuses\nalloc.[ch] to allocation for Git objects and additionally allows us to\nremove inclusions to alloc.h from files that solely used the above\nmacros.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n add-patch.c                        |  1 -\n alias.c                            |  1 -\n alloc.h                            | 75 ------------------------------\n apply.c                            |  1 -\n archive-tar.c                      |  1 -\n archive.c                          |  1 -\n attr.c                             |  1 -\n builtin/blame.c                    |  1 -\n builtin/cat-file.c                 |  1 -\n builtin/checkout--worker.c         |  1 -\n builtin/config.c                   |  1 -\n builtin/credential-cache--daemon.c |  1 -\n builtin/fetch-pack.c               |  1 -\n builtin/fsmonitor--daemon.c        |  1 -\n builtin/grep.c                     |  1 -\n builtin/index-pack.c               |  1 -\n builtin/log.c                      |  1 -\n builtin/merge.c                    |  1 -\n builtin/mktree.c                   |  1 -\n builtin/mv.c                       |  1 -\n builtin/name-rev.c                 |  1 -\n builtin/pack-objects.c             |  1 -\n builtin/repack.c                   |  1 -\n builtin/rev-parse.c                |  1 -\n builtin/revert.c                   |  1 -\n builtin/rm.c                       |  1 -\n builtin/submodule--helper.c        |  1 -\n bulk-checkin.c                     |  1 -\n cache-tree.c                       |  1 -\n chunk-format.c                     |  1 -\n commit-reach.c                     |  1 -\n common.h                           | 75 ++++++++++++++++++++++++++++++\n config.c                           |  1 -\n daemon.c                           |  1 -\n delta-islands.c                    |  1 -\n diff.c                             |  1 -\n diffcore-rename.c                  |  1 -\n dir-iterator.c                     |  1 -\n dir.c                              |  1 -\n ewah/bitmap.c                      |  1 -\n ewah/ewah_bitmap.c                 |  1 -\n fetch-pack.c                       |  1 -\n fmt-merge-msg.c                    |  1 -\n fsck.c                             |  1 -\n help.c                             |  1 -\n http-backend.c                     |  1 -\n line-log.c                         |  1 -\n list-objects-filter-options.c      |  1 -\n list-objects-filter.c              |  1 -\n midx.c                             |  1 -\n object-file.c                      |  1 -\n oid-array.c                        |  1 -\n oidtree.c                          |  1 -\n pack-bitmap-write.c                |  1 -\n pack-bitmap.c                      |  1 -\n pack-objects.c                     |  1 -\n packfile.c                         |  1 -\n parallel-checkout.c                |  1 -\n pretty.c                           |  1 -\n prio-queue.c                       |  1 -\n quote.c                            |  1 -\n read-cache.c                       |  1 -\n ref-filter.c                       |  1 -\n reflog-walk.c                      |  1 -\n refs.c                             |  1 -\n refspec.c                          |  1 -\n remote-curl.c                      |  1 -\n remote.c                           |  1 -\n rerere.c                           |  1 -\n revision.c                         |  1 -\n sequencer.c                        |  1 -\n server-info.c                      |  1 -\n shallow.c                          |  1 -\n sigchain.c                         |  1 -\n sparse-index.c                     |  1 -\n split-index.c                      |  1 -\n strbuf.c                           |  1 -\n string-list.c                      |  1 -\n strvec.c                           |  1 -\n submodule-config.c                 |  1 -\n submodule.c                        |  1 -\n t/helper/test-reach.c              |  1 -\n trace2/tr2_tls.c                   |  1 -\n trailer.c                          |  1 -\n transport.c                        |  1 -\n tree-walk.c                        |  1 -\n userdiff.c                         |  1 -\n worktree.c                         |  1 -\n 88 files changed, 75 insertions(+), 161 deletions(-)\n\ndiff --git a/add-patch.c b/add-patch.c\nindex 8d770d203f..b153d4a37d 100644\n--- a/add-patch.c\n+++ b/add-patch.c\n@@ -1,7 +1,6 @@\n #include \"cache.h\"\n #include \"add-interactive.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"editor.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/alias.c b/alias.c\nindex 54a1a23d2c..38e1339936 100644\n--- a/alias.c\n+++ b/alias.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"alias.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n #include \"strbuf.h\"\ndiff --git a/alloc.h b/alloc.h\nindex 4312db4bd0..3f4a0ad310 100644\n--- a/alloc.h\n+++ b/alloc.h\n@@ -17,79 +17,4 @@ void *alloc_object_node(struct repository *r);\n struct alloc_state *allocate_alloc_state(void);\n void clear_alloc_state(struct alloc_state *s);\n \n-#define alloc_nr(x) (((x)+16)*3/2)\n-\n-/**\n- * Dynamically growing an array using realloc() is error prone and boring.\n- *\n- * Define your array with:\n- *\n- * - a pointer (`item`) that points at the array, initialized to `NULL`\n- *   (although please name the variable based on its contents, not on its\n- *   type);\n- *\n- * - an integer variable (`alloc`) that keeps track of how big the current\n- *   allocation is, initialized to `0`;\n- *\n- * - another integer variable (`nr`) to keep track of how many elements the\n- *   array currently has, initialized to `0`.\n- *\n- * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,\n- * alloc)`.  This ensures that the array can hold at least `n` elements by\n- * calling `realloc(3)` and adjusting `alloc` variable.\n- *\n- * ------------\n- * sometype *item;\n- * size_t nr;\n- * size_t alloc\n- *\n- * for (i = 0; i < nr; i++)\n- * \tif (we like item[i] already)\n- * \t\treturn;\n- *\n- * // we did not like any existing one, so add one\n- * ALLOC_GROW(item, nr + 1, alloc);\n- * item[nr++] = value you like;\n- * ------------\n- *\n- * You are responsible for updating the `nr` variable.\n- *\n- * If you need to specify the number of elements to allocate explicitly\n- * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.\n- *\n- * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some\n- * added niceties.\n- *\n- * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.\n- */\n-#define ALLOC_GROW(x, nr, alloc) \\\n-\tdo { \\\n-\t\tif ((nr) > alloc) { \\\n-\t\t\tif (alloc_nr(alloc) < (nr)) \\\n-\t\t\t\talloc = (nr); \\\n-\t\t\telse \\\n-\t\t\t\talloc = alloc_nr(alloc); \\\n-\t\t\tREALLOC_ARRAY(x, alloc); \\\n-\t\t} \\\n-\t} while (0)\n-\n-/*\n- * Similar to ALLOC_GROW but handles updating of the nr value and\n- * zeroing the bytes of the newly-grown array elements.\n- *\n- * DO NOT USE any expression with side-effect for any of the\n- * arguments.\n- */\n-#define ALLOC_GROW_BY(x, nr, increase, alloc) \\\n-\tdo { \\\n-\t\tif (increase) { \\\n-\t\t\tsize_t new_nr = nr + (increase); \\\n-\t\t\tif (new_nr < nr) \\\n-\t\t\t\tBUG(\"negative growth in ALLOC_GROW_BY\"); \\\n-\t\t\tALLOC_GROW(x, new_nr, alloc); \\\n-\t\t\tmemset((x) + nr, 0, sizeof(*(x)) * (increase)); \\\n-\t\t\tnr = new_nr; \\\n-\t\t} \\\n-\t} while (0)\n-\n #endif\ndiff --git a/apply.c b/apply.c\nindex ef6020b18f..f06eaffa09 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -9,7 +9,6 @@\n \n #include \"cache.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"object-store.h\"\n #include \"blob.h\"\ndiff --git a/archive-tar.c b/archive-tar.c\nindex 4cd81d8161..8d41c4c581 100644\n--- a/archive-tar.c\n+++ b/archive-tar.c\n@@ -2,7 +2,6 @@\n  * Copyright (c) 2005, 2006 Rene Scharfe\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n #include \"git-zlib.h\"\ndiff --git a/archive.c b/archive.c\nindex 8570cf37ff..835f9765f1 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"environment.h\"\ndiff --git a/attr.c b/attr.c\nindex 2d8aeb8b58..56d7c89392 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -7,7 +7,6 @@\n  */\n \n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"exec-cmd.h\"\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 2df6039a6e..421a2ed4ca 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -6,7 +6,6 @@\n  */\n \n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"color.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 0bafc14e6c..83178a24b3 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -5,7 +5,6 @@\n  */\n #define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c\nindex 2120dd1d30..bad7c29eb3 100644\n--- a/builtin/checkout--worker.c\n+++ b/builtin/checkout--worker.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"entry.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 71bb376fb3..04e2bb0dc7 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -1,6 +1,5 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"color.h\"\n #include \"editor.h\"\ndiff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c\nindex 4e571d9951..2122571827 100644\n--- a/builtin/credential-cache--daemon.c\n+++ b/builtin/credential-cache--daemon.c\n@@ -1,6 +1,5 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"object-file.h\"\n #include \"parse-options.h\"\ndiff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c\nindex 3ba0fe5a39..44c05ee86c 100644\n--- a/builtin/fetch-pack.c\n+++ b/builtin/fetch-pack.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"object-file.h\"\ndiff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c\nindex f6dd9a784c..d4b666bf9c 100644\n--- a/builtin/fsmonitor--daemon.c\n+++ b/builtin/fsmonitor--daemon.c\n@@ -1,6 +1,5 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex b86c754def..3e7a485927 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -4,7 +4,6 @@\n  * Copyright (c) 2006 Junio C Hamano\n  */\n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"repository.h\"\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 1e065e9ce3..c05d8a70e0 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"delta.h\"\n #include \"environment.h\"\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 4f162ff4d0..6ac4081d4c 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -6,7 +6,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex b800d4e189..82b832fcf9 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -10,7 +10,6 @@\n #include \"cache.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"editor.h\"\n #include \"environment.h\"\ndiff --git a/builtin/mktree.c b/builtin/mktree.c\nindex 09a7bd5c5c..aa00c70feb 100644\n--- a/builtin/mktree.c\n+++ b/builtin/mktree.c\n@@ -4,7 +4,6 @@\n  * Copyright (c) Junio C Hamano, 2006, 2009\n  */\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"quote.h\"\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex 32935af48e..54f0df021b 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -7,7 +7,6 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/name-rev.c b/builtin/name-rev.c\nindex 593f0506a1..dba4a3aa07 100644\n--- a/builtin/name-rev.c\n+++ b/builtin/name-rev.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 79f3a2f300..a82eb04fee 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex bb7bf60e7c..4e0943a543 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"dir.h\"\n #include \"environment.h\"\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 852e49e340..9a3783597f 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -6,7 +6,6 @@\n #define USE_THE_INDEX_VARIABLE\n #include \"cache.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"commit.h\"\n #include \"environment.h\"\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex 0240ec8593..8247e6592e 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"builtin.h\"\n #include \"parse-options.h\"\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex d36072252e..1a1e409262 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -5,7 +5,6 @@\n  */\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"advice.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 6bf8d666ce..2e478104ab 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1,7 +1,6 @@\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex 9192298db6..68a881a233 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -2,7 +2,6 @@\n  * Copyright (c) 2011, Google Inc.\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"bulk-checkin.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/cache-tree.c b/cache-tree.c\nindex ebfe649b33..2a2c5ad498 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -1,5 +1,4 @@\n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"hex.h\"\n #include \"lockfile.h\"\ndiff --git a/chunk-format.c b/chunk-format.c\nindex 60a73c1b14..0cb125eb38 100644\n--- a/chunk-format.c\n+++ b/chunk-format.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"chunk-format.h\"\n #include \"csum-file.h\"\n #include \"gettext.h\"\ndiff --git a/commit-reach.c b/commit-reach.c\nindex 70bde8af05..812bc6bf92 100644\n--- a/commit-reach.c\n+++ b/commit-reach.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"commit-graph.h\"\n #include \"decorate.h\"\ndiff --git a/common.h b/common.h\nindex 4aa99bc98b..a4a985474d 100644\n--- a/common.h\n+++ b/common.h\n@@ -199,6 +199,81 @@ static inline int cast_size_t_to_int(size_t a)\n  */\n #define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)\n \n+#define alloc_nr(x) (((x)+16)*3/2)\n+\n+/**\n+ * Dynamically growing an array using realloc() is error prone and boring.\n+ *\n+ * Define your array with:\n+ *\n+ * - a pointer (`item`) that points at the array, initialized to `NULL`\n+ *   (although please name the variable based on its contents, not on its\n+ *   type);\n+ *\n+ * - an integer variable (`alloc`) that keeps track of how big the current\n+ *   allocation is, initialized to `0`;\n+ *\n+ * - another integer variable (`nr`) to keep track of how many elements the\n+ *   array currently has, initialized to `0`.\n+ *\n+ * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,\n+ * alloc)`.  This ensures that the array can hold at least `n` elements by\n+ * calling `realloc(3)` and adjusting `alloc` variable.\n+ *\n+ * ------------\n+ * sometype *item;\n+ * size_t nr;\n+ * size_t alloc\n+ *\n+ * for (i = 0; i < nr; i++)\n+ * \tif (we like item[i] already)\n+ * \t\treturn;\n+ *\n+ * // we did not like any existing one, so add one\n+ * ALLOC_GROW(item, nr + 1, alloc);\n+ * item[nr++] = value you like;\n+ * ------------\n+ *\n+ * You are responsible for updating the `nr` variable.\n+ *\n+ * If you need to specify the number of elements to allocate explicitly\n+ * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.\n+ *\n+ * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some\n+ * added niceties.\n+ *\n+ * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.\n+ */\n+#define ALLOC_GROW(x, nr, alloc) \\\n+\tdo { \\\n+\t\tif ((nr) > alloc) { \\\n+\t\t\tif (alloc_nr(alloc) < (nr)) \\\n+\t\t\t\talloc = (nr); \\\n+\t\t\telse \\\n+\t\t\t\talloc = alloc_nr(alloc); \\\n+\t\t\tREALLOC_ARRAY(x, alloc); \\\n+\t\t} \\\n+\t} while (0)\n+\n+/*\n+ * Similar to ALLOC_GROW but handles updating of the nr value and\n+ * zeroing the bytes of the newly-grown array elements.\n+ *\n+ * DO NOT USE any expression with side-effect for any of the\n+ * arguments.\n+ */\n+#define ALLOC_GROW_BY(x, nr, increase, alloc) \\\n+\tdo { \\\n+\t\tif (increase) { \\\n+\t\t\tsize_t new_nr = nr + (increase); \\\n+\t\t\tif (new_nr < nr) \\\n+\t\t\t\tBUG(\"negative growth in ALLOC_GROW_BY\"); \\\n+\t\t\tALLOC_GROW(x, new_nr, alloc); \\\n+\t\t\tmemset((x) + nr, 0, sizeof(*(x)) * (increase)); \\\n+\t\t\tnr = new_nr; \\\n+\t\t} \\\n+\t} while (0)\n+\n #define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))\n #define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))\n #define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))\ndiff --git a/config.c b/config.c\nindex b7cccbe245..2672be0888 100644\n--- a/config.c\n+++ b/config.c\n@@ -8,7 +8,6 @@\n #include \"cache.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"date.h\"\n #include \"branch.h\"\n #include \"config.h\"\ndiff --git a/daemon.c b/daemon.c\nindex 4047b0cf27..2a9ea57a41 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -1,6 +1,5 @@\n #include \"cache.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"pkt-line.h\"\ndiff --git a/delta-islands.c b/delta-islands.c\nindex c824a5f6a4..332f0f7c45 100644\n--- a/delta-islands.c\n+++ b/delta-islands.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"attr.h\"\n #include \"object.h\"\n #include \"blob.h\"\ndiff --git a/diff.c b/diff.c\nindex 4033358cf4..9c3d89dd07 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3,7 +3,6 @@\n  */\n #include \"cache.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"environment.h\"\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex 8e2e7a3ad7..29979b4162 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -3,7 +3,6 @@\n  * Copyright (C) 2005 Junio C Hamano\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n #include \"object-store.h\"\ndiff --git a/dir-iterator.c b/dir-iterator.c\nindex fb7c47f0e8..278b04243a 100644\n--- a/dir-iterator.c\n+++ b/dir-iterator.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"iterator.h\"\n #include \"dir-iterator.h\"\ndiff --git a/dir.c b/dir.c\nindex f235df015e..d2b1fa20e2 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -7,7 +7,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"dir.h\"\ndiff --git a/ewah/bitmap.c b/ewah/bitmap.c\nindex 12d6aa398e..7b525b1ecd 100644\n--- a/ewah/bitmap.c\n+++ b/ewah/bitmap.c\n@@ -17,7 +17,6 @@\n  * along with this program; if not, see <http://www.gnu.org/licenses/>.\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"ewok.h\"\n \n #define EWAH_MASK(x) ((eword_t)1 << (x % BITS_IN_EWORD))\ndiff --git a/ewah/ewah_bitmap.c b/ewah/ewah_bitmap.c\nindex c6d4ffc87c..8785cbc54a 100644\n--- a/ewah/ewah_bitmap.c\n+++ b/ewah/ewah_bitmap.c\n@@ -17,7 +17,6 @@\n  * along with this program; if not, see <http://www.gnu.org/licenses/>.\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"ewok.h\"\n #include \"ewok_rlw.h\"\n \ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 5e3e875670..48438c7d86 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"repository.h\"\n #include \"config.h\"\n #include \"environment.h\"\ndiff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\nindex 5af0d4715b..9939bf2703 100644\n--- a/fmt-merge-msg.c\n+++ b/fmt-merge-msg.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"refs.h\"\ndiff --git a/fsck.c b/fsck.c\nindex adbe8bf59e..3864af088e 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"hex.h\"\n #include \"object-store.h\"\n #include \"repository.h\"\ndiff --git a/help.c b/help.c\nindex 5d7637dce9..c81d43a5fa 100644\n--- a/help.c\n+++ b/help.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"builtin.h\"\n #include \"exec-cmd.h\"\ndiff --git a/http-backend.c b/http-backend.c\nindex 4491cdee39..de5b72658e 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"git-zlib.h\"\ndiff --git a/line-log.c b/line-log.c\nindex 10c19daec4..5cb82d731f 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"line-range.h\"\n #include \"hex.h\"\n #include \"tag.h\"\ndiff --git a/list-objects-filter-options.c b/list-objects-filter-options.c\nindex 2a3b7881af..8a08b7af49 100644\n--- a/list-objects-filter-options.c\n+++ b/list-objects-filter-options.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"config.h\"\n #include \"gettext.h\"\ndiff --git a/list-objects-filter.c b/list-objects-filter.c\nindex 5d270ce598..2742e4a87d 100644\n--- a/list-objects-filter.c\n+++ b/list-objects-filter.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/midx.c b/midx.c\nindex 281a1406a8..59dd343275 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -1,6 +1,5 @@\n #include \"cache.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"csum-file.h\"\n #include \"dir.h\"\ndiff --git a/object-file.c b/object-file.c\nindex 43c1585aa7..f565070be3 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -8,7 +8,6 @@\n  */\n #include \"cache.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"environment.h\"\ndiff --git a/oid-array.c b/oid-array.c\nindex e8228c777b..8e4717746c 100644\n--- a/oid-array.c\n+++ b/oid-array.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"oid-array.h\"\n #include \"hash-lookup.h\"\n \ndiff --git a/oidtree.c b/oidtree.c\nindex 7d57b7b19e..daef175dc7 100644\n--- a/oidtree.c\n+++ b/oidtree.c\n@@ -4,7 +4,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"oidtree.h\"\n-#include \"alloc.h\"\n #include \"hash.h\"\n \n struct oidtree_iter_data {\ndiff --git a/pack-bitmap-write.c b/pack-bitmap-write.c\nindex faf67c94d3..335cc3c781 100644\n--- a/pack-bitmap-write.c\n+++ b/pack-bitmap-write.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex e0fad723bf..133c1a6556 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/pack-objects.c b/pack-objects.c\nindex ccab09fe65..1b8052bece 100644\n--- a/pack-objects.c\n+++ b/pack-objects.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"object.h\"\n #include \"pack.h\"\n #include \"pack-objects.h\"\ndiff --git a/packfile.c b/packfile.c\nindex 96727e63a8..57d6b57107 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1,5 +1,4 @@\n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/parallel-checkout.c b/parallel-checkout.c\nindex 38c4dc665d..906e1ced61 100644\n--- a/parallel-checkout.c\n+++ b/parallel-checkout.c\n@@ -1,5 +1,4 @@\n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"entry.h\"\n #include \"gettext.h\"\ndiff --git a/pretty.c b/pretty.c\nindex 0bb938021b..c162466ec8 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"commit.h\"\n #include \"environment.h\"\ndiff --git a/prio-queue.c b/prio-queue.c\nindex dc2476be53..450775a374 100644\n--- a/prio-queue.c\n+++ b/prio-queue.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"prio-queue.h\"\n \n static inline int compare(struct prio_queue *queue, int i, int j)\ndiff --git a/quote.c b/quote.c\nindex 43c739671e..3c05194496 100644\n--- a/quote.c\n+++ b/quote.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"path.h\"\n #include \"quote.h\"\n #include \"strbuf.h\"\ndiff --git a/read-cache.c b/read-cache.c\nindex 7fa89c684d..ddcd613ff3 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -4,7 +4,6 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 10aab14f03..2961cd6b20 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1,5 +1,4 @@\n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex 4ba1a10c82..d8dd6e7cdf 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"refs.h\"\n #include \"diff.h\"\ndiff --git a/refs.c b/refs.c\nindex 379217b03e..75171b46b2 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -4,7 +4,6 @@\n \n #include \"git-compat-util.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"hashmap.h\"\ndiff --git a/refspec.c b/refspec.c\nindex 7b5c305514..80119bb0e5 100644\n--- a/refspec.c\n+++ b/refspec.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"strvec.h\"\ndiff --git a/remote-curl.c b/remote-curl.c\nindex acf7b2bb40..8a976a0253 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/remote.c b/remote.c\nindex 0764fca0db..cae782c86f 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/rerere.c b/rerere.c\nindex 7ed2493891..66a0d55ead 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -1,6 +1,5 @@\n #include \"cache.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/revision.c b/revision.c\nindex b33cc1d106..f0554d9352 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1,5 +1,4 @@\n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/sequencer.c b/sequencer.c\nindex e773b4999b..23ea4aff4d 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -1,7 +1,6 @@\n #include \"cache.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/server-info.c b/server-info.c\nindex 67ce4ad529..5f216449bc 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -1,5 +1,4 @@\n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"environment.h\"\n #include \"hex.h\"\ndiff --git a/shallow.c b/shallow.c\nindex 9ff8923ccf..c168764d13 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -1,5 +1,4 @@\n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"hex.h\"\n #include \"repository.h\"\n #include \"tempfile.h\"\ndiff --git a/sigchain.c b/sigchain.c\nindex ee778c0580..66123bdbab 100644\n--- a/sigchain.c\n+++ b/sigchain.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"sigchain.h\"\n \n #define SIGCHAIN_MAX_SIGNALS 32\ndiff --git a/sparse-index.c b/sparse-index.c\nindex 886054729e..8f6fcd8250 100644\n--- a/sparse-index.c\n+++ b/sparse-index.c\n@@ -1,5 +1,4 @@\n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"repository.h\"\ndiff --git a/split-index.c b/split-index.c\nindex 5602b74994..6467dc9e23 100644\n--- a/split-index.c\n+++ b/split-index.c\n@@ -1,5 +1,4 @@\n #include \"cache.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"mem-pool.h\"\n #include \"split-index.h\"\ndiff --git a/strbuf.c b/strbuf.c\nindex d486189303..5700eb86d4 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/string-list.c b/string-list.c\nindex db473f273e..ccc105da04 100644\n--- a/string-list.c\n+++ b/string-list.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"string-list.h\"\n-#include \"alloc.h\"\n \n void string_list_init_nodup(struct string_list *list)\n {\ndiff --git a/strvec.c b/strvec.c\nindex 17d54b6c3b..89dc9e7e75 100644\n--- a/strvec.c\n+++ b/strvec.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"strvec.h\"\n-#include \"alloc.h\"\n #include \"hex.h\"\n #include \"strbuf.h\"\n \ndiff --git a/submodule-config.c b/submodule-config.c\nindex 7fc0812b64..30c8508a79 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/submodule.c b/submodule.c\nindex 2e78f51349..4da39e0ede 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -1,6 +1,5 @@\n #include \"cache.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"repository.h\"\n #include \"config.h\"\n #include \"submodule-config.h\"\ndiff --git a/t/helper/test-reach.c b/t/helper/test-reach.c\nindex 5b6f217441..119f4908cf 100644\n--- a/t/helper/test-reach.c\n+++ b/t/helper/test-reach.c\n@@ -1,5 +1,4 @@\n #include \"test-tool.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"commit-reach.h\"\n #include \"config.h\"\ndiff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c\nindex 9f46ae12f5..601c9e5036 100644\n--- a/trace2/tr2_tls.c\n+++ b/trace2/tr2_tls.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"thread-utils.h\"\n #include \"trace.h\"\n #include \"trace2/tr2_tls.h\"\ndiff --git a/trailer.c b/trailer.c\nindex a2c3ed6f28..2170e01f6a 100644\n--- a/trailer.c\n+++ b/trailer.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/transport.c b/transport.c\nindex cd4b7f5528..370b18a4ee 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"hex.h\"\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 2993c48c2f..e8f24c8b3f 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -1,6 +1,5 @@\n #include \"cache.h\"\n #include \"tree-walk.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/userdiff.c b/userdiff.c\nindex eaec6ebb5e..a9f078ade0 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"userdiff.h\"\n #include \"attr.h\"\ndiff --git a/worktree.c b/worktree.c\nindex 7afeaf49fe..0e464241b6 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"repository.h\"\n-- \n2.40.1.606.ga4b1b128d6-goog\n\n"},{"id":"477398","messageId":"xmqqbkikuppz.fsf@gitster.g","threadId":"59752","inReplyTo":"20230516170932.1358685-1-calvinwan@google.com","subject":"Re: [PATCH 0/6] git-compat-util cleanups","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-05-16T17:54:16Z","receivedAt":"2023-05-16T17:54:34Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Calvin Wan <calvinwan@google.com> writes:\n\n> This series focuses on cleaning up and reducing the scope of\n> git-compat-util.h by moving headers to their respective files and\n> separating out functionality from git-compat-util.h to a new file,\n> common.h. I go into more detail in patch 3 as to why I believe this\n> separation is useful. \n>\n> By the end of this series, git-compat-util.h includes common.h which\n> includes wrapper.h and usage.h. Since virtually every file includes\n> git-compat-util.h and the large majority of files use functions defined\n> in common.h, wrapper.h, and usage.h, I believe it makes sense that those\n> are also automatically included with git-compat-util.h.\n>\n> While this series does not intend to draw clearer boundaries for\n> common.h, I am open to ideas for how it can be cleaned up more and if\n> there is a better name for the file. \n\nThis seems to have been based on 'master' around Apr 25th of this\nyear, like 0807e578 (Merge branch 'en/header-split-cache-h',\n2023-04-25).  If this were written some time ago and have been\ntested internally at $WORK or something, *not* rebasing on a later\ntip of 'master' (which you did) is good, but at the same time, it\nwould be nice to hear on which commit the series is designed to be\napplied.  To prepare for the start of the next cycle, however, it\nmay be even better to rebase it on the tip of more recent 'master'\nand test it internally (again), and sending the result out as v2\nwould very much be appreciated ;-)\n\nThanks.\n\n\n"},{"id":"477411","messageId":"CAFySSZDn7vNgXmhO6EzvkX_6_uw-pdGZUjmFmwk=Qst-P2HN2g@mail.gmail.com","threadId":"59752","inReplyTo":"xmqqbkikuppz.fsf@gitster.g","subject":"Re: [PATCH 0/6] git-compat-util cleanups","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-16T19:00:39Z","receivedAt":"2023-05-16T19:00:55Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"On Tue, May 16, 2023 at 10:54 AM Junio C Hamano <gitster@pobox.com> wrote:\n\n> This seems to have been based on 'master' around Apr 25th of this\n> year, like 0807e578 (Merge branch 'en/header-split-cache-h',\n> 2023-04-25).  If this were written some time ago and have been\n> tested internally at $WORK or something, *not* rebasing on a later\n> tip of 'master' (which you did) is good, but at the same time, it\n> would be nice to hear on which commit the series is designed to be\n> applied.  To prepare for the start of the next cycle, however, it\n> may be even better to rebase it on the tip of more recent 'master'\n> and test it internally (again), and sending the result out as v2\n> would very much be appreciated ;-)\n\nok I'll go ahead and do that\n"},{"id":"477414","messageId":"xmqq8rdot1ov.fsf@gitster.g","threadId":"59752","inReplyTo":"20230516170932.1358685-2-calvinwan@google.com","subject":"Re: [PATCH 1/6] strbuf.h: move declarations for strbuf.c functions from git-compat-util.h","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-05-16T21:18:40Z","receivedAt":"2023-05-16T21:18:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Calvin Wan <calvinwan@google.com> writes:\n\n> While functions like starts_with() probably should not belong in the\n> boundaries of the strbuf library, this commit focuses on first splitting\n> out headers from git-compat-util.h.\n\nYeah, compat-util.h started out as a (surprise) \"compatibility aid\"\nthat isolates the knowledge of platform specific inclusion order,\nwhat feature macros to define before including which system header\nfile, etc. but over the years, it accumulated some common niceties\nthat are too small to deserve their own header files.\n\nstarts_with() and skip_prefix() are two examples of such.  \n\nIt is hard to imagine skip_to_optional_arg_default() should belong\nto strbuf API, but if you are booting it out of compat-util,\ndeclaring it in strbuf.h may be the least bad choice, as the\nimplementation sits in strbuf.c (which is a strange place, but that\nis not the fault of this series).\n"},{"id":"477418","messageId":"xmqq353wszdj.fsf@gitster.g","threadId":"59752","inReplyTo":"20230516170932.1358685-3-calvinwan@google.com","subject":"Re: [PATCH 2/6] wrapper.h: move declarations for wrapper.c functions from git-compat-util.h","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-05-16T22:08:40Z","receivedAt":"2023-05-16T22:08:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Calvin Wan <calvinwan@google.com> writes:\n\n> Since the functions in wrapper.c are widely used across the codebase,\n> include it by default in git-compat-util.h. A future patch will remove\n> now unnecessary inclusions of wrapper.h from other files.\n\nThe description taken alone implies the move in the other direction\n(i.e. taking decls from wrapper.h and moving them to\ngit-compat-util.h), but that the patch actually does makes sense.\nSlim compat-util.h by moving decls for wrapper functions that are\ndefined in wrapper.c to wrapper.h, but to avoid impacting the users\nright away, include wrapper.h in the compat-util.h that these users\nexpect to find these decls in.\n\n> Signed-off-by: Calvin Wan <calvinwan@google.com>\n> ---\n>  git-compat-util.h | 113 +---------------------------------------------\n>  wrapper.h         | 111 +++++++++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 112 insertions(+), 112 deletions(-)\n>\n> diff --git a/git-compat-util.h b/git-compat-util.h\n> index 51af0a53aa..9898fe9374 100644\n> --- a/git-compat-util.h\n> +++ b/git-compat-util.h\n> @@ -626,8 +626,7 @@ static inline int git_has_dir_sep(const char *path)\n>  #include \"compat/bswap.h\"\n>  \n>  #include \"wildmatch.h\"\n> -\n> -struct strbuf;\n> +#include \"wrapper.h\"\n>  \n>  /* General helper functions */\n>  NORETURN void usage(const char *err);\n> @@ -1047,36 +1046,6 @@ static inline int cast_size_t_to_int(size_t a)\n>  # define xalloca(size)      (xmalloc(size))\n>  # define xalloca_free(p)    (free(p))\n>  #endif\n> -char *xstrdup(const char *str);\n> -void *xmalloc(size_t size);\n> -void *xmallocz(size_t size);\n> -void *xmallocz_gently(size_t size);\n> -void *xmemdupz(const void *data, size_t len);\n> -char *xstrndup(const char *str, size_t len);\n> -void *xrealloc(void *ptr, size_t size);\n> -void *xcalloc(size_t nmemb, size_t size);\n> -void xsetenv(const char *name, const char *value, int overwrite);\n> -void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n> -const char *mmap_os_err(void);\n> -void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n> -int xopen(const char *path, int flags, ...);\n> -ssize_t xread(int fd, void *buf, size_t len);\n> -ssize_t xwrite(int fd, const void *buf, size_t len);\n> -ssize_t xpread(int fd, void *buf, size_t len, off_t offset);\n> -int xdup(int fd);\n> -FILE *xfopen(const char *path, const char *mode);\n> -FILE *xfdopen(int fd, const char *mode);\n> -int xmkstemp(char *temp_filename);\n> -int xmkstemp_mode(char *temp_filename, int mode);\n> -char *xgetcwd(void);\n> -FILE *fopen_for_writing(const char *path);\n> -FILE *fopen_or_warn(const char *path, const char *mode);\n> -\n> -/*\n> - * Like strncmp, but only return zero if s is NUL-terminated and exactly len\n> - * characters long.  If it is not, consider it greater than t.\n> - */\n> -int xstrncmpz(const char *s, const char *t, size_t len);\n>  \n>  /*\n>   * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note\n> @@ -1178,15 +1147,10 @@ static inline size_t xsize_t(off_t len)\n>  \treturn (size_t) len;\n>  }\n>  \n> -__attribute__((format (printf, 3, 4)))\n> -int xsnprintf(char *dst, size_t max, const char *fmt, ...);\n> -\n>  #ifndef HOST_NAME_MAX\n>  #define HOST_NAME_MAX 256\n>  #endif\n>  \n> -int xgethostname(char *buf, size_t len);\n> -\n>  /* in ctype.c, for kwset users */\n>  extern const unsigned char tolower_trans_tbl[256];\n>  \n> @@ -1427,72 +1391,6 @@ void bug_fl(const char *file, int line, const char *fmt, ...);\n>  #endif\n>  #endif\n>  \n> -enum fsync_action {\n> -\tFSYNC_WRITEOUT_ONLY,\n> -\tFSYNC_HARDWARE_FLUSH\n> -};\n> -\n> -/*\n> - * Issues an fsync against the specified file according to the specified mode.\n> - *\n> - * FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating\n> - * systems to flush the OS cache without issuing a flush command to the storage\n> - * controller. If those interfaces are unavailable, the function fails with\n> - * ENOSYS.\n> - *\n> - * FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that\n> - * changes are durable. It is not expected to fail.\n> - */\n> -int git_fsync(int fd, enum fsync_action action);\n> -\n> -/*\n> - * Writes out trace statistics for fsync using the trace2 API.\n> - */\n> -void trace_git_fsync_stats(void);\n> -\n> -/*\n> - * Preserves errno, prints a message, but gives no warning for ENOENT.\n> - * Returns 0 on success, which includes trying to unlink an object that does\n> - * not exist.\n> - */\n> -int unlink_or_warn(const char *path);\n> - /*\n> -  * Tries to unlink file.  Returns 0 if unlink succeeded\n> -  * or the file already didn't exist.  Returns -1 and\n> -  * appends a message to err suitable for\n> -  * 'error(\"%s\", err->buf)' on error.\n> -  */\n> -int unlink_or_msg(const char *file, struct strbuf *err);\n> -/*\n> - * Preserves errno, prints a message, but gives no warning for ENOENT.\n> - * Returns 0 on success, which includes trying to remove a directory that does\n> - * not exist.\n> - */\n> -int rmdir_or_warn(const char *path);\n> -/*\n> - * Calls the correct function out of {unlink,rmdir}_or_warn based on\n> - * the supplied file mode.\n> - */\n> -int remove_or_warn(unsigned int mode, const char *path);\n> -\n> -/*\n> - * Call access(2), but warn for any error except \"missing file\"\n> - * (ENOENT or ENOTDIR).\n> - */\n> -#define ACCESS_EACCES_OK (1U << 0)\n> -int access_or_warn(const char *path, int mode, unsigned flag);\n> -int access_or_die(const char *path, int mode, unsigned flag);\n> -\n> -/* Warn on an inaccessible file if errno indicates this is an error */\n> -int warn_on_fopen_errors(const char *path);\n> -\n> -/*\n> - * Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent\n> - * may be racy. Do not use this as protection against an attacker who can\n> - * simultaneously create paths.\n> - */\n> -int open_nofollow(const char *path, int flags);\n> -\n>  #ifndef SHELL_PATH\n>  # define SHELL_PATH \"/bin/sh\"\n>  #endif\n> @@ -1632,13 +1530,4 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset)\n>  \t((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))\n>  #endif /* !__GNUC__ */\n>  \n> -void sleep_millisec(int millisec);\n> -\n> -/*\n> - * Generate len bytes from the system cryptographically secure PRNG.\n> - * Returns 0 on success and -1 on error, setting errno.  The inability to\n> - * satisfy the full request is an error.\n> - */\n> -int csprng_bytes(void *buf, size_t len);\n> -\n>  #endif\n> diff --git a/wrapper.h b/wrapper.h\n> index f0c7d0616d..c85b1328d1 100644\n> --- a/wrapper.h\n> +++ b/wrapper.h\n> @@ -1,6 +1,42 @@\n>  #ifndef WRAPPER_H\n>  #define WRAPPER_H\n>  \n> +char *xstrdup(const char *str);\n> +void *xmalloc(size_t size);\n> +void *xmallocz(size_t size);\n> +void *xmallocz_gently(size_t size);\n> +void *xmemdupz(const void *data, size_t len);\n> +char *xstrndup(const char *str, size_t len);\n> +void *xrealloc(void *ptr, size_t size);\n> +void *xcalloc(size_t nmemb, size_t size);\n> +void xsetenv(const char *name, const char *value, int overwrite);\n> +void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n> +const char *mmap_os_err(void);\n> +void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n> +int xopen(const char *path, int flags, ...);\n> +ssize_t xread(int fd, void *buf, size_t len);\n> +ssize_t xwrite(int fd, const void *buf, size_t len);\n> +ssize_t xpread(int fd, void *buf, size_t len, off_t offset);\n> +int xdup(int fd);\n> +FILE *xfopen(const char *path, const char *mode);\n> +FILE *xfdopen(int fd, const char *mode);\n> +int xmkstemp(char *temp_filename);\n> +int xmkstemp_mode(char *temp_filename, int mode);\n> +char *xgetcwd(void);\n> +FILE *fopen_for_writing(const char *path);\n> +FILE *fopen_or_warn(const char *path, const char *mode);\n> +\n> +/*\n> + * Like strncmp, but only return zero if s is NUL-terminated and exactly len\n> + * characters long.  If it is not, consider it greater than t.\n> + */\n> +int xstrncmpz(const char *s, const char *t, size_t len);\n> +\n> +__attribute__((format (printf, 3, 4)))\n> +int xsnprintf(char *dst, size_t max, const char *fmt, ...);\n> +\n> +int xgethostname(char *buf, size_t len);\n> +\n>  /* set default permissions by passing mode arguments to open(2) */\n>  int git_mkstemps_mode(char *pattern, int suffix_len, int mode);\n>  int git_mkstemp_mode(char *pattern, int mode);\n> @@ -33,4 +69,79 @@ void write_file(const char *path, const char *fmt, ...);\n>  /* Return 1 if the file is empty or does not exists, 0 otherwise. */\n>  int is_empty_or_missing_file(const char *filename);\n>  \n> +enum fsync_action {\n> +\tFSYNC_WRITEOUT_ONLY,\n> +\tFSYNC_HARDWARE_FLUSH\n> +};\n> +\n> +/*\n> + * Issues an fsync against the specified file according to the specified mode.\n> + *\n> + * FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating\n> + * systems to flush the OS cache without issuing a flush command to the storage\n> + * controller. If those interfaces are unavailable, the function fails with\n> + * ENOSYS.\n> + *\n> + * FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that\n> + * changes are durable. It is not expected to fail.\n> + */\n> +int git_fsync(int fd, enum fsync_action action);\n> +\n> +/*\n> + * Writes out trace statistics for fsync using the trace2 API.\n> + */\n> +void trace_git_fsync_stats(void);\n> +\n> +/*\n> + * Preserves errno, prints a message, but gives no warning for ENOENT.\n> + * Returns 0 on success, which includes trying to unlink an object that does\n> + * not exist.\n> + */\n> +int unlink_or_warn(const char *path);\n> + /*\n> +  * Tries to unlink file.  Returns 0 if unlink succeeded\n> +  * or the file already didn't exist.  Returns -1 and\n> +  * appends a message to err suitable for\n> +  * 'error(\"%s\", err->buf)' on error.\n> +  */\n> +int unlink_or_msg(const char *file, struct strbuf *err);\n> +/*\n> + * Preserves errno, prints a message, but gives no warning for ENOENT.\n> + * Returns 0 on success, which includes trying to remove a directory that does\n> + * not exist.\n> + */\n> +int rmdir_or_warn(const char *path);\n> +/*\n> + * Calls the correct function out of {unlink,rmdir}_or_warn based on\n> + * the supplied file mode.\n> + */\n> +int remove_or_warn(unsigned int mode, const char *path);\n> +\n> +/*\n> + * Call access(2), but warn for any error except \"missing file\"\n> + * (ENOENT or ENOTDIR).\n> + */\n> +#define ACCESS_EACCES_OK (1U << 0)\n> +int access_or_warn(const char *path, int mode, unsigned flag);\n> +int access_or_die(const char *path, int mode, unsigned flag);\n> +\n> +/* Warn on an inaccessible file if errno indicates this is an error */\n> +int warn_on_fopen_errors(const char *path);\n> +\n> +/*\n> + * Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent\n> + * may be racy. Do not use this as protection against an attacker who can\n> + * simultaneously create paths.\n> + */\n> +int open_nofollow(const char *path, int flags);\n> +\n> +void sleep_millisec(int millisec);\n> +\n> +/*\n> + * Generate len bytes from the system cryptographically secure PRNG.\n> + * Returns 0 on success and -1 on error, setting errno.  The inability to\n> + * satisfy the full request is an error.\n> + */\n> +int csprng_bytes(void *buf, size_t len);\n> +\n>  #endif /* WRAPPER_H */\n"},{"id":"477420","messageId":"xmqqwn17sydw.fsf@gitster.g","threadId":"59752","inReplyTo":"20230516170932.1358685-4-calvinwan@google.com","subject":"Re: [PATCH 3/6] common.h: move non-compat specific macros and functions from git-compat-util.h","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-05-16T22:30:03Z","receivedAt":"2023-05-16T22:30:11Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Calvin Wan <calvinwan@google.com> writes:\n\n> git-compat-util.h has grown to a large and difficult to read file partly\n> because its set of functionality is overloaded. Besides being a\n> compatibility file that ensures Git's operation across different\n> operating systems, it has also become a dumping ground for commonly used\n> macros and static inline functions.\n\nYeah, compat-util.h started out as a (surprise) \"compatibility aid\"\nthat isolates the knowledge of platform specific inclusion order,\nwhat feature macros to define before including which system header\nfile, etc.  \"A dumping ground for common stuff\"---aptly put ;-).\n\n> This commit separates out macros and static inline functions that are\n> compatible across operating systems into common.h.\n\nIt sounds a bit too generic a name to me, but OK.\n\nAt some level I am more or less indifferent, in the sense that both\ncompat-util and common need to be included by a .c file anyway,\nwhether it is _our_ source, or in a future third-party source that\nwants to link with the libified part of Git, so it does notreally\nmake much of a difference if ARRAY_SIZE() is defined in which one of\nthese two headers.  But presumably such a future third-party source\nmay arrange their own system support using their own counterpart to\ncompat-util without using ours, and if that is what motivates this\nchange, I could understand why a more-or-less git-agnostic common.h\ncould be a good idea.\n\nEverything, other than sane-ctype macros, does look like a generally\nuseful git-agnostic helper functions.  If we were to move in this\ndirection, I probably would prefer to separate sane-ctype macros in\na separate header, simply because they are _designed_ to override\nsystem supplied ones and some third-party source may not want to use\nsuch a \"feature\".\n"},{"id":"477463","messageId":"CAFySSZDXYbW2ZUQuaufZr8JSq+HEOgoeqYHRUxnKr0G6ya9znw@mail.gmail.com","threadId":"59752","inReplyTo":"xmqqwn17sydw.fsf@gitster.g","subject":"Re: [PATCH 3/6] common.h: move non-compat specific macros and functions from git-compat-util.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-17T17:26:34Z","receivedAt":"2023-05-17T17:27:27Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"> At some level I am more or less indifferent, in the sense that both\n> compat-util and common need to be included by a .c file anyway,\n> whether it is _our_ source, or in a future third-party source that\n> wants to link with the libified part of Git, so it does notreally\n> make much of a difference if ARRAY_SIZE() is defined in which one of\n> these two headers.  But presumably such a future third-party source\n> may arrange their own system support using their own counterpart to\n> compat-util without using ours, and if that is what motivates this\n> change, I could understand why a more-or-less git-agnostic common.h\n> could be a good idea.\n\nAlso, a later patch moves ALLOC_GROW and other macros from alloc.h to\ncommon.h. I thought it would make more sense to have a common file for\nthese macros to be moved to rather than adding to git-compat-util for\nthe sake of only removing the alloc.h dependency from certain files.\n\n> Everything, other than sane-ctype macros, does look like a generally\n> useful git-agnostic helper functions.  If we were to move in this\n> direction, I probably would prefer to separate sane-ctype macros in\n> a separate header, simply because they are _designed_ to override\n> system supplied ones and some third-party source may not want to use\n> such a \"feature\".\n\nAh that makes sense that they would belong in a separate file like\nctype.h -- I can split those macros out.\n"},{"id":"477668","messageId":"20230523192749.1270992-1-calvinwan@google.com","threadId":"59752","inReplyTo":"20230516170932.1358685-1-calvinwan@google.com","subject":"[PATCH v2 0/7] git-compat-util cleanups","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-23T19:27:48Z","receivedAt":"2023-05-23T19:28:57Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Changes since v1:\n - rebased onto 8afb38ac80f6\n - add a patch to split up sane-ctype macros into a separate file\n   rather than into common.h as suggested by Junio\n===\n\nThis series focuses on cleaning up and reducing the scope of\ngit-compat-util.h by moving headers to their respective files and\nseparating out functionality from git-compat-util.h to a new file,\ncommon.h. I go into more detail in patch 4 as to why I believe this\nseparation is useful. \n\nBy the end of this series, git-compat-util.h includes common.h which\nincludes wrapper.h, and usage.h. Since virtually every file includes\ngit-compat-util.h and the large majority of files use functions defined\nin common.h, wrapper.h, and usage.h, I believe it makes sense that those\nare also automatically included with git-compat-util.h.\n\nWhile this series does not intend to draw clearer boundaries for\ncommon.h, I am open to ideas for how it can be cleaned up more and if\nthere is a better name for the file. \n\nCalvin Wan (7):\n  strbuf.h: move declarations for strbuf.c functions from\n    git-compat-util.h\n  wrapper.h: move declarations for wrapper.c functions from\n    git-compat-util.h\n  sane-ctype.h: move sane-ctype macros from git-compat-util.h\n  common.h: move non-compat specific macros and functions from\n    git-compat-util.h\n  usage.h: move declarations for usage.c functions from\n    git-compat-util.h\n  treewide: remove unnecessary includes for wrapper.h\n  common: move alloc macros to common.h\n\n add-patch.c                        |   1 -\n alias.c                            |   1 -\n alloc.h                            |  75 ----\n apply.c                            |   2 -\n archive-tar.c                      |   1 -\n archive.c                          |   1 -\n attr.c                             |   1 -\n builtin/am.c                       |   1 -\n builtin/bisect.c                   |   1 -\n builtin/blame.c                    |   1 -\n builtin/branch.c                   |   1 -\n builtin/bugreport.c                |   1 -\n builtin/cat-file.c                 |   1 -\n builtin/checkout--worker.c         |   1 -\n builtin/clone.c                    |   1 -\n builtin/config.c                   |   2 -\n builtin/credential-cache--daemon.c |   1 -\n builtin/credential-cache.c         |   1 -\n builtin/difftool.c                 |   1 -\n builtin/fast-import.c              |   1 -\n builtin/fetch-pack.c               |   1 -\n builtin/fmt-merge-msg.c            |   1 -\n builtin/fsmonitor--daemon.c        |   1 -\n builtin/gc.c                       |   1 -\n builtin/get-tar-commit-id.c        |   1 -\n builtin/grep.c                     |   1 -\n builtin/index-pack.c               |   2 -\n builtin/init-db.c                  |   1 -\n builtin/log.c                      |   1 -\n builtin/merge.c                    |   2 -\n builtin/mktree.c                   |   1 -\n builtin/mv.c                       |   1 -\n builtin/name-rev.c                 |   1 -\n builtin/pack-objects.c             |   2 -\n builtin/rebase.c                   |   1 -\n builtin/receive-pack.c             |   1 -\n builtin/repack.c                   |   1 -\n builtin/rerere.c                   |   1 -\n builtin/rev-parse.c                |   1 -\n builtin/revert.c                   |   1 -\n builtin/rm.c                       |   1 -\n builtin/submodule--helper.c        |   1 -\n builtin/symbolic-ref.c             |   1 +\n builtin/unpack-file.c              |   1 -\n builtin/unpack-objects.c           |   1 +\n builtin/worktree.c                 |   1 -\n bulk-checkin.c                     |   2 -\n cache-tree.c                       |   1 -\n chunk-format.c                     |   1 -\n combine-diff.c                     |   1 -\n commit-graph.c                     |   1 -\n commit-reach.c                     |   1 -\n common.h                           | 486 +++++++++++++++++++++\n compat/terminal.c                  |   1 -\n config.c                           |   2 -\n convert.c                          |   1 -\n copy.c                             |   1 -\n csum-file.c                        |   1 -\n daemon.c                           |   2 -\n delta-islands.c                    |   1 -\n diff.c                             |   2 -\n diffcore-rename.c                  |   1 -\n dir-iterator.c                     |   1 -\n dir.c                              |   2 -\n editor.c                           |   1 -\n entry.c                            |   1 -\n environment.c                      |   1 -\n ewah/bitmap.c                      |   1 -\n ewah/ewah_bitmap.c                 |   1 -\n fetch-pack.c                       |   2 -\n fmt-merge-msg.c                    |   1 -\n fsck.c                             |   1 -\n git-compat-util.h                  | 664 +----------------------------\n gpg-interface.c                    |   1 -\n grep.c                             |   1 -\n help.c                             |   1 -\n http-backend.c                     |   2 -\n imap-send.c                        |   1 -\n line-log.c                         |   1 -\n list-objects-filter-options.c      |   1 -\n list-objects-filter.c              |   1 -\n merge-ll.c                         |   1 -\n merge-recursive.c                  |   1 -\n midx.c                             |   1 -\n notes-merge.c                      |   1 -\n object-file.c                      |   2 -\n oid-array.c                        |   1 -\n oidtree.c                          |   1 -\n pack-bitmap-write.c                |   1 -\n pack-bitmap.c                      |   1 -\n pack-objects.c                     |   1 -\n pack-write.c                       |   1 -\n packfile.c                         |   2 -\n parallel-checkout.c                |   2 -\n path.c                             |   1 -\n pkt-line.c                         |   1 -\n pretty.c                           |   1 -\n prio-queue.c                       |   1 -\n quote.c                            |   1 -\n read-cache.c                       |   2 -\n rebase-interactive.c               |   1 -\n ref-filter.c                       |   1 -\n reflog-walk.c                      |   1 -\n refs.c                             |   2 -\n refspec.c                          |   1 -\n remote-curl.c                      |   1 -\n remote.c                           |   1 -\n rerere.c                           |   2 -\n revision.c                         |   1 -\n sane-ctype.h                       |  69 +++\n send-pack.c                        |   1 -\n sequencer.c                        |   2 -\n server-info.c                      |   2 -\n setup.c                            |   1 -\n shallow.c                          |   2 -\n sigchain.c                         |   1 -\n sparse-index.c                     |   1 -\n split-index.c                      |   1 -\n strbuf.c                           |   2 -\n strbuf.h                           |  32 ++\n streaming.c                        |   1 -\n string-list.c                      |   1 -\n strvec.c                           |   1 -\n submodule-config.c                 |   1 -\n submodule.c                        |   1 -\n t/helper/test-delta.c              |   1 -\n t/helper/test-fsmonitor-client.c   |   1 -\n t/helper/test-reach.c              |   1 -\n t/helper/test-read-cache.c         |   1 -\n tag.c                              |   1 -\n tempfile.c                         |   1 -\n trace.c                            |   1 -\n trace2/tr2_tls.c                   |   1 -\n trailer.c                          |   1 -\n transport-helper.c                 |   1 -\n transport.c                        |   2 -\n tree-walk.c                        |   1 -\n upload-pack.c                      |   1 -\n usage.c                            |   1 -\n usage.h                            |  60 +++\n userdiff.c                         |   1 -\n versioncmp.c                       |   1 +\n worktree.c                         |   2 -\n wrapper.c                          |   1 -\n wrapper.h                          | 111 +++++\n write-or-die.c                     |   1 -\n 146 files changed, 764 insertions(+), 896 deletions(-)\n create mode 100644 common.h\n create mode 100644 sane-ctype.h\n create mode 100644 usage.h\n\nRange-diff against v1:\n1:  c3f998df91 ! 1:  a2b7a28e6e strbuf.h: move declarations for strbuf.c functions from git-compat-util.h\n    @@ Commit message\n         boundaries of the strbuf library, this commit focuses on first splitting\n         out headers from git-compat-util.h.\n     \n    + ## builtin/symbolic-ref.c ##\n    +@@\n    + #include \"gettext.h\"\n    + #include \"refs.h\"\n    + #include \"parse-options.h\"\n    ++#include \"strbuf.h\"\n    + \n    + static const char * const git_symbolic_ref_usage[] = {\n    + \tN_(\"git symbolic-ref [-m <reason>] <name> <ref>\"),\n    +\n    + ## builtin/unpack-objects.c ##\n    +@@\n    + #include \"blob.h\"\n    + #include \"commit.h\"\n    + #include \"replace-object.h\"\n    ++#include \"strbuf.h\"\n    + #include \"tag.h\"\n    + #include \"tree.h\"\n    + #include \"tree-walk.h\"\n    +\n      ## git-compat-util.h ##\n     @@ git-compat-util.h: void set_warn_routine(report_fn routine);\n      report_fn get_warn_routine(void);\n    @@ strbuf.h: char *xstrvfmt(const char *fmt, va_list ap);\n     +}\n     +\n      #endif /* STRBUF_H */\n    +\n    + ## versioncmp.c ##\n    +@@\n    + #include \"git-compat-util.h\"\n    + #include \"config.h\"\n    ++#include \"strbuf.h\"\n    + #include \"string-list.h\"\n    + #include \"versioncmp.h\"\n    + \n2:  71176763ff ! 2:  b12fb0e2ff wrapper.h: move declarations for wrapper.c functions from git-compat-util.h\n    @@ Commit message\n     \n      ## git-compat-util.h ##\n     @@ git-compat-util.h: static inline int git_has_dir_sep(const char *path)\n    + \n      #include \"compat/bswap.h\"\n      \n    - #include \"wildmatch.h\"\n    --\n     -struct strbuf;\n     +#include \"wrapper.h\"\n      \n-:  ---------- > 3:  016f671836 sane-ctype.h: move sane-ctype macros from git-compat-util.h\n3:  6c905444cd ! 4:  244650e5c9 common.h: move non-compat specific macros and functions from git-compat-util.h\n    @@ common.h (new)\n     +\treturn (size_t) len;\n     +}\n     +\n    -+/* in ctype.c, for kwset users */\n    -+extern const unsigned char tolower_trans_tbl[256];\n    -+\n    -+/* Sane ctype - no locale, and works with signed chars */\n    -+#undef isascii\n    -+#undef isspace\n    -+#undef isdigit\n    -+#undef isalpha\n    -+#undef isalnum\n    -+#undef isprint\n    -+#undef islower\n    -+#undef isupper\n    -+#undef tolower\n    -+#undef toupper\n    -+#undef iscntrl\n    -+#undef ispunct\n    -+#undef isxdigit\n    -+\n    -+extern const unsigned char sane_ctype[256];\n    -+extern const signed char hexval_table[256];\n    -+#define GIT_SPACE 0x01\n    -+#define GIT_DIGIT 0x02\n    -+#define GIT_ALPHA 0x04\n    -+#define GIT_GLOB_SPECIAL 0x08\n    -+#define GIT_REGEX_SPECIAL 0x10\n    -+#define GIT_PATHSPEC_MAGIC 0x20\n    -+#define GIT_CNTRL 0x40\n    -+#define GIT_PUNCT 0x80\n    -+#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n    -+#define isascii(x) (((x) & ~0x7f) == 0)\n    -+#define isspace(x) sane_istest(x,GIT_SPACE)\n    -+#define isdigit(x) sane_istest(x,GIT_DIGIT)\n    -+#define isalpha(x) sane_istest(x,GIT_ALPHA)\n    -+#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)\n    -+#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)\n    -+#define islower(x) sane_iscase(x, 1)\n    -+#define isupper(x) sane_iscase(x, 0)\n    -+#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)\n    -+#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)\n    -+#define iscntrl(x) (sane_istest(x,GIT_CNTRL))\n    -+#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \\\n    -+\t\tGIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)\n    -+#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n    -+#define tolower(x) sane_case((unsigned char)(x), 0x20)\n    -+#define toupper(x) sane_case((unsigned char)(x), 0)\n    -+#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)\n    -+\n    -+static inline int sane_case(int x, int high)\n    -+{\n    -+\tif (sane_istest(x, GIT_ALPHA))\n    -+\t\tx = (x & ~0x20) | high;\n    -+\treturn x;\n    -+}\n    -+\n    -+static inline int sane_iscase(int x, int is_lower)\n    -+{\n    -+\tif (!sane_istest(x, GIT_ALPHA))\n    -+\t\treturn 0;\n    -+\n    -+\tif (is_lower)\n    -+\t\treturn (x & 0x20) != 0;\n    -+\telse\n    -+\t\treturn (x & 0x20) == 0;\n    -+}\n    -+\n     +/*\n     + * Like skip_prefix, but compare case-insensitively. Note that the comparison\n     + * is done via tolower(), so it is strictly ASCII (no multi-byte characters or\n    @@ git-compat-util.h: static inline int cast_size_t_to_int(size_t a)\n      #define HOST_NAME_MAX 256\n      #endif\n      \n    --/* in ctype.c, for kwset users */\n    --extern const unsigned char tolower_trans_tbl[256];\n    --\n    --/* Sane ctype - no locale, and works with signed chars */\n    --#undef isascii\n    --#undef isspace\n    --#undef isdigit\n    --#undef isalpha\n    --#undef isalnum\n    --#undef isprint\n    --#undef islower\n    --#undef isupper\n    --#undef tolower\n    --#undef toupper\n    --#undef iscntrl\n    --#undef ispunct\n    --#undef isxdigit\n    --\n    --extern const unsigned char sane_ctype[256];\n    --extern const signed char hexval_table[256];\n    --#define GIT_SPACE 0x01\n    --#define GIT_DIGIT 0x02\n    --#define GIT_ALPHA 0x04\n    --#define GIT_GLOB_SPECIAL 0x08\n    --#define GIT_REGEX_SPECIAL 0x10\n    --#define GIT_PATHSPEC_MAGIC 0x20\n    --#define GIT_CNTRL 0x40\n    --#define GIT_PUNCT 0x80\n    --#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n    --#define isascii(x) (((x) & ~0x7f) == 0)\n    --#define isspace(x) sane_istest(x,GIT_SPACE)\n    --#define isdigit(x) sane_istest(x,GIT_DIGIT)\n    --#define isalpha(x) sane_istest(x,GIT_ALPHA)\n    --#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)\n    --#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)\n    --#define islower(x) sane_iscase(x, 1)\n    --#define isupper(x) sane_iscase(x, 0)\n    --#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)\n    --#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)\n    --#define iscntrl(x) (sane_istest(x,GIT_CNTRL))\n    --#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \\\n    --\t\tGIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)\n    --#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n    --#define tolower(x) sane_case((unsigned char)(x), 0x20)\n    --#define toupper(x) sane_case((unsigned char)(x), 0)\n    --#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)\n    --\n    --static inline int sane_case(int x, int high)\n    --{\n    --\tif (sane_istest(x, GIT_ALPHA))\n    --\t\tx = (x & ~0x20) | high;\n    --\treturn x;\n    --}\n    --\n    --static inline int sane_iscase(int x, int is_lower)\n    --{\n    --\tif (!sane_istest(x, GIT_ALPHA))\n    --\t\treturn 0;\n    --\n    --\tif (is_lower)\n    --\t\treturn (x & 0x20) != 0;\n    --\telse\n    --\t\treturn (x & 0x20) == 0;\n    --}\n    --\n    + #include \"sane-ctype.h\"\n    + \n     -/*\n     - * Like skip_prefix, but compare case-insensitively. Note that the comparison\n     - * is done via tolower(), so it is strictly ASCII (no multi-byte characters or\n4:  280a7492ec ! 5:  91a1253ee6 usage.h: move declarations for usage.c functions from git-compat-util.h\n    @@ common.h\n     \n      ## git-compat-util.h ##\n     @@ git-compat-util.h: static inline int git_has_dir_sep(const char *path)\n    + \n      #include \"compat/bswap.h\"\n      \n    - #include \"wildmatch.h\"\n     -#include \"wrapper.h\"\n     -\n     -/* General helper functions */\n    @@ git-compat-util.h: static inline int git_has_dir_sep(const char *path)\n     -int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n     -void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));\n     -void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n    - \n    +-\n      #ifndef NO_OPENSSL\n      #ifdef APPLE_COMMON_CRYPTO\n    + #include \"compat/apple-common-crypto.h\"\n     @@ git-compat-util.h: void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n      #include <openssl/rand.h>\n      #endif\n5:  9b29a77a90 ! 6:  c9850a7c18 treewide: remove unnecessary includes for wrapper.h\n    @@ Commit message\n     \n      ## apply.c ##\n     @@\n    - #include \"apply.h\"\n    - #include \"entry.h\"\n    - #include \"setup.h\"\n    + #include \"symlinks.h\"\n    + #include \"wildmatch.h\"\n    + #include \"ws.h\"\n     -#include \"wrapper.h\"\n      \n      struct gitdiff_data {\n    @@ apply.c\n     \n      ## builtin/am.c ##\n     @@\n    - #include \"pager.h\"\n    + #include \"path.h\"\n      #include \"repository.h\"\n      #include \"pretty.h\"\n     -#include \"wrapper.h\"\n    @@ builtin/clone.c\n     \n      ## builtin/config.c ##\n     @@\n    - #include \"quote.h\"\n      #include \"setup.h\"\n    + #include \"strbuf.h\"\n      #include \"worktree.h\"\n     -#include \"wrapper.h\"\n      \n    @@ builtin/config.c\n     \n      ## builtin/credential-cache.c ##\n     @@\n    - #include \"builtin.h\"\n    - #include \"gettext.h\"\n      #include \"parse-options.h\"\n    + #include \"path.h\"\n    + #include \"strbuf.h\"\n     -#include \"wrapper.h\"\n      #include \"write-or-die.h\"\n      \n    @@ builtin/gc.c\n     \n      ## builtin/get-tar-commit-id.c ##\n     @@\n    + #include \"commit.h\"\n      #include \"tar.h\"\n    - #include \"builtin.h\"\n      #include \"quote.h\"\n     -#include \"wrapper.h\"\n      \n    @@ builtin/index-pack.c\n     \n      ## builtin/init-db.c ##\n     @@\n    - #include \"parse-options.h\"\n    + #include \"path.h\"\n      #include \"setup.h\"\n    - #include \"worktree.h\"\n    + #include \"strbuf.h\"\n     -#include \"wrapper.h\"\n      \n    - #ifndef DEFAULT_GIT_TEMPLATE_DIR\n    - #define DEFAULT_GIT_TEMPLATE_DIR \"/usr/share/git-core/templates\"\n    + static int guess_repository_type(const char *git_dir)\n    + {\n     \n      ## builtin/merge.c ##\n     @@\n    @@ builtin/receive-pack.c\n     \n      ## builtin/rerere.c ##\n     @@\n    - #include \"parse-options.h\"\n    + #include \"repository.h\"\n      #include \"string-list.h\"\n      #include \"rerere.h\"\n     -#include \"wrapper.h\"\n    @@ builtin/unpack-file.c\n     @@\n      #include \"hex.h\"\n      #include \"object-name.h\"\n    - #include \"object-store.h\"\n    + #include \"object-store-ll.h\"\n     -#include \"wrapper.h\"\n      \n      static char *create_temp_file(struct object_id *oid)\n    @@ bulk-checkin.c\n     @@\n      #include \"packfile.h\"\n      #include \"object-file.h\"\n    - #include \"object-store.h\"\n    + #include \"object-store-ll.h\"\n     -#include \"wrapper.h\"\n      \n      static int odb_transaction_nesting;\n    @@ combine-diff.c\n     \n      ## commit-graph.c ##\n     @@\n    - #include \"json-writer.h\"\n      #include \"trace2.h\"\n    + #include \"tree.h\"\n      #include \"chunk-format.h\"\n     -#include \"wrapper.h\"\n      \n    @@ compat/terminal.c\n     \n      ## config.c ##\n     @@\n    - #include \"setup.h\"\n    - #include \"trace2.h\"\n    + #include \"wildmatch.h\"\n      #include \"worktree.h\"\n    + #include \"ws.h\"\n     -#include \"wrapper.h\"\n      #include \"write-or-die.h\"\n      \n    @@ convert.c\n     @@\n      #include \"trace.h\"\n      #include \"utf8.h\"\n    - #include \"ll-merge.h\"\n    + #include \"merge-ll.h\"\n     -#include \"wrapper.h\"\n      \n      /*\n    @@ convert.c\n     \n      ## copy.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n    + #include \"copy.h\"\n    + #include \"path.h\"\n     -#include \"wrapper.h\"\n      \n      int copy_fd(int ifd, int ofd)\n    @@ copy.c\n     \n      ## csum-file.c ##\n     @@\n    - #include \"git-compat-util.h\"\n      #include \"progress.h\"\n      #include \"csum-file.h\"\n    + #include \"hash.h\"\n     -#include \"wrapper.h\"\n      \n      static void verify_buffer_or_die(struct hashfile *f,\n    @@ daemon.c\n     \n      ## diff.c ##\n     @@\n    - #include \"object-name.h\"\n      #include \"setup.h\"\n      #include \"strmap.h\"\n    + #include \"ws.h\"\n     -#include \"wrapper.h\"\n      \n      #ifdef NO_FAST_WORKING_DIRECTORY\n    @@ diff.c\n     \n      ## dir.c ##\n     @@\n    - #include \"setup.h\"\n    - #include \"submodule-config.h\"\n    + #include \"symlinks.h\"\n      #include \"trace2.h\"\n    + #include \"tree.h\"\n     -#include \"wrapper.h\"\n      \n      /*\n    @@ gpg-interface.c\n      #include \"tempfile.h\"\n      #include \"alias.h\"\n     -#include \"wrapper.h\"\n    + #include \"environment.h\"\n      \n      static int git_gpg_config(const char *, const char *, void *);\n    - \n     \n      ## grep.c ##\n     @@\n    @@ grep.c\n     \n      ## http-backend.c ##\n     @@\n    - #include \"object-store.h\"\n    + #include \"object-store-ll.h\"\n      #include \"protocol.h\"\n      #include \"date.h\"\n     -#include \"wrapper.h\"\n    @@ http-backend.c\n     \n      ## imap-send.c ##\n     @@\n    - #include \"run-command.h\"\n      #include \"parse-options.h\"\n      #include \"setup.h\"\n    + #include \"strbuf.h\"\n     -#include \"wrapper.h\"\n      #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)\n      typedef void *SSL;\n      #endif\n     \n    - ## ll-merge.c ##\n    + ## merge-ll.c ##\n     @@\n    - #include \"run-command.h\"\n    - #include \"ll-merge.h\"\n    + #include \"merge-ll.h\"\n      #include \"quote.h\"\n    + #include \"strbuf.h\"\n     -#include \"wrapper.h\"\n      \n      struct ll_merge_driver;\n    @@ object-file.c\n     \n      ## pack-write.c ##\n     @@\n    - #include \"oidmap.h\"\n    - #include \"pack-objects.h\"\n      #include \"pack-revindex.h\"\n    + #include \"path.h\"\n    + #include \"strbuf.h\"\n     -#include \"wrapper.h\"\n      \n      void reset_pack_idx_option(struct pack_idx_option *opts)\n    @@ packfile.c\n     \n      ## parallel-checkout.c ##\n     @@\n    - #include \"streaming.h\"\n    + #include \"symlinks.h\"\n      #include \"thread-utils.h\"\n      #include \"trace2.h\"\n     -#include \"wrapper.h\"\n    @@ parallel-checkout.c\n     \n      ## path.c ##\n     @@\n    - #include \"object-store.h\"\n    + #include \"object-store-ll.h\"\n      #include \"lockfile.h\"\n      #include \"exec-cmd.h\"\n     -#include \"wrapper.h\"\n    @@ rebase-interactive.c\n     \n      ## refs.c ##\n     @@\n    - #include \"sigchain.h\"\n      #include \"date.h\"\n      #include \"commit.h\"\n    + #include \"wildmatch.h\"\n     -#include \"wrapper.h\"\n      \n      /*\n    @@ refs.c\n     \n      ## rerere.c ##\n     @@\n    - #include \"object-store.h\"\n    + #include \"object-store-ll.h\"\n      #include \"hash-lookup.h\"\n      #include \"strmap.h\"\n     -#include \"wrapper.h\"\n    @@ sequencer.c\n     \n      ## server-info.c ##\n     @@\n    - #include \"object-file.h\"\n    - #include \"object-store.h\"\n    + #include \"object-store-ll.h\"\n    + #include \"server-info.h\"\n      #include \"strbuf.h\"\n     -#include \"wrapper.h\"\n      \n    @@ server-info.c\n     \n      ## setup.c ##\n     @@\n    - #include \"promisor-remote.h\"\n      #include \"quote.h\"\n      #include \"trace2.h\"\n    + #include \"worktree.h\"\n     -#include \"wrapper.h\"\n      \n      static int inside_git_dir = -1;\n    @@ setup.c\n     \n      ## shallow.c ##\n     @@\n    - #include \"commit-reach.h\"\n      #include \"shallow.h\"\n    + #include \"statinfo.h\"\n      #include \"trace.h\"\n     -#include \"wrapper.h\"\n      \n    @@ strbuf.c\n     \n      ## streaming.c ##\n     @@\n    - #include \"object-store.h\"\n    + #include \"object-store-ll.h\"\n      #include \"replace-object.h\"\n      #include \"packfile.h\"\n     -#include \"wrapper.h\"\n    @@ t/helper/test-fsmonitor-client.c\n     \n      ## t/helper/test-read-cache.c ##\n     @@\n    - #include \"cache.h\"\n    - #include \"config.h\"\n    + #include \"read-cache-ll.h\"\n    + #include \"repository.h\"\n      #include \"setup.h\"\n     -#include \"wrapper.h\"\n      \n    @@ transport-helper.c\n     \n      ## transport.c ##\n     @@\n    - #include \"object-store.h\"\n    + #include \"object-store-ll.h\"\n      #include \"color.h\"\n      #include \"bundle-uri.h\"\n     -#include \"wrapper.h\"\n    @@ worktree.c\n     \n      ## wrapper.c ##\n     @@\n    - #include \"config.h\"\n    - #include \"gettext.h\"\n    + #include \"repository.h\"\n    + #include \"strbuf.h\"\n      #include \"trace2.h\"\n     -#include \"wrapper.h\"\n      \n6:  9604b66c72 ! 7:  067b28ec09 common: move alloc macros to common.h\n    @@ Commit message\n     \n      ## add-patch.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n      #include \"add-interactive.h\"\n      #include \"advice.h\"\n     -#include \"alloc.h\"\n    @@ alloc.h: void *alloc_object_node(struct repository *r);\n      ## apply.c ##\n     @@\n      \n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n      #include \"abspath.h\"\n     -#include \"alloc.h\"\n    + #include \"base85.h\"\n      #include \"config.h\"\n    - #include \"object-store.h\"\n    - #include \"blob.h\"\n    + #include \"object-store-ll.h\"\n     \n      ## archive-tar.c ##\n     @@\n    @@ attr.c\n     @@\n       */\n      \n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n      #include \"config.h\"\n      #include \"environment.h\"\n    @@ builtin/cat-file.c\n     @@\n       */\n      #define USE_THE_INDEX_VARIABLE\n    - #include \"cache.h\"\n    + #include \"builtin.h\"\n     -#include \"alloc.h\"\n      #include \"config.h\"\n      #include \"convert.h\"\n    - #include \"builtin.h\"\n    + #include \"diff.h\"\n     \n      ## builtin/checkout--worker.c ##\n     @@\n    @@ builtin/grep.c\n     @@\n       * Copyright (c) 2006 Junio C Hamano\n       */\n    - #include \"cache.h\"\n    + #include \"builtin.h\"\n     -#include \"alloc.h\"\n      #include \"gettext.h\"\n      #include \"hex.h\"\n    @@ builtin/log.c\n     \n      ## builtin/merge.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"builtin.h\"\n      #include \"abspath.h\"\n      #include \"advice.h\"\n     -#include \"alloc.h\"\n    @@ builtin/repack.c\n      ## builtin/rev-parse.c ##\n     @@\n      #define USE_THE_INDEX_VARIABLE\n    - #include \"cache.h\"\n    + #include \"builtin.h\"\n      #include \"abspath.h\"\n     -#include \"alloc.h\"\n      #include \"config.h\"\n    @@ bulk-checkin.c\n     \n      ## cache-tree.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n      #include \"environment.h\"\n      #include \"hex.h\"\n    @@ common.h: static inline int cast_size_t_to_int(size_t a)\n     \n      ## config.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n      #include \"abspath.h\"\n      #include \"advice.h\"\n     -#include \"alloc.h\"\n    @@ config.c\n     \n      ## daemon.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n      #include \"abspath.h\"\n     -#include \"alloc.h\"\n      #include \"config.h\"\n      #include \"environment.h\"\n    - #include \"pkt-line.h\"\n    + #include \"path.h\"\n     \n      ## delta-islands.c ##\n     @@\n    @@ delta-islands.c\n      ## diff.c ##\n     @@\n       */\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n      #include \"abspath.h\"\n     -#include \"alloc.h\"\n    + #include \"base85.h\"\n      #include \"config.h\"\n      #include \"convert.h\"\n    - #include \"environment.h\"\n     \n      ## diffcore-rename.c ##\n     @@\n    @@ diffcore-rename.c\n     -#include \"alloc.h\"\n      #include \"diff.h\"\n      #include \"diffcore.h\"\n    - #include \"object-store.h\"\n    + #include \"object-store-ll.h\"\n     \n      ## dir-iterator.c ##\n     @@\n    @@ fetch-pack.c\n     -#include \"alloc.h\"\n      #include \"repository.h\"\n      #include \"config.h\"\n    - #include \"environment.h\"\n    + #include \"date.h\"\n     \n      ## fmt-merge-msg.c ##\n     @@\n    @@ fsck.c\n     @@\n      #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n    + #include \"date.h\"\n    + #include \"dir.h\"\n      #include \"hex.h\"\n    - #include \"object-store.h\"\n    - #include \"repository.h\"\n     \n      ## help.c ##\n     @@\n    @@ list-objects-filter.c\n     \n      ## midx.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n      #include \"abspath.h\"\n     -#include \"alloc.h\"\n      #include \"config.h\"\n    @@ midx.c\n      ## object-file.c ##\n     @@\n       */\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n      #include \"abspath.h\"\n     -#include \"alloc.h\"\n      #include \"config.h\"\n    @@ pack-objects.c\n     \n      ## packfile.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n      #include \"environment.h\"\n      #include \"gettext.h\"\n    @@ packfile.c\n     \n      ## parallel-checkout.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n      #include \"config.h\"\n      #include \"entry.h\"\n    @@ read-cache.c\n     @@\n       * Copyright (C) Linus Torvalds, 2005\n       */\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n    + #include \"bulk-checkin.h\"\n      #include \"config.h\"\n    - #include \"diff.h\"\n    - #include \"diffcore.h\"\n    + #include \"date.h\"\n     \n      ## ref-filter.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n      #include \"environment.h\"\n      #include \"gettext.h\"\n    - #include \"hex.h\"\n    + #include \"gpg-interface.h\"\n     \n      ## reflog-walk.c ##\n     @@\n    @@ refspec.c\n      #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n      #include \"gettext.h\"\n    + #include \"hash.h\"\n      #include \"hex.h\"\n    - #include \"strvec.h\"\n     \n      ## remote-curl.c ##\n     @@\n    @@ remote.c\n     \n      ## rerere.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n      #include \"abspath.h\"\n     -#include \"alloc.h\"\n      #include \"config.h\"\n    + #include \"copy.h\"\n      #include \"gettext.h\"\n    - #include \"hex.h\"\n     \n      ## revision.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n      #include \"config.h\"\n      #include \"environment.h\"\n    @@ revision.c\n     \n      ## sequencer.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n      #include \"abspath.h\"\n      #include \"advice.h\"\n     -#include \"alloc.h\"\n      #include \"config.h\"\n    + #include \"copy.h\"\n      #include \"environment.h\"\n    - #include \"gettext.h\"\n     \n      ## server-info.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n      #include \"dir.h\"\n      #include \"environment.h\"\n    @@ server-info.c\n     \n      ## shallow.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n      #include \"hex.h\"\n      #include \"repository.h\"\n    @@ sigchain.c\n     \n      ## sparse-index.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n      #include \"environment.h\"\n      #include \"gettext.h\"\n    - #include \"repository.h\"\n    + #include \"name-hash.h\"\n     \n      ## split-index.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n     -#include \"alloc.h\"\n      #include \"gettext.h\"\n    + #include \"hash.h\"\n      #include \"mem-pool.h\"\n    - #include \"split-index.h\"\n     \n      ## strbuf.c ##\n     @@\n      #include \"git-compat-util.h\"\n    - #include \"abspath.h\"\n     -#include \"alloc.h\"\n    - #include \"environment.h\"\n      #include \"gettext.h\"\n      #include \"hex.h\"\n    + #include \"path.h\"\n     \n      ## string-list.c ##\n     @@\n    @@ submodule-config.c\n     \n      ## submodule.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n      #include \"abspath.h\"\n     -#include \"alloc.h\"\n      #include \"repository.h\"\n    @@ transport.c\n     \n      ## tree-walk.c ##\n     @@\n    - #include \"cache.h\"\n    + #include \"git-compat-util.h\"\n      #include \"tree-walk.h\"\n     -#include \"alloc.h\"\n      #include \"dir.h\"\n    @@ worktree.c\n     -#include \"alloc.h\"\n      #include \"environment.h\"\n      #include \"gettext.h\"\n    - #include \"repository.h\"\n    + #include \"path.h\"\n-- \n2.40.1.698.g37aff9b760-goog\n\n"},{"id":"477669","messageId":"20230523192949.1271671-1-calvinwan@google.com","threadId":"59752","inReplyTo":"20230523192749.1270992-1-calvinwan@google.com","subject":"[PATCH v2 1/7] strbuf.h: move declarations for strbuf.c functions from git-compat-util.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-23T19:29:43Z","receivedAt":"2023-05-23T19:30:27Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"While functions like starts_with() probably should not belong in the\nboundaries of the strbuf library, this commit focuses on first splitting\nout headers from git-compat-util.h.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n builtin/symbolic-ref.c   |  1 +\n builtin/unpack-objects.c |  1 +\n git-compat-util.h        | 32 --------------------------------\n strbuf.h                 | 32 ++++++++++++++++++++++++++++++++\n versioncmp.c             |  1 +\n 5 files changed, 35 insertions(+), 32 deletions(-)\n\ndiff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c\nindex a61fa3c0f8..c9defe4d2e 100644\n--- a/builtin/symbolic-ref.c\n+++ b/builtin/symbolic-ref.c\n@@ -3,6 +3,7 @@\n #include \"gettext.h\"\n #include \"refs.h\"\n #include \"parse-options.h\"\n+#include \"strbuf.h\"\n \n static const char * const git_symbolic_ref_usage[] = {\n \tN_(\"git symbolic-ref [-m <reason>] <name> <ref>\"),\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex b4b46ae729..0510e60e6e 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -12,6 +12,7 @@\n #include \"blob.h\"\n #include \"commit.h\"\n #include \"replace-object.h\"\n+#include \"strbuf.h\"\n #include \"tag.h\"\n #include \"tree.h\"\n #include \"tree-walk.h\"\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 1889da7986..fe9e86bad0 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -677,9 +677,6 @@ void set_warn_routine(report_fn routine);\n report_fn get_warn_routine(void);\n void set_die_is_recursing_routine(int (*routine)(void));\n \n-int starts_with(const char *str, const char *prefix);\n-int istarts_with(const char *str, const char *prefix);\n-\n /*\n  * If the string \"str\" begins with the string found in \"prefix\", return 1.\n  * The \"out\" parameter is set to \"str + strlen(prefix)\" (i.e., to the point in\n@@ -708,29 +705,6 @@ static inline int skip_prefix(const char *str, const char *prefix,\n \treturn 0;\n }\n \n-/*\n- * If the string \"str\" is the same as the string in \"prefix\", then the \"arg\"\n- * parameter is set to the \"def\" parameter and 1 is returned.\n- * If the string \"str\" begins with the string found in \"prefix\" and then a\n- * \"=\" sign, then the \"arg\" parameter is set to \"str + strlen(prefix) + 1\"\n- * (i.e., to the point in the string right after the prefix and the \"=\" sign),\n- * and 1 is returned.\n- *\n- * Otherwise, return 0 and leave \"arg\" untouched.\n- *\n- * When we accept both a \"--key\" and a \"--key=<val>\" option, this function\n- * can be used instead of !strcmp(arg, \"--key\") and then\n- * skip_prefix(arg, \"--key=\", &arg) to parse such an option.\n- */\n-int skip_to_optional_arg_default(const char *str, const char *prefix,\n-\t\t\t\t const char **arg, const char *def);\n-\n-static inline int skip_to_optional_arg(const char *str, const char *prefix,\n-\t\t\t\t       const char **arg)\n-{\n-\treturn skip_to_optional_arg_default(str, prefix, arg, \"\");\n-}\n-\n /*\n  * Like skip_prefix, but promises never to read past \"len\" bytes of the input\n  * buffer, and returns the remaining number of bytes in \"out\" via \"outlen\".\n@@ -775,12 +749,6 @@ static inline int strip_suffix(const char *str, const char *suffix, size_t *len)\n \treturn strip_suffix_mem(str, len, suffix);\n }\n \n-static inline int ends_with(const char *str, const char *suffix)\n-{\n-\tsize_t len;\n-\treturn strip_suffix(str, suffix, &len);\n-}\n-\n #define SWAP(a, b) do {\t\t\t\t\t\t\\\n \tvoid *_swap_a_ptr = &(a);\t\t\t\t\\\n \tvoid *_swap_b_ptr = &(b);\t\t\t\t\\\ndiff --git a/strbuf.h b/strbuf.h\nindex 8903195416..28b3038e83 100644\n--- a/strbuf.h\n+++ b/strbuf.h\n@@ -698,4 +698,36 @@ char *xstrvfmt(const char *fmt, va_list ap);\n __attribute__((format (printf, 1, 2)))\n char *xstrfmt(const char *fmt, ...);\n \n+int starts_with(const char *str, const char *prefix);\n+int istarts_with(const char *str, const char *prefix);\n+\n+/*\n+ * If the string \"str\" is the same as the string in \"prefix\", then the \"arg\"\n+ * parameter is set to the \"def\" parameter and 1 is returned.\n+ * If the string \"str\" begins with the string found in \"prefix\" and then a\n+ * \"=\" sign, then the \"arg\" parameter is set to \"str + strlen(prefix) + 1\"\n+ * (i.e., to the point in the string right after the prefix and the \"=\" sign),\n+ * and 1 is returned.\n+ *\n+ * Otherwise, return 0 and leave \"arg\" untouched.\n+ *\n+ * When we accept both a \"--key\" and a \"--key=<val>\" option, this function\n+ * can be used instead of !strcmp(arg, \"--key\") and then\n+ * skip_prefix(arg, \"--key=\", &arg) to parse such an option.\n+ */\n+int skip_to_optional_arg_default(const char *str, const char *prefix,\n+\t\t\t\t const char **arg, const char *def);\n+\n+static inline int skip_to_optional_arg(const char *str, const char *prefix,\n+\t\t\t\t       const char **arg)\n+{\n+\treturn skip_to_optional_arg_default(str, prefix, arg, \"\");\n+}\n+\n+static inline int ends_with(const char *str, const char *suffix)\n+{\n+\tsize_t len;\n+\treturn strip_suffix(str, suffix, &len);\n+}\n+\n #endif /* STRBUF_H */\ndiff --git a/versioncmp.c b/versioncmp.c\nindex 74cc7c43f0..45e676cbca 100644\n--- a/versioncmp.c\n+++ b/versioncmp.c\n@@ -1,5 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"config.h\"\n+#include \"strbuf.h\"\n #include \"string-list.h\"\n #include \"versioncmp.h\"\n \n-- \n2.40.1.698.g37aff9b760-goog\n\n"},{"id":"477670","messageId":"20230523192949.1271671-2-calvinwan@google.com","threadId":"59752","inReplyTo":"20230523192749.1270992-1-calvinwan@google.com","subject":"[PATCH v2 2/7] wrapper.h: move declarations for wrapper.c functions from git-compat-util.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-23T19:29:44Z","receivedAt":"2023-05-23T19:30:28Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Since the functions in wrapper.c are widely used across the codebase,\ninclude it by default in git-compat-util.h. A future patch will remove\nnow unnecessary inclusions of wrapper.h from other files.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n git-compat-util.h | 112 +---------------------------------------------\n wrapper.h         | 111 +++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 112 insertions(+), 111 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex fe9e86bad0..f8e68baf29 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -625,7 +625,7 @@ static inline int git_has_dir_sep(const char *path)\n \n #include \"compat/bswap.h\"\n \n-struct strbuf;\n+#include \"wrapper.h\"\n \n /* General helper functions */\n NORETURN void usage(const char *err);\n@@ -1045,36 +1045,6 @@ static inline int cast_size_t_to_int(size_t a)\n # define xalloca(size)      (xmalloc(size))\n # define xalloca_free(p)    (free(p))\n #endif\n-char *xstrdup(const char *str);\n-void *xmalloc(size_t size);\n-void *xmallocz(size_t size);\n-void *xmallocz_gently(size_t size);\n-void *xmemdupz(const void *data, size_t len);\n-char *xstrndup(const char *str, size_t len);\n-void *xrealloc(void *ptr, size_t size);\n-void *xcalloc(size_t nmemb, size_t size);\n-void xsetenv(const char *name, const char *value, int overwrite);\n-void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n-const char *mmap_os_err(void);\n-void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n-int xopen(const char *path, int flags, ...);\n-ssize_t xread(int fd, void *buf, size_t len);\n-ssize_t xwrite(int fd, const void *buf, size_t len);\n-ssize_t xpread(int fd, void *buf, size_t len, off_t offset);\n-int xdup(int fd);\n-FILE *xfopen(const char *path, const char *mode);\n-FILE *xfdopen(int fd, const char *mode);\n-int xmkstemp(char *temp_filename);\n-int xmkstemp_mode(char *temp_filename, int mode);\n-char *xgetcwd(void);\n-FILE *fopen_for_writing(const char *path);\n-FILE *fopen_or_warn(const char *path, const char *mode);\n-\n-/*\n- * Like strncmp, but only return zero if s is NUL-terminated and exactly len\n- * characters long.  If it is not, consider it greater than t.\n- */\n-int xstrncmpz(const char *s, const char *t, size_t len);\n \n /*\n  * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note\n@@ -1176,15 +1146,10 @@ static inline size_t xsize_t(off_t len)\n \treturn (size_t) len;\n }\n \n-__attribute__((format (printf, 3, 4)))\n-int xsnprintf(char *dst, size_t max, const char *fmt, ...);\n-\n #ifndef HOST_NAME_MAX\n #define HOST_NAME_MAX 256\n #endif\n \n-int xgethostname(char *buf, size_t len);\n-\n /* in ctype.c, for kwset users */\n extern const unsigned char tolower_trans_tbl[256];\n \n@@ -1425,72 +1390,6 @@ void bug_fl(const char *file, int line, const char *fmt, ...);\n #endif\n #endif\n \n-enum fsync_action {\n-\tFSYNC_WRITEOUT_ONLY,\n-\tFSYNC_HARDWARE_FLUSH\n-};\n-\n-/*\n- * Issues an fsync against the specified file according to the specified mode.\n- *\n- * FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating\n- * systems to flush the OS cache without issuing a flush command to the storage\n- * controller. If those interfaces are unavailable, the function fails with\n- * ENOSYS.\n- *\n- * FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that\n- * changes are durable. It is not expected to fail.\n- */\n-int git_fsync(int fd, enum fsync_action action);\n-\n-/*\n- * Writes out trace statistics for fsync using the trace2 API.\n- */\n-void trace_git_fsync_stats(void);\n-\n-/*\n- * Preserves errno, prints a message, but gives no warning for ENOENT.\n- * Returns 0 on success, which includes trying to unlink an object that does\n- * not exist.\n- */\n-int unlink_or_warn(const char *path);\n- /*\n-  * Tries to unlink file.  Returns 0 if unlink succeeded\n-  * or the file already didn't exist.  Returns -1 and\n-  * appends a message to err suitable for\n-  * 'error(\"%s\", err->buf)' on error.\n-  */\n-int unlink_or_msg(const char *file, struct strbuf *err);\n-/*\n- * Preserves errno, prints a message, but gives no warning for ENOENT.\n- * Returns 0 on success, which includes trying to remove a directory that does\n- * not exist.\n- */\n-int rmdir_or_warn(const char *path);\n-/*\n- * Calls the correct function out of {unlink,rmdir}_or_warn based on\n- * the supplied file mode.\n- */\n-int remove_or_warn(unsigned int mode, const char *path);\n-\n-/*\n- * Call access(2), but warn for any error except \"missing file\"\n- * (ENOENT or ENOTDIR).\n- */\n-#define ACCESS_EACCES_OK (1U << 0)\n-int access_or_warn(const char *path, int mode, unsigned flag);\n-int access_or_die(const char *path, int mode, unsigned flag);\n-\n-/* Warn on an inaccessible file if errno indicates this is an error */\n-int warn_on_fopen_errors(const char *path);\n-\n-/*\n- * Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent\n- * may be racy. Do not use this as protection against an attacker who can\n- * simultaneously create paths.\n- */\n-int open_nofollow(const char *path, int flags);\n-\n #ifndef SHELL_PATH\n # define SHELL_PATH \"/bin/sh\"\n #endif\n@@ -1630,13 +1529,4 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset)\n \t((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))\n #endif /* !__GNUC__ */\n \n-void sleep_millisec(int millisec);\n-\n-/*\n- * Generate len bytes from the system cryptographically secure PRNG.\n- * Returns 0 on success and -1 on error, setting errno.  The inability to\n- * satisfy the full request is an error.\n- */\n-int csprng_bytes(void *buf, size_t len);\n-\n #endif\ndiff --git a/wrapper.h b/wrapper.h\nindex f0c7d0616d..c85b1328d1 100644\n--- a/wrapper.h\n+++ b/wrapper.h\n@@ -1,6 +1,42 @@\n #ifndef WRAPPER_H\n #define WRAPPER_H\n \n+char *xstrdup(const char *str);\n+void *xmalloc(size_t size);\n+void *xmallocz(size_t size);\n+void *xmallocz_gently(size_t size);\n+void *xmemdupz(const void *data, size_t len);\n+char *xstrndup(const char *str, size_t len);\n+void *xrealloc(void *ptr, size_t size);\n+void *xcalloc(size_t nmemb, size_t size);\n+void xsetenv(const char *name, const char *value, int overwrite);\n+void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n+const char *mmap_os_err(void);\n+void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n+int xopen(const char *path, int flags, ...);\n+ssize_t xread(int fd, void *buf, size_t len);\n+ssize_t xwrite(int fd, const void *buf, size_t len);\n+ssize_t xpread(int fd, void *buf, size_t len, off_t offset);\n+int xdup(int fd);\n+FILE *xfopen(const char *path, const char *mode);\n+FILE *xfdopen(int fd, const char *mode);\n+int xmkstemp(char *temp_filename);\n+int xmkstemp_mode(char *temp_filename, int mode);\n+char *xgetcwd(void);\n+FILE *fopen_for_writing(const char *path);\n+FILE *fopen_or_warn(const char *path, const char *mode);\n+\n+/*\n+ * Like strncmp, but only return zero if s is NUL-terminated and exactly len\n+ * characters long.  If it is not, consider it greater than t.\n+ */\n+int xstrncmpz(const char *s, const char *t, size_t len);\n+\n+__attribute__((format (printf, 3, 4)))\n+int xsnprintf(char *dst, size_t max, const char *fmt, ...);\n+\n+int xgethostname(char *buf, size_t len);\n+\n /* set default permissions by passing mode arguments to open(2) */\n int git_mkstemps_mode(char *pattern, int suffix_len, int mode);\n int git_mkstemp_mode(char *pattern, int mode);\n@@ -33,4 +69,79 @@ void write_file(const char *path, const char *fmt, ...);\n /* Return 1 if the file is empty or does not exists, 0 otherwise. */\n int is_empty_or_missing_file(const char *filename);\n \n+enum fsync_action {\n+\tFSYNC_WRITEOUT_ONLY,\n+\tFSYNC_HARDWARE_FLUSH\n+};\n+\n+/*\n+ * Issues an fsync against the specified file according to the specified mode.\n+ *\n+ * FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating\n+ * systems to flush the OS cache without issuing a flush command to the storage\n+ * controller. If those interfaces are unavailable, the function fails with\n+ * ENOSYS.\n+ *\n+ * FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that\n+ * changes are durable. It is not expected to fail.\n+ */\n+int git_fsync(int fd, enum fsync_action action);\n+\n+/*\n+ * Writes out trace statistics for fsync using the trace2 API.\n+ */\n+void trace_git_fsync_stats(void);\n+\n+/*\n+ * Preserves errno, prints a message, but gives no warning for ENOENT.\n+ * Returns 0 on success, which includes trying to unlink an object that does\n+ * not exist.\n+ */\n+int unlink_or_warn(const char *path);\n+ /*\n+  * Tries to unlink file.  Returns 0 if unlink succeeded\n+  * or the file already didn't exist.  Returns -1 and\n+  * appends a message to err suitable for\n+  * 'error(\"%s\", err->buf)' on error.\n+  */\n+int unlink_or_msg(const char *file, struct strbuf *err);\n+/*\n+ * Preserves errno, prints a message, but gives no warning for ENOENT.\n+ * Returns 0 on success, which includes trying to remove a directory that does\n+ * not exist.\n+ */\n+int rmdir_or_warn(const char *path);\n+/*\n+ * Calls the correct function out of {unlink,rmdir}_or_warn based on\n+ * the supplied file mode.\n+ */\n+int remove_or_warn(unsigned int mode, const char *path);\n+\n+/*\n+ * Call access(2), but warn for any error except \"missing file\"\n+ * (ENOENT or ENOTDIR).\n+ */\n+#define ACCESS_EACCES_OK (1U << 0)\n+int access_or_warn(const char *path, int mode, unsigned flag);\n+int access_or_die(const char *path, int mode, unsigned flag);\n+\n+/* Warn on an inaccessible file if errno indicates this is an error */\n+int warn_on_fopen_errors(const char *path);\n+\n+/*\n+ * Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent\n+ * may be racy. Do not use this as protection against an attacker who can\n+ * simultaneously create paths.\n+ */\n+int open_nofollow(const char *path, int flags);\n+\n+void sleep_millisec(int millisec);\n+\n+/*\n+ * Generate len bytes from the system cryptographically secure PRNG.\n+ * Returns 0 on success and -1 on error, setting errno.  The inability to\n+ * satisfy the full request is an error.\n+ */\n+int csprng_bytes(void *buf, size_t len);\n+\n #endif /* WRAPPER_H */\n-- \n2.40.1.698.g37aff9b760-goog\n\n"},{"id":"477671","messageId":"20230523192949.1271671-3-calvinwan@google.com","threadId":"59752","inReplyTo":"20230523192749.1270992-1-calvinwan@google.com","subject":"[PATCH v2 3/7] sane-ctype.h: move sane-ctype macros from git-compat-util.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-23T19:29:45Z","receivedAt":"2023-05-23T19:30:30Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Splitting these macros from git-compat-util.h cleans up the file and\nallows future third-party sources to not use these overrides if they do\nnot wish to.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n git-compat-util.h | 65 +-------------------------------------------\n sane-ctype.h      | 69 +++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 70 insertions(+), 64 deletions(-)\n create mode 100644 sane-ctype.h\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex f8e68baf29..9d3c21acbb 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -1150,70 +1150,7 @@ static inline size_t xsize_t(off_t len)\n #define HOST_NAME_MAX 256\n #endif\n \n-/* in ctype.c, for kwset users */\n-extern const unsigned char tolower_trans_tbl[256];\n-\n-/* Sane ctype - no locale, and works with signed chars */\n-#undef isascii\n-#undef isspace\n-#undef isdigit\n-#undef isalpha\n-#undef isalnum\n-#undef isprint\n-#undef islower\n-#undef isupper\n-#undef tolower\n-#undef toupper\n-#undef iscntrl\n-#undef ispunct\n-#undef isxdigit\n-\n-extern const unsigned char sane_ctype[256];\n-extern const signed char hexval_table[256];\n-#define GIT_SPACE 0x01\n-#define GIT_DIGIT 0x02\n-#define GIT_ALPHA 0x04\n-#define GIT_GLOB_SPECIAL 0x08\n-#define GIT_REGEX_SPECIAL 0x10\n-#define GIT_PATHSPEC_MAGIC 0x20\n-#define GIT_CNTRL 0x40\n-#define GIT_PUNCT 0x80\n-#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n-#define isascii(x) (((x) & ~0x7f) == 0)\n-#define isspace(x) sane_istest(x,GIT_SPACE)\n-#define isdigit(x) sane_istest(x,GIT_DIGIT)\n-#define isalpha(x) sane_istest(x,GIT_ALPHA)\n-#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)\n-#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)\n-#define islower(x) sane_iscase(x, 1)\n-#define isupper(x) sane_iscase(x, 0)\n-#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)\n-#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)\n-#define iscntrl(x) (sane_istest(x,GIT_CNTRL))\n-#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \\\n-\t\tGIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)\n-#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n-#define tolower(x) sane_case((unsigned char)(x), 0x20)\n-#define toupper(x) sane_case((unsigned char)(x), 0)\n-#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)\n-\n-static inline int sane_case(int x, int high)\n-{\n-\tif (sane_istest(x, GIT_ALPHA))\n-\t\tx = (x & ~0x20) | high;\n-\treturn x;\n-}\n-\n-static inline int sane_iscase(int x, int is_lower)\n-{\n-\tif (!sane_istest(x, GIT_ALPHA))\n-\t\treturn 0;\n-\n-\tif (is_lower)\n-\t\treturn (x & 0x20) != 0;\n-\telse\n-\t\treturn (x & 0x20) == 0;\n-}\n+#include \"sane-ctype.h\"\n \n /*\n  * Like skip_prefix, but compare case-insensitively. Note that the comparison\ndiff --git a/sane-ctype.h b/sane-ctype.h\nnew file mode 100644\nindex 0000000000..df06bcbe14\n--- /dev/null\n+++ b/sane-ctype.h\n@@ -0,0 +1,69 @@\n+#ifndef SANE_CTYPE_H\n+#define SANE_CTYPE_H\n+\n+/* in ctype.c, for kwset users */\n+extern const unsigned char tolower_trans_tbl[256];\n+\n+/* Sane ctype - no locale, and works with signed chars */\n+#undef isascii\n+#undef isspace\n+#undef isdigit\n+#undef isalpha\n+#undef isalnum\n+#undef isprint\n+#undef islower\n+#undef isupper\n+#undef tolower\n+#undef toupper\n+#undef iscntrl\n+#undef ispunct\n+#undef isxdigit\n+\n+extern const unsigned char sane_ctype[256];\n+extern const signed char hexval_table[256];\n+#define GIT_SPACE 0x01\n+#define GIT_DIGIT 0x02\n+#define GIT_ALPHA 0x04\n+#define GIT_GLOB_SPECIAL 0x08\n+#define GIT_REGEX_SPECIAL 0x10\n+#define GIT_PATHSPEC_MAGIC 0x20\n+#define GIT_CNTRL 0x40\n+#define GIT_PUNCT 0x80\n+#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n+#define isascii(x) (((x) & ~0x7f) == 0)\n+#define isspace(x) sane_istest(x,GIT_SPACE)\n+#define isdigit(x) sane_istest(x,GIT_DIGIT)\n+#define isalpha(x) sane_istest(x,GIT_ALPHA)\n+#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)\n+#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)\n+#define islower(x) sane_iscase(x, 1)\n+#define isupper(x) sane_iscase(x, 0)\n+#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)\n+#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)\n+#define iscntrl(x) (sane_istest(x,GIT_CNTRL))\n+#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \\\n+\t\tGIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)\n+#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n+#define tolower(x) sane_case((unsigned char)(x), 0x20)\n+#define toupper(x) sane_case((unsigned char)(x), 0)\n+#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)\n+\n+static inline int sane_case(int x, int high)\n+{\n+\tif (sane_istest(x, GIT_ALPHA))\n+\t\tx = (x & ~0x20) | high;\n+\treturn x;\n+}\n+\n+static inline int sane_iscase(int x, int is_lower)\n+{\n+\tif (!sane_istest(x, GIT_ALPHA))\n+\t\treturn 0;\n+\n+\tif (is_lower)\n+\t\treturn (x & 0x20) != 0;\n+\telse\n+\t\treturn (x & 0x20) == 0;\n+}\n+\n+#endif\n-- \n2.40.1.698.g37aff9b760-goog\n\n"},{"id":"477672","messageId":"20230523192949.1271671-5-calvinwan@google.com","threadId":"59752","inReplyTo":"20230523192749.1270992-1-calvinwan@google.com","subject":"[PATCH v2 5/7] usage.h: move declarations for usage.c functions from git-compat-util.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-23T19:29:47Z","receivedAt":"2023-05-23T19:30:36Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Signed-off-by: Calvin Wan <calvinwan@google.com>\n---\n common.h          |  1 +\n git-compat-util.h | 55 -------------------------------------------\n usage.h           | 60 +++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 61 insertions(+), 55 deletions(-)\n create mode 100644 usage.h\n\ndiff --git a/common.h b/common.h\nindex 0f164c1071..e3b673847d 100644\n--- a/common.h\n+++ b/common.h\n@@ -3,6 +3,7 @@\n \n #include \"git-compat-util.h\"\n #include \"wrapper.h\"\n+#include \"usage.h\"\n \n /*\n  * ARRAY_SIZE - get the number of elements in a visible array\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex f73c8727d1..481dac22b0 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -572,20 +572,6 @@ static inline int git_has_dir_sep(const char *path)\n \n #include \"compat/bswap.h\"\n \n-#include \"wrapper.h\"\n-\n-/* General helper functions */\n-NORETURN void usage(const char *err);\n-NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-int die_message(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-int die_message_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-int error(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-\n #ifndef NO_OPENSSL\n #ifdef APPLE_COMMON_CRYPTO\n #include \"compat/apple-common-crypto.h\"\n@@ -600,30 +586,6 @@ void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n #include <openssl/rand.h>\n #endif\n \n-/*\n- * Let callers be aware of the constant return value; this can help\n- * gcc with -Wuninitialized analysis. We restrict this trick to gcc, though,\n- * because other compilers may be confused by this.\n- */\n-#if defined(__GNUC__)\n-static inline int const_error(void)\n-{\n-\treturn -1;\n-}\n-#define error(...) (error(__VA_ARGS__), const_error())\n-#define error_errno(...) (error_errno(__VA_ARGS__), const_error())\n-#endif\n-\n-typedef void (*report_fn)(const char *, va_list params);\n-\n-void set_die_routine(NORETURN_PTR report_fn routine);\n-report_fn get_die_message_routine(void);\n-void set_error_routine(report_fn routine);\n-report_fn get_error_routine(void);\n-void set_warn_routine(report_fn routine);\n-report_fn get_warn_routine(void);\n-void set_die_is_recursing_routine(int (*routine)(void));\n-\n #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)\n \n #ifndef PROT_READ\n@@ -942,23 +904,6 @@ int git_regcomp(regex_t *preg, const char *pattern, int cflags);\n #endif\n #endif\n \n-/* usage.c: only to be used for testing BUG() implementation (see test-tool) */\n-extern int BUG_exit_code;\n-\n-/* usage.c: if bug() is called we should have a BUG_if_bug() afterwards */\n-extern int bug_called_must_BUG;\n-\n-__attribute__((format (printf, 3, 4))) NORETURN\n-void BUG_fl(const char *file, int line, const char *fmt, ...);\n-#define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__)\n-__attribute__((format (printf, 3, 4)))\n-void bug_fl(const char *file, int line, const char *fmt, ...);\n-#define bug(...) bug_fl(__FILE__, __LINE__, __VA_ARGS__)\n-#define BUG_if_bug(...) do { \\\n-\tif (bug_called_must_BUG) \\\n-\t\tBUG_fl(__FILE__, __LINE__, __VA_ARGS__); \\\n-} while (0)\n-\n #ifndef FSYNC_METHOD_DEFAULT\n #ifdef __APPLE__\n #define FSYNC_METHOD_DEFAULT FSYNC_METHOD_WRITEOUT_ONLY\ndiff --git a/usage.h b/usage.h\nnew file mode 100644\nindex 0000000000..770076e684\n--- /dev/null\n+++ b/usage.h\n@@ -0,0 +1,60 @@\n+#ifndef USAGE_H\n+#define USAGE_H\n+\n+#include \"git-compat-util.h\"\n+\n+/* General helper functions */\n+NORETURN void usage(const char *err);\n+NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+int error(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+int die_message(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+int die_message_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+\n+void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+\n+/*\n+ * Let callers be aware of the constant return value; this can help\n+ * gcc with -Wuninitialized analysis. We restrict this trick to gcc, though,\n+ * because other compilers may be confused by this.\n+ */\n+#if defined(__GNUC__)\n+static inline int const_error(void)\n+{\n+\treturn -1;\n+}\n+#define error(...) (error(__VA_ARGS__), const_error())\n+#define error_errno(...) (error_errno(__VA_ARGS__), const_error())\n+#endif\n+\n+typedef void (*report_fn)(const char *, va_list params);\n+\n+void set_die_routine(NORETURN_PTR report_fn routine);\n+report_fn get_die_message_routine(void);\n+void set_error_routine(report_fn routine);\n+report_fn get_error_routine(void);\n+void set_warn_routine(report_fn routine);\n+report_fn get_warn_routine(void);\n+void set_die_is_recursing_routine(int (*routine)(void));\n+\n+/* usage.c: only to be used for testing BUG() implementation (see test-tool) */\n+extern int BUG_exit_code;\n+\n+/* usage.c: if bug() is called we should have a BUG_if_bug() afterwards */\n+extern int bug_called_must_BUG;\n+\n+__attribute__((format (printf, 3, 4))) NORETURN\n+void BUG_fl(const char *file, int line, const char *fmt, ...);\n+#define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__)\n+__attribute__((format (printf, 3, 4)))\n+void bug_fl(const char *file, int line, const char *fmt, ...);\n+#define bug(...) bug_fl(__FILE__, __LINE__, __VA_ARGS__)\n+#define BUG_if_bug(...) do { \\\n+\tif (bug_called_must_BUG) \\\n+\t\tBUG_fl(__FILE__, __LINE__, __VA_ARGS__); \\\n+} while (0)\n+\n+#endif /* USAGE_H */\n-- \n2.40.1.698.g37aff9b760-goog\n\n"},{"id":"477673","messageId":"20230523192949.1271671-4-calvinwan@google.com","threadId":"59752","inReplyTo":"20230523192749.1270992-1-calvinwan@google.com","subject":"[PATCH v2 4/7] common.h: move non-compat specific macros and functions from git-compat-util.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-23T19:29:46Z","receivedAt":"2023-05-23T19:30:37Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"git-compat-util.h has grown to a large and difficult to read file partly\nbecause its set of functionality is overloaded. Besides being a\ncompatibility file that ensures Git's operation across different\noperating systems, it has also become a dumping ground for commonly used\nmacros and static inline functions.\n\nThis commit separates out macros and static inline functions that are\ncompatible across operating systems into common.h. common.h is\nreincluded back into git-compat-util.h so that other files do not also\nhave to include it. The eventual goal is for common.h to be separated\nout into more reasonable boundaries, but for now this should be a good\nfirst step towards that goal.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n common.h          | 410 ++++++++++++++++++++++++++++++++++++++++++++++\n git-compat-util.h | 402 +--------------------------------------------\n 2 files changed, 412 insertions(+), 400 deletions(-)\n create mode 100644 common.h\n\ndiff --git a/common.h b/common.h\nnew file mode 100644\nindex 0000000000..0f164c1071\n--- /dev/null\n+++ b/common.h\n@@ -0,0 +1,410 @@\n+#ifndef COMMON_H\n+#define COMMON_H\n+\n+#include \"git-compat-util.h\"\n+#include \"wrapper.h\"\n+\n+/*\n+ * ARRAY_SIZE - get the number of elements in a visible array\n+ * @x: the array whose size you want.\n+ *\n+ * This does not work on pointers, or arrays declared as [], or\n+ * function parameters.  With correct compiler support, such usage\n+ * will cause a build error (see the build_assert_or_zero macro).\n+ */\n+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + BARF_UNLESS_AN_ARRAY(x))\n+\n+#define bitsizeof(x)  (CHAR_BIT * sizeof(x))\n+\n+#define maximum_signed_value_of_type(a) \\\n+    (INTMAX_MAX >> (bitsizeof(intmax_t) - bitsizeof(a)))\n+\n+#define maximum_unsigned_value_of_type(a) \\\n+    (UINTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a)))\n+\n+/*\n+ * Signed integer overflow is undefined in C, so here's a helper macro\n+ * to detect if the sum of two integers will overflow.\n+ *\n+ * Requires: a >= 0, typeof(a) equals typeof(b)\n+ */\n+#define signed_add_overflows(a, b) \\\n+    ((b) > maximum_signed_value_of_type(a) - (a))\n+\n+#define unsigned_add_overflows(a, b) \\\n+    ((b) > maximum_unsigned_value_of_type(a) - (a))\n+\n+/*\n+ * Returns true if the multiplication of \"a\" and \"b\" will\n+ * overflow. The types of \"a\" and \"b\" must match and must be unsigned.\n+ * Note that this macro evaluates \"a\" twice!\n+ */\n+#define unsigned_mult_overflows(a, b) \\\n+    ((a) && (b) > maximum_unsigned_value_of_type(a) / (a))\n+\n+/*\n+ * Returns true if the left shift of \"a\" by \"shift\" bits will\n+ * overflow. The type of \"a\" must be unsigned.\n+ */\n+#define unsigned_left_shift_overflows(a, shift) \\\n+    ((shift) < bitsizeof(a) && \\\n+     (a) > maximum_unsigned_value_of_type(a) >> (shift))\n+\n+#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))\n+#define HAS_MULTI_BITS(i)  ((i) & ((i) - 1))  /* checks if an integer has more than 1 bit set */\n+\n+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))\n+\n+/* Approximation of the length of the decimal representation of this type. */\n+#define decimal_length(x)\t((int)(sizeof(x) * 2.56 + 0.5) + 1)\n+\n+/*\n+ * If the string \"str\" begins with the string found in \"prefix\", return 1.\n+ * The \"out\" parameter is set to \"str + strlen(prefix)\" (i.e., to the point in\n+ * the string right after the prefix).\n+ *\n+ * Otherwise, return 0 and leave \"out\" untouched.\n+ *\n+ * Examples:\n+ *\n+ *   [extract branch name, fail if not a branch]\n+ *   if (!skip_prefix(ref, \"refs/heads/\", &branch)\n+ *\treturn -1;\n+ *\n+ *   [skip prefix if present, otherwise use whole string]\n+ *   skip_prefix(name, \"refs/heads/\", &name);\n+ */\n+static inline int skip_prefix(const char *str, const char *prefix,\n+\t\t\t      const char **out)\n+{\n+\tdo {\n+\t\tif (!*prefix) {\n+\t\t\t*out = str;\n+\t\t\treturn 1;\n+\t\t}\n+\t} while (*str++ == *prefix++);\n+\treturn 0;\n+}\n+\n+/*\n+ * Like skip_prefix, but promises never to read past \"len\" bytes of the input\n+ * buffer, and returns the remaining number of bytes in \"out\" via \"outlen\".\n+ */\n+static inline int skip_prefix_mem(const char *buf, size_t len,\n+\t\t\t\t  const char *prefix,\n+\t\t\t\t  const char **out, size_t *outlen)\n+{\n+\tsize_t prefix_len = strlen(prefix);\n+\tif (prefix_len <= len && !memcmp(buf, prefix, prefix_len)) {\n+\t\t*out = buf + prefix_len;\n+\t\t*outlen = len - prefix_len;\n+\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+/*\n+ * If buf ends with suffix, return 1 and subtract the length of the suffix\n+ * from *len. Otherwise, return 0 and leave *len untouched.\n+ */\n+static inline int strip_suffix_mem(const char *buf, size_t *len,\n+\t\t\t\t   const char *suffix)\n+{\n+\tsize_t suflen = strlen(suffix);\n+\tif (*len < suflen || memcmp(buf + (*len - suflen), suffix, suflen))\n+\t\treturn 0;\n+\t*len -= suflen;\n+\treturn 1;\n+}\n+\n+/*\n+ * If str ends with suffix, return 1 and set *len to the size of the string\n+ * without the suffix. Otherwise, return 0 and set *len to the size of the\n+ * string.\n+ *\n+ * Note that we do _not_ NUL-terminate str to the new length.\n+ */\n+static inline int strip_suffix(const char *str, const char *suffix, size_t *len)\n+{\n+\t*len = strlen(str);\n+\treturn strip_suffix_mem(str, len, suffix);\n+}\n+\n+#define SWAP(a, b) do {\t\t\t\t\t\t\\\n+\tvoid *_swap_a_ptr = &(a);\t\t\t\t\\\n+\tvoid *_swap_b_ptr = &(b);\t\t\t\t\\\n+\tunsigned char _swap_buffer[sizeof(a)];\t\t\t\\\n+\tmemcpy(_swap_buffer, _swap_a_ptr, sizeof(a));\t\t\\\n+\tmemcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a) +\t\t\\\n+\t       BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b)));\t\\\n+\tmemcpy(_swap_b_ptr, _swap_buffer, sizeof(a));\t\t\\\n+} while (0)\n+\n+static inline size_t st_add(size_t a, size_t b)\n+{\n+\tif (unsigned_add_overflows(a, b))\n+\t\tdie(\"size_t overflow: %\"PRIuMAX\" + %\"PRIuMAX,\n+\t\t    (uintmax_t)a, (uintmax_t)b);\n+\treturn a + b;\n+}\n+#define st_add3(a,b,c)   st_add(st_add((a),(b)),(c))\n+#define st_add4(a,b,c,d) st_add(st_add3((a),(b),(c)),(d))\n+\n+static inline size_t st_mult(size_t a, size_t b)\n+{\n+\tif (unsigned_mult_overflows(a, b))\n+\t\tdie(\"size_t overflow: %\"PRIuMAX\" * %\"PRIuMAX,\n+\t\t    (uintmax_t)a, (uintmax_t)b);\n+\treturn a * b;\n+}\n+\n+static inline size_t st_sub(size_t a, size_t b)\n+{\n+\tif (a < b)\n+\t\tdie(\"size_t underflow: %\"PRIuMAX\" - %\"PRIuMAX,\n+\t\t    (uintmax_t)a, (uintmax_t)b);\n+\treturn a - b;\n+}\n+\n+static inline size_t st_left_shift(size_t a, unsigned shift)\n+{\n+\tif (unsigned_left_shift_overflows(a, shift))\n+\t\tdie(\"size_t overflow: %\"PRIuMAX\" << %u\",\n+\t\t    (uintmax_t)a, shift);\n+\treturn a << shift;\n+}\n+\n+static inline unsigned long cast_size_t_to_ulong(size_t a)\n+{\n+\tif (a != (unsigned long)a)\n+\t\tdie(\"object too large to read on this platform: %\"\n+\t\t    PRIuMAX\" is cut off to %lu\",\n+\t\t    (uintmax_t)a, (unsigned long)a);\n+\treturn (unsigned long)a;\n+}\n+\n+static inline int cast_size_t_to_int(size_t a)\n+{\n+\tif (a > INT_MAX)\n+\t\tdie(\"number too large to represent as int on this platform: %\"PRIuMAX,\n+\t\t    (uintmax_t)a);\n+\treturn (int)a;\n+}\n+\n+\n+/*\n+ * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note\n+ * that ptr is used twice, so don't pass e.g. ptr++.\n+ */\n+#define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)\n+\n+#define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))\n+#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))\n+#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))\n+\n+#define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \\\n+\tBARF_UNLESS_COPYABLE((dst), (src)))\n+static inline void copy_array(void *dst, const void *src, size_t n, size_t size)\n+{\n+\tif (n)\n+\t\tmemcpy(dst, src, st_mult(size, n));\n+}\n+\n+#define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \\\n+\tBARF_UNLESS_COPYABLE((dst), (src)))\n+static inline void move_array(void *dst, const void *src, size_t n, size_t size)\n+{\n+\tif (n)\n+\t\tmemmove(dst, src, st_mult(size, n));\n+}\n+\n+#define DUP_ARRAY(dst, src, n) do { \\\n+\tsize_t dup_array_n_ = (n); \\\n+\tCOPY_ARRAY(ALLOC_ARRAY((dst), dup_array_n_), (src), dup_array_n_); \\\n+} while (0)\n+\n+/*\n+ * These functions help you allocate structs with flex arrays, and copy\n+ * the data directly into the array. For example, if you had:\n+ *\n+ *   struct foo {\n+ *     int bar;\n+ *     char name[FLEX_ARRAY];\n+ *   };\n+ *\n+ * you can do:\n+ *\n+ *   struct foo *f;\n+ *   FLEX_ALLOC_MEM(f, name, src, len);\n+ *\n+ * to allocate a \"foo\" with the contents of \"src\" in the \"name\" field.\n+ * The resulting struct is automatically zero'd, and the flex-array field\n+ * is NUL-terminated (whether the incoming src buffer was or not).\n+ *\n+ * The FLEXPTR_* variants operate on structs that don't use flex-arrays,\n+ * but do want to store a pointer to some extra data in the same allocated\n+ * block. For example, if you have:\n+ *\n+ *   struct foo {\n+ *     char *name;\n+ *     int bar;\n+ *   };\n+ *\n+ * you can do:\n+ *\n+ *   struct foo *f;\n+ *   FLEXPTR_ALLOC_STR(f, name, src);\n+ *\n+ * and \"name\" will point to a block of memory after the struct, which will be\n+ * freed along with the struct (but the pointer can be repointed anywhere).\n+ *\n+ * The *_STR variants accept a string parameter rather than a ptr/len\n+ * combination.\n+ *\n+ * Note that these macros will evaluate the first parameter multiple\n+ * times, and it must be assignable as an lvalue.\n+ */\n+#define FLEX_ALLOC_MEM(x, flexname, buf, len) do { \\\n+\tsize_t flex_array_len_ = (len); \\\n+\t(x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \\\n+\tmemcpy((void *)(x)->flexname, (buf), flex_array_len_); \\\n+} while (0)\n+#define FLEXPTR_ALLOC_MEM(x, ptrname, buf, len) do { \\\n+\tsize_t flex_array_len_ = (len); \\\n+\t(x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \\\n+\tmemcpy((x) + 1, (buf), flex_array_len_); \\\n+\t(x)->ptrname = (void *)((x)+1); \\\n+} while(0)\n+#define FLEX_ALLOC_STR(x, flexname, str) \\\n+\tFLEX_ALLOC_MEM((x), flexname, (str), strlen(str))\n+#define FLEXPTR_ALLOC_STR(x, ptrname, str) \\\n+\tFLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))\n+\n+static inline char *xstrdup_or_null(const char *str)\n+{\n+\treturn str ? xstrdup(str) : NULL;\n+}\n+\n+static inline size_t xsize_t(off_t len)\n+{\n+\tif (len < 0 || (uintmax_t) len > SIZE_MAX)\n+\t\tdie(\"Cannot handle files this big\");\n+\treturn (size_t) len;\n+}\n+\n+/*\n+ * Like skip_prefix, but compare case-insensitively. Note that the comparison\n+ * is done via tolower(), so it is strictly ASCII (no multi-byte characters or\n+ * locale-specific conversions).\n+ */\n+static inline int skip_iprefix(const char *str, const char *prefix,\n+\t\t\t       const char **out)\n+{\n+\tdo {\n+\t\tif (!*prefix) {\n+\t\t\t*out = str;\n+\t\t\treturn 1;\n+\t\t}\n+\t} while (tolower(*str++) == tolower(*prefix++));\n+\treturn 0;\n+}\n+\n+/*\n+ * Like skip_prefix_mem, but compare case-insensitively. Note that the\n+ * comparison is done via tolower(), so it is strictly ASCII (no multi-byte\n+ * characters or locale-specific conversions).\n+ */\n+static inline int skip_iprefix_mem(const char *buf, size_t len,\n+\t\t\t\t   const char *prefix,\n+\t\t\t\t   const char **out, size_t *outlen)\n+{\n+\tdo {\n+\t\tif (!*prefix) {\n+\t\t\t*out = buf;\n+\t\t\t*outlen = len;\n+\t\t\treturn 1;\n+\t\t}\n+\t} while (len-- > 0 && tolower(*buf++) == tolower(*prefix++));\n+\treturn 0;\n+}\n+\n+static inline int strtoul_ui(char const *s, int base, unsigned int *result)\n+{\n+\tunsigned long ul;\n+\tchar *p;\n+\n+\terrno = 0;\n+\t/* negative values would be accepted by strtoul */\n+\tif (strchr(s, '-'))\n+\t\treturn -1;\n+\tul = strtoul(s, &p, base);\n+\tif (errno || *p || p == s || (unsigned int) ul != ul)\n+\t\treturn -1;\n+\t*result = ul;\n+\treturn 0;\n+}\n+\n+static inline int strtol_i(char const *s, int base, int *result)\n+{\n+\tlong ul;\n+\tchar *p;\n+\n+\terrno = 0;\n+\tul = strtol(s, &p, base);\n+\tif (errno || *p || p == s || (int) ul != ul)\n+\t\treturn -1;\n+\t*result = ul;\n+\treturn 0;\n+}\n+\n+static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,\n+\t\t\t      size_t nmatch, regmatch_t pmatch[], int eflags)\n+{\n+\tassert(nmatch > 0 && pmatch);\n+\tpmatch[0].rm_so = 0;\n+\tpmatch[0].rm_eo = size;\n+\treturn regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);\n+}\n+\n+/*\n+ * Our code often opens a path to an optional file, to work on its\n+ * contents when we can successfully open it.  We can ignore a failure\n+ * to open if such an optional file does not exist, but we do want to\n+ * report a failure in opening for other reasons (e.g. we got an I/O\n+ * error, or the file is there, but we lack the permission to open).\n+ *\n+ * Call this function after seeing an error from open() or fopen() to\n+ * see if the errno indicates a missing file that we can safely ignore.\n+ */\n+static inline int is_missing_file_error(int errno_)\n+{\n+\treturn (errno_ == ENOENT || errno_ == ENOTDIR);\n+}\n+\n+/*\n+ * container_of - Get the address of an object containing a field.\n+ *\n+ * @ptr: pointer to the field.\n+ * @type: type of the object.\n+ * @member: name of the field within the object.\n+ */\n+#define container_of(ptr, type, member) \\\n+\t((type *) ((char *)(ptr) - offsetof(type, member)))\n+\n+/*\n+ * helper function for `container_of_or_null' to avoid multiple\n+ * evaluation of @ptr\n+ */\n+static inline void *container_of_or_null_offset(void *ptr, size_t offset)\n+{\n+\treturn ptr ? (char *)ptr - offset : NULL;\n+}\n+\n+/*\n+ * like `container_of', but allows returned value to be NULL\n+ */\n+#define container_of_or_null(ptr, type, member) \\\n+\t(type *)container_of_or_null_offset(ptr, offsetof(type, member))\n+\n+\n+#endif\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 9d3c21acbb..f73c8727d1 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -106,51 +106,6 @@ struct strbuf;\n \tBUILD_ASSERT_OR_ZERO(0 ? ((*(dst) = *(src)), 0) : \\\n \t\t\t\t sizeof(*(dst)) == sizeof(*(src)))\n #endif\n-/*\n- * ARRAY_SIZE - get the number of elements in a visible array\n- * @x: the array whose size you want.\n- *\n- * This does not work on pointers, or arrays declared as [], or\n- * function parameters.  With correct compiler support, such usage\n- * will cause a build error (see the build_assert_or_zero macro).\n- */\n-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + BARF_UNLESS_AN_ARRAY(x))\n-\n-#define bitsizeof(x)  (CHAR_BIT * sizeof(x))\n-\n-#define maximum_signed_value_of_type(a) \\\n-    (INTMAX_MAX >> (bitsizeof(intmax_t) - bitsizeof(a)))\n-\n-#define maximum_unsigned_value_of_type(a) \\\n-    (UINTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a)))\n-\n-/*\n- * Signed integer overflow is undefined in C, so here's a helper macro\n- * to detect if the sum of two integers will overflow.\n- *\n- * Requires: a >= 0, typeof(a) equals typeof(b)\n- */\n-#define signed_add_overflows(a, b) \\\n-    ((b) > maximum_signed_value_of_type(a) - (a))\n-\n-#define unsigned_add_overflows(a, b) \\\n-    ((b) > maximum_unsigned_value_of_type(a) - (a))\n-\n-/*\n- * Returns true if the multiplication of \"a\" and \"b\" will\n- * overflow. The types of \"a\" and \"b\" must match and must be unsigned.\n- * Note that this macro evaluates \"a\" twice!\n- */\n-#define unsigned_mult_overflows(a, b) \\\n-    ((a) && (b) > maximum_unsigned_value_of_type(a) / (a))\n-\n-/*\n- * Returns true if the left shift of \"a\" by \"shift\" bits will\n- * overflow. The type of \"a\" must be unsigned.\n- */\n-#define unsigned_left_shift_overflows(a, shift) \\\n-    ((shift) < bitsizeof(a) && \\\n-     (a) > maximum_unsigned_value_of_type(a) >> (shift))\n \n #ifdef __GNUC__\n #define TYPEOF(x) (__typeof__(x))\n@@ -158,14 +113,6 @@ struct strbuf;\n #define TYPEOF(x)\n #endif\n \n-#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))\n-#define HAS_MULTI_BITS(i)  ((i) & ((i) - 1))  /* checks if an integer has more than 1 bit set */\n-\n-#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))\n-\n-/* Approximation of the length of the decimal representation of this type. */\n-#define decimal_length(x)\t((int)(sizeof(x) * 2.56 + 0.5) + 1)\n-\n #ifdef __MINGW64__\n #define _POSIX_C_SOURCE 1\n #elif defined(__sun__)\n@@ -677,88 +624,6 @@ void set_warn_routine(report_fn routine);\n report_fn get_warn_routine(void);\n void set_die_is_recursing_routine(int (*routine)(void));\n \n-/*\n- * If the string \"str\" begins with the string found in \"prefix\", return 1.\n- * The \"out\" parameter is set to \"str + strlen(prefix)\" (i.e., to the point in\n- * the string right after the prefix).\n- *\n- * Otherwise, return 0 and leave \"out\" untouched.\n- *\n- * Examples:\n- *\n- *   [extract branch name, fail if not a branch]\n- *   if (!skip_prefix(ref, \"refs/heads/\", &branch)\n- *\treturn -1;\n- *\n- *   [skip prefix if present, otherwise use whole string]\n- *   skip_prefix(name, \"refs/heads/\", &name);\n- */\n-static inline int skip_prefix(const char *str, const char *prefix,\n-\t\t\t      const char **out)\n-{\n-\tdo {\n-\t\tif (!*prefix) {\n-\t\t\t*out = str;\n-\t\t\treturn 1;\n-\t\t}\n-\t} while (*str++ == *prefix++);\n-\treturn 0;\n-}\n-\n-/*\n- * Like skip_prefix, but promises never to read past \"len\" bytes of the input\n- * buffer, and returns the remaining number of bytes in \"out\" via \"outlen\".\n- */\n-static inline int skip_prefix_mem(const char *buf, size_t len,\n-\t\t\t\t  const char *prefix,\n-\t\t\t\t  const char **out, size_t *outlen)\n-{\n-\tsize_t prefix_len = strlen(prefix);\n-\tif (prefix_len <= len && !memcmp(buf, prefix, prefix_len)) {\n-\t\t*out = buf + prefix_len;\n-\t\t*outlen = len - prefix_len;\n-\t\treturn 1;\n-\t}\n-\treturn 0;\n-}\n-\n-/*\n- * If buf ends with suffix, return 1 and subtract the length of the suffix\n- * from *len. Otherwise, return 0 and leave *len untouched.\n- */\n-static inline int strip_suffix_mem(const char *buf, size_t *len,\n-\t\t\t\t   const char *suffix)\n-{\n-\tsize_t suflen = strlen(suffix);\n-\tif (*len < suflen || memcmp(buf + (*len - suflen), suffix, suflen))\n-\t\treturn 0;\n-\t*len -= suflen;\n-\treturn 1;\n-}\n-\n-/*\n- * If str ends with suffix, return 1 and set *len to the size of the string\n- * without the suffix. Otherwise, return 0 and set *len to the size of the\n- * string.\n- *\n- * Note that we do _not_ NUL-terminate str to the new length.\n- */\n-static inline int strip_suffix(const char *str, const char *suffix, size_t *len)\n-{\n-\t*len = strlen(str);\n-\treturn strip_suffix_mem(str, len, suffix);\n-}\n-\n-#define SWAP(a, b) do {\t\t\t\t\t\t\\\n-\tvoid *_swap_a_ptr = &(a);\t\t\t\t\\\n-\tvoid *_swap_b_ptr = &(b);\t\t\t\t\\\n-\tunsigned char _swap_buffer[sizeof(a)];\t\t\t\\\n-\tmemcpy(_swap_buffer, _swap_a_ptr, sizeof(a));\t\t\\\n-\tmemcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a) +\t\t\\\n-\t       BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b)));\t\\\n-\tmemcpy(_swap_b_ptr, _swap_buffer, sizeof(a));\t\t\\\n-} while (0)\n-\n #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)\n \n #ifndef PROT_READ\n@@ -964,57 +829,6 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size);\n int git_atexit(void (*handler)(void));\n #endif\n \n-static inline size_t st_add(size_t a, size_t b)\n-{\n-\tif (unsigned_add_overflows(a, b))\n-\t\tdie(\"size_t overflow: %\"PRIuMAX\" + %\"PRIuMAX,\n-\t\t    (uintmax_t)a, (uintmax_t)b);\n-\treturn a + b;\n-}\n-#define st_add3(a,b,c)   st_add(st_add((a),(b)),(c))\n-#define st_add4(a,b,c,d) st_add(st_add3((a),(b),(c)),(d))\n-\n-static inline size_t st_mult(size_t a, size_t b)\n-{\n-\tif (unsigned_mult_overflows(a, b))\n-\t\tdie(\"size_t overflow: %\"PRIuMAX\" * %\"PRIuMAX,\n-\t\t    (uintmax_t)a, (uintmax_t)b);\n-\treturn a * b;\n-}\n-\n-static inline size_t st_sub(size_t a, size_t b)\n-{\n-\tif (a < b)\n-\t\tdie(\"size_t underflow: %\"PRIuMAX\" - %\"PRIuMAX,\n-\t\t    (uintmax_t)a, (uintmax_t)b);\n-\treturn a - b;\n-}\n-\n-static inline size_t st_left_shift(size_t a, unsigned shift)\n-{\n-\tif (unsigned_left_shift_overflows(a, shift))\n-\t\tdie(\"size_t overflow: %\"PRIuMAX\" << %u\",\n-\t\t    (uintmax_t)a, shift);\n-\treturn a << shift;\n-}\n-\n-static inline unsigned long cast_size_t_to_ulong(size_t a)\n-{\n-\tif (a != (unsigned long)a)\n-\t\tdie(\"object too large to read on this platform: %\"\n-\t\t    PRIuMAX\" is cut off to %lu\",\n-\t\t    (uintmax_t)a, (unsigned long)a);\n-\treturn (unsigned long)a;\n-}\n-\n-static inline int cast_size_t_to_int(size_t a)\n-{\n-\tif (a > INT_MAX)\n-\t\tdie(\"number too large to represent as int on this platform: %\"PRIuMAX,\n-\t\t    (uintmax_t)a);\n-\treturn (int)a;\n-}\n-\n /*\n  * Limit size of IO chunks, because huge chunks only cause pain.  OS X\n  * 64-bit is buggy, returning EINVAL if len >= INT_MAX; and even in\n@@ -1046,177 +860,12 @@ static inline int cast_size_t_to_int(size_t a)\n # define xalloca_free(p)    (free(p))\n #endif\n \n-/*\n- * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note\n- * that ptr is used twice, so don't pass e.g. ptr++.\n- */\n-#define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)\n-\n-#define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))\n-#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))\n-#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))\n-\n-#define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \\\n-\tBARF_UNLESS_COPYABLE((dst), (src)))\n-static inline void copy_array(void *dst, const void *src, size_t n, size_t size)\n-{\n-\tif (n)\n-\t\tmemcpy(dst, src, st_mult(size, n));\n-}\n-\n-#define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \\\n-\tBARF_UNLESS_COPYABLE((dst), (src)))\n-static inline void move_array(void *dst, const void *src, size_t n, size_t size)\n-{\n-\tif (n)\n-\t\tmemmove(dst, src, st_mult(size, n));\n-}\n-\n-#define DUP_ARRAY(dst, src, n) do { \\\n-\tsize_t dup_array_n_ = (n); \\\n-\tCOPY_ARRAY(ALLOC_ARRAY((dst), dup_array_n_), (src), dup_array_n_); \\\n-} while (0)\n-\n-/*\n- * These functions help you allocate structs with flex arrays, and copy\n- * the data directly into the array. For example, if you had:\n- *\n- *   struct foo {\n- *     int bar;\n- *     char name[FLEX_ARRAY];\n- *   };\n- *\n- * you can do:\n- *\n- *   struct foo *f;\n- *   FLEX_ALLOC_MEM(f, name, src, len);\n- *\n- * to allocate a \"foo\" with the contents of \"src\" in the \"name\" field.\n- * The resulting struct is automatically zero'd, and the flex-array field\n- * is NUL-terminated (whether the incoming src buffer was or not).\n- *\n- * The FLEXPTR_* variants operate on structs that don't use flex-arrays,\n- * but do want to store a pointer to some extra data in the same allocated\n- * block. For example, if you have:\n- *\n- *   struct foo {\n- *     char *name;\n- *     int bar;\n- *   };\n- *\n- * you can do:\n- *\n- *   struct foo *f;\n- *   FLEXPTR_ALLOC_STR(f, name, src);\n- *\n- * and \"name\" will point to a block of memory after the struct, which will be\n- * freed along with the struct (but the pointer can be repointed anywhere).\n- *\n- * The *_STR variants accept a string parameter rather than a ptr/len\n- * combination.\n- *\n- * Note that these macros will evaluate the first parameter multiple\n- * times, and it must be assignable as an lvalue.\n- */\n-#define FLEX_ALLOC_MEM(x, flexname, buf, len) do { \\\n-\tsize_t flex_array_len_ = (len); \\\n-\t(x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \\\n-\tmemcpy((void *)(x)->flexname, (buf), flex_array_len_); \\\n-} while (0)\n-#define FLEXPTR_ALLOC_MEM(x, ptrname, buf, len) do { \\\n-\tsize_t flex_array_len_ = (len); \\\n-\t(x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \\\n-\tmemcpy((x) + 1, (buf), flex_array_len_); \\\n-\t(x)->ptrname = (void *)((x)+1); \\\n-} while(0)\n-#define FLEX_ALLOC_STR(x, flexname, str) \\\n-\tFLEX_ALLOC_MEM((x), flexname, (str), strlen(str))\n-#define FLEXPTR_ALLOC_STR(x, ptrname, str) \\\n-\tFLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))\n-\n-static inline char *xstrdup_or_null(const char *str)\n-{\n-\treturn str ? xstrdup(str) : NULL;\n-}\n-\n-static inline size_t xsize_t(off_t len)\n-{\n-\tif (len < 0 || (uintmax_t) len > SIZE_MAX)\n-\t\tdie(\"Cannot handle files this big\");\n-\treturn (size_t) len;\n-}\n-\n #ifndef HOST_NAME_MAX\n #define HOST_NAME_MAX 256\n #endif\n \n #include \"sane-ctype.h\"\n \n-/*\n- * Like skip_prefix, but compare case-insensitively. Note that the comparison\n- * is done via tolower(), so it is strictly ASCII (no multi-byte characters or\n- * locale-specific conversions).\n- */\n-static inline int skip_iprefix(const char *str, const char *prefix,\n-\t\t\t       const char **out)\n-{\n-\tdo {\n-\t\tif (!*prefix) {\n-\t\t\t*out = str;\n-\t\t\treturn 1;\n-\t\t}\n-\t} while (tolower(*str++) == tolower(*prefix++));\n-\treturn 0;\n-}\n-\n-/*\n- * Like skip_prefix_mem, but compare case-insensitively. Note that the\n- * comparison is done via tolower(), so it is strictly ASCII (no multi-byte\n- * characters or locale-specific conversions).\n- */\n-static inline int skip_iprefix_mem(const char *buf, size_t len,\n-\t\t\t\t   const char *prefix,\n-\t\t\t\t   const char **out, size_t *outlen)\n-{\n-\tdo {\n-\t\tif (!*prefix) {\n-\t\t\t*out = buf;\n-\t\t\t*outlen = len;\n-\t\t\treturn 1;\n-\t\t}\n-\t} while (len-- > 0 && tolower(*buf++) == tolower(*prefix++));\n-\treturn 0;\n-}\n-\n-static inline int strtoul_ui(char const *s, int base, unsigned int *result)\n-{\n-\tunsigned long ul;\n-\tchar *p;\n-\n-\terrno = 0;\n-\t/* negative values would be accepted by strtoul */\n-\tif (strchr(s, '-'))\n-\t\treturn -1;\n-\tul = strtoul(s, &p, base);\n-\tif (errno || *p || p == s || (unsigned int) ul != ul)\n-\t\treturn -1;\n-\t*result = ul;\n-\treturn 0;\n-}\n-\n-static inline int strtol_i(char const *s, int base, int *result)\n-{\n-\tlong ul;\n-\tchar *p;\n-\n-\terrno = 0;\n-\tul = strtol(s, &p, base);\n-\tif (errno || *p || p == s || (int) ul != ul)\n-\t\treturn -1;\n-\t*result = ul;\n-\treturn 0;\n-}\n-\n void git_stable_qsort(void *base, size_t nmemb, size_t size,\n \t\t      int(*compar)(const void *, const void *));\n #ifdef INTERNAL_QSORT\n@@ -1249,15 +898,6 @@ int git_qsort_s(void *base, size_t nmemb, size_t size,\n #error \"Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd\"\n #endif\n \n-static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,\n-\t\t\t      size_t nmatch, regmatch_t pmatch[], int eflags)\n-{\n-\tassert(nmatch > 0 && pmatch);\n-\tpmatch[0].rm_so = 0;\n-\tpmatch[0].rm_eo = size;\n-\treturn regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);\n-}\n-\n #ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS\n int git_regcomp(regex_t *preg, const char *pattern, int cflags);\n #define regcomp git_regcomp\n@@ -1366,21 +1006,6 @@ int git_access(const char *path, int mode);\n # endif\n #endif\n \n-/*\n- * Our code often opens a path to an optional file, to work on its\n- * contents when we can successfully open it.  We can ignore a failure\n- * to open if such an optional file does not exist, but we do want to\n- * report a failure in opening for other reasons (e.g. we got an I/O\n- * error, or the file is there, but we lack the permission to open).\n- *\n- * Call this function after seeing an error from open() or fopen() to\n- * see if the errno indicates a missing file that we can safely ignore.\n- */\n-static inline int is_missing_file_error(int errno_)\n-{\n-\treturn (errno_ == ENOENT || errno_ == ENOTDIR);\n-}\n-\n int cmd_main(int, const char **);\n \n /*\n@@ -1422,37 +1047,14 @@ int uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,\n \t\tuLong *sourceLen);\n #endif\n \n+#include \"common.h\"\n+\n /*\n  * This include must come after system headers, since it introduces macros that\n  * replace system names.\n  */\n #include \"banned.h\"\n \n-/*\n- * container_of - Get the address of an object containing a field.\n- *\n- * @ptr: pointer to the field.\n- * @type: type of the object.\n- * @member: name of the field within the object.\n- */\n-#define container_of(ptr, type, member) \\\n-\t((type *) ((char *)(ptr) - offsetof(type, member)))\n-\n-/*\n- * helper function for `container_of_or_null' to avoid multiple\n- * evaluation of @ptr\n- */\n-static inline void *container_of_or_null_offset(void *ptr, size_t offset)\n-{\n-\treturn ptr ? (char *)ptr - offset : NULL;\n-}\n-\n-/*\n- * like `container_of', but allows returned value to be NULL\n- */\n-#define container_of_or_null(ptr, type, member) \\\n-\t(type *)container_of_or_null_offset(ptr, offsetof(type, member))\n-\n /*\n  * like offsetof(), but takes a pointer to a variable of type which\n  * contains @member, instead of a specified type.\n-- \n2.40.1.698.g37aff9b760-goog\n\n"},{"id":"477674","messageId":"20230523192949.1271671-6-calvinwan@google.com","threadId":"59752","inReplyTo":"20230523192749.1270992-1-calvinwan@google.com","subject":"[PATCH v2 6/7] treewide: remove unnecessary includes for wrapper.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-23T19:29:48Z","receivedAt":"2023-05-23T19:30:49Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Signed-off-by: Calvin Wan <calvinwan@google.com>\n---\n apply.c                          | 1 -\n builtin/am.c                     | 1 -\n builtin/bisect.c                 | 1 -\n builtin/branch.c                 | 1 -\n builtin/bugreport.c              | 1 -\n builtin/clone.c                  | 1 -\n builtin/config.c                 | 1 -\n builtin/credential-cache.c       | 1 -\n builtin/difftool.c               | 1 -\n builtin/fast-import.c            | 1 -\n builtin/fmt-merge-msg.c          | 1 -\n builtin/gc.c                     | 1 -\n builtin/get-tar-commit-id.c      | 1 -\n builtin/index-pack.c             | 1 -\n builtin/init-db.c                | 1 -\n builtin/merge.c                  | 1 -\n builtin/pack-objects.c           | 1 -\n builtin/rebase.c                 | 1 -\n builtin/receive-pack.c           | 1 -\n builtin/rerere.c                 | 1 -\n builtin/unpack-file.c            | 1 -\n builtin/worktree.c               | 1 -\n bulk-checkin.c                   | 1 -\n combine-diff.c                   | 1 -\n commit-graph.c                   | 1 -\n compat/terminal.c                | 1 -\n config.c                         | 1 -\n convert.c                        | 1 -\n copy.c                           | 1 -\n csum-file.c                      | 1 -\n daemon.c                         | 1 -\n diff.c                           | 1 -\n dir.c                            | 1 -\n editor.c                         | 1 -\n entry.c                          | 1 -\n environment.c                    | 1 -\n fetch-pack.c                     | 1 -\n gpg-interface.c                  | 1 -\n grep.c                           | 1 -\n http-backend.c                   | 1 -\n imap-send.c                      | 1 -\n merge-ll.c                       | 1 -\n merge-recursive.c                | 1 -\n notes-merge.c                    | 1 -\n object-file.c                    | 1 -\n pack-write.c                     | 1 -\n packfile.c                       | 1 -\n parallel-checkout.c              | 1 -\n path.c                           | 1 -\n pkt-line.c                       | 1 -\n read-cache.c                     | 1 -\n rebase-interactive.c             | 1 -\n refs.c                           | 1 -\n rerere.c                         | 1 -\n send-pack.c                      | 1 -\n sequencer.c                      | 1 -\n server-info.c                    | 1 -\n setup.c                          | 1 -\n shallow.c                        | 1 -\n strbuf.c                         | 1 -\n streaming.c                      | 1 -\n t/helper/test-delta.c            | 1 -\n t/helper/test-fsmonitor-client.c | 1 -\n t/helper/test-read-cache.c       | 1 -\n tag.c                            | 1 -\n tempfile.c                       | 1 -\n trace.c                          | 1 -\n transport-helper.c               | 1 -\n transport.c                      | 1 -\n upload-pack.c                    | 1 -\n usage.c                          | 1 -\n worktree.c                       | 1 -\n wrapper.c                        | 1 -\n write-or-die.c                   | 1 -\n 74 files changed, 74 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 8bd0109fcc..99c2a91de7 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -37,7 +37,6 @@\n #include \"symlinks.h\"\n #include \"wildmatch.h\"\n #include \"ws.h\"\n-#include \"wrapper.h\"\n \n struct gitdiff_data {\n \tstruct strbuf *root;\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 5fab159599..dcb89439b1 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -44,7 +44,6 @@\n #include \"path.h\"\n #include \"repository.h\"\n #include \"pretty.h\"\n-#include \"wrapper.h\"\n \n /**\n  * Returns the length of the first line of msg.\ndiff --git a/builtin/bisect.c b/builtin/bisect.c\nindex 6478df3489..65478ef40f 100644\n--- a/builtin/bisect.c\n+++ b/builtin/bisect.c\n@@ -15,7 +15,6 @@\n #include \"prompt.h\"\n #include \"quote.h\"\n #include \"revision.h\"\n-#include \"wrapper.h\"\n \n static GIT_PATH_FUNC(git_path_bisect_terms, \"BISECT_TERMS\")\n static GIT_PATH_FUNC(git_path_bisect_expected_rev, \"BISECT_EXPECTED_REV\")\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 6249fa1809..ff8a875c03 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -28,7 +28,6 @@\n #include \"worktree.h\"\n #include \"help.h\"\n #include \"commit-reach.h\"\n-#include \"wrapper.h\"\n \n static const char * const builtin_branch_usage[] = {\n \tN_(\"git branch [<options>] [-r | -a] [--merged] [--no-merged]\"),\ndiff --git a/builtin/bugreport.c b/builtin/bugreport.c\nindex daf6c23657..d2ae5c305d 100644\n--- a/builtin/bugreport.c\n+++ b/builtin/bugreport.c\n@@ -11,7 +11,6 @@\n #include \"diagnose.h\"\n #include \"object-file.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n static void get_system_info(struct strbuf *sys_info)\n {\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 687a686269..3fc0e5d7c0 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -45,7 +45,6 @@\n #include \"hook.h\"\n #include \"bundle.h\"\n #include \"bundle-uri.h\"\n-#include \"wrapper.h\"\n \n /*\n  * Overall FIXMEs:\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 30f6d9fe67..c01f136a2b 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -14,7 +14,6 @@\n #include \"setup.h\"\n #include \"strbuf.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n \n static const char *const builtin_config_usage[] = {\n \tN_(\"git config [<options>]\"),\ndiff --git a/builtin/credential-cache.c b/builtin/credential-cache.c\nindex ff3a47badb..43b9d0e5b1 100644\n--- a/builtin/credential-cache.c\n+++ b/builtin/credential-cache.c\n@@ -3,7 +3,6 @@\n #include \"parse-options.h\"\n #include \"path.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n #ifndef NO_UNIX_SOCKETS\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex e2c9ab7d5d..aeb0f92409 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -32,7 +32,6 @@\n #include \"dir.h\"\n #include \"entry.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n static int trust_exit_code;\n \ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex 2ee19c7373..4dbb10aff3 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -26,7 +26,6 @@\n #include \"commit-reach.h\"\n #include \"khash.h\"\n #include \"date.h\"\n-#include \"wrapper.h\"\n \n #define PACK_ID_BITS 16\n #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex cc81241642..0f9855b680 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -3,7 +3,6 @@\n #include \"fmt-merge-msg.h\"\n #include \"gettext.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n \n static const char * const fmt_merge_msg_usage[] = {\n \tN_(\"git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]\"),\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 91eec7703a..19d73067aa 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -41,7 +41,6 @@\n #include \"hook.h\"\n #include \"setup.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n #define FAILED_RUN \"failed to run %s\"\n \ndiff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c\nindex 9303e386cc..20d0dfe9cf 100644\n--- a/builtin/get-tar-commit-id.c\n+++ b/builtin/get-tar-commit-id.c\n@@ -5,7 +5,6 @@\n #include \"commit.h\"\n #include \"tar.h\"\n #include \"quote.h\"\n-#include \"wrapper.h\"\n \n static const char builtin_get_tar_commit_id_usage[] =\n \"git get-tar-commit-id\";\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 820860265d..f58f9db69d 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -25,7 +25,6 @@\n #include \"replace-object.h\"\n #include \"promisor-remote.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n static const char index_pack_usage[] =\n \"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])\";\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 0d8bd4d721..cb727c826f 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -13,7 +13,6 @@\n #include \"path.h\"\n #include \"setup.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n static int guess_repository_type(const char *git_dir)\n {\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 41fe0d8e5e..2f2f0a0b4c 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -53,7 +53,6 @@\n #include \"commit-reach.h\"\n #include \"wt-status.h\"\n #include \"commit-graph.h\"\n-#include \"wrapper.h\"\n \n #define DEFAULT_TWOHEAD (1<<0)\n #define DEFAULT_OCTOPUS (1<<1)\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex af9352b228..6409c07c7d 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -43,7 +43,6 @@\n #include \"promisor-remote.h\"\n #include \"pack-mtimes.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n \n /*\n  * Objects we are going to pack are collected in the `to_pack` structure.\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 555c5d3f02..6c23e7b25c 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -37,7 +37,6 @@\n #include \"reset.h\"\n #include \"trace2.h\"\n #include \"hook.h\"\n-#include \"wrapper.h\"\n \n static char const * const builtin_rebase_usage[] = {\n \tN_(\"git rebase [-i] [options] [--exec <cmd>] \"\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex 2b2faa5d18..2d7f0355dc 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -40,7 +40,6 @@\n #include \"worktree.h\"\n #include \"shallow.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n \n static const char * const receive_pack_usage[] = {\n \tN_(\"git receive-pack <git-dir>\"),\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 0458db9cad..07a9d37275 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -6,7 +6,6 @@\n #include \"repository.h\"\n #include \"string-list.h\"\n #include \"rerere.h\"\n-#include \"wrapper.h\"\n #include \"xdiff/xdiff.h\"\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\ndiff --git a/builtin/unpack-file.c b/builtin/unpack-file.c\nindex 6842a6c499..c129e2bb6c 100644\n--- a/builtin/unpack-file.c\n+++ b/builtin/unpack-file.c\n@@ -3,7 +3,6 @@\n #include \"hex.h\"\n #include \"object-name.h\"\n #include \"object-store-ll.h\"\n-#include \"wrapper.h\"\n \n static char *create_temp_file(struct object_id *oid)\n {\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 4780b3b5f5..cc6d143ad0 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -24,7 +24,6 @@\n #include \"submodule.h\"\n #include \"utf8.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n #include \"quote.h\"\n \n #define BUILTIN_WORKTREE_ADD_USAGE \\\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex e2f71db0f6..fec6816259 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -17,7 +17,6 @@\n #include \"packfile.h\"\n #include \"object-file.h\"\n #include \"object-store-ll.h\"\n-#include \"wrapper.h\"\n \n static int odb_transaction_nesting;\n \ndiff --git a/combine-diff.c b/combine-diff.c\nindex 11e9d7494a..f90f442482 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -17,7 +17,6 @@\n #include \"userdiff.h\"\n #include \"oid-array.h\"\n #include \"revision.h\"\n-#include \"wrapper.h\"\n \n static int compare_paths(const struct combine_diff_path *one,\n \t\t\t  const struct diff_filespec *two)\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 8f43eb12d4..55d288cb3b 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -26,7 +26,6 @@\n #include \"trace2.h\"\n #include \"tree.h\"\n #include \"chunk-format.h\"\n-#include \"wrapper.h\"\n \n void git_test_write_commit_graph_or_die(void)\n {\ndiff --git a/compat/terminal.c b/compat/terminal.c\nindex d87e321189..83d95e8656 100644\n--- a/compat/terminal.c\n+++ b/compat/terminal.c\n@@ -6,7 +6,6 @@\n #include \"run-command.h\"\n #include \"string-list.h\"\n #include \"hashmap.h\"\n-#include \"wrapper.h\"\n \n #if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE)\n \ndiff --git a/config.c b/config.c\nindex e08e2332a6..cc97c18141 100644\n--- a/config.c\n+++ b/config.c\n@@ -39,7 +39,6 @@\n #include \"wildmatch.h\"\n #include \"worktree.h\"\n #include \"ws.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n struct config_source {\ndiff --git a/convert.c b/convert.c\nindex 3d8325d49e..4aef90a7b6 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -16,7 +16,6 @@\n #include \"trace.h\"\n #include \"utf8.h\"\n #include \"merge-ll.h\"\n-#include \"wrapper.h\"\n \n /*\n  * convert.c - convert a file when checking it out and checking it in.\ndiff --git a/copy.c b/copy.c\nindex 882c79cffb..23d84c6c1d 100644\n--- a/copy.c\n+++ b/copy.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"copy.h\"\n #include \"path.h\"\n-#include \"wrapper.h\"\n \n int copy_fd(int ifd, int ofd)\n {\ndiff --git a/csum-file.c b/csum-file.c\nindex daf9b06dff..cd01713244 100644\n--- a/csum-file.c\n+++ b/csum-file.c\n@@ -11,7 +11,6 @@\n #include \"progress.h\"\n #include \"csum-file.h\"\n #include \"hash.h\"\n-#include \"wrapper.h\"\n \n static void verify_buffer_or_die(struct hashfile *f,\n \t\t\t\t const void *buf,\ndiff --git a/daemon.c b/daemon.c\nindex 7139cc201d..3722edf46c 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -10,7 +10,6 @@\n #include \"setup.h\"\n #include \"strbuf.h\"\n #include \"string-list.h\"\n-#include \"wrapper.h\"\n \n #ifdef NO_INITGROUPS\n #define initgroups(x, y) (0) /* nothing */\ndiff --git a/diff.c b/diff.c\nindex 351d1d0591..10c8597ba0 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -43,7 +43,6 @@\n #include \"setup.h\"\n #include \"strmap.h\"\n #include \"ws.h\"\n-#include \"wrapper.h\"\n \n #ifdef NO_FAST_WORKING_DIRECTORY\n #define FAST_WORKING_DIRECTORY 0\ndiff --git a/dir.c b/dir.c\nindex 3acac7beb1..d270a1be36 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -32,7 +32,6 @@\n #include \"symlinks.h\"\n #include \"trace2.h\"\n #include \"tree.h\"\n-#include \"wrapper.h\"\n \n /*\n  * Tells read_directory_recursive how a file or directory should be treated.\ndiff --git a/editor.c b/editor.c\nindex 38c5dbbb79..b67b802ddf 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -11,7 +11,6 @@\n #include \"strvec.h\"\n #include \"run-command.h\"\n #include \"sigchain.h\"\n-#include \"wrapper.h\"\n \n #ifndef DEFAULT_EDITOR\n #define DEFAULT_EDITOR \"vi\"\ndiff --git a/entry.c b/entry.c\nindex f9a7c726a4..43767f9043 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -14,7 +14,6 @@\n #include \"fsmonitor.h\"\n #include \"entry.h\"\n #include \"parallel-checkout.h\"\n-#include \"wrapper.h\"\n \n static void create_directories(const char *path, int path_len,\n \t\t\t       const struct checkout *state)\ndiff --git a/environment.c b/environment.c\nindex 5e9b331279..73b5b59ecf 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -28,7 +28,6 @@\n #include \"setup.h\"\n #include \"shallow.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n int trust_executable_bit = 1;\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex a432eacab9..84a24ff9b1 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -34,7 +34,6 @@\n #include \"commit-graph.h\"\n #include \"sigchain.h\"\n #include \"mergesort.h\"\n-#include \"wrapper.h\"\n \n static int transfer_unpack_limit = -1;\n static int fetch_unpack_limit = -1;\ndiff --git a/gpg-interface.c b/gpg-interface.c\nindex 6a3817bbca..206ffdd79e 100644\n--- a/gpg-interface.c\n+++ b/gpg-interface.c\n@@ -12,7 +12,6 @@\n #include \"sigchain.h\"\n #include \"tempfile.h\"\n #include \"alias.h\"\n-#include \"wrapper.h\"\n #include \"environment.h\"\n \n static int git_gpg_config(const char *, const char *, void *);\ndiff --git a/grep.c b/grep.c\nindex ebcd647478..a3cc8224db 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -12,7 +12,6 @@\n #include \"commit.h\"\n #include \"quote.h\"\n #include \"help.h\"\n-#include \"wrapper.h\"\n \n static int grep_source_load(struct grep_source *gs);\n static int grep_source_is_binary(struct grep_source *gs,\ndiff --git a/http-backend.c b/http-backend.c\nindex 895fac35f7..01d0405597 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -19,7 +19,6 @@\n #include \"object-store-ll.h\"\n #include \"protocol.h\"\n #include \"date.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n static const char content_type[] = \"Content-Type\";\ndiff --git a/imap-send.c b/imap-send.c\nindex d1f312a07c..ef0b6a3f03 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -30,7 +30,6 @@\n #include \"parse-options.h\"\n #include \"setup.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)\n typedef void *SSL;\n #endif\ndiff --git a/merge-ll.c b/merge-ll.c\nindex 740b8c6bfd..ad26d7e260 100644\n--- a/merge-ll.c\n+++ b/merge-ll.c\n@@ -13,7 +13,6 @@\n #include \"merge-ll.h\"\n #include \"quote.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n struct ll_merge_driver;\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 43f6b2d036..6a4081bb0f 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -38,7 +38,6 @@\n #include \"tag.h\"\n #include \"tree-walk.h\"\n #include \"unpack-trees.h\"\n-#include \"wrapper.h\"\n #include \"xdiff-interface.h\"\n \n struct merge_options_internal {\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 071947894e..8799b522a5 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -20,7 +20,6 @@\n #include \"trace.h\"\n #include \"notes-utils.h\"\n #include \"commit-reach.h\"\n-#include \"wrapper.h\"\n \n struct notes_merge_pair {\n \tstruct object_id obj, base, local, remote;\ndiff --git a/object-file.c b/object-file.c\nindex 8d87720dd5..527b740018 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -44,7 +44,6 @@\n #include \"setup.h\"\n #include \"submodule.h\"\n #include \"fsck.h\"\n-#include \"wrapper.h\"\n \n /* The maximum size for an object header. */\n #define MAX_HEADER_LEN 32\ndiff --git a/pack-write.c b/pack-write.c\nindex af48813a9b..b19ddf15b2 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -12,7 +12,6 @@\n #include \"pack-revindex.h\"\n #include \"path.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n void reset_pack_idx_option(struct pack_idx_option *opts)\n {\ndiff --git a/packfile.c b/packfile.c\nindex c60aeb05ec..7683a6dbea 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -24,7 +24,6 @@\n #include \"commit-graph.h\"\n #include \"pack-revindex.h\"\n #include \"promisor-remote.h\"\n-#include \"wrapper.h\"\n \n char *odb_pack_name(struct strbuf *buf,\n \t\t    const unsigned char *hash,\ndiff --git a/parallel-checkout.c b/parallel-checkout.c\nindex 602fbf19d3..8637723461 100644\n--- a/parallel-checkout.c\n+++ b/parallel-checkout.c\n@@ -15,7 +15,6 @@\n #include \"symlinks.h\"\n #include \"thread-utils.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n struct pc_worker {\n \tstruct child_process cp;\ndiff --git a/path.c b/path.c\nindex 044a50bad0..67e2690efe 100644\n--- a/path.c\n+++ b/path.c\n@@ -18,7 +18,6 @@\n #include \"object-store-ll.h\"\n #include \"lockfile.h\"\n #include \"exec-cmd.h\"\n-#include \"wrapper.h\"\n \n static int get_st_mode_bits(const char *path, int *mode)\n {\ndiff --git a/pkt-line.c b/pkt-line.c\nindex 62b4208b66..6e4166132d 100644\n--- a/pkt-line.c\n+++ b/pkt-line.c\n@@ -5,7 +5,6 @@\n #include \"hex.h\"\n #include \"run-command.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n char packet_buffer[LARGE_PACKET_MAX];\ndiff --git a/read-cache.c b/read-cache.c\nindex b9a995e5a1..140b4f96a0 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -46,7 +46,6 @@\n #include \"csum-file.h\"\n #include \"promisor-remote.h\"\n #include \"hook.h\"\n-#include \"wrapper.h\"\n \n /* Mask for the name length in ce_flags in the on-disk index */\n \ndiff --git a/rebase-interactive.c b/rebase-interactive.c\nindex f286404d4b..d9718409b3 100644\n--- a/rebase-interactive.c\n+++ b/rebase-interactive.c\n@@ -11,7 +11,6 @@\n #include \"config.h\"\n #include \"dir.h\"\n #include \"object-name.h\"\n-#include \"wrapper.h\"\n \n static const char edit_todo_list_advice[] =\n N_(\"You can fix this with 'git rebase --edit-todo' \"\ndiff --git a/refs.c b/refs.c\nindex 3065e514fd..1cba800add 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -30,7 +30,6 @@\n #include \"date.h\"\n #include \"commit.h\"\n #include \"wildmatch.h\"\n-#include \"wrapper.h\"\n \n /*\n  * List of all available backends\ndiff --git a/rerere.c b/rerere.c\nindex e2b8597f88..4227c9612a 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -20,7 +20,6 @@\n #include \"object-store-ll.h\"\n #include \"hash-lookup.h\"\n #include \"strmap.h\"\n-#include \"wrapper.h\"\n \n #define RESOLVED 0\n #define PUNTED 1\ndiff --git a/send-pack.c b/send-pack.c\nindex 9510bef856..89aca9d829 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -15,7 +15,6 @@\n #include \"quote.h\"\n #include \"transport.h\"\n #include \"version.h\"\n-#include \"wrapper.h\"\n #include \"oid-array.h\"\n #include \"gpg-interface.h\"\n #include \"shallow.h\"\ndiff --git a/sequencer.c b/sequencer.c\nindex 6a5498281e..5891466d91 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -49,7 +49,6 @@\n #include \"rebase-interactive.h\"\n #include \"reset.h\"\n #include \"branch.h\"\n-#include \"wrapper.h\"\n \n #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n \ndiff --git a/server-info.c b/server-info.c\nindex 382e481a2b..f350713ecf 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -14,7 +14,6 @@\n #include \"object-store-ll.h\"\n #include \"server-info.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n struct update_info_ctx {\n \tFILE *cur_fp;\ndiff --git a/setup.c b/setup.c\nindex 3c383c972c..1b2f16229b 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -17,7 +17,6 @@\n #include \"quote.h\"\n #include \"trace2.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n \n static int inside_git_dir = -1;\n static int inside_work_tree = -1;\ndiff --git a/shallow.c b/shallow.c\nindex f3ef94d4c9..2fad3504b7 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -20,7 +20,6 @@\n #include \"shallow.h\"\n #include \"statinfo.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n \n void set_alternate_shallow_file(struct repository *r, const char *path, int override)\n {\ndiff --git a/strbuf.c b/strbuf.c\nindex 37fd5247b3..77e205d0be 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -7,7 +7,6 @@\n #include \"string-list.h\"\n #include \"utf8.h\"\n #include \"date.h\"\n-#include \"wrapper.h\"\n \n int starts_with(const char *str, const char *prefix)\n {\ndiff --git a/streaming.c b/streaming.c\nindex 49791ab958..10adf625b2 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -10,7 +10,6 @@\n #include \"object-store-ll.h\"\n #include \"replace-object.h\"\n #include \"packfile.h\"\n-#include \"wrapper.h\"\n \n typedef int (*open_istream_fn)(struct git_istream *,\n \t\t\t       struct repository *,\ndiff --git a/t/helper/test-delta.c b/t/helper/test-delta.c\nindex e7d134ec25..6bc787a474 100644\n--- a/t/helper/test-delta.c\n+++ b/t/helper/test-delta.c\n@@ -11,7 +11,6 @@\n #include \"test-tool.h\"\n #include \"git-compat-util.h\"\n #include \"delta.h\"\n-#include \"wrapper.h\"\n \n static const char usage_str[] =\n \t\"test-tool delta (-d|-p) <from_file> <data_file> <out_file>\";\ndiff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c\nindex 58d1dc5fc8..8280984d08 100644\n--- a/t/helper/test-fsmonitor-client.c\n+++ b/t/helper/test-fsmonitor-client.c\n@@ -11,7 +11,6 @@\n #include \"setup.h\"\n #include \"thread-utils.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n #ifndef HAVE_FSMONITOR_DAEMON_BACKEND\n int cmd__fsmonitor_client(int argc UNUSED, const char **argv UNUSED)\ndiff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c\nindex 56c2d25f35..1acd362346 100644\n--- a/t/helper/test-read-cache.c\n+++ b/t/helper/test-read-cache.c\n@@ -4,7 +4,6 @@\n #include \"read-cache-ll.h\"\n #include \"repository.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n int cmd__read_cache(int argc, const char **argv)\n {\ndiff --git a/tag.c b/tag.c\nindex c356d58890..c1537e30cb 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -11,7 +11,6 @@\n #include \"gpg-interface.h\"\n #include \"hex.h\"\n #include \"packfile.h\"\n-#include \"wrapper.h\"\n \n const char *tag_type = \"tag\";\n \ndiff --git a/tempfile.c b/tempfile.c\nindex 6c88a63b42..ecdebf1afb 100644\n--- a/tempfile.c\n+++ b/tempfile.c\n@@ -47,7 +47,6 @@\n #include \"path.h\"\n #include \"tempfile.h\"\n #include \"sigchain.h\"\n-#include \"wrapper.h\"\n \n static VOLATILE_LIST_HEAD(tempfile_list);\n \ndiff --git a/trace.c b/trace.c\nindex 592c141d78..971a68abe8 100644\n--- a/trace.c\n+++ b/trace.c\n@@ -27,7 +27,6 @@\n #include \"quote.h\"\n #include \"setup.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n \n struct trace_key trace_default_key = { \"GIT_TRACE\", 0, 0, 0 };\n struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE);\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 5c0bc6a896..49811ef176 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -19,7 +19,6 @@\n #include \"refspec.h\"\n #include \"transport-internal.h\"\n #include \"protocol.h\"\n-#include \"wrapper.h\"\n \n static int debug;\n \ndiff --git a/transport.c b/transport.c\nindex 4dc187a388..0a5794a944 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -30,7 +30,6 @@\n #include \"object-store-ll.h\"\n #include \"color.h\"\n #include \"bundle-uri.h\"\n-#include \"wrapper.h\"\n \n static int transport_use_color = -1;\n static char transport_colors[][COLOR_MAXLEN] = {\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 3a176a7209..3dc92d5aac 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -32,7 +32,6 @@\n #include \"commit-graph.h\"\n #include \"commit-reach.h\"\n #include \"shallow.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n /* Remember to update object flag allocation in object.h */\ndiff --git a/usage.c b/usage.c\nindex 46d99f8bd4..09f0ed509b 100644\n--- a/usage.c\n+++ b/usage.c\n@@ -6,7 +6,6 @@\n #include \"git-compat-util.h\"\n #include \"gettext.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n static void vreportf(const char *prefix, const char *err, va_list params)\n {\ndiff --git a/worktree.c b/worktree.c\nindex f9aa371ca7..2018c127ca 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -12,7 +12,6 @@\n #include \"dir.h\"\n #include \"wt-status.h\"\n #include \"config.h\"\n-#include \"wrapper.h\"\n \n void free_worktrees(struct worktree **worktrees)\n {\ndiff --git a/wrapper.c b/wrapper.c\nindex 67f5f5dbe1..22be9812a7 100644\n--- a/wrapper.c\n+++ b/wrapper.c\n@@ -9,7 +9,6 @@\n #include \"repository.h\"\n #include \"strbuf.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n static intmax_t count_fsync_writeout_only;\n static intmax_t count_fsync_hardware_flush;\ndiff --git a/write-or-die.c b/write-or-die.c\nindex cc9e0787a1..d8355c0c3e 100644\n--- a/write-or-die.c\n+++ b/write-or-die.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"config.h\"\n #include \"run-command.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n /*\n-- \n2.40.1.698.g37aff9b760-goog\n\n"},{"id":"477675","messageId":"20230523192949.1271671-7-calvinwan@google.com","threadId":"59752","inReplyTo":"20230523192749.1270992-1-calvinwan@google.com","subject":"[PATCH v2 7/7] common: move alloc macros to common.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-05-23T19:29:49Z","receivedAt":"2023-05-23T19:30:50Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"alloc_nr, ALLOC_GROW, and ALLOC_GROW_BY are commonly used macros for\ndynamic array allocation. Moving these macros to common.h focuses\nalloc.[ch] to allocation for Git objects and additionally allows us to\nremove inclusions to alloc.h from files that solely used the above\nmacros.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n add-patch.c                        |  1 -\n alias.c                            |  1 -\n alloc.h                            | 75 ------------------------------\n apply.c                            |  1 -\n archive-tar.c                      |  1 -\n archive.c                          |  1 -\n attr.c                             |  1 -\n builtin/blame.c                    |  1 -\n builtin/cat-file.c                 |  1 -\n builtin/checkout--worker.c         |  1 -\n builtin/config.c                   |  1 -\n builtin/credential-cache--daemon.c |  1 -\n builtin/fetch-pack.c               |  1 -\n builtin/fsmonitor--daemon.c        |  1 -\n builtin/grep.c                     |  1 -\n builtin/index-pack.c               |  1 -\n builtin/log.c                      |  1 -\n builtin/merge.c                    |  1 -\n builtin/mktree.c                   |  1 -\n builtin/mv.c                       |  1 -\n builtin/name-rev.c                 |  1 -\n builtin/pack-objects.c             |  1 -\n builtin/repack.c                   |  1 -\n builtin/rev-parse.c                |  1 -\n builtin/revert.c                   |  1 -\n builtin/rm.c                       |  1 -\n builtin/submodule--helper.c        |  1 -\n bulk-checkin.c                     |  1 -\n cache-tree.c                       |  1 -\n chunk-format.c                     |  1 -\n commit-reach.c                     |  1 -\n common.h                           | 75 ++++++++++++++++++++++++++++++\n config.c                           |  1 -\n daemon.c                           |  1 -\n delta-islands.c                    |  1 -\n diff.c                             |  1 -\n diffcore-rename.c                  |  1 -\n dir-iterator.c                     |  1 -\n dir.c                              |  1 -\n ewah/bitmap.c                      |  1 -\n ewah/ewah_bitmap.c                 |  1 -\n fetch-pack.c                       |  1 -\n fmt-merge-msg.c                    |  1 -\n fsck.c                             |  1 -\n help.c                             |  1 -\n http-backend.c                     |  1 -\n line-log.c                         |  1 -\n list-objects-filter-options.c      |  1 -\n list-objects-filter.c              |  1 -\n midx.c                             |  1 -\n object-file.c                      |  1 -\n oid-array.c                        |  1 -\n oidtree.c                          |  1 -\n pack-bitmap-write.c                |  1 -\n pack-bitmap.c                      |  1 -\n pack-objects.c                     |  1 -\n packfile.c                         |  1 -\n parallel-checkout.c                |  1 -\n pretty.c                           |  1 -\n prio-queue.c                       |  1 -\n quote.c                            |  1 -\n read-cache.c                       |  1 -\n ref-filter.c                       |  1 -\n reflog-walk.c                      |  1 -\n refs.c                             |  1 -\n refspec.c                          |  1 -\n remote-curl.c                      |  1 -\n remote.c                           |  1 -\n rerere.c                           |  1 -\n revision.c                         |  1 -\n sequencer.c                        |  1 -\n server-info.c                      |  1 -\n shallow.c                          |  1 -\n sigchain.c                         |  1 -\n sparse-index.c                     |  1 -\n split-index.c                      |  1 -\n strbuf.c                           |  1 -\n string-list.c                      |  1 -\n strvec.c                           |  1 -\n submodule-config.c                 |  1 -\n submodule.c                        |  1 -\n t/helper/test-reach.c              |  1 -\n trace2/tr2_tls.c                   |  1 -\n trailer.c                          |  1 -\n transport.c                        |  1 -\n tree-walk.c                        |  1 -\n userdiff.c                         |  1 -\n worktree.c                         |  1 -\n 88 files changed, 75 insertions(+), 161 deletions(-)\n\ndiff --git a/add-patch.c b/add-patch.c\nindex ba629add62..bfe19876cd 100644\n--- a/add-patch.c\n+++ b/add-patch.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"add-interactive.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"editor.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/alias.c b/alias.c\nindex 54a1a23d2c..38e1339936 100644\n--- a/alias.c\n+++ b/alias.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"alias.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n #include \"strbuf.h\"\ndiff --git a/alloc.h b/alloc.h\nindex 4312db4bd0..3f4a0ad310 100644\n--- a/alloc.h\n+++ b/alloc.h\n@@ -17,79 +17,4 @@ void *alloc_object_node(struct repository *r);\n struct alloc_state *allocate_alloc_state(void);\n void clear_alloc_state(struct alloc_state *s);\n \n-#define alloc_nr(x) (((x)+16)*3/2)\n-\n-/**\n- * Dynamically growing an array using realloc() is error prone and boring.\n- *\n- * Define your array with:\n- *\n- * - a pointer (`item`) that points at the array, initialized to `NULL`\n- *   (although please name the variable based on its contents, not on its\n- *   type);\n- *\n- * - an integer variable (`alloc`) that keeps track of how big the current\n- *   allocation is, initialized to `0`;\n- *\n- * - another integer variable (`nr`) to keep track of how many elements the\n- *   array currently has, initialized to `0`.\n- *\n- * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,\n- * alloc)`.  This ensures that the array can hold at least `n` elements by\n- * calling `realloc(3)` and adjusting `alloc` variable.\n- *\n- * ------------\n- * sometype *item;\n- * size_t nr;\n- * size_t alloc\n- *\n- * for (i = 0; i < nr; i++)\n- * \tif (we like item[i] already)\n- * \t\treturn;\n- *\n- * // we did not like any existing one, so add one\n- * ALLOC_GROW(item, nr + 1, alloc);\n- * item[nr++] = value you like;\n- * ------------\n- *\n- * You are responsible for updating the `nr` variable.\n- *\n- * If you need to specify the number of elements to allocate explicitly\n- * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.\n- *\n- * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some\n- * added niceties.\n- *\n- * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.\n- */\n-#define ALLOC_GROW(x, nr, alloc) \\\n-\tdo { \\\n-\t\tif ((nr) > alloc) { \\\n-\t\t\tif (alloc_nr(alloc) < (nr)) \\\n-\t\t\t\talloc = (nr); \\\n-\t\t\telse \\\n-\t\t\t\talloc = alloc_nr(alloc); \\\n-\t\t\tREALLOC_ARRAY(x, alloc); \\\n-\t\t} \\\n-\t} while (0)\n-\n-/*\n- * Similar to ALLOC_GROW but handles updating of the nr value and\n- * zeroing the bytes of the newly-grown array elements.\n- *\n- * DO NOT USE any expression with side-effect for any of the\n- * arguments.\n- */\n-#define ALLOC_GROW_BY(x, nr, increase, alloc) \\\n-\tdo { \\\n-\t\tif (increase) { \\\n-\t\t\tsize_t new_nr = nr + (increase); \\\n-\t\t\tif (new_nr < nr) \\\n-\t\t\t\tBUG(\"negative growth in ALLOC_GROW_BY\"); \\\n-\t\t\tALLOC_GROW(x, new_nr, alloc); \\\n-\t\t\tmemset((x) + nr, 0, sizeof(*(x)) * (increase)); \\\n-\t\t\tnr = new_nr; \\\n-\t\t} \\\n-\t} while (0)\n-\n #endif\ndiff --git a/apply.c b/apply.c\nindex 99c2a91de7..6b9ce54f7d 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -9,7 +9,6 @@\n \n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"base85.h\"\n #include \"config.h\"\n #include \"object-store-ll.h\"\ndiff --git a/archive-tar.c b/archive-tar.c\nindex fc06ff4c5d..704bf0612e 100644\n--- a/archive-tar.c\n+++ b/archive-tar.c\n@@ -2,7 +2,6 @@\n  * Copyright (c) 2005, 2006 Rene Scharfe\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n #include \"git-zlib.h\"\ndiff --git a/archive.c b/archive.c\nindex 1817cca9f4..ca11db185b 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"environment.h\"\ndiff --git a/attr.c b/attr.c\nindex 7d39ac4a29..e9c81b6e07 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -7,7 +7,6 @@\n  */\n \n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"exec-cmd.h\"\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex e811e7fbfb..9a3f9facea 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -6,7 +6,6 @@\n  */\n \n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"color.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 8ce5492d55..6266861365 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -5,7 +5,6 @@\n  */\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"diff.h\"\ndiff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c\nindex c655dc4b13..6b62b5375b 100644\n--- a/builtin/checkout--worker.c\n+++ b/builtin/checkout--worker.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"entry.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/config.c b/builtin/config.c\nindex c01f136a2b..49b82b5323 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -1,6 +1,5 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"color.h\"\n #include \"editor.h\"\ndiff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c\nindex 756c5f02ae..db8c49605c 100644\n--- a/builtin/credential-cache--daemon.c\n+++ b/builtin/credential-cache--daemon.c\n@@ -1,6 +1,5 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"object-file.h\"\n #include \"parse-options.h\"\ndiff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c\nindex 3ba0fe5a39..44c05ee86c 100644\n--- a/builtin/fetch-pack.c\n+++ b/builtin/fetch-pack.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"object-file.h\"\ndiff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c\nindex 74d1d6a585..0194f1e263 100644\n--- a/builtin/fsmonitor--daemon.c\n+++ b/builtin/fsmonitor--daemon.c\n@@ -1,6 +1,5 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 72e70b3a48..c60cf2007f 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -4,7 +4,6 @@\n  * Copyright (c) 2006 Junio C Hamano\n  */\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"repository.h\"\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex f58f9db69d..57812a276a 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"delta.h\"\n #include \"environment.h\"\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 486548c57e..c1cf36c38e 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -6,7 +6,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 2f2f0a0b4c..059f3ecb84 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -10,7 +10,6 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"editor.h\"\n #include \"environment.h\"\ndiff --git a/builtin/mktree.c b/builtin/mktree.c\nindex 0eea810c7e..9a22d4e277 100644\n--- a/builtin/mktree.c\n+++ b/builtin/mktree.c\n@@ -4,7 +4,6 @@\n  * Copyright (c) Junio C Hamano, 2006, 2009\n  */\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"quote.h\"\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex ae462bd7d4..fa84fcb20d 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -7,7 +7,6 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/name-rev.c b/builtin/name-rev.c\nindex c3b722b36f..c706fa3720 100644\n--- a/builtin/name-rev.c\n+++ b/builtin/name-rev.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 6409c07c7d..869a21b38f 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 6c896c9c80..60ae514fd5 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"dir.h\"\n #include \"environment.h\"\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 4a219ea93b..161077aa79 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -6,7 +6,6 @@\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"commit.h\"\n #include \"environment.h\"\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex b3c6d75a1d..66d12e8c6f 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"builtin.h\"\n #include \"parse-options.h\"\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex 463eeabcea..dff819ae50 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -5,7 +5,6 @@\n  */\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"advice.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex baf6ff88c3..e22cf4e4ee 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1,7 +1,6 @@\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex fec6816259..73bff3a23d 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -2,7 +2,6 @@\n  * Copyright (c) 2011, Google Inc.\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"bulk-checkin.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/cache-tree.c b/cache-tree.c\nindex 84d7491420..641427ed41 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"hex.h\"\n #include \"lockfile.h\"\ndiff --git a/chunk-format.c b/chunk-format.c\nindex e7d613c907..140dfa0dcc 100644\n--- a/chunk-format.c\n+++ b/chunk-format.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"chunk-format.h\"\n #include \"csum-file.h\"\n #include \"gettext.h\"\ndiff --git a/commit-reach.c b/commit-reach.c\nindex 70bde8af05..812bc6bf92 100644\n--- a/commit-reach.c\n+++ b/commit-reach.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"commit-graph.h\"\n #include \"decorate.h\"\ndiff --git a/common.h b/common.h\nindex e3b673847d..b0c68eb2a2 100644\n--- a/common.h\n+++ b/common.h\n@@ -199,6 +199,81 @@ static inline int cast_size_t_to_int(size_t a)\n  */\n #define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)\n \n+#define alloc_nr(x) (((x)+16)*3/2)\n+\n+/**\n+ * Dynamically growing an array using realloc() is error prone and boring.\n+ *\n+ * Define your array with:\n+ *\n+ * - a pointer (`item`) that points at the array, initialized to `NULL`\n+ *   (although please name the variable based on its contents, not on its\n+ *   type);\n+ *\n+ * - an integer variable (`alloc`) that keeps track of how big the current\n+ *   allocation is, initialized to `0`;\n+ *\n+ * - another integer variable (`nr`) to keep track of how many elements the\n+ *   array currently has, initialized to `0`.\n+ *\n+ * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,\n+ * alloc)`.  This ensures that the array can hold at least `n` elements by\n+ * calling `realloc(3)` and adjusting `alloc` variable.\n+ *\n+ * ------------\n+ * sometype *item;\n+ * size_t nr;\n+ * size_t alloc\n+ *\n+ * for (i = 0; i < nr; i++)\n+ * \tif (we like item[i] already)\n+ * \t\treturn;\n+ *\n+ * // we did not like any existing one, so add one\n+ * ALLOC_GROW(item, nr + 1, alloc);\n+ * item[nr++] = value you like;\n+ * ------------\n+ *\n+ * You are responsible for updating the `nr` variable.\n+ *\n+ * If you need to specify the number of elements to allocate explicitly\n+ * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.\n+ *\n+ * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some\n+ * added niceties.\n+ *\n+ * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.\n+ */\n+#define ALLOC_GROW(x, nr, alloc) \\\n+\tdo { \\\n+\t\tif ((nr) > alloc) { \\\n+\t\t\tif (alloc_nr(alloc) < (nr)) \\\n+\t\t\t\talloc = (nr); \\\n+\t\t\telse \\\n+\t\t\t\talloc = alloc_nr(alloc); \\\n+\t\t\tREALLOC_ARRAY(x, alloc); \\\n+\t\t} \\\n+\t} while (0)\n+\n+/*\n+ * Similar to ALLOC_GROW but handles updating of the nr value and\n+ * zeroing the bytes of the newly-grown array elements.\n+ *\n+ * DO NOT USE any expression with side-effect for any of the\n+ * arguments.\n+ */\n+#define ALLOC_GROW_BY(x, nr, increase, alloc) \\\n+\tdo { \\\n+\t\tif (increase) { \\\n+\t\t\tsize_t new_nr = nr + (increase); \\\n+\t\t\tif (new_nr < nr) \\\n+\t\t\t\tBUG(\"negative growth in ALLOC_GROW_BY\"); \\\n+\t\t\tALLOC_GROW(x, new_nr, alloc); \\\n+\t\t\tmemset((x) + nr, 0, sizeof(*(x)) * (increase)); \\\n+\t\t\tnr = new_nr; \\\n+\t\t} \\\n+\t} while (0)\n+\n #define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))\n #define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))\n #define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))\ndiff --git a/config.c b/config.c\nindex cc97c18141..09851a6909 100644\n--- a/config.c\n+++ b/config.c\n@@ -8,7 +8,6 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"date.h\"\n #include \"branch.h\"\n #include \"config.h\"\ndiff --git a/daemon.c b/daemon.c\nindex 3722edf46c..1edc9a8510 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"path.h\"\ndiff --git a/delta-islands.c b/delta-islands.c\nindex c824a5f6a4..332f0f7c45 100644\n--- a/delta-islands.c\n+++ b/delta-islands.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"attr.h\"\n #include \"object.h\"\n #include \"blob.h\"\ndiff --git a/diff.c b/diff.c\nindex 10c8597ba0..8709d87b86 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3,7 +3,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"base85.h\"\n #include \"config.h\"\n #include \"convert.h\"\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex 926b554bd5..5a6e2bcac7 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -3,7 +3,6 @@\n  * Copyright (C) 2005 Junio C Hamano\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n #include \"object-store-ll.h\"\ndiff --git a/dir-iterator.c b/dir-iterator.c\nindex fb7c47f0e8..278b04243a 100644\n--- a/dir-iterator.c\n+++ b/dir-iterator.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"iterator.h\"\n #include \"dir-iterator.h\"\ndiff --git a/dir.c b/dir.c\nindex d270a1be36..c9dc69fc24 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -7,7 +7,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"dir.h\"\ndiff --git a/ewah/bitmap.c b/ewah/bitmap.c\nindex 12d6aa398e..7b525b1ecd 100644\n--- a/ewah/bitmap.c\n+++ b/ewah/bitmap.c\n@@ -17,7 +17,6 @@\n  * along with this program; if not, see <http://www.gnu.org/licenses/>.\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"ewok.h\"\n \n #define EWAH_MASK(x) ((eword_t)1 << (x % BITS_IN_EWORD))\ndiff --git a/ewah/ewah_bitmap.c b/ewah/ewah_bitmap.c\nindex c6d4ffc87c..8785cbc54a 100644\n--- a/ewah/ewah_bitmap.c\n+++ b/ewah/ewah_bitmap.c\n@@ -17,7 +17,6 @@\n  * along with this program; if not, see <http://www.gnu.org/licenses/>.\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"ewok.h\"\n #include \"ewok_rlw.h\"\n \ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 84a24ff9b1..6198f3adaf 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"repository.h\"\n #include \"config.h\"\n #include \"date.h\"\ndiff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\nindex ac9c1b9c6c..ff8884eecd 100644\n--- a/fmt-merge-msg.c\n+++ b/fmt-merge-msg.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"refs.h\"\ndiff --git a/fsck.c b/fsck.c\nindex a219d6f2c0..2035c4e00b 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"date.h\"\n #include \"dir.h\"\n #include \"hex.h\"\ndiff --git a/help.c b/help.c\nindex 5d7637dce9..c81d43a5fa 100644\n--- a/help.c\n+++ b/help.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"builtin.h\"\n #include \"exec-cmd.h\"\ndiff --git a/http-backend.c b/http-backend.c\nindex 01d0405597..ff07b87e64 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"git-zlib.h\"\ndiff --git a/line-log.c b/line-log.c\nindex 2eff914bf3..790ab73212 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"line-range.h\"\n #include \"hex.h\"\n #include \"tag.h\"\ndiff --git a/list-objects-filter-options.c b/list-objects-filter-options.c\nindex 2a3b7881af..8a08b7af49 100644\n--- a/list-objects-filter-options.c\n+++ b/list-objects-filter-options.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"config.h\"\n #include \"gettext.h\"\ndiff --git a/list-objects-filter.c b/list-objects-filter.c\nindex e075a66c99..9327ccd505 100644\n--- a/list-objects-filter.c\n+++ b/list-objects-filter.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/midx.c b/midx.c\nindex db459e448b..3a16acabbc 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"csum-file.h\"\n #include \"dir.h\"\ndiff --git a/object-file.c b/object-file.c\nindex 527b740018..5ebe1b00c5 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -8,7 +8,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"environment.h\"\ndiff --git a/oid-array.c b/oid-array.c\nindex e8228c777b..8e4717746c 100644\n--- a/oid-array.c\n+++ b/oid-array.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"oid-array.h\"\n #include \"hash-lookup.h\"\n \ndiff --git a/oidtree.c b/oidtree.c\nindex 7d57b7b19e..daef175dc7 100644\n--- a/oidtree.c\n+++ b/oidtree.c\n@@ -4,7 +4,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"oidtree.h\"\n-#include \"alloc.h\"\n #include \"hash.h\"\n \n struct oidtree_iter_data {\ndiff --git a/pack-bitmap-write.c b/pack-bitmap-write.c\nindex d86f4e739a..f6757c3cbf 100644\n--- a/pack-bitmap-write.c\n+++ b/pack-bitmap-write.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex 07dda2b22e..1ff813a5ba 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/pack-objects.c b/pack-objects.c\nindex ccab09fe65..1b8052bece 100644\n--- a/pack-objects.c\n+++ b/pack-objects.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"object.h\"\n #include \"pack.h\"\n #include \"pack-objects.h\"\ndiff --git a/packfile.c b/packfile.c\nindex 7683a6dbea..0f80c8ba1f 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/parallel-checkout.c b/parallel-checkout.c\nindex 8637723461..b5a714c711 100644\n--- a/parallel-checkout.c\n+++ b/parallel-checkout.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"entry.h\"\n #include \"gettext.h\"\ndiff --git a/pretty.c b/pretty.c\nindex d4bc4b0286..c417dcbf72 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"commit.h\"\n #include \"environment.h\"\ndiff --git a/prio-queue.c b/prio-queue.c\nindex dc2476be53..450775a374 100644\n--- a/prio-queue.c\n+++ b/prio-queue.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"prio-queue.h\"\n \n static inline int compare(struct prio_queue *queue, int i, int j)\ndiff --git a/quote.c b/quote.c\nindex 43c739671e..3c05194496 100644\n--- a/quote.c\n+++ b/quote.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"path.h\"\n #include \"quote.h\"\n #include \"strbuf.h\"\ndiff --git a/read-cache.c b/read-cache.c\nindex 140b4f96a0..53d71134e2 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -4,7 +4,6 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"bulk-checkin.h\"\n #include \"config.h\"\n #include \"date.h\"\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 771fa6c133..33d5576968 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"gpg-interface.h\"\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex d337e64431..d216f6f966 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"refs.h\"\n #include \"diff.h\"\ndiff --git a/refs.c b/refs.c\nindex 1cba800add..bf6624adff 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -4,7 +4,6 @@\n \n #include \"git-compat-util.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"hashmap.h\"\ndiff --git a/refspec.c b/refspec.c\nindex 57f6c2aaf9..d60932f4de 100644\n--- a/refspec.c\n+++ b/refspec.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hash.h\"\n #include \"hex.h\"\ndiff --git a/remote-curl.c b/remote-curl.c\nindex acf7b2bb40..8a976a0253 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/remote.c b/remote.c\nindex 6538b6037d..e5e165de1c 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/rerere.c b/rerere.c\nindex 4227c9612a..7070f75014 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"copy.h\"\n #include \"gettext.h\"\ndiff --git a/revision.c b/revision.c\nindex c53e9f84ae..fa219afaad 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/sequencer.c b/sequencer.c\nindex 5891466d91..8f18001dab 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"copy.h\"\n #include \"environment.h\"\ndiff --git a/server-info.c b/server-info.c\nindex f350713ecf..e2fe0f9143 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"environment.h\"\n #include \"hex.h\"\ndiff --git a/shallow.c b/shallow.c\nindex 2fad3504b7..5413719fd4 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"hex.h\"\n #include \"repository.h\"\n #include \"tempfile.h\"\ndiff --git a/sigchain.c b/sigchain.c\nindex ee778c0580..66123bdbab 100644\n--- a/sigchain.c\n+++ b/sigchain.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"sigchain.h\"\n \n #define SIGCHAIN_MAX_SIGNALS 32\ndiff --git a/sparse-index.c b/sparse-index.c\nindex 90d0462256..1fdb07a9e6 100644\n--- a/sparse-index.c\n+++ b/sparse-index.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"name-hash.h\"\ndiff --git a/split-index.c b/split-index.c\nindex 0ee3865a55..8c38687c04 100644\n--- a/split-index.c\n+++ b/split-index.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hash.h\"\n #include \"mem-pool.h\"\ndiff --git a/strbuf.c b/strbuf.c\nindex 77e205d0be..8f64beb2a1 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"path.h\"\ndiff --git a/string-list.c b/string-list.c\nindex 0f8ac117fd..954569f381 100644\n--- a/string-list.c\n+++ b/string-list.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"string-list.h\"\n-#include \"alloc.h\"\n \n void string_list_init_nodup(struct string_list *list)\n {\ndiff --git a/strvec.c b/strvec.c\nindex 17d54b6c3b..89dc9e7e75 100644\n--- a/strvec.c\n+++ b/strvec.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"strvec.h\"\n-#include \"alloc.h\"\n #include \"hex.h\"\n #include \"strbuf.h\"\n \ndiff --git a/submodule-config.c b/submodule-config.c\nindex 8a247b3be0..d39d365f1b 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/submodule.c b/submodule.c\nindex cba36d6080..e7a907bc25 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"repository.h\"\n #include \"config.h\"\n #include \"submodule-config.h\"\ndiff --git a/t/helper/test-reach.c b/t/helper/test-reach.c\nindex ef58f10c2d..3e173399a0 100644\n--- a/t/helper/test-reach.c\n+++ b/t/helper/test-reach.c\n@@ -1,5 +1,4 @@\n #include \"test-tool.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"commit-reach.h\"\n #include \"config.h\"\ndiff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c\nindex 9f46ae12f5..601c9e5036 100644\n--- a/trace2/tr2_tls.c\n+++ b/trace2/tr2_tls.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"thread-utils.h\"\n #include \"trace.h\"\n #include \"trace2/tr2_tls.h\"\ndiff --git a/trailer.c b/trailer.c\nindex a2c3ed6f28..2170e01f6a 100644\n--- a/trailer.c\n+++ b/trailer.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/transport.c b/transport.c\nindex 0a5794a944..219af8fd50 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"hex.h\"\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 42ed86ef58..6c07913f3f 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"tree-walk.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/userdiff.c b/userdiff.c\nindex 664c7c1402..e399543823 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"userdiff.h\"\n #include \"attr.h\"\ndiff --git a/worktree.c b/worktree.c\nindex 2018c127ca..7410dce811 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"path.h\"\n-- \n2.40.1.698.g37aff9b760-goog\n\n"},{"id":"477741","messageId":"20230526210338.2290394-1-jonathantanmy@google.com","threadId":"59752","inReplyTo":"20230523192749.1270992-1-calvinwan@google.com","subject":"Re: [PATCH v2 0/7] git-compat-util cleanups","fromName":"Jonathan Tan","fromEmail":"jonathantanmy@google.com","sentAt":"2023-05-26T21:03:38Z","receivedAt":"2023-05-26T21:03:44Z","isPatch":true,"sender":{"key":"jonathantanmy@fastmail.com","avatar":null},"body":"Calvin Wan <calvinwan@google.com> writes:\n> Changes since v1:\n>  - rebased onto 8afb38ac80f6\n\nI couldn't find this object. Calvin and I resolved this off-list, so I\ncan proceed with the review, but remember to rebase onto a more stable\nbase in version 3.\n \n"},{"id":"477742","messageId":"20230526210633.2290844-1-jonathantanmy@google.com","threadId":"59752","inReplyTo":"20230523192949.1271671-1-calvinwan@google.com","subject":"Re: [PATCH v2 1/7] strbuf.h: move declarations for strbuf.c functions from git-compat-util.h","fromName":"Jonathan Tan","fromEmail":"jonathantanmy@google.com","sentAt":"2023-05-26T21:06:33Z","receivedAt":"2023-05-26T21:06:43Z","isPatch":true,"sender":{"key":"jonathantanmy@fastmail.com","avatar":null},"body":"Calvin Wan <calvinwan@google.com> writes:\n> While functions like starts_with() probably should not belong in the\n> boundaries of the strbuf library, this commit focuses on first splitting\n> out headers from git-compat-util.h.\n> \n> Signed-off-by: Calvin Wan <calvinwan@google.com>\n\nI know we don't follow the 50-character rule for commit message headers\nall the time, but I don't think it's necessary to break it here for\na relatively simple-to-explain change. Maybe \"git-compat-util: move\nstrbuf.c funcs to its header\". Same for the other patches.\n\nThe patch itself looks good.\n \n"},{"id":"477743","messageId":"20230526211911.2291886-1-jonathantanmy@google.com","threadId":"59752","inReplyTo":"20230523192949.1271671-3-calvinwan@google.com","subject":"Re: [PATCH v2 3/7] sane-ctype.h: move sane-ctype macros from git-compat-util.h","fromName":"Jonathan Tan","fromEmail":"jonathantanmy@google.com","sentAt":"2023-05-26T21:19:11Z","receivedAt":"2023-05-26T21:19:18Z","isPatch":true,"sender":{"key":"jonathantanmy@fastmail.com","avatar":null},"body":"Calvin Wan <calvinwan@google.com> writes:\n> Splitting these macros from git-compat-util.h cleans up the file and\n> allows future third-party sources to not use these overrides if they do\n> not wish to.\n> \n> Signed-off-by: Calvin Wan <calvinwan@google.com>\n> ---\n>  git-compat-util.h | 65 +-------------------------------------------\n>  sane-ctype.h      | 69 +++++++++++++++++++++++++++++++++++++++++++++++\n\nAny specific reason for the \"sane-\" prefix? I think it would make more\nsense if it was just named ctype.h: see below.\n\n> -/* in ctype.c, for kwset users */\n> -extern const unsigned char tolower_trans_tbl[256];\n\nI'm not sure what this has to do with sanity, but this is indeed defined\nin ctype.c, so it's easier to justify moving this out if the criterion\nwas \"what's in ctype.c\" rather than \"what's related to sane ctypes\".\n\n> -extern const signed char hexval_table[256];\n\nAnd this one has nothing to do with ctypes or sanity, but rather, what's\nconsidered to be a hex character. I think we need another patch to move\nthis to hex.h.\n\n> -#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n\nSame for this one.\n\nWith the above suggestions, I think we do get what we want - a split\nbetween things that make ctype more sane and between other compat stuff,\nand also a split between those two and more platform-agnostic things\nlike what a hex character is.\n"},{"id":"477744","messageId":"20230526212525.2293692-1-jonathantanmy@google.com","threadId":"59752","inReplyTo":"20230523192949.1271671-2-calvinwan@google.com","subject":"Re: [PATCH v2 2/7] wrapper.h: move declarations for wrapper.c functions from git-compat-util.h","fromName":"Jonathan Tan","fromEmail":"jonathantanmy@google.com","sentAt":"2023-05-26T21:25:25Z","receivedAt":"2023-05-26T21:25:31Z","isPatch":true,"sender":{"key":"jonathantanmy@fastmail.com","avatar":null},"body":"Calvin Wan <calvinwan@google.com> writes:\n> Since the functions in wrapper.c are widely used across the codebase,\n> include it by default in git-compat-util.h. A future patch will remove\n> now unnecessary inclusions of wrapper.h from other files.\n> \n> Signed-off-by: Calvin Wan <calvinwan@google.com>\n\nThanks. So currently, if you wanted to xmmap, you don't have to include\nwrapper.h, but if you wanted to read_in_full, you do. Making Git code\ntreat functions like those 2 in the same way makes sense to me.\n \n"},{"id":"477745","messageId":"20230526212759.2294075-1-jonathantanmy@google.com","threadId":"59752","inReplyTo":"20230523192949.1271671-7-calvinwan@google.com","subject":"Re: [PATCH v2 7/7] common: move alloc macros to common.h","fromName":"Jonathan Tan","fromEmail":"jonathantanmy@google.com","sentAt":"2023-05-26T21:27:59Z","receivedAt":"2023-05-26T21:28:05Z","isPatch":true,"sender":{"key":"jonathantanmy@fastmail.com","avatar":null},"body":"Calvin Wan <calvinwan@google.com> writes:\n> alloc_nr, ALLOC_GROW, and ALLOC_GROW_BY are commonly used macros for\n> dynamic array allocation. Moving these macros to common.h focuses\n> alloc.[ch] to allocation for Git objects and additionally allows us to\n> remove inclusions to alloc.h from files that solely used the above\n> macros.\n> \n> Signed-off-by: Calvin Wan <calvinwan@google.com>\n\nAh, indeed, \"alloc.h\" was used for 2 different allocation-related\nthings. This change makes sense, of course.\n \nThanks for this patch set. Overall, it looks good (except for some minor\ncomments that I've given in other emails).\n"},{"id":"477769","messageId":"4d29e5d4-6ce3-c099-15a7-e89ad787780d@gmail.com","threadId":"59752","inReplyTo":"20230526211911.2291886-1-jonathantanmy@google.com","subject":"Re: [PATCH v2 3/7] sane-ctype.h: move sane-ctype macros from git-compat-util.h","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2023-05-28T12:04:11Z","receivedAt":"2023-05-28T12:04:17Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Calvin and Jonathan\n\nOn 26/05/2023 22:19, Jonathan Tan wrote:\n> Calvin Wan <calvinwan@google.com> writes:\n>> Splitting these macros from git-compat-util.h cleans up the file and\n>> allows future third-party sources to not use these overrides if they do\n>> not wish to.\n\nI think splitting these out makes sense. If you have time to add a \ncomment highlighting the differences from the standard library versions \nthat would be really helpful. As far as I know the differences are\n\n  - our versions are locale independent\n  - our isspace() does not consider '\\v' or '\\f' to be space\n  - our versions expect a signed or unsigned char rather than an int\n    as their argument\n  - our versions do not accept EOF\n  - our versions do not require an explicit cast to avoid undefined\n    behavior when passing char on systems where char is signed\n\n>> Signed-off-by: Calvin Wan <calvinwan@google.com>\n>> ---\n>>   git-compat-util.h | 65 +-------------------------------------------\n>>   sane-ctype.h      | 69 +++++++++++++++++++++++++++++++++++++++++++++++\n> \n> Any specific reason for the \"sane-\" prefix? I think it would make more\n> sense if it was just named ctype.h: see below.\n\nI don't have a strong opinion either way but \"sane-ctype.h\" makes it \nclearer why we're doing something different to the standard library.\n\n>> -/* in ctype.c, for kwset users */\n>> -extern const unsigned char tolower_trans_tbl[256];\n> \n> I'm not sure what this has to do with sanity, but this is indeed defined\n> in ctype.c, so it's easier to justify moving this out if the criterion\n> was \"what's in ctype.c\" rather than \"what's related to sane ctypes\".\n\nThere is only one user of this so it could be moved to \ndiffcore-pickaxe.c or kwset.c where it would be more discoverable if \nanyone needs to add another user in the future.\n\n>> -extern const signed char hexval_table[256];\n> \n> And this one has nothing to do with ctypes or sanity, but rather, what's\n> considered to be a hex character. I think we need another patch to move\n> this to hex.h.\n\nIsn't \"what's considered  to be a hex character\" related to ctypes and \nsanity though as it is used by the \"sane\" definition of isxdigit().\n\n>> -#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n> \n> Same for this one.\n\nI'd much rather keep all of our \"sane\" ctype replacements in one place \nas Calvin is proposing. isxdigit() is defined in <ctype.h> so it should \nbe in our \"sane\" version of that header.\n\nBest Wishes\n\nPhillip\n\n> With the above suggestions, I think we do get what we want - a split\n> between things that make ctype more sane and between other compat stuff,\n> and also a split between those two and more platform-agnostic things\n> like what a hex character is.\n"},{"id":"477803","messageId":"20230530172933.2781693-1-jonathantanmy@google.com","threadId":"59752","inReplyTo":"4d29e5d4-6ce3-c099-15a7-e89ad787780d@gmail.com","subject":"Re: [PATCH v2 3/7] sane-ctype.h: move sane-ctype macros from git-compat-util.h","fromName":"Jonathan Tan","fromEmail":"jonathantanmy@google.com","sentAt":"2023-05-30T17:29:33Z","receivedAt":"2023-05-30T17:30:18Z","isPatch":true,"sender":{"key":"jonathantanmy@fastmail.com","avatar":null},"body":"Phillip Wood <phillip.wood123@gmail.com> writes:\n> > Any specific reason for the \"sane-\" prefix? I think it would make more\n> > sense if it was just named ctype.h: see below.\n> \n> I don't have a strong opinion either way but \"sane-ctype.h\" makes it \n> clearer why we're doing something different to the standard library.\n\nAh...that's true.\n\n> >> -extern const signed char hexval_table[256];\n> > \n> > And this one has nothing to do with ctypes or sanity, but rather, what's\n> > considered to be a hex character. I think we need another patch to move\n> > this to hex.h.\n> \n> Isn't \"what's considered  to be a hex character\" related to ctypes and \n> sanity though as it is used by the \"sane\" definition of isxdigit().\n> \n> >> -#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n> > \n> > Same for this one.\n> \n> I'd much rather keep all of our \"sane\" ctype replacements in one place \n> as Calvin is proposing. isxdigit() is defined in <ctype.h> so it should \n> be in our \"sane\" version of that header.\n\nGood point. \n"},{"id":"477847","messageId":"xmqqjzwnes6w.fsf@gitster.g","threadId":"59752","inReplyTo":"20230526211911.2291886-1-jonathantanmy@google.com","subject":"Re: [PATCH v2 3/7] sane-ctype.h: move sane-ctype macros from git-compat-util.h","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-06-01T04:12:55Z","receivedAt":"2023-06-01T04:13:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jonathan Tan <jonathantanmy@google.com> writes:\n\n> Any specific reason for the \"sane-\" prefix? I think it would make more\n> sense if it was just named ctype.h: see below.\n\nI think it is a good idea to keep the sane prefix for two reasons\nthat were described in 4546738b (Unlocalized isspace and friends,\n2005-10-13):\n\n    Do our own ctype.h, just to get the sane semantics: we want\n    locale-independence, _and_ we want the right signed behaviour. Plus we\n    only use a very small subset of ctype.h anyway (isspace, isalpha,\n    isdigit and isalnum).\n\n"},{"id":"478097","messageId":"20230606170711.912972-1-calvinwan@google.com","threadId":"59752","inReplyTo":"20230523192749.1270992-1-calvinwan@google.com","subject":"[PATCH v3 0/8] git-compat-util cleanups","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-06T17:07:11Z","receivedAt":"2023-06-06T17:07:30Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Changes since v2:\n - rebased on 2.41, en/header-split-cache-h-part-3, and cw/strbuf-cleanup\n   (originally rebased onto seen which is why the range-diff is like that)\n - moved tolower_trans_tbl to kwset rather than sane-ctype\n - rewrote commit message headers to be shorter\n\nThis series focuses on cleaning up and reducing the scope of\ngit-compat-util.h by moving headers to their respective files and\nseparating out functionality from git-compat-util.h to a new file,\ncommon.h. I go into more detail in patch 5 as to why I believe this\nseparation is useful. \n\nBy the end of this series, git-compat-util.h includes common.h which\nincludes wrapper.h, and usage.h. Since virtually every file includes\ngit-compat-util.h and the large majority of files use functions defined\nin common.h, wrapper.h, and usage.h, I believe it makes sense that those\nare also automatically included with git-compat-util.h.\n\nCalvin Wan (8):\n  git-compat-util: move strbuf.c funcs to its header\n  git-compat-util: move wrapper.c funcs to its header\n  sane-ctype.h: create header for sane-ctype macros\n  kwset: move translation table from ctype\n  common.h: move non-compat specific macros and functions\n  git-compat-util: move usage.c funcs to its header\n  treewide: remove unnecessary includes for wrapper.h\n  common: move alloc macros to common.h\n\n add-patch.c                        |   1 -\n alias.c                            |   1 -\n alloc.h                            |  75 ----\n apply.c                            |   2 -\n archive-tar.c                      |   1 -\n archive.c                          |   1 -\n attr.c                             |   1 -\n builtin/am.c                       |   1 -\n builtin/bisect.c                   |   1 -\n builtin/blame.c                    |   1 -\n builtin/branch.c                   |   1 -\n builtin/bugreport.c                |   1 -\n builtin/cat-file.c                 |   1 -\n builtin/checkout--worker.c         |   1 -\n builtin/clone.c                    |   1 -\n builtin/config.c                   |   2 -\n builtin/credential-cache--daemon.c |   1 -\n builtin/credential-cache.c         |   1 -\n builtin/difftool.c                 |   1 -\n builtin/fast-import.c              |   1 -\n builtin/fetch-pack.c               |   1 -\n builtin/fmt-merge-msg.c            |   1 -\n builtin/fsmonitor--daemon.c        |   1 -\n builtin/gc.c                       |   1 -\n builtin/get-tar-commit-id.c        |   1 -\n builtin/grep.c                     |   1 -\n builtin/index-pack.c               |   2 -\n builtin/init-db.c                  |   1 -\n builtin/log.c                      |   1 -\n builtin/merge.c                    |   2 -\n builtin/mktree.c                   |   1 -\n builtin/mv.c                       |   1 -\n builtin/name-rev.c                 |   1 -\n builtin/pack-objects.c             |   2 -\n builtin/rebase.c                   |   1 -\n builtin/receive-pack.c             |   1 -\n builtin/repack.c                   |   1 -\n builtin/rerere.c                   |   1 -\n builtin/rev-parse.c                |   1 -\n builtin/revert.c                   |   1 -\n builtin/rm.c                       |   1 -\n builtin/submodule--helper.c        |   1 -\n builtin/symbolic-ref.c             |   1 +\n builtin/unpack-file.c              |   1 -\n builtin/unpack-objects.c           |   1 +\n builtin/worktree.c                 |   1 -\n bulk-checkin.c                     |   2 -\n cache-tree.c                       |   1 -\n chunk-format.c                     |   1 -\n combine-diff.c                     |   1 -\n commit-graph.c                     |   1 -\n commit-reach.c                     |   1 -\n common.h                           | 486 +++++++++++++++++++++\n compat/terminal.c                  |   1 -\n config.c                           |   2 -\n convert.c                          |   1 -\n copy.c                             |   1 -\n csum-file.c                        |   1 -\n ctype.c                            |  36 --\n daemon.c                           |   2 -\n delta-islands.c                    |   1 -\n diff.c                             |   2 -\n diffcore-rename.c                  |   1 -\n dir-iterator.c                     |   1 -\n dir.c                              |   2 -\n editor.c                           |   1 -\n entry.c                            |   1 -\n environment.c                      |   1 -\n ewah/bitmap.c                      |   1 -\n ewah/ewah_bitmap.c                 |   1 -\n fetch-pack.c                       |   2 -\n fmt-merge-msg.c                    |   1 -\n fsck.c                             |   1 -\n git-compat-util.h                  | 664 +----------------------------\n gpg-interface.c                    |   1 -\n grep.c                             |   1 -\n help.c                             |   1 -\n http-backend.c                     |   2 -\n imap-send.c                        |   1 -\n kwset.c                            |  36 ++\n kwset.h                            |   2 +\n line-log.c                         |   1 -\n list-objects-filter-options.c      |   1 -\n list-objects-filter.c              |   1 -\n merge-ll.c                         |   1 -\n merge-recursive.c                  |   1 -\n midx.c                             |   1 -\n notes-merge.c                      |   1 -\n object-file.c                      |   2 -\n oid-array.c                        |   1 -\n oidtree.c                          |   1 -\n pack-bitmap-write.c                |   1 -\n pack-bitmap.c                      |   1 -\n pack-objects.c                     |   1 -\n pack-write.c                       |   1 -\n packfile.c                         |   2 -\n parallel-checkout.c                |   2 -\n path.c                             |   1 -\n pkt-line.c                         |   1 -\n pretty.c                           |   1 -\n prio-queue.c                       |   1 -\n quote.c                            |   1 -\n read-cache.c                       |   2 -\n rebase-interactive.c               |   1 -\n ref-filter.c                       |   1 -\n reflog-walk.c                      |   1 -\n refs.c                             |   2 -\n refspec.c                          |   1 -\n remote-curl.c                      |   1 -\n remote.c                           |   1 -\n rerere.c                           |   2 -\n revision.c                         |   1 -\n sane-ctype.h                       |  66 +++\n send-pack.c                        |   1 -\n sequencer.c                        |   2 -\n server-info.c                      |   2 -\n setup.c                            |   1 -\n shallow.c                          |   2 -\n sigchain.c                         |   1 -\n sparse-index.c                     |   1 -\n split-index.c                      |   1 -\n strbuf.c                           |   2 -\n strbuf.h                           |  32 ++\n streaming.c                        |   1 -\n string-list.c                      |   1 -\n strvec.c                           |   1 -\n submodule-config.c                 |   1 -\n submodule.c                        |   1 -\n t/helper/test-delta.c              |   1 -\n t/helper/test-fsmonitor-client.c   |   1 -\n t/helper/test-reach.c              |   1 -\n t/helper/test-read-cache.c         |   1 -\n tag.c                              |   1 -\n tempfile.c                         |   1 -\n trace.c                            |   1 -\n trace2/tr2_tls.c                   |   1 -\n trailer.c                          |   1 -\n transport-helper.c                 |   1 -\n transport.c                        |   2 -\n tree-walk.c                        |   1 -\n upload-pack.c                      |   1 -\n usage.c                            |   1 -\n usage.h                            |  60 +++\n userdiff.c                         |   1 -\n versioncmp.c                       |   1 +\n worktree.c                         |   2 -\n wrapper.c                          |   1 -\n wrapper.h                          | 111 +++++\n write-or-die.c                     |   1 -\n 149 files changed, 799 insertions(+), 932 deletions(-)\n create mode 100644 common.h\n create mode 100644 sane-ctype.h\n create mode 100644 usage.h\n\nRange-diff against v2:\n  1:  08f55ec7b2 <   -:  ---------- diff-merges: implement [no-]hide option and log.diffMergesHide config\n  2:  b9873596ec <   -:  ---------- diff-merges: implement log.diffMerges-m-imply-p config\n  3:  56c961db8d <   -:  ---------- diff-merges: support list of values for --diff-merges\n  4:  96f5dc2cfe <   -:  ---------- diff-merges: issue warning on lone '-m' option\n  5:  0200086346 <   -:  ---------- diff-merges: improve --diff-merges documentation\n  6:  f216b8d143 <   -:  ---------- test-lib: allow storing counts with test harnesses\n  7:  78bb2515d6 <   -:  ---------- checkout/switch: disallow checking out same branch in multiple worktrees\n  8:  f2111f451f <   -:  ---------- imap-send: note \"auth_method\", not \"host\" on auth method failure\n  9:  f161e8fd64 <   -:  ---------- imap-send doc: the imap.sslVerify is used with imap.tunnel\n 10:  ddfd0c2740 <   -:  ---------- imap-send: replace auto-probe libcurl with hard dependency\n 11:  647ddc1bf8 <   -:  ---------- imap-send: make --curl no-optional\n 12:  bbf79fd38d <   -:  ---------- imap-send: remove old --no-curl codepath\n 13:  ded420f1d1 <   -:  ---------- imap-send: correctly report \"host\" when using \"tunnel\"\n 14:  4bef181256 <   -:  ---------- pull: conflict hint pull.rebase suggestion should offer \"merges\" vs \"true\"\n 15:  fe944b5c26 <   -:  ---------- run-command: add on_stderr_output_fn to run_processes_parallel_opts\n 16:  079d6eec74 <   -:  ---------- submodule: rename strbuf variable\n 17:  c306d4ce36 <   -:  ---------- submodule: move status parsing into function\n 18:  7cce9de786 <   -:  ---------- submodule: refactor is_submodule_modified()\n 19:  a8a6e3a99b <   -:  ---------- diff-lib: refactor out diff_change logic\n 20:  ab60254a51 <   -:  ---------- diff-lib: parallelize run_diff_files for submodules\n 21:  f8762b1cef <   -:  ---------- pack-bitmap.c: hide bitmap internals in `read_u8()`\n 22:  82d838ac61 <   -:  ---------- pack-bitmap.c: hide bitmap internals in `read_be32()`\n 23:  5abc4c1c89 <   -:  ---------- pack-bitmap.c: drop unnecessary 'inline's\n 24:  0e2a13eb16 <   -:  ---------- pack-bitmap.c: factor out manual `map_pos` manipulation\n 25:  e535db7c69 <   -:  ---------- pack-bitmap.c: use `bitmap_index_seek()` where possible\n 26:  3acd24d42a <   -:  ---------- pack-bitmap.c: factor out `bitmap_index_seek_commit()`\n 27:  1cf6fbc4f7 <   -:  ---------- SQUASH??? the test marked to expect failure passes from day one\n 28:  3ff774e34f <   -:  ---------- fsmonitor: handle differences between Windows named pipe functions\n 29:  fce46cf78e <   -:  ---------- diff-index: enable sparse index\n 30:  f7cfd68b91 <   -:  ---------- usage: clarify --recurse-submodules as a boolean\n 31:  2739b3473a <   -:  ---------- rebase -i: move unlink() calls\n 32:  486312cec7 <   -:  ---------- rebase -i: remove patch file after conflict resolution\n 33:  a2fbbcb270 <   -:  ---------- sequencer: factor out part of pick_commits()\n 34:  193623fd97 <   -:  ---------- rebase --continue: refuse to commit after failed command\n 35:  cfc27593ab <   -:  ---------- rebase: fix rewritten list for failed pick\n 36:  bf1932c2f3 <   -:  ---------- rebase -i: fix adding failed command to the todo list\n 37:  bd111141aa <   -:  ---------- cocci: add headings to and reword README\n 38:  3bd0097cfc <   -:  ---------- cocci: codify authoring and reviewing practices\n 39:  62a8a36709 <   -:  ---------- notes.c: cleanup 'strbuf_grow' call in 'append_edit'\n 40:  39a609ec6c <   -:  ---------- notes.c: use designated initializers for clarity\n 41:  e9a0a06d38 <   -:  ---------- t3321: add test cases about the notes stripspace behavior\n 42:  3993a53a13 <   -:  ---------- notes.c: introduce '--separator=<paragraph-break>' option\n 43:  ad3d1f8feb <   -:  ---------- notes.c: append separator instead of insert by pos\n 44:  aa382bf677 <   -:  ---------- notes.c: introduce \"--[no-]stripspace\" option\n 45:  8e9a6aa3f7 <   -:  ---------- sequencer: beautify subject of reverts of reverts\n 46:  9d484b92ed <   -:  ---------- diff: fix interaction between the \"-s\" option and other options\n 47:  fe90355361 <   -:  ---------- object: add object_array initializer helper function\n 48:  47ff853f02 <   -:  ---------- pack-bitmap.c: extract `fill_in_bitmap()`\n 49:  b0afdce5da <   -:  ---------- pack-bitmap.c: use commit boundary during bitmap traversal\n 50:  6ba979b352 <   -:  ---------- t6429: remove switching aspects of fast-rebase\n 51:  cd85a8aab3 <   -:  ---------- replay: introduce new builtin\n 52:  ff6b4688a7 <   -:  ---------- replay: start using parse_options API\n 53:  d1e55ff4ab <   -:  ---------- replay: die() instead of failing assert()\n 54:  93461549f2 <   -:  ---------- replay: introduce pick_regular_commit()\n 55:  1bf61baa21 <   -:  ---------- replay: don't simplify history\n 56:  317ac15b14 <   -:  ---------- replay: add an important FIXME comment about gpg signing\n 57:  a195c920d9 <   -:  ---------- replay: remove progress and info output\n 58:  20e96266a5 <   -:  ---------- replay: remove HEAD related sanity check\n 59:  acf68154a0 <   -:  ---------- replay: make it a minimal server side command\n 60:  e02064abfc <   -:  ---------- replay: use standard revision ranges\n 61:  33296b563c <   -:  ---------- replay: disallow revision specific options and pathspecs\n 62:  e436c4e38f <   -:  ---------- replay: add --advance or 'cherry-pick' mode\n 63:  657ce1ace6 <   -:  ---------- replay: add --contained to rebase contained branches\n 64:  145695cc72 <   -:  ---------- replay: stop assuming replayed branches do not diverge\n 65:  b37a7d7a8a <   -:  ---------- SQUASH???\n 66:  ec664ab737 <   -:  ---------- cat-file: quote-format name in error when using -z\n 67:  982ff2c961 <   -:  ---------- object tests: add test for unexpected objects in tags\n 68:  d5afcaa611 <   -:  ---------- tag: don't misreport type of tagged objects in errors\n 69:  cdc90612fd <   -:  ---------- tag: don't emit potentially incorrect \"object is a X, not a Y\"\n 70:  b745672f8d <   -:  ---------- doc: trailer: fix grammar\n 71:  354fc9157c <   -:  ---------- doc: trailer: swap verb order\n 72:  267aea4472 <   -:  ---------- doc: trailer: drop \"commit message part\" phrasing\n 73:  2d75fde295 <   -:  ---------- doc: trailer: examples: avoid the word \"message\" by itself\n 74:  e2087e448a <   -:  ---------- doc: trailer: remove redundant phrasing\n 75:  479d93ea37 <   -:  ---------- doc: trailer: use angle brackets for <token> and <value>\n 76:  4361055f15 <   -:  ---------- doc: trailer.<token>.command: emphasize deprecation\n 77:  4fc3593f55 <   -:  ---------- doc: trailer: mention 'key' in DESCRIPTION\n 78:  05d3be026d <   -:  ---------- doc: trailer: add more examples in DESCRIPTION\n 79:  d0ca92a7fe <   -:  ---------- strbuf: clarify API boundary\n 80:  689ece6602 <   -:  ---------- abspath: move related functions to abspath\n 81:  eaec86fb92 <   -:  ---------- credential-store: move related functions to credential-store file\n 82:  d1272d1469 <   -:  ---------- object-name: move related functions to object-name\n 83:  9a5bb4efa0 <   -:  ---------- path: move related function to path\n 84:  88da41d9ff <   -:  ---------- strbuf: clarify dependency\n 85:  6897be8f14 <   -:  ---------- strbuf: remove global variable\n 86:  283174b214 <   -:  ---------- docs: clarify git-pack-refs --all will pack all refs\n 87:  826ae79fca <   -:  ---------- pack-refs: teach --exclude option to exclude refs from being packed\n 88:  4fe42f326e <   -:  ---------- pack-refs: teach pack-refs --include option\n 89:  836ada9931 <   -:  ---------- refs.c: rename `ref_filter`\n 90:  ccd9c98044 <   -:  ---------- ref-filter.h: provide `REF_FILTER_INIT`\n 91:  25d2495e4a <   -:  ---------- ref-filter: clear reachable list pointers after freeing\n 92:  b10cd5c909 <   -:  ---------- ref-filter: add `ref_filter_clear()`\n 93:  d3e45e84fd <   -:  ---------- ref-filter.c: parameterize match functions over patterns\n 94:  389f8c1827 <   -:  ---------- builtin/for-each-ref.c: add `--exclude` option\n 95:  60ccf68ae5 <   -:  ---------- refs: plumb `exclude_patterns` argument throughout\n 96:  c5950cfc7b <   -:  ---------- refs/packed-backend.c: refactor `find_reference_location()`\n 97:  d2be75e8d2 <   -:  ---------- refs/packed-backend.c: implement jump lists to avoid excluded pattern(s)\n 98:  9a66abb6ce <   -:  ---------- refs/packed-backend.c: add trace2 counters for jump list\n 99:  54b1444a51 <   -:  ---------- revision.h: store hidden refs in a `strvec`\n100:  fe10c7fe7a <   -:  ---------- refs/packed-backend.c: ignore complicated hidden refs rules\n101:  3df995b8c5 <   -:  ---------- refs.h: let `for_each_namespaced_ref()` take excluded patterns\n102:  c41619ccdc <   -:  ---------- builtin/receive-pack.c: avoid enumerating hidden references\n103:  fb22f5bcea <   -:  ---------- upload-pack.c: avoid enumerating hidden refs where possible\n104:  bd3fabf816 <   -:  ---------- ls-refs.c: avoid enumerating hidden refs where possible\n105:  342e04e6fd <   -:  ---------- reachable.c: extract `obj_is_recent()`\n106:  8b19941a02 <   -:  ---------- gc: introduce `gc.recentObjectsHook`\n107:  955ee54d92 <   -:  ---------- init-db: document existing bug with core.bare in template config\n108:  d404ac1027 <   -:  ---------- init-db: remove unnecessary global variable\n109:  0a76a5fb02 <   -:  ---------- init-db, clone: change unnecessary global into passed parameter\n110:  3f85c72fad <   -:  ---------- setup: adopt shared init-db & clone code\n111:  4956a5ec86 <   -:  ---------- read-cache: move shared commit and ls-files code\n112:  c862a92083 <   -:  ---------- add: modify add_files_to_cache() to avoid globals\n113:  eb6220a10a <   -:  ---------- read-cache: move shared add/checkout/commit code\n114:  b5ee0a2bf4 <   -:  ---------- statinfo: move stat_{data,validity} functions from cache/read-cache\n115:  ccdfc96750 <   -:  ---------- run-command.h: move declarations for run-command.c from cache.h\n116:  74eab62313 <   -:  ---------- name-hash.h: move declarations for name-hash.c from cache.h\n117:  8ccc457fff <   -:  ---------- sparse-index.h: move declarations for sparse-index.c from cache.h\n118:  e1f4132af8 <   -:  ---------- preload-index.h: move declarations for preload-index.c from elsewhere\n119:  cea0ce693d <   -:  ---------- diff.h: move declaration for global in diff.c from cache.h\n120:  e114585b13 <   -:  ---------- merge.h: move declarations for merge.c from cache.h\n121:  dc45fab4e7 <   -:  ---------- repository.h: move declaration of the_index from cache.h\n122:  433097258d <   -:  ---------- read-cache*.h: move declarations for read-cache.c functions from cache.h\n123:  4275a22e16 <   -:  ---------- cache.h: remove this no-longer-used header\n124:  e1fcb3a534 <   -:  ---------- log-tree: replace include of revision.h with simple forward declaration\n125:  f6a61d3055 <   -:  ---------- repository: remove unnecessary include of path.h\n126:  4666f5120d <   -:  ---------- diff.h: remove unnecessary include of oidset.h\n127:  5e67baddca <   -:  ---------- list-objects-filter-options.h: remove unneccessary include\n128:  64667610fc <   -:  ---------- builtin.h: remove unneccessary includes\n129:  19c8e8012b <   -:  ---------- git-compat-util.h: remove unneccessary include of wildmatch.h\n130:  50b5ecfaf0 <   -:  ---------- merge-ll: rename from ll-merge\n131:  aaf326e1cd <   -:  ---------- khash: name the structs that khash declares\n132:  52c6131caa <   -:  ---------- object-store-ll.h: split this header out of object-store.h\n133:  25547a5791 <   -:  ---------- hash-ll, hashmap: move oidhash() to hash-ll\n134:  d677f7e76a <   -:  ---------- fsmonitor-ll.h: split this header out of fsmonitor.h\n135:  719515fdd0 <   -:  ---------- doc: tag: document `TAG_EDITMSG`\n136:  669c11de85 <   -:  ---------- t/t7004-tag: add regression test for successful tag creation\n137:  08c12ec1d0 <   -:  ---------- tag: keep the message file in case ref transaction fails\n138:  2372aa4195 <   -:  ---------- credential/libsecret: store new attributes\n139:  a40449bcd4 <   -:  ---------- fetch: drop unused DISPLAY_FORMAT_UNKNOWN enum value\n140:  6bc7a37e79 <   -:  ---------- fetch: drop unneeded NULL-check for `remote_ref`\n141:  d1adf85b0a <   -:  ---------- fetch: pass through `fetch_config` directly\n142:  b779a25e05 <   -:  ---------- fetch: use `fetch_config` to store \"fetch.prune\" value\n143:  2b472cfeac <   -:  ---------- fetch: use `fetch_config` to store \"fetch.pruneTags\" value\n144:  ba28b2ca5d <   -:  ---------- fetch: use `fetch_config` to store \"fetch.showForcedUpdates\" value\n145:  56e8bb4fb4 <   -:  ---------- fetch: use `fetch_config` to store \"fetch.recurseSubmodules\" value\n146:  ac197cc094 <   -:  ---------- fetch: use `fetch_config` to store \"fetch.parallel\" value\n147:  f7e063f326 <   -:  ---------- fetch: use `fetch_config` to store \"submodule.fetchJobs\" value\n148:  b71f919dda <   -:  ---------- worktree add: include -B in usage docs\n149:  1b28fbd218 <   -:  ---------- t2400: cleanup created worktree in test\n150:  ed6db0e9ff <   -:  ---------- t2400: refactor \"worktree add\" opt exclusion tests\n151:  9ccdace1e8 <   -:  ---------- t2400: add tests to verify --quiet\n152:  7ab8918985 <   -:  ---------- worktree add: add --orphan flag\n153:  35f0383ca6 <   -:  ---------- worktree add: introduce \"try --orphan\" hint\n154:  128e5496b3 <   -:  ---------- worktree add: extend DWIM to infer --orphan\n155:  926c40d04b <   -:  ---------- worktree add: emit warn when there is a bad HEAD\n156:  48c5fbfb89 <   -:  ---------- diff-tree: integrate with sparse index\n157:  cfa120947e <   -:  ---------- format-patch: free rev.message_id when exiting\n158:  00bf685975 <   -:  ---------- show-ref doc: update for internal consistency\n159:  0f45b5bc32 <   -:  ---------- show-branch doc: say <ref>, not <reference>\n160:  21c9bac2c7 <   -:  ---------- ls-remote doc: remove redundant --tags example\n161:  e959fa452f <   -:  ---------- ls-remote doc: show peeled tags in examples\n162:  a5b076321a <   -:  ---------- ls-remote doc: explain what each example does\n163:  51f9d2e563 <   -:  ---------- ls-remote doc: document the output format\n164:  c6d26a9dda <   -:  ---------- format-patch: free elements of rev.ref_message_ids list\n165:  2f68c99a3b <   -:  ---------- t0000-basic: modernize test format\n166:  27990663f0 <   -:  ---------- t0030-stripspace: modernize test format\n167:  3c2f5d26c0 <   -:  ---------- t3210-pack-refs: modernize test format\n168:  58db6e450b <   -:  ---------- t1001-read-tree-m-2way: modernize test format\n169:  a10bb2ded5 <   -:  ---------- t1002-read-tree-m-u-2way: modernize test format\n170:  350c484239 <   -:  ---------- t1006-cat-file: modernize test format\n171:  0a6cb5c42f <   -:  ---------- t3500-cherry: modernize test format\n172:  0aa0266c4b <   -:  ---------- t3700-add: modernize test format\n173:  a8fcc0ac89 <   -:  ---------- t3903-stash: modernize test format\n174:  9cfcbcc095 <   -:  ---------- t4002-diff-basic: modernize test format\n175:  9297229d15 <   -:  ---------- t4003-diff-rename-1: modernize test format\n176:  93fc423e9a <   -:  ---------- t4004-diff-rename-symlink: modernize test format\n177:  3da9be913a <   -:  ---------- t4202-log: modernize test format\n178:  1afebc92ef <   -:  ---------- t4206-log-follow-harder-copies: modernize test format\n179:  e478a52087 <   -:  ---------- t5300-pack-object: modernize test format\n180:  cc0c1ad9ad <   -:  ---------- t5301-sliding-window: modernize test format\n181:  aac864059f <   -:  ---------- t5303-pack-corruption-resilience: modernize test format\n182:  a45bb750db <   -:  ---------- t5306-pack-nobase: modernize test format\n183:  32942346aa <   -:  ---------- t6050-replace: modernize test format\n184:  3b8724bce6 <   -:  ---------- t7101-reset-empty-subdirs: modernize test format\n185:  a32a724b03 <   -:  ---------- t7110-reset-merge: modernize test format\n186:  c970681f50 <   -:  ---------- t7111-reset-table: modernize test format\n187:  10dae78533 <   -:  ---------- t7201-co: modernize test format\n188:  a6171e1478 <   -:  ---------- t7508-status: modernize test format\n189:  bd48dfad69 <   -:  ---------- t7600-merge: modernize test format\n190:  3a3b98be91 <   -:  ---------- t7700-repack: modernize test format\n191:  be1fce6dae <   -:  ---------- t9100-git-svn-basic: modernize test format\n192:  7d7097bf59 <   -:  ---------- t9104-git-svn-follow-parent: modernize test format\n193:  7dac6347c5 <   -:  ---------- t9200-git-cvsexportcommit: modernize test format\n194:  447a3b7331 <   -:  ---------- t9400-git-cvsserver-server: modernize test format\n195:  bc11bac329 <   -:  ---------- revisions.txt: use description list for special refs\n196:  6ec5f46071 <   -:  ---------- revisions.txt: document more special refs\n197:  1ef3c61b78 <   -:  ---------- completion: complete REVERT_HEAD and BISECT_HEAD\n198:  b7dd54a2c7 <   -:  ---------- git-merge.txt: modernize word choice in \"True merge\" section\n199:  4fa1edb988 <   -:  ---------- Documentation: document AUTO_MERGE\n200:  982ff3a649 <   -:  ---------- completion: complete AUTO_MERGE\n201:  3a5d53d3c0 <   -:  ---------- t4216: test wrong bloom filter version rejection\n202:  5a91f9682b <   -:  ---------- commit-graph: fix murmur3, bump filter ver. to 2\n203:  3d3906ce28 <   -:  ---------- ### match next\n204:  9d9c164d7e <   -:  ---------- cherry-pick: refuse cherry-pick sequence if index is dirty\n205:  d091928b02 <   -:  ---------- ls-files: aligin format atoms wtih ls-tree\n206:  a2b7a28e6e !   1:  d352eae308 strbuf.h: move declarations for strbuf.c functions from git-compat-util.h\n    @@ Metadata\n     Author: Calvin Wan <calvinwan@google.com>\n     \n      ## Commit message ##\n    -    strbuf.h: move declarations for strbuf.c functions from git-compat-util.h\n    +    git-compat-util: move strbuf.c funcs to its header\n     \n         While functions like starts_with() probably should not belong in the\n         boundaries of the strbuf library, this commit focuses on first splitting\n207:  b12fb0e2ff !   2:  fe4fd6f92a wrapper.h: move declarations for wrapper.c functions from git-compat-util.h\n    @@ Metadata\n     Author: Calvin Wan <calvinwan@google.com>\n     \n      ## Commit message ##\n    -    wrapper.h: move declarations for wrapper.c functions from git-compat-util.h\n    +    git-compat-util: move wrapper.c funcs to its header\n     \n         Since the functions in wrapper.c are widely used across the codebase,\n         include it by default in git-compat-util.h. A future patch will remove\n208:  016f671836 !   3:  ec7ea12f7c sane-ctype.h: move sane-ctype macros from git-compat-util.h\n    @@ Metadata\n     Author: Calvin Wan <calvinwan@google.com>\n     \n      ## Commit message ##\n    -    sane-ctype.h: move sane-ctype macros from git-compat-util.h\n    +    sane-ctype.h: create header for sane-ctype macros\n     \n         Splitting these macros from git-compat-util.h cleans up the file and\n         allows future third-party sources to not use these overrides if they do\n    @@ Commit message\n     \n      ## git-compat-util.h ##\n     @@ git-compat-util.h: static inline size_t xsize_t(off_t len)\n    - #define HOST_NAME_MAX 256\n    - #endif\n    + /* in ctype.c, for kwset users */\n    + extern const unsigned char tolower_trans_tbl[256];\n      \n    --/* in ctype.c, for kwset users */\n    --extern const unsigned char tolower_trans_tbl[256];\n    --\n     -/* Sane ctype - no locale, and works with signed chars */\n     -#undef isascii\n     -#undef isspace\n    @@ sane-ctype.h (new)\n     +#ifndef SANE_CTYPE_H\n     +#define SANE_CTYPE_H\n     +\n    -+/* in ctype.c, for kwset users */\n    -+extern const unsigned char tolower_trans_tbl[256];\n    -+\n     +/* Sane ctype - no locale, and works with signed chars */\n     +#undef isascii\n     +#undef isspace\n  -:  ---------- >   4:  4f95b4121e kwset: move translation table from ctype\n209:  244650e5c9 !   5:  36525e39d5 common.h: move non-compat specific macros and functions from git-compat-util.h\n    @@ Metadata\n     Author: Calvin Wan <calvinwan@google.com>\n     \n      ## Commit message ##\n    -    common.h: move non-compat specific macros and functions from git-compat-util.h\n    +    common.h: move non-compat specific macros and functions\n     \n         git-compat-util.h has grown to a large and difficult to read file partly\n         because its set of functionality is overloaded. Besides being a\n210:  91a1253ee6 !   6:  21f0f31ff3 usage.h: move declarations for usage.c functions from git-compat-util.h\n    @@ Metadata\n     Author: Calvin Wan <calvinwan@google.com>\n     \n      ## Commit message ##\n    -    usage.h: move declarations for usage.c functions from git-compat-util.h\n    +    git-compat-util: move usage.c funcs to its header\n     \n      ## common.h ##\n     @@\n211:  c9850a7c18 =   7:  531db31c5c treewide: remove unnecessary includes for wrapper.h\n212:  067b28ec09 !   8:  98694f7add common: move alloc macros to common.h\n    @@ strbuf.c\n     -#include \"alloc.h\"\n      #include \"gettext.h\"\n      #include \"hex.h\"\n    - #include \"path.h\"\n    + #include \"strbuf.h\"\n     \n      ## string-list.c ##\n     @@\n-- \n2.41.0.rc2.161.g9c6817b8e7-goog\n\n"},{"id":"478098","messageId":"20230606171002.914075-1-calvinwan@google.com","threadId":"59752","inReplyTo":"20230606170711.912972-1-calvinwan@google.com","subject":"[PATCH v3 1/8] git-compat-util: move strbuf.c funcs to its header","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-06T17:09:55Z","receivedAt":"2023-06-06T17:10:13Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"While functions like starts_with() probably should not belong in the\nboundaries of the strbuf library, this commit focuses on first splitting\nout headers from git-compat-util.h.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n builtin/symbolic-ref.c   |  1 +\n builtin/unpack-objects.c |  1 +\n git-compat-util.h        | 32 --------------------------------\n strbuf.h                 | 32 ++++++++++++++++++++++++++++++++\n versioncmp.c             |  1 +\n 5 files changed, 35 insertions(+), 32 deletions(-)\n\ndiff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c\nindex a61fa3c0f8..c9defe4d2e 100644\n--- a/builtin/symbolic-ref.c\n+++ b/builtin/symbolic-ref.c\n@@ -3,6 +3,7 @@\n #include \"gettext.h\"\n #include \"refs.h\"\n #include \"parse-options.h\"\n+#include \"strbuf.h\"\n \n static const char * const git_symbolic_ref_usage[] = {\n \tN_(\"git symbolic-ref [-m <reason>] <name> <ref>\"),\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex b4b46ae729..0510e60e6e 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -12,6 +12,7 @@\n #include \"blob.h\"\n #include \"commit.h\"\n #include \"replace-object.h\"\n+#include \"strbuf.h\"\n #include \"tag.h\"\n #include \"tree.h\"\n #include \"tree-walk.h\"\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 1889da7986..fe9e86bad0 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -677,9 +677,6 @@ void set_warn_routine(report_fn routine);\n report_fn get_warn_routine(void);\n void set_die_is_recursing_routine(int (*routine)(void));\n \n-int starts_with(const char *str, const char *prefix);\n-int istarts_with(const char *str, const char *prefix);\n-\n /*\n  * If the string \"str\" begins with the string found in \"prefix\", return 1.\n  * The \"out\" parameter is set to \"str + strlen(prefix)\" (i.e., to the point in\n@@ -708,29 +705,6 @@ static inline int skip_prefix(const char *str, const char *prefix,\n \treturn 0;\n }\n \n-/*\n- * If the string \"str\" is the same as the string in \"prefix\", then the \"arg\"\n- * parameter is set to the \"def\" parameter and 1 is returned.\n- * If the string \"str\" begins with the string found in \"prefix\" and then a\n- * \"=\" sign, then the \"arg\" parameter is set to \"str + strlen(prefix) + 1\"\n- * (i.e., to the point in the string right after the prefix and the \"=\" sign),\n- * and 1 is returned.\n- *\n- * Otherwise, return 0 and leave \"arg\" untouched.\n- *\n- * When we accept both a \"--key\" and a \"--key=<val>\" option, this function\n- * can be used instead of !strcmp(arg, \"--key\") and then\n- * skip_prefix(arg, \"--key=\", &arg) to parse such an option.\n- */\n-int skip_to_optional_arg_default(const char *str, const char *prefix,\n-\t\t\t\t const char **arg, const char *def);\n-\n-static inline int skip_to_optional_arg(const char *str, const char *prefix,\n-\t\t\t\t       const char **arg)\n-{\n-\treturn skip_to_optional_arg_default(str, prefix, arg, \"\");\n-}\n-\n /*\n  * Like skip_prefix, but promises never to read past \"len\" bytes of the input\n  * buffer, and returns the remaining number of bytes in \"out\" via \"outlen\".\n@@ -775,12 +749,6 @@ static inline int strip_suffix(const char *str, const char *suffix, size_t *len)\n \treturn strip_suffix_mem(str, len, suffix);\n }\n \n-static inline int ends_with(const char *str, const char *suffix)\n-{\n-\tsize_t len;\n-\treturn strip_suffix(str, suffix, &len);\n-}\n-\n #define SWAP(a, b) do {\t\t\t\t\t\t\\\n \tvoid *_swap_a_ptr = &(a);\t\t\t\t\\\n \tvoid *_swap_b_ptr = &(b);\t\t\t\t\\\ndiff --git a/strbuf.h b/strbuf.h\nindex 8903195416..28b3038e83 100644\n--- a/strbuf.h\n+++ b/strbuf.h\n@@ -698,4 +698,36 @@ char *xstrvfmt(const char *fmt, va_list ap);\n __attribute__((format (printf, 1, 2)))\n char *xstrfmt(const char *fmt, ...);\n \n+int starts_with(const char *str, const char *prefix);\n+int istarts_with(const char *str, const char *prefix);\n+\n+/*\n+ * If the string \"str\" is the same as the string in \"prefix\", then the \"arg\"\n+ * parameter is set to the \"def\" parameter and 1 is returned.\n+ * If the string \"str\" begins with the string found in \"prefix\" and then a\n+ * \"=\" sign, then the \"arg\" parameter is set to \"str + strlen(prefix) + 1\"\n+ * (i.e., to the point in the string right after the prefix and the \"=\" sign),\n+ * and 1 is returned.\n+ *\n+ * Otherwise, return 0 and leave \"arg\" untouched.\n+ *\n+ * When we accept both a \"--key\" and a \"--key=<val>\" option, this function\n+ * can be used instead of !strcmp(arg, \"--key\") and then\n+ * skip_prefix(arg, \"--key=\", &arg) to parse such an option.\n+ */\n+int skip_to_optional_arg_default(const char *str, const char *prefix,\n+\t\t\t\t const char **arg, const char *def);\n+\n+static inline int skip_to_optional_arg(const char *str, const char *prefix,\n+\t\t\t\t       const char **arg)\n+{\n+\treturn skip_to_optional_arg_default(str, prefix, arg, \"\");\n+}\n+\n+static inline int ends_with(const char *str, const char *suffix)\n+{\n+\tsize_t len;\n+\treturn strip_suffix(str, suffix, &len);\n+}\n+\n #endif /* STRBUF_H */\ndiff --git a/versioncmp.c b/versioncmp.c\nindex 74cc7c43f0..45e676cbca 100644\n--- a/versioncmp.c\n+++ b/versioncmp.c\n@@ -1,5 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"config.h\"\n+#include \"strbuf.h\"\n #include \"string-list.h\"\n #include \"versioncmp.h\"\n \n-- \n2.41.0.rc2.161.g9c6817b8e7-goog\n\n"},{"id":"478099","messageId":"20230606171002.914075-2-calvinwan@google.com","threadId":"59752","inReplyTo":"20230606170711.912972-1-calvinwan@google.com","subject":"[PATCH v3 2/8] git-compat-util: move wrapper.c funcs to its header","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-06T17:09:56Z","receivedAt":"2023-06-06T17:10:15Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Since the functions in wrapper.c are widely used across the codebase,\ninclude it by default in git-compat-util.h. A future patch will remove\nnow unnecessary inclusions of wrapper.h from other files.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n git-compat-util.h | 112 +---------------------------------------------\n wrapper.h         | 111 +++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 112 insertions(+), 111 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex fe9e86bad0..f8e68baf29 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -625,7 +625,7 @@ static inline int git_has_dir_sep(const char *path)\n \n #include \"compat/bswap.h\"\n \n-struct strbuf;\n+#include \"wrapper.h\"\n \n /* General helper functions */\n NORETURN void usage(const char *err);\n@@ -1045,36 +1045,6 @@ static inline int cast_size_t_to_int(size_t a)\n # define xalloca(size)      (xmalloc(size))\n # define xalloca_free(p)    (free(p))\n #endif\n-char *xstrdup(const char *str);\n-void *xmalloc(size_t size);\n-void *xmallocz(size_t size);\n-void *xmallocz_gently(size_t size);\n-void *xmemdupz(const void *data, size_t len);\n-char *xstrndup(const char *str, size_t len);\n-void *xrealloc(void *ptr, size_t size);\n-void *xcalloc(size_t nmemb, size_t size);\n-void xsetenv(const char *name, const char *value, int overwrite);\n-void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n-const char *mmap_os_err(void);\n-void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n-int xopen(const char *path, int flags, ...);\n-ssize_t xread(int fd, void *buf, size_t len);\n-ssize_t xwrite(int fd, const void *buf, size_t len);\n-ssize_t xpread(int fd, void *buf, size_t len, off_t offset);\n-int xdup(int fd);\n-FILE *xfopen(const char *path, const char *mode);\n-FILE *xfdopen(int fd, const char *mode);\n-int xmkstemp(char *temp_filename);\n-int xmkstemp_mode(char *temp_filename, int mode);\n-char *xgetcwd(void);\n-FILE *fopen_for_writing(const char *path);\n-FILE *fopen_or_warn(const char *path, const char *mode);\n-\n-/*\n- * Like strncmp, but only return zero if s is NUL-terminated and exactly len\n- * characters long.  If it is not, consider it greater than t.\n- */\n-int xstrncmpz(const char *s, const char *t, size_t len);\n \n /*\n  * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note\n@@ -1176,15 +1146,10 @@ static inline size_t xsize_t(off_t len)\n \treturn (size_t) len;\n }\n \n-__attribute__((format (printf, 3, 4)))\n-int xsnprintf(char *dst, size_t max, const char *fmt, ...);\n-\n #ifndef HOST_NAME_MAX\n #define HOST_NAME_MAX 256\n #endif\n \n-int xgethostname(char *buf, size_t len);\n-\n /* in ctype.c, for kwset users */\n extern const unsigned char tolower_trans_tbl[256];\n \n@@ -1425,72 +1390,6 @@ void bug_fl(const char *file, int line, const char *fmt, ...);\n #endif\n #endif\n \n-enum fsync_action {\n-\tFSYNC_WRITEOUT_ONLY,\n-\tFSYNC_HARDWARE_FLUSH\n-};\n-\n-/*\n- * Issues an fsync against the specified file according to the specified mode.\n- *\n- * FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating\n- * systems to flush the OS cache without issuing a flush command to the storage\n- * controller. If those interfaces are unavailable, the function fails with\n- * ENOSYS.\n- *\n- * FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that\n- * changes are durable. It is not expected to fail.\n- */\n-int git_fsync(int fd, enum fsync_action action);\n-\n-/*\n- * Writes out trace statistics for fsync using the trace2 API.\n- */\n-void trace_git_fsync_stats(void);\n-\n-/*\n- * Preserves errno, prints a message, but gives no warning for ENOENT.\n- * Returns 0 on success, which includes trying to unlink an object that does\n- * not exist.\n- */\n-int unlink_or_warn(const char *path);\n- /*\n-  * Tries to unlink file.  Returns 0 if unlink succeeded\n-  * or the file already didn't exist.  Returns -1 and\n-  * appends a message to err suitable for\n-  * 'error(\"%s\", err->buf)' on error.\n-  */\n-int unlink_or_msg(const char *file, struct strbuf *err);\n-/*\n- * Preserves errno, prints a message, but gives no warning for ENOENT.\n- * Returns 0 on success, which includes trying to remove a directory that does\n- * not exist.\n- */\n-int rmdir_or_warn(const char *path);\n-/*\n- * Calls the correct function out of {unlink,rmdir}_or_warn based on\n- * the supplied file mode.\n- */\n-int remove_or_warn(unsigned int mode, const char *path);\n-\n-/*\n- * Call access(2), but warn for any error except \"missing file\"\n- * (ENOENT or ENOTDIR).\n- */\n-#define ACCESS_EACCES_OK (1U << 0)\n-int access_or_warn(const char *path, int mode, unsigned flag);\n-int access_or_die(const char *path, int mode, unsigned flag);\n-\n-/* Warn on an inaccessible file if errno indicates this is an error */\n-int warn_on_fopen_errors(const char *path);\n-\n-/*\n- * Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent\n- * may be racy. Do not use this as protection against an attacker who can\n- * simultaneously create paths.\n- */\n-int open_nofollow(const char *path, int flags);\n-\n #ifndef SHELL_PATH\n # define SHELL_PATH \"/bin/sh\"\n #endif\n@@ -1630,13 +1529,4 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset)\n \t((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))\n #endif /* !__GNUC__ */\n \n-void sleep_millisec(int millisec);\n-\n-/*\n- * Generate len bytes from the system cryptographically secure PRNG.\n- * Returns 0 on success and -1 on error, setting errno.  The inability to\n- * satisfy the full request is an error.\n- */\n-int csprng_bytes(void *buf, size_t len);\n-\n #endif\ndiff --git a/wrapper.h b/wrapper.h\nindex f0c7d0616d..c85b1328d1 100644\n--- a/wrapper.h\n+++ b/wrapper.h\n@@ -1,6 +1,42 @@\n #ifndef WRAPPER_H\n #define WRAPPER_H\n \n+char *xstrdup(const char *str);\n+void *xmalloc(size_t size);\n+void *xmallocz(size_t size);\n+void *xmallocz_gently(size_t size);\n+void *xmemdupz(const void *data, size_t len);\n+char *xstrndup(const char *str, size_t len);\n+void *xrealloc(void *ptr, size_t size);\n+void *xcalloc(size_t nmemb, size_t size);\n+void xsetenv(const char *name, const char *value, int overwrite);\n+void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n+const char *mmap_os_err(void);\n+void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n+int xopen(const char *path, int flags, ...);\n+ssize_t xread(int fd, void *buf, size_t len);\n+ssize_t xwrite(int fd, const void *buf, size_t len);\n+ssize_t xpread(int fd, void *buf, size_t len, off_t offset);\n+int xdup(int fd);\n+FILE *xfopen(const char *path, const char *mode);\n+FILE *xfdopen(int fd, const char *mode);\n+int xmkstemp(char *temp_filename);\n+int xmkstemp_mode(char *temp_filename, int mode);\n+char *xgetcwd(void);\n+FILE *fopen_for_writing(const char *path);\n+FILE *fopen_or_warn(const char *path, const char *mode);\n+\n+/*\n+ * Like strncmp, but only return zero if s is NUL-terminated and exactly len\n+ * characters long.  If it is not, consider it greater than t.\n+ */\n+int xstrncmpz(const char *s, const char *t, size_t len);\n+\n+__attribute__((format (printf, 3, 4)))\n+int xsnprintf(char *dst, size_t max, const char *fmt, ...);\n+\n+int xgethostname(char *buf, size_t len);\n+\n /* set default permissions by passing mode arguments to open(2) */\n int git_mkstemps_mode(char *pattern, int suffix_len, int mode);\n int git_mkstemp_mode(char *pattern, int mode);\n@@ -33,4 +69,79 @@ void write_file(const char *path, const char *fmt, ...);\n /* Return 1 if the file is empty or does not exists, 0 otherwise. */\n int is_empty_or_missing_file(const char *filename);\n \n+enum fsync_action {\n+\tFSYNC_WRITEOUT_ONLY,\n+\tFSYNC_HARDWARE_FLUSH\n+};\n+\n+/*\n+ * Issues an fsync against the specified file according to the specified mode.\n+ *\n+ * FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating\n+ * systems to flush the OS cache without issuing a flush command to the storage\n+ * controller. If those interfaces are unavailable, the function fails with\n+ * ENOSYS.\n+ *\n+ * FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that\n+ * changes are durable. It is not expected to fail.\n+ */\n+int git_fsync(int fd, enum fsync_action action);\n+\n+/*\n+ * Writes out trace statistics for fsync using the trace2 API.\n+ */\n+void trace_git_fsync_stats(void);\n+\n+/*\n+ * Preserves errno, prints a message, but gives no warning for ENOENT.\n+ * Returns 0 on success, which includes trying to unlink an object that does\n+ * not exist.\n+ */\n+int unlink_or_warn(const char *path);\n+ /*\n+  * Tries to unlink file.  Returns 0 if unlink succeeded\n+  * or the file already didn't exist.  Returns -1 and\n+  * appends a message to err suitable for\n+  * 'error(\"%s\", err->buf)' on error.\n+  */\n+int unlink_or_msg(const char *file, struct strbuf *err);\n+/*\n+ * Preserves errno, prints a message, but gives no warning for ENOENT.\n+ * Returns 0 on success, which includes trying to remove a directory that does\n+ * not exist.\n+ */\n+int rmdir_or_warn(const char *path);\n+/*\n+ * Calls the correct function out of {unlink,rmdir}_or_warn based on\n+ * the supplied file mode.\n+ */\n+int remove_or_warn(unsigned int mode, const char *path);\n+\n+/*\n+ * Call access(2), but warn for any error except \"missing file\"\n+ * (ENOENT or ENOTDIR).\n+ */\n+#define ACCESS_EACCES_OK (1U << 0)\n+int access_or_warn(const char *path, int mode, unsigned flag);\n+int access_or_die(const char *path, int mode, unsigned flag);\n+\n+/* Warn on an inaccessible file if errno indicates this is an error */\n+int warn_on_fopen_errors(const char *path);\n+\n+/*\n+ * Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent\n+ * may be racy. Do not use this as protection against an attacker who can\n+ * simultaneously create paths.\n+ */\n+int open_nofollow(const char *path, int flags);\n+\n+void sleep_millisec(int millisec);\n+\n+/*\n+ * Generate len bytes from the system cryptographically secure PRNG.\n+ * Returns 0 on success and -1 on error, setting errno.  The inability to\n+ * satisfy the full request is an error.\n+ */\n+int csprng_bytes(void *buf, size_t len);\n+\n #endif /* WRAPPER_H */\n-- \n2.41.0.rc2.161.g9c6817b8e7-goog\n\n"},{"id":"478100","messageId":"20230606171002.914075-3-calvinwan@google.com","threadId":"59752","inReplyTo":"20230606170711.912972-1-calvinwan@google.com","subject":"[PATCH v3 3/8] sane-ctype.h: create header for sane-ctype macros","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-06T17:09:57Z","receivedAt":"2023-06-06T17:10:24Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Splitting these macros from git-compat-util.h cleans up the file and\nallows future third-party sources to not use these overrides if they do\nnot wish to.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n git-compat-util.h | 62 +-------------------------------------------\n sane-ctype.h      | 66 +++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 67 insertions(+), 61 deletions(-)\n create mode 100644 sane-ctype.h\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex f8e68baf29..2151d8b437 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -1153,67 +1153,7 @@ static inline size_t xsize_t(off_t len)\n /* in ctype.c, for kwset users */\n extern const unsigned char tolower_trans_tbl[256];\n \n-/* Sane ctype - no locale, and works with signed chars */\n-#undef isascii\n-#undef isspace\n-#undef isdigit\n-#undef isalpha\n-#undef isalnum\n-#undef isprint\n-#undef islower\n-#undef isupper\n-#undef tolower\n-#undef toupper\n-#undef iscntrl\n-#undef ispunct\n-#undef isxdigit\n-\n-extern const unsigned char sane_ctype[256];\n-extern const signed char hexval_table[256];\n-#define GIT_SPACE 0x01\n-#define GIT_DIGIT 0x02\n-#define GIT_ALPHA 0x04\n-#define GIT_GLOB_SPECIAL 0x08\n-#define GIT_REGEX_SPECIAL 0x10\n-#define GIT_PATHSPEC_MAGIC 0x20\n-#define GIT_CNTRL 0x40\n-#define GIT_PUNCT 0x80\n-#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n-#define isascii(x) (((x) & ~0x7f) == 0)\n-#define isspace(x) sane_istest(x,GIT_SPACE)\n-#define isdigit(x) sane_istest(x,GIT_DIGIT)\n-#define isalpha(x) sane_istest(x,GIT_ALPHA)\n-#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)\n-#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)\n-#define islower(x) sane_iscase(x, 1)\n-#define isupper(x) sane_iscase(x, 0)\n-#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)\n-#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)\n-#define iscntrl(x) (sane_istest(x,GIT_CNTRL))\n-#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \\\n-\t\tGIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)\n-#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n-#define tolower(x) sane_case((unsigned char)(x), 0x20)\n-#define toupper(x) sane_case((unsigned char)(x), 0)\n-#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)\n-\n-static inline int sane_case(int x, int high)\n-{\n-\tif (sane_istest(x, GIT_ALPHA))\n-\t\tx = (x & ~0x20) | high;\n-\treturn x;\n-}\n-\n-static inline int sane_iscase(int x, int is_lower)\n-{\n-\tif (!sane_istest(x, GIT_ALPHA))\n-\t\treturn 0;\n-\n-\tif (is_lower)\n-\t\treturn (x & 0x20) != 0;\n-\telse\n-\t\treturn (x & 0x20) == 0;\n-}\n+#include \"sane-ctype.h\"\n \n /*\n  * Like skip_prefix, but compare case-insensitively. Note that the comparison\ndiff --git a/sane-ctype.h b/sane-ctype.h\nnew file mode 100644\nindex 0000000000..cbea1b299b\n--- /dev/null\n+++ b/sane-ctype.h\n@@ -0,0 +1,66 @@\n+#ifndef SANE_CTYPE_H\n+#define SANE_CTYPE_H\n+\n+/* Sane ctype - no locale, and works with signed chars */\n+#undef isascii\n+#undef isspace\n+#undef isdigit\n+#undef isalpha\n+#undef isalnum\n+#undef isprint\n+#undef islower\n+#undef isupper\n+#undef tolower\n+#undef toupper\n+#undef iscntrl\n+#undef ispunct\n+#undef isxdigit\n+\n+extern const unsigned char sane_ctype[256];\n+extern const signed char hexval_table[256];\n+#define GIT_SPACE 0x01\n+#define GIT_DIGIT 0x02\n+#define GIT_ALPHA 0x04\n+#define GIT_GLOB_SPECIAL 0x08\n+#define GIT_REGEX_SPECIAL 0x10\n+#define GIT_PATHSPEC_MAGIC 0x20\n+#define GIT_CNTRL 0x40\n+#define GIT_PUNCT 0x80\n+#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n+#define isascii(x) (((x) & ~0x7f) == 0)\n+#define isspace(x) sane_istest(x,GIT_SPACE)\n+#define isdigit(x) sane_istest(x,GIT_DIGIT)\n+#define isalpha(x) sane_istest(x,GIT_ALPHA)\n+#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)\n+#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)\n+#define islower(x) sane_iscase(x, 1)\n+#define isupper(x) sane_iscase(x, 0)\n+#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)\n+#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)\n+#define iscntrl(x) (sane_istest(x,GIT_CNTRL))\n+#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \\\n+\t\tGIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)\n+#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n+#define tolower(x) sane_case((unsigned char)(x), 0x20)\n+#define toupper(x) sane_case((unsigned char)(x), 0)\n+#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)\n+\n+static inline int sane_case(int x, int high)\n+{\n+\tif (sane_istest(x, GIT_ALPHA))\n+\t\tx = (x & ~0x20) | high;\n+\treturn x;\n+}\n+\n+static inline int sane_iscase(int x, int is_lower)\n+{\n+\tif (!sane_istest(x, GIT_ALPHA))\n+\t\treturn 0;\n+\n+\tif (is_lower)\n+\t\treturn (x & 0x20) != 0;\n+\telse\n+\t\treturn (x & 0x20) == 0;\n+}\n+\n+#endif\n-- \n2.41.0.rc2.161.g9c6817b8e7-goog\n\n"},{"id":"478101","messageId":"20230606171002.914075-4-calvinwan@google.com","threadId":"59752","inReplyTo":"20230606170711.912972-1-calvinwan@google.com","subject":"[PATCH v3 4/8] kwset: move translation table from ctype","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-06T17:09:58Z","receivedAt":"2023-06-06T17:10:26Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"This table was originally introduced to solely be used with kwset\nmachinery (0f871cf56e), so it would make sense for it to belong in\nkwset.[ch] rather than ctype.c and git-compat-util.h. It is only used in\ndiffcore-pickaxe.c, which already includes kwset.h so no other headers\nhave to be modified.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n ctype.c           | 36 ------------------------------------\n git-compat-util.h |  3 ---\n kwset.c           | 36 ++++++++++++++++++++++++++++++++++++\n kwset.h           |  2 ++\n 4 files changed, 38 insertions(+), 39 deletions(-)\n\ndiff --git a/ctype.c b/ctype.c\nindex fc0225cebd..3451745550 100644\n--- a/ctype.c\n+++ b/ctype.c\n@@ -28,39 +28,3 @@ const unsigned char sane_ctype[256] = {\n \tA, A, A, A, A, A, A, A, A, A, A, R, R, U, P, X,\t\t/* 112..127 */\n \t/* Nothing in the 128.. range */\n };\n-\n-/* For case-insensitive kwset */\n-const unsigned char tolower_trans_tbl[256] = {\n-\t0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n-\t0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n-\t0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n-\t0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n-\t ' ',  '!',  '\"',  '#',  '$',  '%',  '&', 0x27,\n-\t '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',\n-\t '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',\n-\t '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',\n-\t '@',  'a',  'b',  'c',  'd',  'e',  'f',  'g',\n-\t 'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',\n-\t 'p',  'q',  'r',  's',  't',  'u',  'v',  'w',\n-\t 'x',  'y',  'z',  '[', 0x5c,  ']',  '^',  '_',\n-\t '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',\n-\t 'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',\n-\t 'p',  'q',  'r',  's',  't',  'u',  'v',  'w',\n-\t 'x',  'y',  'z',  '{',  '|',  '}',  '~', 0x7f,\n-\t0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n-\t0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n-\t0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n-\t0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n-\t0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n-\t0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n-\t0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n-\t0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n-\t0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n-\t0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n-\t0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n-\t0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n-\t0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n-\t0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n-\t0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n-\t0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n-};\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 2151d8b437..9d3c21acbb 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -1150,9 +1150,6 @@ static inline size_t xsize_t(off_t len)\n #define HOST_NAME_MAX 256\n #endif\n \n-/* in ctype.c, for kwset users */\n-extern const unsigned char tolower_trans_tbl[256];\n-\n #include \"sane-ctype.h\"\n \n /*\ndiff --git a/kwset.c b/kwset.c\nindex 4b14d4f86b..bbfcf815a5 100644\n--- a/kwset.c\n+++ b/kwset.c\n@@ -49,6 +49,42 @@ static void *obstack_chunk_alloc(long size)\n \n #define U(c) ((unsigned char) (c))\n \n+/* For case-insensitive kwset */\n+const unsigned char tolower_trans_tbl[256] = {\n+\t0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n+\t0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n+\t0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n+\t0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n+\t ' ',  '!',  '\"',  '#',  '$',  '%',  '&', 0x27,\n+\t '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',\n+\t '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',\n+\t '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',\n+\t '@',  'a',  'b',  'c',  'd',  'e',  'f',  'g',\n+\t 'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',\n+\t 'p',  'q',  'r',  's',  't',  'u',  'v',  'w',\n+\t 'x',  'y',  'z',  '[', 0x5c,  ']',  '^',  '_',\n+\t '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',\n+\t 'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',\n+\t 'p',  'q',  'r',  's',  't',  'u',  'v',  'w',\n+\t 'x',  'y',  'z',  '{',  '|',  '}',  '~', 0x7f,\n+\t0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n+\t0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n+\t0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n+\t0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n+\t0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n+\t0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n+\t0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n+\t0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n+\t0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n+\t0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n+\t0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n+\t0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n+\t0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n+\t0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n+\t0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n+\t0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n+};\n+\n /* Balanced tree of edges and labels leaving a given trie node. */\n struct tree\n {\ndiff --git a/kwset.h b/kwset.h\nindex f50ecae573..d42a793a30 100644\n--- a/kwset.h\n+++ b/kwset.h\n@@ -26,6 +26,8 @@\n    The author may be reached (Email) at the address mike@ai.mit.edu,\n    or (US mail) as Mike Haertel c/o Free Software Foundation. */\n \n+extern const unsigned char tolower_trans_tbl[256];\n+\n struct kwsmatch\n {\n   int index;\t\t\t/* Index number of matching keyword. */\n-- \n2.41.0.rc2.161.g9c6817b8e7-goog\n\n"},{"id":"478102","messageId":"20230606171002.914075-5-calvinwan@google.com","threadId":"59752","inReplyTo":"20230606170711.912972-1-calvinwan@google.com","subject":"[PATCH v3 5/8] common.h: move non-compat specific macros and functions","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-06T17:09:59Z","receivedAt":"2023-06-06T17:10:30Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"git-compat-util.h has grown to a large and difficult to read file partly\nbecause its set of functionality is overloaded. Besides being a\ncompatibility file that ensures Git's operation across different\noperating systems, it has also become a dumping ground for commonly used\nmacros and static inline functions.\n\nThis commit separates out macros and static inline functions that are\ncompatible across operating systems into common.h. common.h is\nreincluded back into git-compat-util.h so that other files do not also\nhave to include it. The eventual goal is for common.h to be separated\nout into more reasonable boundaries, but for now this should be a good\nfirst step towards that goal.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n common.h          | 410 ++++++++++++++++++++++++++++++++++++++++++++++\n git-compat-util.h | 402 +--------------------------------------------\n 2 files changed, 412 insertions(+), 400 deletions(-)\n create mode 100644 common.h\n\ndiff --git a/common.h b/common.h\nnew file mode 100644\nindex 0000000000..0f164c1071\n--- /dev/null\n+++ b/common.h\n@@ -0,0 +1,410 @@\n+#ifndef COMMON_H\n+#define COMMON_H\n+\n+#include \"git-compat-util.h\"\n+#include \"wrapper.h\"\n+\n+/*\n+ * ARRAY_SIZE - get the number of elements in a visible array\n+ * @x: the array whose size you want.\n+ *\n+ * This does not work on pointers, or arrays declared as [], or\n+ * function parameters.  With correct compiler support, such usage\n+ * will cause a build error (see the build_assert_or_zero macro).\n+ */\n+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + BARF_UNLESS_AN_ARRAY(x))\n+\n+#define bitsizeof(x)  (CHAR_BIT * sizeof(x))\n+\n+#define maximum_signed_value_of_type(a) \\\n+    (INTMAX_MAX >> (bitsizeof(intmax_t) - bitsizeof(a)))\n+\n+#define maximum_unsigned_value_of_type(a) \\\n+    (UINTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a)))\n+\n+/*\n+ * Signed integer overflow is undefined in C, so here's a helper macro\n+ * to detect if the sum of two integers will overflow.\n+ *\n+ * Requires: a >= 0, typeof(a) equals typeof(b)\n+ */\n+#define signed_add_overflows(a, b) \\\n+    ((b) > maximum_signed_value_of_type(a) - (a))\n+\n+#define unsigned_add_overflows(a, b) \\\n+    ((b) > maximum_unsigned_value_of_type(a) - (a))\n+\n+/*\n+ * Returns true if the multiplication of \"a\" and \"b\" will\n+ * overflow. The types of \"a\" and \"b\" must match and must be unsigned.\n+ * Note that this macro evaluates \"a\" twice!\n+ */\n+#define unsigned_mult_overflows(a, b) \\\n+    ((a) && (b) > maximum_unsigned_value_of_type(a) / (a))\n+\n+/*\n+ * Returns true if the left shift of \"a\" by \"shift\" bits will\n+ * overflow. The type of \"a\" must be unsigned.\n+ */\n+#define unsigned_left_shift_overflows(a, shift) \\\n+    ((shift) < bitsizeof(a) && \\\n+     (a) > maximum_unsigned_value_of_type(a) >> (shift))\n+\n+#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))\n+#define HAS_MULTI_BITS(i)  ((i) & ((i) - 1))  /* checks if an integer has more than 1 bit set */\n+\n+#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))\n+\n+/* Approximation of the length of the decimal representation of this type. */\n+#define decimal_length(x)\t((int)(sizeof(x) * 2.56 + 0.5) + 1)\n+\n+/*\n+ * If the string \"str\" begins with the string found in \"prefix\", return 1.\n+ * The \"out\" parameter is set to \"str + strlen(prefix)\" (i.e., to the point in\n+ * the string right after the prefix).\n+ *\n+ * Otherwise, return 0 and leave \"out\" untouched.\n+ *\n+ * Examples:\n+ *\n+ *   [extract branch name, fail if not a branch]\n+ *   if (!skip_prefix(ref, \"refs/heads/\", &branch)\n+ *\treturn -1;\n+ *\n+ *   [skip prefix if present, otherwise use whole string]\n+ *   skip_prefix(name, \"refs/heads/\", &name);\n+ */\n+static inline int skip_prefix(const char *str, const char *prefix,\n+\t\t\t      const char **out)\n+{\n+\tdo {\n+\t\tif (!*prefix) {\n+\t\t\t*out = str;\n+\t\t\treturn 1;\n+\t\t}\n+\t} while (*str++ == *prefix++);\n+\treturn 0;\n+}\n+\n+/*\n+ * Like skip_prefix, but promises never to read past \"len\" bytes of the input\n+ * buffer, and returns the remaining number of bytes in \"out\" via \"outlen\".\n+ */\n+static inline int skip_prefix_mem(const char *buf, size_t len,\n+\t\t\t\t  const char *prefix,\n+\t\t\t\t  const char **out, size_t *outlen)\n+{\n+\tsize_t prefix_len = strlen(prefix);\n+\tif (prefix_len <= len && !memcmp(buf, prefix, prefix_len)) {\n+\t\t*out = buf + prefix_len;\n+\t\t*outlen = len - prefix_len;\n+\t\treturn 1;\n+\t}\n+\treturn 0;\n+}\n+\n+/*\n+ * If buf ends with suffix, return 1 and subtract the length of the suffix\n+ * from *len. Otherwise, return 0 and leave *len untouched.\n+ */\n+static inline int strip_suffix_mem(const char *buf, size_t *len,\n+\t\t\t\t   const char *suffix)\n+{\n+\tsize_t suflen = strlen(suffix);\n+\tif (*len < suflen || memcmp(buf + (*len - suflen), suffix, suflen))\n+\t\treturn 0;\n+\t*len -= suflen;\n+\treturn 1;\n+}\n+\n+/*\n+ * If str ends with suffix, return 1 and set *len to the size of the string\n+ * without the suffix. Otherwise, return 0 and set *len to the size of the\n+ * string.\n+ *\n+ * Note that we do _not_ NUL-terminate str to the new length.\n+ */\n+static inline int strip_suffix(const char *str, const char *suffix, size_t *len)\n+{\n+\t*len = strlen(str);\n+\treturn strip_suffix_mem(str, len, suffix);\n+}\n+\n+#define SWAP(a, b) do {\t\t\t\t\t\t\\\n+\tvoid *_swap_a_ptr = &(a);\t\t\t\t\\\n+\tvoid *_swap_b_ptr = &(b);\t\t\t\t\\\n+\tunsigned char _swap_buffer[sizeof(a)];\t\t\t\\\n+\tmemcpy(_swap_buffer, _swap_a_ptr, sizeof(a));\t\t\\\n+\tmemcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a) +\t\t\\\n+\t       BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b)));\t\\\n+\tmemcpy(_swap_b_ptr, _swap_buffer, sizeof(a));\t\t\\\n+} while (0)\n+\n+static inline size_t st_add(size_t a, size_t b)\n+{\n+\tif (unsigned_add_overflows(a, b))\n+\t\tdie(\"size_t overflow: %\"PRIuMAX\" + %\"PRIuMAX,\n+\t\t    (uintmax_t)a, (uintmax_t)b);\n+\treturn a + b;\n+}\n+#define st_add3(a,b,c)   st_add(st_add((a),(b)),(c))\n+#define st_add4(a,b,c,d) st_add(st_add3((a),(b),(c)),(d))\n+\n+static inline size_t st_mult(size_t a, size_t b)\n+{\n+\tif (unsigned_mult_overflows(a, b))\n+\t\tdie(\"size_t overflow: %\"PRIuMAX\" * %\"PRIuMAX,\n+\t\t    (uintmax_t)a, (uintmax_t)b);\n+\treturn a * b;\n+}\n+\n+static inline size_t st_sub(size_t a, size_t b)\n+{\n+\tif (a < b)\n+\t\tdie(\"size_t underflow: %\"PRIuMAX\" - %\"PRIuMAX,\n+\t\t    (uintmax_t)a, (uintmax_t)b);\n+\treturn a - b;\n+}\n+\n+static inline size_t st_left_shift(size_t a, unsigned shift)\n+{\n+\tif (unsigned_left_shift_overflows(a, shift))\n+\t\tdie(\"size_t overflow: %\"PRIuMAX\" << %u\",\n+\t\t    (uintmax_t)a, shift);\n+\treturn a << shift;\n+}\n+\n+static inline unsigned long cast_size_t_to_ulong(size_t a)\n+{\n+\tif (a != (unsigned long)a)\n+\t\tdie(\"object too large to read on this platform: %\"\n+\t\t    PRIuMAX\" is cut off to %lu\",\n+\t\t    (uintmax_t)a, (unsigned long)a);\n+\treturn (unsigned long)a;\n+}\n+\n+static inline int cast_size_t_to_int(size_t a)\n+{\n+\tif (a > INT_MAX)\n+\t\tdie(\"number too large to represent as int on this platform: %\"PRIuMAX,\n+\t\t    (uintmax_t)a);\n+\treturn (int)a;\n+}\n+\n+\n+/*\n+ * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note\n+ * that ptr is used twice, so don't pass e.g. ptr++.\n+ */\n+#define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)\n+\n+#define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))\n+#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))\n+#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))\n+\n+#define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \\\n+\tBARF_UNLESS_COPYABLE((dst), (src)))\n+static inline void copy_array(void *dst, const void *src, size_t n, size_t size)\n+{\n+\tif (n)\n+\t\tmemcpy(dst, src, st_mult(size, n));\n+}\n+\n+#define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \\\n+\tBARF_UNLESS_COPYABLE((dst), (src)))\n+static inline void move_array(void *dst, const void *src, size_t n, size_t size)\n+{\n+\tif (n)\n+\t\tmemmove(dst, src, st_mult(size, n));\n+}\n+\n+#define DUP_ARRAY(dst, src, n) do { \\\n+\tsize_t dup_array_n_ = (n); \\\n+\tCOPY_ARRAY(ALLOC_ARRAY((dst), dup_array_n_), (src), dup_array_n_); \\\n+} while (0)\n+\n+/*\n+ * These functions help you allocate structs with flex arrays, and copy\n+ * the data directly into the array. For example, if you had:\n+ *\n+ *   struct foo {\n+ *     int bar;\n+ *     char name[FLEX_ARRAY];\n+ *   };\n+ *\n+ * you can do:\n+ *\n+ *   struct foo *f;\n+ *   FLEX_ALLOC_MEM(f, name, src, len);\n+ *\n+ * to allocate a \"foo\" with the contents of \"src\" in the \"name\" field.\n+ * The resulting struct is automatically zero'd, and the flex-array field\n+ * is NUL-terminated (whether the incoming src buffer was or not).\n+ *\n+ * The FLEXPTR_* variants operate on structs that don't use flex-arrays,\n+ * but do want to store a pointer to some extra data in the same allocated\n+ * block. For example, if you have:\n+ *\n+ *   struct foo {\n+ *     char *name;\n+ *     int bar;\n+ *   };\n+ *\n+ * you can do:\n+ *\n+ *   struct foo *f;\n+ *   FLEXPTR_ALLOC_STR(f, name, src);\n+ *\n+ * and \"name\" will point to a block of memory after the struct, which will be\n+ * freed along with the struct (but the pointer can be repointed anywhere).\n+ *\n+ * The *_STR variants accept a string parameter rather than a ptr/len\n+ * combination.\n+ *\n+ * Note that these macros will evaluate the first parameter multiple\n+ * times, and it must be assignable as an lvalue.\n+ */\n+#define FLEX_ALLOC_MEM(x, flexname, buf, len) do { \\\n+\tsize_t flex_array_len_ = (len); \\\n+\t(x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \\\n+\tmemcpy((void *)(x)->flexname, (buf), flex_array_len_); \\\n+} while (0)\n+#define FLEXPTR_ALLOC_MEM(x, ptrname, buf, len) do { \\\n+\tsize_t flex_array_len_ = (len); \\\n+\t(x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \\\n+\tmemcpy((x) + 1, (buf), flex_array_len_); \\\n+\t(x)->ptrname = (void *)((x)+1); \\\n+} while(0)\n+#define FLEX_ALLOC_STR(x, flexname, str) \\\n+\tFLEX_ALLOC_MEM((x), flexname, (str), strlen(str))\n+#define FLEXPTR_ALLOC_STR(x, ptrname, str) \\\n+\tFLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))\n+\n+static inline char *xstrdup_or_null(const char *str)\n+{\n+\treturn str ? xstrdup(str) : NULL;\n+}\n+\n+static inline size_t xsize_t(off_t len)\n+{\n+\tif (len < 0 || (uintmax_t) len > SIZE_MAX)\n+\t\tdie(\"Cannot handle files this big\");\n+\treturn (size_t) len;\n+}\n+\n+/*\n+ * Like skip_prefix, but compare case-insensitively. Note that the comparison\n+ * is done via tolower(), so it is strictly ASCII (no multi-byte characters or\n+ * locale-specific conversions).\n+ */\n+static inline int skip_iprefix(const char *str, const char *prefix,\n+\t\t\t       const char **out)\n+{\n+\tdo {\n+\t\tif (!*prefix) {\n+\t\t\t*out = str;\n+\t\t\treturn 1;\n+\t\t}\n+\t} while (tolower(*str++) == tolower(*prefix++));\n+\treturn 0;\n+}\n+\n+/*\n+ * Like skip_prefix_mem, but compare case-insensitively. Note that the\n+ * comparison is done via tolower(), so it is strictly ASCII (no multi-byte\n+ * characters or locale-specific conversions).\n+ */\n+static inline int skip_iprefix_mem(const char *buf, size_t len,\n+\t\t\t\t   const char *prefix,\n+\t\t\t\t   const char **out, size_t *outlen)\n+{\n+\tdo {\n+\t\tif (!*prefix) {\n+\t\t\t*out = buf;\n+\t\t\t*outlen = len;\n+\t\t\treturn 1;\n+\t\t}\n+\t} while (len-- > 0 && tolower(*buf++) == tolower(*prefix++));\n+\treturn 0;\n+}\n+\n+static inline int strtoul_ui(char const *s, int base, unsigned int *result)\n+{\n+\tunsigned long ul;\n+\tchar *p;\n+\n+\terrno = 0;\n+\t/* negative values would be accepted by strtoul */\n+\tif (strchr(s, '-'))\n+\t\treturn -1;\n+\tul = strtoul(s, &p, base);\n+\tif (errno || *p || p == s || (unsigned int) ul != ul)\n+\t\treturn -1;\n+\t*result = ul;\n+\treturn 0;\n+}\n+\n+static inline int strtol_i(char const *s, int base, int *result)\n+{\n+\tlong ul;\n+\tchar *p;\n+\n+\terrno = 0;\n+\tul = strtol(s, &p, base);\n+\tif (errno || *p || p == s || (int) ul != ul)\n+\t\treturn -1;\n+\t*result = ul;\n+\treturn 0;\n+}\n+\n+static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,\n+\t\t\t      size_t nmatch, regmatch_t pmatch[], int eflags)\n+{\n+\tassert(nmatch > 0 && pmatch);\n+\tpmatch[0].rm_so = 0;\n+\tpmatch[0].rm_eo = size;\n+\treturn regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);\n+}\n+\n+/*\n+ * Our code often opens a path to an optional file, to work on its\n+ * contents when we can successfully open it.  We can ignore a failure\n+ * to open if such an optional file does not exist, but we do want to\n+ * report a failure in opening for other reasons (e.g. we got an I/O\n+ * error, or the file is there, but we lack the permission to open).\n+ *\n+ * Call this function after seeing an error from open() or fopen() to\n+ * see if the errno indicates a missing file that we can safely ignore.\n+ */\n+static inline int is_missing_file_error(int errno_)\n+{\n+\treturn (errno_ == ENOENT || errno_ == ENOTDIR);\n+}\n+\n+/*\n+ * container_of - Get the address of an object containing a field.\n+ *\n+ * @ptr: pointer to the field.\n+ * @type: type of the object.\n+ * @member: name of the field within the object.\n+ */\n+#define container_of(ptr, type, member) \\\n+\t((type *) ((char *)(ptr) - offsetof(type, member)))\n+\n+/*\n+ * helper function for `container_of_or_null' to avoid multiple\n+ * evaluation of @ptr\n+ */\n+static inline void *container_of_or_null_offset(void *ptr, size_t offset)\n+{\n+\treturn ptr ? (char *)ptr - offset : NULL;\n+}\n+\n+/*\n+ * like `container_of', but allows returned value to be NULL\n+ */\n+#define container_of_or_null(ptr, type, member) \\\n+\t(type *)container_of_or_null_offset(ptr, offsetof(type, member))\n+\n+\n+#endif\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 9d3c21acbb..f73c8727d1 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -106,51 +106,6 @@ struct strbuf;\n \tBUILD_ASSERT_OR_ZERO(0 ? ((*(dst) = *(src)), 0) : \\\n \t\t\t\t sizeof(*(dst)) == sizeof(*(src)))\n #endif\n-/*\n- * ARRAY_SIZE - get the number of elements in a visible array\n- * @x: the array whose size you want.\n- *\n- * This does not work on pointers, or arrays declared as [], or\n- * function parameters.  With correct compiler support, such usage\n- * will cause a build error (see the build_assert_or_zero macro).\n- */\n-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]) + BARF_UNLESS_AN_ARRAY(x))\n-\n-#define bitsizeof(x)  (CHAR_BIT * sizeof(x))\n-\n-#define maximum_signed_value_of_type(a) \\\n-    (INTMAX_MAX >> (bitsizeof(intmax_t) - bitsizeof(a)))\n-\n-#define maximum_unsigned_value_of_type(a) \\\n-    (UINTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a)))\n-\n-/*\n- * Signed integer overflow is undefined in C, so here's a helper macro\n- * to detect if the sum of two integers will overflow.\n- *\n- * Requires: a >= 0, typeof(a) equals typeof(b)\n- */\n-#define signed_add_overflows(a, b) \\\n-    ((b) > maximum_signed_value_of_type(a) - (a))\n-\n-#define unsigned_add_overflows(a, b) \\\n-    ((b) > maximum_unsigned_value_of_type(a) - (a))\n-\n-/*\n- * Returns true if the multiplication of \"a\" and \"b\" will\n- * overflow. The types of \"a\" and \"b\" must match and must be unsigned.\n- * Note that this macro evaluates \"a\" twice!\n- */\n-#define unsigned_mult_overflows(a, b) \\\n-    ((a) && (b) > maximum_unsigned_value_of_type(a) / (a))\n-\n-/*\n- * Returns true if the left shift of \"a\" by \"shift\" bits will\n- * overflow. The type of \"a\" must be unsigned.\n- */\n-#define unsigned_left_shift_overflows(a, shift) \\\n-    ((shift) < bitsizeof(a) && \\\n-     (a) > maximum_unsigned_value_of_type(a) >> (shift))\n \n #ifdef __GNUC__\n #define TYPEOF(x) (__typeof__(x))\n@@ -158,14 +113,6 @@ struct strbuf;\n #define TYPEOF(x)\n #endif\n \n-#define MSB(x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits))))\n-#define HAS_MULTI_BITS(i)  ((i) & ((i) - 1))  /* checks if an integer has more than 1 bit set */\n-\n-#define DIV_ROUND_UP(n,d) (((n) + (d) - 1) / (d))\n-\n-/* Approximation of the length of the decimal representation of this type. */\n-#define decimal_length(x)\t((int)(sizeof(x) * 2.56 + 0.5) + 1)\n-\n #ifdef __MINGW64__\n #define _POSIX_C_SOURCE 1\n #elif defined(__sun__)\n@@ -677,88 +624,6 @@ void set_warn_routine(report_fn routine);\n report_fn get_warn_routine(void);\n void set_die_is_recursing_routine(int (*routine)(void));\n \n-/*\n- * If the string \"str\" begins with the string found in \"prefix\", return 1.\n- * The \"out\" parameter is set to \"str + strlen(prefix)\" (i.e., to the point in\n- * the string right after the prefix).\n- *\n- * Otherwise, return 0 and leave \"out\" untouched.\n- *\n- * Examples:\n- *\n- *   [extract branch name, fail if not a branch]\n- *   if (!skip_prefix(ref, \"refs/heads/\", &branch)\n- *\treturn -1;\n- *\n- *   [skip prefix if present, otherwise use whole string]\n- *   skip_prefix(name, \"refs/heads/\", &name);\n- */\n-static inline int skip_prefix(const char *str, const char *prefix,\n-\t\t\t      const char **out)\n-{\n-\tdo {\n-\t\tif (!*prefix) {\n-\t\t\t*out = str;\n-\t\t\treturn 1;\n-\t\t}\n-\t} while (*str++ == *prefix++);\n-\treturn 0;\n-}\n-\n-/*\n- * Like skip_prefix, but promises never to read past \"len\" bytes of the input\n- * buffer, and returns the remaining number of bytes in \"out\" via \"outlen\".\n- */\n-static inline int skip_prefix_mem(const char *buf, size_t len,\n-\t\t\t\t  const char *prefix,\n-\t\t\t\t  const char **out, size_t *outlen)\n-{\n-\tsize_t prefix_len = strlen(prefix);\n-\tif (prefix_len <= len && !memcmp(buf, prefix, prefix_len)) {\n-\t\t*out = buf + prefix_len;\n-\t\t*outlen = len - prefix_len;\n-\t\treturn 1;\n-\t}\n-\treturn 0;\n-}\n-\n-/*\n- * If buf ends with suffix, return 1 and subtract the length of the suffix\n- * from *len. Otherwise, return 0 and leave *len untouched.\n- */\n-static inline int strip_suffix_mem(const char *buf, size_t *len,\n-\t\t\t\t   const char *suffix)\n-{\n-\tsize_t suflen = strlen(suffix);\n-\tif (*len < suflen || memcmp(buf + (*len - suflen), suffix, suflen))\n-\t\treturn 0;\n-\t*len -= suflen;\n-\treturn 1;\n-}\n-\n-/*\n- * If str ends with suffix, return 1 and set *len to the size of the string\n- * without the suffix. Otherwise, return 0 and set *len to the size of the\n- * string.\n- *\n- * Note that we do _not_ NUL-terminate str to the new length.\n- */\n-static inline int strip_suffix(const char *str, const char *suffix, size_t *len)\n-{\n-\t*len = strlen(str);\n-\treturn strip_suffix_mem(str, len, suffix);\n-}\n-\n-#define SWAP(a, b) do {\t\t\t\t\t\t\\\n-\tvoid *_swap_a_ptr = &(a);\t\t\t\t\\\n-\tvoid *_swap_b_ptr = &(b);\t\t\t\t\\\n-\tunsigned char _swap_buffer[sizeof(a)];\t\t\t\\\n-\tmemcpy(_swap_buffer, _swap_a_ptr, sizeof(a));\t\t\\\n-\tmemcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a) +\t\t\\\n-\t       BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b)));\t\\\n-\tmemcpy(_swap_b_ptr, _swap_buffer, sizeof(a));\t\t\\\n-} while (0)\n-\n #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)\n \n #ifndef PROT_READ\n@@ -964,57 +829,6 @@ const char *inet_ntop(int af, const void *src, char *dst, size_t size);\n int git_atexit(void (*handler)(void));\n #endif\n \n-static inline size_t st_add(size_t a, size_t b)\n-{\n-\tif (unsigned_add_overflows(a, b))\n-\t\tdie(\"size_t overflow: %\"PRIuMAX\" + %\"PRIuMAX,\n-\t\t    (uintmax_t)a, (uintmax_t)b);\n-\treturn a + b;\n-}\n-#define st_add3(a,b,c)   st_add(st_add((a),(b)),(c))\n-#define st_add4(a,b,c,d) st_add(st_add3((a),(b),(c)),(d))\n-\n-static inline size_t st_mult(size_t a, size_t b)\n-{\n-\tif (unsigned_mult_overflows(a, b))\n-\t\tdie(\"size_t overflow: %\"PRIuMAX\" * %\"PRIuMAX,\n-\t\t    (uintmax_t)a, (uintmax_t)b);\n-\treturn a * b;\n-}\n-\n-static inline size_t st_sub(size_t a, size_t b)\n-{\n-\tif (a < b)\n-\t\tdie(\"size_t underflow: %\"PRIuMAX\" - %\"PRIuMAX,\n-\t\t    (uintmax_t)a, (uintmax_t)b);\n-\treturn a - b;\n-}\n-\n-static inline size_t st_left_shift(size_t a, unsigned shift)\n-{\n-\tif (unsigned_left_shift_overflows(a, shift))\n-\t\tdie(\"size_t overflow: %\"PRIuMAX\" << %u\",\n-\t\t    (uintmax_t)a, shift);\n-\treturn a << shift;\n-}\n-\n-static inline unsigned long cast_size_t_to_ulong(size_t a)\n-{\n-\tif (a != (unsigned long)a)\n-\t\tdie(\"object too large to read on this platform: %\"\n-\t\t    PRIuMAX\" is cut off to %lu\",\n-\t\t    (uintmax_t)a, (unsigned long)a);\n-\treturn (unsigned long)a;\n-}\n-\n-static inline int cast_size_t_to_int(size_t a)\n-{\n-\tif (a > INT_MAX)\n-\t\tdie(\"number too large to represent as int on this platform: %\"PRIuMAX,\n-\t\t    (uintmax_t)a);\n-\treturn (int)a;\n-}\n-\n /*\n  * Limit size of IO chunks, because huge chunks only cause pain.  OS X\n  * 64-bit is buggy, returning EINVAL if len >= INT_MAX; and even in\n@@ -1046,177 +860,12 @@ static inline int cast_size_t_to_int(size_t a)\n # define xalloca_free(p)    (free(p))\n #endif\n \n-/*\n- * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note\n- * that ptr is used twice, so don't pass e.g. ptr++.\n- */\n-#define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)\n-\n-#define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))\n-#define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))\n-#define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))\n-\n-#define COPY_ARRAY(dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \\\n-\tBARF_UNLESS_COPYABLE((dst), (src)))\n-static inline void copy_array(void *dst, const void *src, size_t n, size_t size)\n-{\n-\tif (n)\n-\t\tmemcpy(dst, src, st_mult(size, n));\n-}\n-\n-#define MOVE_ARRAY(dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \\\n-\tBARF_UNLESS_COPYABLE((dst), (src)))\n-static inline void move_array(void *dst, const void *src, size_t n, size_t size)\n-{\n-\tif (n)\n-\t\tmemmove(dst, src, st_mult(size, n));\n-}\n-\n-#define DUP_ARRAY(dst, src, n) do { \\\n-\tsize_t dup_array_n_ = (n); \\\n-\tCOPY_ARRAY(ALLOC_ARRAY((dst), dup_array_n_), (src), dup_array_n_); \\\n-} while (0)\n-\n-/*\n- * These functions help you allocate structs with flex arrays, and copy\n- * the data directly into the array. For example, if you had:\n- *\n- *   struct foo {\n- *     int bar;\n- *     char name[FLEX_ARRAY];\n- *   };\n- *\n- * you can do:\n- *\n- *   struct foo *f;\n- *   FLEX_ALLOC_MEM(f, name, src, len);\n- *\n- * to allocate a \"foo\" with the contents of \"src\" in the \"name\" field.\n- * The resulting struct is automatically zero'd, and the flex-array field\n- * is NUL-terminated (whether the incoming src buffer was or not).\n- *\n- * The FLEXPTR_* variants operate on structs that don't use flex-arrays,\n- * but do want to store a pointer to some extra data in the same allocated\n- * block. For example, if you have:\n- *\n- *   struct foo {\n- *     char *name;\n- *     int bar;\n- *   };\n- *\n- * you can do:\n- *\n- *   struct foo *f;\n- *   FLEXPTR_ALLOC_STR(f, name, src);\n- *\n- * and \"name\" will point to a block of memory after the struct, which will be\n- * freed along with the struct (but the pointer can be repointed anywhere).\n- *\n- * The *_STR variants accept a string parameter rather than a ptr/len\n- * combination.\n- *\n- * Note that these macros will evaluate the first parameter multiple\n- * times, and it must be assignable as an lvalue.\n- */\n-#define FLEX_ALLOC_MEM(x, flexname, buf, len) do { \\\n-\tsize_t flex_array_len_ = (len); \\\n-\t(x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \\\n-\tmemcpy((void *)(x)->flexname, (buf), flex_array_len_); \\\n-} while (0)\n-#define FLEXPTR_ALLOC_MEM(x, ptrname, buf, len) do { \\\n-\tsize_t flex_array_len_ = (len); \\\n-\t(x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \\\n-\tmemcpy((x) + 1, (buf), flex_array_len_); \\\n-\t(x)->ptrname = (void *)((x)+1); \\\n-} while(0)\n-#define FLEX_ALLOC_STR(x, flexname, str) \\\n-\tFLEX_ALLOC_MEM((x), flexname, (str), strlen(str))\n-#define FLEXPTR_ALLOC_STR(x, ptrname, str) \\\n-\tFLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))\n-\n-static inline char *xstrdup_or_null(const char *str)\n-{\n-\treturn str ? xstrdup(str) : NULL;\n-}\n-\n-static inline size_t xsize_t(off_t len)\n-{\n-\tif (len < 0 || (uintmax_t) len > SIZE_MAX)\n-\t\tdie(\"Cannot handle files this big\");\n-\treturn (size_t) len;\n-}\n-\n #ifndef HOST_NAME_MAX\n #define HOST_NAME_MAX 256\n #endif\n \n #include \"sane-ctype.h\"\n \n-/*\n- * Like skip_prefix, but compare case-insensitively. Note that the comparison\n- * is done via tolower(), so it is strictly ASCII (no multi-byte characters or\n- * locale-specific conversions).\n- */\n-static inline int skip_iprefix(const char *str, const char *prefix,\n-\t\t\t       const char **out)\n-{\n-\tdo {\n-\t\tif (!*prefix) {\n-\t\t\t*out = str;\n-\t\t\treturn 1;\n-\t\t}\n-\t} while (tolower(*str++) == tolower(*prefix++));\n-\treturn 0;\n-}\n-\n-/*\n- * Like skip_prefix_mem, but compare case-insensitively. Note that the\n- * comparison is done via tolower(), so it is strictly ASCII (no multi-byte\n- * characters or locale-specific conversions).\n- */\n-static inline int skip_iprefix_mem(const char *buf, size_t len,\n-\t\t\t\t   const char *prefix,\n-\t\t\t\t   const char **out, size_t *outlen)\n-{\n-\tdo {\n-\t\tif (!*prefix) {\n-\t\t\t*out = buf;\n-\t\t\t*outlen = len;\n-\t\t\treturn 1;\n-\t\t}\n-\t} while (len-- > 0 && tolower(*buf++) == tolower(*prefix++));\n-\treturn 0;\n-}\n-\n-static inline int strtoul_ui(char const *s, int base, unsigned int *result)\n-{\n-\tunsigned long ul;\n-\tchar *p;\n-\n-\terrno = 0;\n-\t/* negative values would be accepted by strtoul */\n-\tif (strchr(s, '-'))\n-\t\treturn -1;\n-\tul = strtoul(s, &p, base);\n-\tif (errno || *p || p == s || (unsigned int) ul != ul)\n-\t\treturn -1;\n-\t*result = ul;\n-\treturn 0;\n-}\n-\n-static inline int strtol_i(char const *s, int base, int *result)\n-{\n-\tlong ul;\n-\tchar *p;\n-\n-\terrno = 0;\n-\tul = strtol(s, &p, base);\n-\tif (errno || *p || p == s || (int) ul != ul)\n-\t\treturn -1;\n-\t*result = ul;\n-\treturn 0;\n-}\n-\n void git_stable_qsort(void *base, size_t nmemb, size_t size,\n \t\t      int(*compar)(const void *, const void *));\n #ifdef INTERNAL_QSORT\n@@ -1249,15 +898,6 @@ int git_qsort_s(void *base, size_t nmemb, size_t size,\n #error \"Git requires REG_STARTEND support. Compile with NO_REGEX=NeedsStartEnd\"\n #endif\n \n-static inline int regexec_buf(const regex_t *preg, const char *buf, size_t size,\n-\t\t\t      size_t nmatch, regmatch_t pmatch[], int eflags)\n-{\n-\tassert(nmatch > 0 && pmatch);\n-\tpmatch[0].rm_so = 0;\n-\tpmatch[0].rm_eo = size;\n-\treturn regexec(preg, buf, nmatch, pmatch, eflags | REG_STARTEND);\n-}\n-\n #ifdef USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS\n int git_regcomp(regex_t *preg, const char *pattern, int cflags);\n #define regcomp git_regcomp\n@@ -1366,21 +1006,6 @@ int git_access(const char *path, int mode);\n # endif\n #endif\n \n-/*\n- * Our code often opens a path to an optional file, to work on its\n- * contents when we can successfully open it.  We can ignore a failure\n- * to open if such an optional file does not exist, but we do want to\n- * report a failure in opening for other reasons (e.g. we got an I/O\n- * error, or the file is there, but we lack the permission to open).\n- *\n- * Call this function after seeing an error from open() or fopen() to\n- * see if the errno indicates a missing file that we can safely ignore.\n- */\n-static inline int is_missing_file_error(int errno_)\n-{\n-\treturn (errno_ == ENOENT || errno_ == ENOTDIR);\n-}\n-\n int cmd_main(int, const char **);\n \n /*\n@@ -1422,37 +1047,14 @@ int uncompress2(Bytef *dest, uLongf *destLen, const Bytef *source,\n \t\tuLong *sourceLen);\n #endif\n \n+#include \"common.h\"\n+\n /*\n  * This include must come after system headers, since it introduces macros that\n  * replace system names.\n  */\n #include \"banned.h\"\n \n-/*\n- * container_of - Get the address of an object containing a field.\n- *\n- * @ptr: pointer to the field.\n- * @type: type of the object.\n- * @member: name of the field within the object.\n- */\n-#define container_of(ptr, type, member) \\\n-\t((type *) ((char *)(ptr) - offsetof(type, member)))\n-\n-/*\n- * helper function for `container_of_or_null' to avoid multiple\n- * evaluation of @ptr\n- */\n-static inline void *container_of_or_null_offset(void *ptr, size_t offset)\n-{\n-\treturn ptr ? (char *)ptr - offset : NULL;\n-}\n-\n-/*\n- * like `container_of', but allows returned value to be NULL\n- */\n-#define container_of_or_null(ptr, type, member) \\\n-\t(type *)container_of_or_null_offset(ptr, offsetof(type, member))\n-\n /*\n  * like offsetof(), but takes a pointer to a variable of type which\n  * contains @member, instead of a specified type.\n-- \n2.41.0.rc2.161.g9c6817b8e7-goog\n\n"},{"id":"478103","messageId":"20230606171002.914075-6-calvinwan@google.com","threadId":"59752","inReplyTo":"20230606170711.912972-1-calvinwan@google.com","subject":"[PATCH v3 6/8] git-compat-util: move usage.c funcs to its header","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-06T17:10:00Z","receivedAt":"2023-06-06T17:10:35Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Signed-off-by: Calvin Wan <calvinwan@google.com>\n---\n common.h          |  1 +\n git-compat-util.h | 55 -------------------------------------------\n usage.h           | 60 +++++++++++++++++++++++++++++++++++++++++++++++\n 3 files changed, 61 insertions(+), 55 deletions(-)\n create mode 100644 usage.h\n\ndiff --git a/common.h b/common.h\nindex 0f164c1071..e3b673847d 100644\n--- a/common.h\n+++ b/common.h\n@@ -3,6 +3,7 @@\n \n #include \"git-compat-util.h\"\n #include \"wrapper.h\"\n+#include \"usage.h\"\n \n /*\n  * ARRAY_SIZE - get the number of elements in a visible array\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex f73c8727d1..481dac22b0 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -572,20 +572,6 @@ static inline int git_has_dir_sep(const char *path)\n \n #include \"compat/bswap.h\"\n \n-#include \"wrapper.h\"\n-\n-/* General helper functions */\n-NORETURN void usage(const char *err);\n-NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-int die_message(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-int die_message_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-int error(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n-\n #ifndef NO_OPENSSL\n #ifdef APPLE_COMMON_CRYPTO\n #include \"compat/apple-common-crypto.h\"\n@@ -600,30 +586,6 @@ void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n #include <openssl/rand.h>\n #endif\n \n-/*\n- * Let callers be aware of the constant return value; this can help\n- * gcc with -Wuninitialized analysis. We restrict this trick to gcc, though,\n- * because other compilers may be confused by this.\n- */\n-#if defined(__GNUC__)\n-static inline int const_error(void)\n-{\n-\treturn -1;\n-}\n-#define error(...) (error(__VA_ARGS__), const_error())\n-#define error_errno(...) (error_errno(__VA_ARGS__), const_error())\n-#endif\n-\n-typedef void (*report_fn)(const char *, va_list params);\n-\n-void set_die_routine(NORETURN_PTR report_fn routine);\n-report_fn get_die_message_routine(void);\n-void set_error_routine(report_fn routine);\n-report_fn get_error_routine(void);\n-void set_warn_routine(report_fn routine);\n-report_fn get_warn_routine(void);\n-void set_die_is_recursing_routine(int (*routine)(void));\n-\n #if defined(NO_MMAP) || defined(USE_WIN32_MMAP)\n \n #ifndef PROT_READ\n@@ -942,23 +904,6 @@ int git_regcomp(regex_t *preg, const char *pattern, int cflags);\n #endif\n #endif\n \n-/* usage.c: only to be used for testing BUG() implementation (see test-tool) */\n-extern int BUG_exit_code;\n-\n-/* usage.c: if bug() is called we should have a BUG_if_bug() afterwards */\n-extern int bug_called_must_BUG;\n-\n-__attribute__((format (printf, 3, 4))) NORETURN\n-void BUG_fl(const char *file, int line, const char *fmt, ...);\n-#define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__)\n-__attribute__((format (printf, 3, 4)))\n-void bug_fl(const char *file, int line, const char *fmt, ...);\n-#define bug(...) bug_fl(__FILE__, __LINE__, __VA_ARGS__)\n-#define BUG_if_bug(...) do { \\\n-\tif (bug_called_must_BUG) \\\n-\t\tBUG_fl(__FILE__, __LINE__, __VA_ARGS__); \\\n-} while (0)\n-\n #ifndef FSYNC_METHOD_DEFAULT\n #ifdef __APPLE__\n #define FSYNC_METHOD_DEFAULT FSYNC_METHOD_WRITEOUT_ONLY\ndiff --git a/usage.h b/usage.h\nnew file mode 100644\nindex 0000000000..770076e684\n--- /dev/null\n+++ b/usage.h\n@@ -0,0 +1,60 @@\n+#ifndef USAGE_H\n+#define USAGE_H\n+\n+#include \"git-compat-util.h\"\n+\n+/* General helper functions */\n+NORETURN void usage(const char *err);\n+NORETURN void usagef(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+NORETURN void die(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+NORETURN void die_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+int error(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+int die_message(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+int die_message_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+\n+void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));\n+\n+/*\n+ * Let callers be aware of the constant return value; this can help\n+ * gcc with -Wuninitialized analysis. We restrict this trick to gcc, though,\n+ * because other compilers may be confused by this.\n+ */\n+#if defined(__GNUC__)\n+static inline int const_error(void)\n+{\n+\treturn -1;\n+}\n+#define error(...) (error(__VA_ARGS__), const_error())\n+#define error_errno(...) (error_errno(__VA_ARGS__), const_error())\n+#endif\n+\n+typedef void (*report_fn)(const char *, va_list params);\n+\n+void set_die_routine(NORETURN_PTR report_fn routine);\n+report_fn get_die_message_routine(void);\n+void set_error_routine(report_fn routine);\n+report_fn get_error_routine(void);\n+void set_warn_routine(report_fn routine);\n+report_fn get_warn_routine(void);\n+void set_die_is_recursing_routine(int (*routine)(void));\n+\n+/* usage.c: only to be used for testing BUG() implementation (see test-tool) */\n+extern int BUG_exit_code;\n+\n+/* usage.c: if bug() is called we should have a BUG_if_bug() afterwards */\n+extern int bug_called_must_BUG;\n+\n+__attribute__((format (printf, 3, 4))) NORETURN\n+void BUG_fl(const char *file, int line, const char *fmt, ...);\n+#define BUG(...) BUG_fl(__FILE__, __LINE__, __VA_ARGS__)\n+__attribute__((format (printf, 3, 4)))\n+void bug_fl(const char *file, int line, const char *fmt, ...);\n+#define bug(...) bug_fl(__FILE__, __LINE__, __VA_ARGS__)\n+#define BUG_if_bug(...) do { \\\n+\tif (bug_called_must_BUG) \\\n+\t\tBUG_fl(__FILE__, __LINE__, __VA_ARGS__); \\\n+} while (0)\n+\n+#endif /* USAGE_H */\n-- \n2.41.0.rc2.161.g9c6817b8e7-goog\n\n"},{"id":"478104","messageId":"20230606171002.914075-7-calvinwan@google.com","threadId":"59752","inReplyTo":"20230606170711.912972-1-calvinwan@google.com","subject":"[PATCH v3 7/8] treewide: remove unnecessary includes for wrapper.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-06T17:10:01Z","receivedAt":"2023-06-06T17:10:44Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Signed-off-by: Calvin Wan <calvinwan@google.com>\n---\n apply.c                          | 1 -\n builtin/am.c                     | 1 -\n builtin/bisect.c                 | 1 -\n builtin/branch.c                 | 1 -\n builtin/bugreport.c              | 1 -\n builtin/clone.c                  | 1 -\n builtin/config.c                 | 1 -\n builtin/credential-cache.c       | 1 -\n builtin/difftool.c               | 1 -\n builtin/fast-import.c            | 1 -\n builtin/fmt-merge-msg.c          | 1 -\n builtin/gc.c                     | 1 -\n builtin/get-tar-commit-id.c      | 1 -\n builtin/index-pack.c             | 1 -\n builtin/init-db.c                | 1 -\n builtin/merge.c                  | 1 -\n builtin/pack-objects.c           | 1 -\n builtin/rebase.c                 | 1 -\n builtin/receive-pack.c           | 1 -\n builtin/rerere.c                 | 1 -\n builtin/unpack-file.c            | 1 -\n builtin/worktree.c               | 1 -\n bulk-checkin.c                   | 1 -\n combine-diff.c                   | 1 -\n commit-graph.c                   | 1 -\n compat/terminal.c                | 1 -\n config.c                         | 1 -\n convert.c                        | 1 -\n copy.c                           | 1 -\n csum-file.c                      | 1 -\n daemon.c                         | 1 -\n diff.c                           | 1 -\n dir.c                            | 1 -\n editor.c                         | 1 -\n entry.c                          | 1 -\n environment.c                    | 1 -\n fetch-pack.c                     | 1 -\n gpg-interface.c                  | 1 -\n grep.c                           | 1 -\n http-backend.c                   | 1 -\n imap-send.c                      | 1 -\n merge-ll.c                       | 1 -\n merge-recursive.c                | 1 -\n notes-merge.c                    | 1 -\n object-file.c                    | 1 -\n pack-write.c                     | 1 -\n packfile.c                       | 1 -\n parallel-checkout.c              | 1 -\n path.c                           | 1 -\n pkt-line.c                       | 1 -\n read-cache.c                     | 1 -\n rebase-interactive.c             | 1 -\n refs.c                           | 1 -\n rerere.c                         | 1 -\n send-pack.c                      | 1 -\n sequencer.c                      | 1 -\n server-info.c                    | 1 -\n setup.c                          | 1 -\n shallow.c                        | 1 -\n strbuf.c                         | 1 -\n streaming.c                      | 1 -\n t/helper/test-delta.c            | 1 -\n t/helper/test-fsmonitor-client.c | 1 -\n t/helper/test-read-cache.c       | 1 -\n tag.c                            | 1 -\n tempfile.c                       | 1 -\n trace.c                          | 1 -\n transport-helper.c               | 1 -\n transport.c                      | 1 -\n upload-pack.c                    | 1 -\n usage.c                          | 1 -\n worktree.c                       | 1 -\n wrapper.c                        | 1 -\n write-or-die.c                   | 1 -\n 74 files changed, 74 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 8bd0109fcc..99c2a91de7 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -37,7 +37,6 @@\n #include \"symlinks.h\"\n #include \"wildmatch.h\"\n #include \"ws.h\"\n-#include \"wrapper.h\"\n \n struct gitdiff_data {\n \tstruct strbuf *root;\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 5fab159599..dcb89439b1 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -44,7 +44,6 @@\n #include \"path.h\"\n #include \"repository.h\"\n #include \"pretty.h\"\n-#include \"wrapper.h\"\n \n /**\n  * Returns the length of the first line of msg.\ndiff --git a/builtin/bisect.c b/builtin/bisect.c\nindex 6478df3489..65478ef40f 100644\n--- a/builtin/bisect.c\n+++ b/builtin/bisect.c\n@@ -15,7 +15,6 @@\n #include \"prompt.h\"\n #include \"quote.h\"\n #include \"revision.h\"\n-#include \"wrapper.h\"\n \n static GIT_PATH_FUNC(git_path_bisect_terms, \"BISECT_TERMS\")\n static GIT_PATH_FUNC(git_path_bisect_expected_rev, \"BISECT_EXPECTED_REV\")\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 4e4e4c1083..5597f37da9 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -28,7 +28,6 @@\n #include \"worktree.h\"\n #include \"help.h\"\n #include \"commit-reach.h\"\n-#include \"wrapper.h\"\n \n static const char * const builtin_branch_usage[] = {\n \tN_(\"git branch [<options>] [-r | -a] [--merged] [--no-merged]\"),\ndiff --git a/builtin/bugreport.c b/builtin/bugreport.c\nindex daf6c23657..d2ae5c305d 100644\n--- a/builtin/bugreport.c\n+++ b/builtin/bugreport.c\n@@ -11,7 +11,6 @@\n #include \"diagnose.h\"\n #include \"object-file.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n static void get_system_info(struct strbuf *sys_info)\n {\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 687a686269..3fc0e5d7c0 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -45,7 +45,6 @@\n #include \"hook.h\"\n #include \"bundle.h\"\n #include \"bundle-uri.h\"\n-#include \"wrapper.h\"\n \n /*\n  * Overall FIXMEs:\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 30f6d9fe67..c01f136a2b 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -14,7 +14,6 @@\n #include \"setup.h\"\n #include \"strbuf.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n \n static const char *const builtin_config_usage[] = {\n \tN_(\"git config [<options>]\"),\ndiff --git a/builtin/credential-cache.c b/builtin/credential-cache.c\nindex ff3a47badb..43b9d0e5b1 100644\n--- a/builtin/credential-cache.c\n+++ b/builtin/credential-cache.c\n@@ -3,7 +3,6 @@\n #include \"parse-options.h\"\n #include \"path.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n #ifndef NO_UNIX_SOCKETS\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex e2c9ab7d5d..aeb0f92409 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -32,7 +32,6 @@\n #include \"dir.h\"\n #include \"entry.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n static int trust_exit_code;\n \ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex 2ee19c7373..4dbb10aff3 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -26,7 +26,6 @@\n #include \"commit-reach.h\"\n #include \"khash.h\"\n #include \"date.h\"\n-#include \"wrapper.h\"\n \n #define PACK_ID_BITS 16\n #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex cc81241642..0f9855b680 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -3,7 +3,6 @@\n #include \"fmt-merge-msg.h\"\n #include \"gettext.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n \n static const char * const fmt_merge_msg_usage[] = {\n \tN_(\"git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]\"),\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 91eec7703a..19d73067aa 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -41,7 +41,6 @@\n #include \"hook.h\"\n #include \"setup.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n #define FAILED_RUN \"failed to run %s\"\n \ndiff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c\nindex 9303e386cc..20d0dfe9cf 100644\n--- a/builtin/get-tar-commit-id.c\n+++ b/builtin/get-tar-commit-id.c\n@@ -5,7 +5,6 @@\n #include \"commit.h\"\n #include \"tar.h\"\n #include \"quote.h\"\n-#include \"wrapper.h\"\n \n static const char builtin_get_tar_commit_id_usage[] =\n \"git get-tar-commit-id\";\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 820860265d..f58f9db69d 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -25,7 +25,6 @@\n #include \"replace-object.h\"\n #include \"promisor-remote.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n static const char index_pack_usage[] =\n \"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])\";\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 0d8bd4d721..cb727c826f 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -13,7 +13,6 @@\n #include \"path.h\"\n #include \"setup.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n static int guess_repository_type(const char *git_dir)\n {\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 41fe0d8e5e..2f2f0a0b4c 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -53,7 +53,6 @@\n #include \"commit-reach.h\"\n #include \"wt-status.h\"\n #include \"commit-graph.h\"\n-#include \"wrapper.h\"\n \n #define DEFAULT_TWOHEAD (1<<0)\n #define DEFAULT_OCTOPUS (1<<1)\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex af9352b228..6409c07c7d 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -43,7 +43,6 @@\n #include \"promisor-remote.h\"\n #include \"pack-mtimes.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n \n /*\n  * Objects we are going to pack are collected in the `to_pack` structure.\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 555c5d3f02..6c23e7b25c 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -37,7 +37,6 @@\n #include \"reset.h\"\n #include \"trace2.h\"\n #include \"hook.h\"\n-#include \"wrapper.h\"\n \n static char const * const builtin_rebase_usage[] = {\n \tN_(\"git rebase [-i] [options] [--exec <cmd>] \"\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex 91caaf8706..f3c7c5f6cc 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -40,7 +40,6 @@\n #include \"worktree.h\"\n #include \"shallow.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n \n static const char * const receive_pack_usage[] = {\n \tN_(\"git receive-pack <git-dir>\"),\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 0458db9cad..07a9d37275 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -6,7 +6,6 @@\n #include \"repository.h\"\n #include \"string-list.h\"\n #include \"rerere.h\"\n-#include \"wrapper.h\"\n #include \"xdiff/xdiff.h\"\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\ndiff --git a/builtin/unpack-file.c b/builtin/unpack-file.c\nindex 6842a6c499..c129e2bb6c 100644\n--- a/builtin/unpack-file.c\n+++ b/builtin/unpack-file.c\n@@ -3,7 +3,6 @@\n #include \"hex.h\"\n #include \"object-name.h\"\n #include \"object-store-ll.h\"\n-#include \"wrapper.h\"\n \n static char *create_temp_file(struct object_id *oid)\n {\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 6ba463f696..6ae0356a4e 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -22,7 +22,6 @@\n #include \"submodule.h\"\n #include \"utf8.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n #include \"quote.h\"\n \n #define BUILTIN_WORKTREE_ADD_USAGE \\\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex e2f71db0f6..fec6816259 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -17,7 +17,6 @@\n #include \"packfile.h\"\n #include \"object-file.h\"\n #include \"object-store-ll.h\"\n-#include \"wrapper.h\"\n \n static int odb_transaction_nesting;\n \ndiff --git a/combine-diff.c b/combine-diff.c\nindex 11e9d7494a..f90f442482 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -17,7 +17,6 @@\n #include \"userdiff.h\"\n #include \"oid-array.h\"\n #include \"revision.h\"\n-#include \"wrapper.h\"\n \n static int compare_paths(const struct combine_diff_path *one,\n \t\t\t  const struct diff_filespec *two)\ndiff --git a/commit-graph.c b/commit-graph.c\nindex 9e989f4349..22cdfe5c17 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -26,7 +26,6 @@\n #include \"trace2.h\"\n #include \"tree.h\"\n #include \"chunk-format.h\"\n-#include \"wrapper.h\"\n \n void git_test_write_commit_graph_or_die(void)\n {\ndiff --git a/compat/terminal.c b/compat/terminal.c\nindex d87e321189..83d95e8656 100644\n--- a/compat/terminal.c\n+++ b/compat/terminal.c\n@@ -6,7 +6,6 @@\n #include \"run-command.h\"\n #include \"string-list.h\"\n #include \"hashmap.h\"\n-#include \"wrapper.h\"\n \n #if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE)\n \ndiff --git a/config.c b/config.c\nindex e08e2332a6..cc97c18141 100644\n--- a/config.c\n+++ b/config.c\n@@ -39,7 +39,6 @@\n #include \"wildmatch.h\"\n #include \"worktree.h\"\n #include \"ws.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n struct config_source {\ndiff --git a/convert.c b/convert.c\nindex 3d8325d49e..4aef90a7b6 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -16,7 +16,6 @@\n #include \"trace.h\"\n #include \"utf8.h\"\n #include \"merge-ll.h\"\n-#include \"wrapper.h\"\n \n /*\n  * convert.c - convert a file when checking it out and checking it in.\ndiff --git a/copy.c b/copy.c\nindex 882c79cffb..23d84c6c1d 100644\n--- a/copy.c\n+++ b/copy.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"copy.h\"\n #include \"path.h\"\n-#include \"wrapper.h\"\n \n int copy_fd(int ifd, int ofd)\n {\ndiff --git a/csum-file.c b/csum-file.c\nindex daf9b06dff..cd01713244 100644\n--- a/csum-file.c\n+++ b/csum-file.c\n@@ -11,7 +11,6 @@\n #include \"progress.h\"\n #include \"csum-file.h\"\n #include \"hash.h\"\n-#include \"wrapper.h\"\n \n static void verify_buffer_or_die(struct hashfile *f,\n \t\t\t\t const void *buf,\ndiff --git a/daemon.c b/daemon.c\nindex 7139cc201d..3722edf46c 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -10,7 +10,6 @@\n #include \"setup.h\"\n #include \"strbuf.h\"\n #include \"string-list.h\"\n-#include \"wrapper.h\"\n \n #ifdef NO_INITGROUPS\n #define initgroups(x, y) (0) /* nothing */\ndiff --git a/diff.c b/diff.c\nindex 86efea20f5..bdc4b07dde 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -43,7 +43,6 @@\n #include \"setup.h\"\n #include \"strmap.h\"\n #include \"ws.h\"\n-#include \"wrapper.h\"\n \n #ifdef NO_FAST_WORKING_DIRECTORY\n #define FAST_WORKING_DIRECTORY 0\ndiff --git a/dir.c b/dir.c\nindex 3acac7beb1..d270a1be36 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -32,7 +32,6 @@\n #include \"symlinks.h\"\n #include \"trace2.h\"\n #include \"tree.h\"\n-#include \"wrapper.h\"\n \n /*\n  * Tells read_directory_recursive how a file or directory should be treated.\ndiff --git a/editor.c b/editor.c\nindex 38c5dbbb79..b67b802ddf 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -11,7 +11,6 @@\n #include \"strvec.h\"\n #include \"run-command.h\"\n #include \"sigchain.h\"\n-#include \"wrapper.h\"\n \n #ifndef DEFAULT_EDITOR\n #define DEFAULT_EDITOR \"vi\"\ndiff --git a/entry.c b/entry.c\nindex f9a7c726a4..43767f9043 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -14,7 +14,6 @@\n #include \"fsmonitor.h\"\n #include \"entry.h\"\n #include \"parallel-checkout.h\"\n-#include \"wrapper.h\"\n \n static void create_directories(const char *path, int path_len,\n \t\t\t       const struct checkout *state)\ndiff --git a/environment.c b/environment.c\nindex 5e9b331279..73b5b59ecf 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -28,7 +28,6 @@\n #include \"setup.h\"\n #include \"shallow.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n int trust_executable_bit = 1;\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex a432eacab9..84a24ff9b1 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -34,7 +34,6 @@\n #include \"commit-graph.h\"\n #include \"sigchain.h\"\n #include \"mergesort.h\"\n-#include \"wrapper.h\"\n \n static int transfer_unpack_limit = -1;\n static int fetch_unpack_limit = -1;\ndiff --git a/gpg-interface.c b/gpg-interface.c\nindex 6a3817bbca..206ffdd79e 100644\n--- a/gpg-interface.c\n+++ b/gpg-interface.c\n@@ -12,7 +12,6 @@\n #include \"sigchain.h\"\n #include \"tempfile.h\"\n #include \"alias.h\"\n-#include \"wrapper.h\"\n #include \"environment.h\"\n \n static int git_gpg_config(const char *, const char *, void *);\ndiff --git a/grep.c b/grep.c\nindex ebcd647478..a3cc8224db 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -12,7 +12,6 @@\n #include \"commit.h\"\n #include \"quote.h\"\n #include \"help.h\"\n-#include \"wrapper.h\"\n \n static int grep_source_load(struct grep_source *gs);\n static int grep_source_is_binary(struct grep_source *gs,\ndiff --git a/http-backend.c b/http-backend.c\nindex e1969c05dc..25a19c21b9 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -19,7 +19,6 @@\n #include \"object-store-ll.h\"\n #include \"protocol.h\"\n #include \"date.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n static const char content_type[] = \"Content-Type\";\ndiff --git a/imap-send.c b/imap-send.c\nindex 7f5426177a..ee5b98467b 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -30,7 +30,6 @@\n #include \"parse-options.h\"\n #include \"setup.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)\n typedef void *SSL;\n #endif\ndiff --git a/merge-ll.c b/merge-ll.c\nindex 740b8c6bfd..ad26d7e260 100644\n--- a/merge-ll.c\n+++ b/merge-ll.c\n@@ -13,7 +13,6 @@\n #include \"merge-ll.h\"\n #include \"quote.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n struct ll_merge_driver;\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 43f6b2d036..6a4081bb0f 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -38,7 +38,6 @@\n #include \"tag.h\"\n #include \"tree-walk.h\"\n #include \"unpack-trees.h\"\n-#include \"wrapper.h\"\n #include \"xdiff-interface.h\"\n \n struct merge_options_internal {\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 071947894e..8799b522a5 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -20,7 +20,6 @@\n #include \"trace.h\"\n #include \"notes-utils.h\"\n #include \"commit-reach.h\"\n-#include \"wrapper.h\"\n \n struct notes_merge_pair {\n \tstruct object_id obj, base, local, remote;\ndiff --git a/object-file.c b/object-file.c\nindex 8d87720dd5..527b740018 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -44,7 +44,6 @@\n #include \"setup.h\"\n #include \"submodule.h\"\n #include \"fsck.h\"\n-#include \"wrapper.h\"\n \n /* The maximum size for an object header. */\n #define MAX_HEADER_LEN 32\ndiff --git a/pack-write.c b/pack-write.c\nindex af48813a9b..b19ddf15b2 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -12,7 +12,6 @@\n #include \"pack-revindex.h\"\n #include \"path.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n void reset_pack_idx_option(struct pack_idx_option *opts)\n {\ndiff --git a/packfile.c b/packfile.c\nindex c60aeb05ec..7683a6dbea 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -24,7 +24,6 @@\n #include \"commit-graph.h\"\n #include \"pack-revindex.h\"\n #include \"promisor-remote.h\"\n-#include \"wrapper.h\"\n \n char *odb_pack_name(struct strbuf *buf,\n \t\t    const unsigned char *hash,\ndiff --git a/parallel-checkout.c b/parallel-checkout.c\nindex 602fbf19d3..8637723461 100644\n--- a/parallel-checkout.c\n+++ b/parallel-checkout.c\n@@ -15,7 +15,6 @@\n #include \"symlinks.h\"\n #include \"thread-utils.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n struct pc_worker {\n \tstruct child_process cp;\ndiff --git a/path.c b/path.c\nindex 044a50bad0..67e2690efe 100644\n--- a/path.c\n+++ b/path.c\n@@ -18,7 +18,6 @@\n #include \"object-store-ll.h\"\n #include \"lockfile.h\"\n #include \"exec-cmd.h\"\n-#include \"wrapper.h\"\n \n static int get_st_mode_bits(const char *path, int *mode)\n {\ndiff --git a/pkt-line.c b/pkt-line.c\nindex 62b4208b66..6e4166132d 100644\n--- a/pkt-line.c\n+++ b/pkt-line.c\n@@ -5,7 +5,6 @@\n #include \"hex.h\"\n #include \"run-command.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n char packet_buffer[LARGE_PACKET_MAX];\ndiff --git a/read-cache.c b/read-cache.c\nindex b9a995e5a1..140b4f96a0 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -46,7 +46,6 @@\n #include \"csum-file.h\"\n #include \"promisor-remote.h\"\n #include \"hook.h\"\n-#include \"wrapper.h\"\n \n /* Mask for the name length in ce_flags in the on-disk index */\n \ndiff --git a/rebase-interactive.c b/rebase-interactive.c\nindex f286404d4b..d9718409b3 100644\n--- a/rebase-interactive.c\n+++ b/rebase-interactive.c\n@@ -11,7 +11,6 @@\n #include \"config.h\"\n #include \"dir.h\"\n #include \"object-name.h\"\n-#include \"wrapper.h\"\n \n static const char edit_todo_list_advice[] =\n N_(\"You can fix this with 'git rebase --edit-todo' \"\ndiff --git a/refs.c b/refs.c\nindex 54a827b45b..ad27ba12af 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -30,7 +30,6 @@\n #include \"date.h\"\n #include \"commit.h\"\n #include \"wildmatch.h\"\n-#include \"wrapper.h\"\n \n /*\n  * List of all available backends\ndiff --git a/rerere.c b/rerere.c\nindex e2b8597f88..4227c9612a 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -20,7 +20,6 @@\n #include \"object-store-ll.h\"\n #include \"hash-lookup.h\"\n #include \"strmap.h\"\n-#include \"wrapper.h\"\n \n #define RESOLVED 0\n #define PUNTED 1\ndiff --git a/send-pack.c b/send-pack.c\nindex 9510bef856..89aca9d829 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -15,7 +15,6 @@\n #include \"quote.h\"\n #include \"transport.h\"\n #include \"version.h\"\n-#include \"wrapper.h\"\n #include \"oid-array.h\"\n #include \"gpg-interface.h\"\n #include \"shallow.h\"\ndiff --git a/sequencer.c b/sequencer.c\nindex bd1e183a43..de5a89ca66 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -49,7 +49,6 @@\n #include \"rebase-interactive.h\"\n #include \"reset.h\"\n #include \"branch.h\"\n-#include \"wrapper.h\"\n \n #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n \ndiff --git a/server-info.c b/server-info.c\nindex 382e481a2b..f350713ecf 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -14,7 +14,6 @@\n #include \"object-store-ll.h\"\n #include \"server-info.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n struct update_info_ctx {\n \tFILE *cur_fp;\ndiff --git a/setup.c b/setup.c\nindex 3c383c972c..1b2f16229b 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -17,7 +17,6 @@\n #include \"quote.h\"\n #include \"trace2.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n \n static int inside_git_dir = -1;\n static int inside_work_tree = -1;\ndiff --git a/shallow.c b/shallow.c\nindex f3ef94d4c9..2fad3504b7 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -20,7 +20,6 @@\n #include \"shallow.h\"\n #include \"statinfo.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n \n void set_alternate_shallow_file(struct repository *r, const char *path, int override)\n {\ndiff --git a/strbuf.c b/strbuf.c\nindex c2713371be..c86aa0e802 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -8,7 +8,6 @@\n #include \"string-list.h\"\n #include \"utf8.h\"\n #include \"date.h\"\n-#include \"wrapper.h\"\n \n int starts_with(const char *str, const char *prefix)\n {\ndiff --git a/streaming.c b/streaming.c\nindex 49791ab958..10adf625b2 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -10,7 +10,6 @@\n #include \"object-store-ll.h\"\n #include \"replace-object.h\"\n #include \"packfile.h\"\n-#include \"wrapper.h\"\n \n typedef int (*open_istream_fn)(struct git_istream *,\n \t\t\t       struct repository *,\ndiff --git a/t/helper/test-delta.c b/t/helper/test-delta.c\nindex e7d134ec25..6bc787a474 100644\n--- a/t/helper/test-delta.c\n+++ b/t/helper/test-delta.c\n@@ -11,7 +11,6 @@\n #include \"test-tool.h\"\n #include \"git-compat-util.h\"\n #include \"delta.h\"\n-#include \"wrapper.h\"\n \n static const char usage_str[] =\n \t\"test-tool delta (-d|-p) <from_file> <data_file> <out_file>\";\ndiff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c\nindex 58d1dc5fc8..8280984d08 100644\n--- a/t/helper/test-fsmonitor-client.c\n+++ b/t/helper/test-fsmonitor-client.c\n@@ -11,7 +11,6 @@\n #include \"setup.h\"\n #include \"thread-utils.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n #ifndef HAVE_FSMONITOR_DAEMON_BACKEND\n int cmd__fsmonitor_client(int argc UNUSED, const char **argv UNUSED)\ndiff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c\nindex 56c2d25f35..1acd362346 100644\n--- a/t/helper/test-read-cache.c\n+++ b/t/helper/test-read-cache.c\n@@ -4,7 +4,6 @@\n #include \"read-cache-ll.h\"\n #include \"repository.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n int cmd__read_cache(int argc, const char **argv)\n {\ndiff --git a/tag.c b/tag.c\nindex c5426484b2..fc3834db46 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -10,7 +10,6 @@\n #include \"gpg-interface.h\"\n #include \"hex.h\"\n #include \"packfile.h\"\n-#include \"wrapper.h\"\n \n const char *tag_type = \"tag\";\n \ndiff --git a/tempfile.c b/tempfile.c\nindex 6c88a63b42..ecdebf1afb 100644\n--- a/tempfile.c\n+++ b/tempfile.c\n@@ -47,7 +47,6 @@\n #include \"path.h\"\n #include \"tempfile.h\"\n #include \"sigchain.h\"\n-#include \"wrapper.h\"\n \n static VOLATILE_LIST_HEAD(tempfile_list);\n \ndiff --git a/trace.c b/trace.c\nindex 592c141d78..971a68abe8 100644\n--- a/trace.c\n+++ b/trace.c\n@@ -27,7 +27,6 @@\n #include \"quote.h\"\n #include \"setup.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n \n struct trace_key trace_default_key = { \"GIT_TRACE\", 0, 0, 0 };\n struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE);\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 5c0bc6a896..49811ef176 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -19,7 +19,6 @@\n #include \"refspec.h\"\n #include \"transport-internal.h\"\n #include \"protocol.h\"\n-#include \"wrapper.h\"\n \n static int debug;\n \ndiff --git a/transport.c b/transport.c\nindex 4dc187a388..0a5794a944 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -30,7 +30,6 @@\n #include \"object-store-ll.h\"\n #include \"color.h\"\n #include \"bundle-uri.h\"\n-#include \"wrapper.h\"\n \n static int transport_use_color = -1;\n static char transport_colors[][COLOR_MAXLEN] = {\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 318b650b1e..05b3ef461f 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -32,7 +32,6 @@\n #include \"commit-graph.h\"\n #include \"commit-reach.h\"\n #include \"shallow.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n /* Remember to update object flag allocation in object.h */\ndiff --git a/usage.c b/usage.c\nindex 46d99f8bd4..09f0ed509b 100644\n--- a/usage.c\n+++ b/usage.c\n@@ -6,7 +6,6 @@\n #include \"git-compat-util.h\"\n #include \"gettext.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n static void vreportf(const char *prefix, const char *err, va_list params)\n {\ndiff --git a/worktree.c b/worktree.c\nindex f9aa371ca7..2018c127ca 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -12,7 +12,6 @@\n #include \"dir.h\"\n #include \"wt-status.h\"\n #include \"config.h\"\n-#include \"wrapper.h\"\n \n void free_worktrees(struct worktree **worktrees)\n {\ndiff --git a/wrapper.c b/wrapper.c\nindex 67f5f5dbe1..22be9812a7 100644\n--- a/wrapper.c\n+++ b/wrapper.c\n@@ -9,7 +9,6 @@\n #include \"repository.h\"\n #include \"strbuf.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n static intmax_t count_fsync_writeout_only;\n static intmax_t count_fsync_hardware_flush;\ndiff --git a/write-or-die.c b/write-or-die.c\nindex cc9e0787a1..d8355c0c3e 100644\n--- a/write-or-die.c\n+++ b/write-or-die.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"config.h\"\n #include \"run-command.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n /*\n-- \n2.41.0.rc2.161.g9c6817b8e7-goog\n\n"},{"id":"478105","messageId":"20230606171002.914075-8-calvinwan@google.com","threadId":"59752","inReplyTo":"20230606170711.912972-1-calvinwan@google.com","subject":"[PATCH v3 8/8] common: move alloc macros to common.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-06T17:10:02Z","receivedAt":"2023-06-06T17:10:53Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"alloc_nr, ALLOC_GROW, and ALLOC_GROW_BY are commonly used macros for\ndynamic array allocation. Moving these macros to common.h focuses\nalloc.[ch] to allocation for Git objects and additionally allows us to\nremove inclusions to alloc.h from files that solely used the above\nmacros.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n add-patch.c                        |  1 -\n alias.c                            |  1 -\n alloc.h                            | 75 ------------------------------\n apply.c                            |  1 -\n archive-tar.c                      |  1 -\n archive.c                          |  1 -\n attr.c                             |  1 -\n builtin/blame.c                    |  1 -\n builtin/cat-file.c                 |  1 -\n builtin/checkout--worker.c         |  1 -\n builtin/config.c                   |  1 -\n builtin/credential-cache--daemon.c |  1 -\n builtin/fetch-pack.c               |  1 -\n builtin/fsmonitor--daemon.c        |  1 -\n builtin/grep.c                     |  1 -\n builtin/index-pack.c               |  1 -\n builtin/log.c                      |  1 -\n builtin/merge.c                    |  1 -\n builtin/mktree.c                   |  1 -\n builtin/mv.c                       |  1 -\n builtin/name-rev.c                 |  1 -\n builtin/pack-objects.c             |  1 -\n builtin/repack.c                   |  1 -\n builtin/rev-parse.c                |  1 -\n builtin/revert.c                   |  1 -\n builtin/rm.c                       |  1 -\n builtin/submodule--helper.c        |  1 -\n bulk-checkin.c                     |  1 -\n cache-tree.c                       |  1 -\n chunk-format.c                     |  1 -\n commit-reach.c                     |  1 -\n common.h                           | 75 ++++++++++++++++++++++++++++++\n config.c                           |  1 -\n daemon.c                           |  1 -\n delta-islands.c                    |  1 -\n diff.c                             |  1 -\n diffcore-rename.c                  |  1 -\n dir-iterator.c                     |  1 -\n dir.c                              |  1 -\n ewah/bitmap.c                      |  1 -\n ewah/ewah_bitmap.c                 |  1 -\n fetch-pack.c                       |  1 -\n fmt-merge-msg.c                    |  1 -\n fsck.c                             |  1 -\n help.c                             |  1 -\n http-backend.c                     |  1 -\n line-log.c                         |  1 -\n list-objects-filter-options.c      |  1 -\n list-objects-filter.c              |  1 -\n midx.c                             |  1 -\n object-file.c                      |  1 -\n oid-array.c                        |  1 -\n oidtree.c                          |  1 -\n pack-bitmap-write.c                |  1 -\n pack-bitmap.c                      |  1 -\n pack-objects.c                     |  1 -\n packfile.c                         |  1 -\n parallel-checkout.c                |  1 -\n pretty.c                           |  1 -\n prio-queue.c                       |  1 -\n quote.c                            |  1 -\n read-cache.c                       |  1 -\n ref-filter.c                       |  1 -\n reflog-walk.c                      |  1 -\n refs.c                             |  1 -\n refspec.c                          |  1 -\n remote-curl.c                      |  1 -\n remote.c                           |  1 -\n rerere.c                           |  1 -\n revision.c                         |  1 -\n sequencer.c                        |  1 -\n server-info.c                      |  1 -\n shallow.c                          |  1 -\n sigchain.c                         |  1 -\n sparse-index.c                     |  1 -\n split-index.c                      |  1 -\n strbuf.c                           |  1 -\n string-list.c                      |  1 -\n strvec.c                           |  1 -\n submodule-config.c                 |  1 -\n submodule.c                        |  1 -\n t/helper/test-reach.c              |  1 -\n trace2/tr2_tls.c                   |  1 -\n trailer.c                          |  1 -\n transport.c                        |  1 -\n tree-walk.c                        |  1 -\n userdiff.c                         |  1 -\n worktree.c                         |  1 -\n 88 files changed, 75 insertions(+), 161 deletions(-)\n\ndiff --git a/add-patch.c b/add-patch.c\nindex ba629add62..bfe19876cd 100644\n--- a/add-patch.c\n+++ b/add-patch.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"add-interactive.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"editor.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/alias.c b/alias.c\nindex 54a1a23d2c..38e1339936 100644\n--- a/alias.c\n+++ b/alias.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"alias.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n #include \"strbuf.h\"\ndiff --git a/alloc.h b/alloc.h\nindex 4312db4bd0..3f4a0ad310 100644\n--- a/alloc.h\n+++ b/alloc.h\n@@ -17,79 +17,4 @@ void *alloc_object_node(struct repository *r);\n struct alloc_state *allocate_alloc_state(void);\n void clear_alloc_state(struct alloc_state *s);\n \n-#define alloc_nr(x) (((x)+16)*3/2)\n-\n-/**\n- * Dynamically growing an array using realloc() is error prone and boring.\n- *\n- * Define your array with:\n- *\n- * - a pointer (`item`) that points at the array, initialized to `NULL`\n- *   (although please name the variable based on its contents, not on its\n- *   type);\n- *\n- * - an integer variable (`alloc`) that keeps track of how big the current\n- *   allocation is, initialized to `0`;\n- *\n- * - another integer variable (`nr`) to keep track of how many elements the\n- *   array currently has, initialized to `0`.\n- *\n- * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,\n- * alloc)`.  This ensures that the array can hold at least `n` elements by\n- * calling `realloc(3)` and adjusting `alloc` variable.\n- *\n- * ------------\n- * sometype *item;\n- * size_t nr;\n- * size_t alloc\n- *\n- * for (i = 0; i < nr; i++)\n- * \tif (we like item[i] already)\n- * \t\treturn;\n- *\n- * // we did not like any existing one, so add one\n- * ALLOC_GROW(item, nr + 1, alloc);\n- * item[nr++] = value you like;\n- * ------------\n- *\n- * You are responsible for updating the `nr` variable.\n- *\n- * If you need to specify the number of elements to allocate explicitly\n- * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.\n- *\n- * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some\n- * added niceties.\n- *\n- * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.\n- */\n-#define ALLOC_GROW(x, nr, alloc) \\\n-\tdo { \\\n-\t\tif ((nr) > alloc) { \\\n-\t\t\tif (alloc_nr(alloc) < (nr)) \\\n-\t\t\t\talloc = (nr); \\\n-\t\t\telse \\\n-\t\t\t\talloc = alloc_nr(alloc); \\\n-\t\t\tREALLOC_ARRAY(x, alloc); \\\n-\t\t} \\\n-\t} while (0)\n-\n-/*\n- * Similar to ALLOC_GROW but handles updating of the nr value and\n- * zeroing the bytes of the newly-grown array elements.\n- *\n- * DO NOT USE any expression with side-effect for any of the\n- * arguments.\n- */\n-#define ALLOC_GROW_BY(x, nr, increase, alloc) \\\n-\tdo { \\\n-\t\tif (increase) { \\\n-\t\t\tsize_t new_nr = nr + (increase); \\\n-\t\t\tif (new_nr < nr) \\\n-\t\t\t\tBUG(\"negative growth in ALLOC_GROW_BY\"); \\\n-\t\t\tALLOC_GROW(x, new_nr, alloc); \\\n-\t\t\tmemset((x) + nr, 0, sizeof(*(x)) * (increase)); \\\n-\t\t\tnr = new_nr; \\\n-\t\t} \\\n-\t} while (0)\n-\n #endif\ndiff --git a/apply.c b/apply.c\nindex 99c2a91de7..6b9ce54f7d 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -9,7 +9,6 @@\n \n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"base85.h\"\n #include \"config.h\"\n #include \"object-store-ll.h\"\ndiff --git a/archive-tar.c b/archive-tar.c\nindex fc06ff4c5d..704bf0612e 100644\n--- a/archive-tar.c\n+++ b/archive-tar.c\n@@ -2,7 +2,6 @@\n  * Copyright (c) 2005, 2006 Rene Scharfe\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n #include \"git-zlib.h\"\ndiff --git a/archive.c b/archive.c\nindex 1817cca9f4..ca11db185b 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"environment.h\"\ndiff --git a/attr.c b/attr.c\nindex 7d39ac4a29..e9c81b6e07 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -7,7 +7,6 @@\n  */\n \n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"exec-cmd.h\"\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex e811e7fbfb..9a3f9facea 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -6,7 +6,6 @@\n  */\n \n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"color.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 48ccca95a1..4b786adbe4 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -5,7 +5,6 @@\n  */\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"diff.h\"\ndiff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c\nindex c655dc4b13..6b62b5375b 100644\n--- a/builtin/checkout--worker.c\n+++ b/builtin/checkout--worker.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"entry.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/config.c b/builtin/config.c\nindex c01f136a2b..49b82b5323 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -1,6 +1,5 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"color.h\"\n #include \"editor.h\"\ndiff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c\nindex 756c5f02ae..db8c49605c 100644\n--- a/builtin/credential-cache--daemon.c\n+++ b/builtin/credential-cache--daemon.c\n@@ -1,6 +1,5 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"object-file.h\"\n #include \"parse-options.h\"\ndiff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c\nindex 3ba0fe5a39..44c05ee86c 100644\n--- a/builtin/fetch-pack.c\n+++ b/builtin/fetch-pack.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"object-file.h\"\ndiff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c\nindex 74d1d6a585..0194f1e263 100644\n--- a/builtin/fsmonitor--daemon.c\n+++ b/builtin/fsmonitor--daemon.c\n@@ -1,6 +1,5 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 72e70b3a48..c60cf2007f 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -4,7 +4,6 @@\n  * Copyright (c) 2006 Junio C Hamano\n  */\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"repository.h\"\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex f58f9db69d..57812a276a 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"delta.h\"\n #include \"environment.h\"\ndiff --git a/builtin/log.c b/builtin/log.c\nindex d6543ba1f6..03954fb749 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -6,7 +6,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 2f2f0a0b4c..059f3ecb84 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -10,7 +10,6 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"editor.h\"\n #include \"environment.h\"\ndiff --git a/builtin/mktree.c b/builtin/mktree.c\nindex 0eea810c7e..9a22d4e277 100644\n--- a/builtin/mktree.c\n+++ b/builtin/mktree.c\n@@ -4,7 +4,6 @@\n  * Copyright (c) Junio C Hamano, 2006, 2009\n  */\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"quote.h\"\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex ae462bd7d4..fa84fcb20d 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -7,7 +7,6 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/name-rev.c b/builtin/name-rev.c\nindex c3b722b36f..c706fa3720 100644\n--- a/builtin/name-rev.c\n+++ b/builtin/name-rev.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 6409c07c7d..869a21b38f 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 6c896c9c80..60ae514fd5 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"dir.h\"\n #include \"environment.h\"\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 4a219ea93b..161077aa79 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -6,7 +6,6 @@\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"commit.h\"\n #include \"environment.h\"\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex f6f07d9b53..e6f9a1ad26 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"builtin.h\"\n #include \"parse-options.h\"\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex 463eeabcea..dff819ae50 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -5,7 +5,6 @@\n  */\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"advice.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex baf6ff88c3..e22cf4e4ee 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1,7 +1,6 @@\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex fec6816259..73bff3a23d 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -2,7 +2,6 @@\n  * Copyright (c) 2011, Google Inc.\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"bulk-checkin.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/cache-tree.c b/cache-tree.c\nindex 84d7491420..641427ed41 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"hex.h\"\n #include \"lockfile.h\"\ndiff --git a/chunk-format.c b/chunk-format.c\nindex e7d613c907..140dfa0dcc 100644\n--- a/chunk-format.c\n+++ b/chunk-format.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"chunk-format.h\"\n #include \"csum-file.h\"\n #include \"gettext.h\"\ndiff --git a/commit-reach.c b/commit-reach.c\nindex 70bde8af05..812bc6bf92 100644\n--- a/commit-reach.c\n+++ b/commit-reach.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"commit-graph.h\"\n #include \"decorate.h\"\ndiff --git a/common.h b/common.h\nindex e3b673847d..b0c68eb2a2 100644\n--- a/common.h\n+++ b/common.h\n@@ -199,6 +199,81 @@ static inline int cast_size_t_to_int(size_t a)\n  */\n #define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)\n \n+#define alloc_nr(x) (((x)+16)*3/2)\n+\n+/**\n+ * Dynamically growing an array using realloc() is error prone and boring.\n+ *\n+ * Define your array with:\n+ *\n+ * - a pointer (`item`) that points at the array, initialized to `NULL`\n+ *   (although please name the variable based on its contents, not on its\n+ *   type);\n+ *\n+ * - an integer variable (`alloc`) that keeps track of how big the current\n+ *   allocation is, initialized to `0`;\n+ *\n+ * - another integer variable (`nr`) to keep track of how many elements the\n+ *   array currently has, initialized to `0`.\n+ *\n+ * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,\n+ * alloc)`.  This ensures that the array can hold at least `n` elements by\n+ * calling `realloc(3)` and adjusting `alloc` variable.\n+ *\n+ * ------------\n+ * sometype *item;\n+ * size_t nr;\n+ * size_t alloc\n+ *\n+ * for (i = 0; i < nr; i++)\n+ * \tif (we like item[i] already)\n+ * \t\treturn;\n+ *\n+ * // we did not like any existing one, so add one\n+ * ALLOC_GROW(item, nr + 1, alloc);\n+ * item[nr++] = value you like;\n+ * ------------\n+ *\n+ * You are responsible for updating the `nr` variable.\n+ *\n+ * If you need to specify the number of elements to allocate explicitly\n+ * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.\n+ *\n+ * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some\n+ * added niceties.\n+ *\n+ * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.\n+ */\n+#define ALLOC_GROW(x, nr, alloc) \\\n+\tdo { \\\n+\t\tif ((nr) > alloc) { \\\n+\t\t\tif (alloc_nr(alloc) < (nr)) \\\n+\t\t\t\talloc = (nr); \\\n+\t\t\telse \\\n+\t\t\t\talloc = alloc_nr(alloc); \\\n+\t\t\tREALLOC_ARRAY(x, alloc); \\\n+\t\t} \\\n+\t} while (0)\n+\n+/*\n+ * Similar to ALLOC_GROW but handles updating of the nr value and\n+ * zeroing the bytes of the newly-grown array elements.\n+ *\n+ * DO NOT USE any expression with side-effect for any of the\n+ * arguments.\n+ */\n+#define ALLOC_GROW_BY(x, nr, increase, alloc) \\\n+\tdo { \\\n+\t\tif (increase) { \\\n+\t\t\tsize_t new_nr = nr + (increase); \\\n+\t\t\tif (new_nr < nr) \\\n+\t\t\t\tBUG(\"negative growth in ALLOC_GROW_BY\"); \\\n+\t\t\tALLOC_GROW(x, new_nr, alloc); \\\n+\t\t\tmemset((x) + nr, 0, sizeof(*(x)) * (increase)); \\\n+\t\t\tnr = new_nr; \\\n+\t\t} \\\n+\t} while (0)\n+\n #define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))\n #define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))\n #define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))\ndiff --git a/config.c b/config.c\nindex cc97c18141..09851a6909 100644\n--- a/config.c\n+++ b/config.c\n@@ -8,7 +8,6 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"date.h\"\n #include \"branch.h\"\n #include \"config.h\"\ndiff --git a/daemon.c b/daemon.c\nindex 3722edf46c..1edc9a8510 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"path.h\"\ndiff --git a/delta-islands.c b/delta-islands.c\nindex c824a5f6a4..332f0f7c45 100644\n--- a/delta-islands.c\n+++ b/delta-islands.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"attr.h\"\n #include \"object.h\"\n #include \"blob.h\"\ndiff --git a/diff.c b/diff.c\nindex bdc4b07dde..b48438c1e1 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3,7 +3,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"base85.h\"\n #include \"config.h\"\n #include \"convert.h\"\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex 926b554bd5..5a6e2bcac7 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -3,7 +3,6 @@\n  * Copyright (C) 2005 Junio C Hamano\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n #include \"object-store-ll.h\"\ndiff --git a/dir-iterator.c b/dir-iterator.c\nindex fb7c47f0e8..278b04243a 100644\n--- a/dir-iterator.c\n+++ b/dir-iterator.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"iterator.h\"\n #include \"dir-iterator.h\"\ndiff --git a/dir.c b/dir.c\nindex d270a1be36..c9dc69fc24 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -7,7 +7,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"dir.h\"\ndiff --git a/ewah/bitmap.c b/ewah/bitmap.c\nindex 12d6aa398e..7b525b1ecd 100644\n--- a/ewah/bitmap.c\n+++ b/ewah/bitmap.c\n@@ -17,7 +17,6 @@\n  * along with this program; if not, see <http://www.gnu.org/licenses/>.\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"ewok.h\"\n \n #define EWAH_MASK(x) ((eword_t)1 << (x % BITS_IN_EWORD))\ndiff --git a/ewah/ewah_bitmap.c b/ewah/ewah_bitmap.c\nindex c6d4ffc87c..8785cbc54a 100644\n--- a/ewah/ewah_bitmap.c\n+++ b/ewah/ewah_bitmap.c\n@@ -17,7 +17,6 @@\n  * along with this program; if not, see <http://www.gnu.org/licenses/>.\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"ewok.h\"\n #include \"ewok_rlw.h\"\n \ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 84a24ff9b1..6198f3adaf 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"repository.h\"\n #include \"config.h\"\n #include \"date.h\"\ndiff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\nindex ac9c1b9c6c..ff8884eecd 100644\n--- a/fmt-merge-msg.c\n+++ b/fmt-merge-msg.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"refs.h\"\ndiff --git a/fsck.c b/fsck.c\nindex a219d6f2c0..2035c4e00b 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"date.h\"\n #include \"dir.h\"\n #include \"hex.h\"\ndiff --git a/help.c b/help.c\nindex 5d7637dce9..c81d43a5fa 100644\n--- a/help.c\n+++ b/help.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"builtin.h\"\n #include \"exec-cmd.h\"\ndiff --git a/http-backend.c b/http-backend.c\nindex 25a19c21b9..e24399ed10 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"git-zlib.h\"\ndiff --git a/line-log.c b/line-log.c\nindex 2eff914bf3..790ab73212 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"line-range.h\"\n #include \"hex.h\"\n #include \"tag.h\"\ndiff --git a/list-objects-filter-options.c b/list-objects-filter-options.c\nindex 2a3b7881af..8a08b7af49 100644\n--- a/list-objects-filter-options.c\n+++ b/list-objects-filter-options.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"config.h\"\n #include \"gettext.h\"\ndiff --git a/list-objects-filter.c b/list-objects-filter.c\nindex e075a66c99..9327ccd505 100644\n--- a/list-objects-filter.c\n+++ b/list-objects-filter.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/midx.c b/midx.c\nindex db459e448b..3a16acabbc 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"csum-file.h\"\n #include \"dir.h\"\ndiff --git a/object-file.c b/object-file.c\nindex 527b740018..5ebe1b00c5 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -8,7 +8,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"environment.h\"\ndiff --git a/oid-array.c b/oid-array.c\nindex e8228c777b..8e4717746c 100644\n--- a/oid-array.c\n+++ b/oid-array.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"oid-array.h\"\n #include \"hash-lookup.h\"\n \ndiff --git a/oidtree.c b/oidtree.c\nindex 7d57b7b19e..daef175dc7 100644\n--- a/oidtree.c\n+++ b/oidtree.c\n@@ -4,7 +4,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"oidtree.h\"\n-#include \"alloc.h\"\n #include \"hash.h\"\n \n struct oidtree_iter_data {\ndiff --git a/pack-bitmap-write.c b/pack-bitmap-write.c\nindex d86f4e739a..f6757c3cbf 100644\n--- a/pack-bitmap-write.c\n+++ b/pack-bitmap-write.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex 576e613837..a69b80320f 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/pack-objects.c b/pack-objects.c\nindex ccab09fe65..1b8052bece 100644\n--- a/pack-objects.c\n+++ b/pack-objects.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"object.h\"\n #include \"pack.h\"\n #include \"pack-objects.h\"\ndiff --git a/packfile.c b/packfile.c\nindex 7683a6dbea..0f80c8ba1f 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/parallel-checkout.c b/parallel-checkout.c\nindex 8637723461..b5a714c711 100644\n--- a/parallel-checkout.c\n+++ b/parallel-checkout.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"entry.h\"\n #include \"gettext.h\"\ndiff --git a/pretty.c b/pretty.c\nindex d4bc4b0286..c417dcbf72 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"commit.h\"\n #include \"environment.h\"\ndiff --git a/prio-queue.c b/prio-queue.c\nindex dc2476be53..450775a374 100644\n--- a/prio-queue.c\n+++ b/prio-queue.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"prio-queue.h\"\n \n static inline int compare(struct prio_queue *queue, int i, int j)\ndiff --git a/quote.c b/quote.c\nindex 43c739671e..3c05194496 100644\n--- a/quote.c\n+++ b/quote.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"path.h\"\n #include \"quote.h\"\n #include \"strbuf.h\"\ndiff --git a/read-cache.c b/read-cache.c\nindex 140b4f96a0..53d71134e2 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -4,7 +4,6 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"bulk-checkin.h\"\n #include \"config.h\"\n #include \"date.h\"\ndiff --git a/ref-filter.c b/ref-filter.c\nindex e0d03a9f8e..2ed0ecf260 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"gpg-interface.h\"\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex d337e64431..d216f6f966 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"refs.h\"\n #include \"diff.h\"\ndiff --git a/refs.c b/refs.c\nindex ad27ba12af..039799af45 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -4,7 +4,6 @@\n \n #include \"git-compat-util.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"hashmap.h\"\ndiff --git a/refspec.c b/refspec.c\nindex 57f6c2aaf9..d60932f4de 100644\n--- a/refspec.c\n+++ b/refspec.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hash.h\"\n #include \"hex.h\"\ndiff --git a/remote-curl.c b/remote-curl.c\nindex acf7b2bb40..8a976a0253 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/remote.c b/remote.c\nindex 6538b6037d..e5e165de1c 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/rerere.c b/rerere.c\nindex 4227c9612a..7070f75014 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"copy.h\"\n #include \"gettext.h\"\ndiff --git a/revision.c b/revision.c\nindex 84768565ce..985b8b2f51 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/sequencer.c b/sequencer.c\nindex de5a89ca66..f343954999 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"copy.h\"\n #include \"environment.h\"\ndiff --git a/server-info.c b/server-info.c\nindex f350713ecf..e2fe0f9143 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"environment.h\"\n #include \"hex.h\"\ndiff --git a/shallow.c b/shallow.c\nindex 2fad3504b7..5413719fd4 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"hex.h\"\n #include \"repository.h\"\n #include \"tempfile.h\"\ndiff --git a/sigchain.c b/sigchain.c\nindex ee778c0580..66123bdbab 100644\n--- a/sigchain.c\n+++ b/sigchain.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"sigchain.h\"\n \n #define SIGCHAIN_MAX_SIGNALS 32\ndiff --git a/sparse-index.c b/sparse-index.c\nindex 90d0462256..1fdb07a9e6 100644\n--- a/sparse-index.c\n+++ b/sparse-index.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"name-hash.h\"\ndiff --git a/split-index.c b/split-index.c\nindex 0ee3865a55..8c38687c04 100644\n--- a/split-index.c\n+++ b/split-index.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hash.h\"\n #include \"mem-pool.h\"\ndiff --git a/strbuf.c b/strbuf.c\nindex c86aa0e802..4901d28875 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"strbuf.h\"\ndiff --git a/string-list.c b/string-list.c\nindex 0f8ac117fd..954569f381 100644\n--- a/string-list.c\n+++ b/string-list.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"string-list.h\"\n-#include \"alloc.h\"\n \n void string_list_init_nodup(struct string_list *list)\n {\ndiff --git a/strvec.c b/strvec.c\nindex 17d54b6c3b..89dc9e7e75 100644\n--- a/strvec.c\n+++ b/strvec.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"strvec.h\"\n-#include \"alloc.h\"\n #include \"hex.h\"\n #include \"strbuf.h\"\n \ndiff --git a/submodule-config.c b/submodule-config.c\nindex 1efd547169..69cbe49278 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/submodule.c b/submodule.c\nindex f0f8788d2e..e603a19a87 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"repository.h\"\n #include \"config.h\"\n #include \"submodule-config.h\"\ndiff --git a/t/helper/test-reach.c b/t/helper/test-reach.c\nindex 5b6f217441..119f4908cf 100644\n--- a/t/helper/test-reach.c\n+++ b/t/helper/test-reach.c\n@@ -1,5 +1,4 @@\n #include \"test-tool.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"commit-reach.h\"\n #include \"config.h\"\ndiff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c\nindex 9f46ae12f5..601c9e5036 100644\n--- a/trace2/tr2_tls.c\n+++ b/trace2/tr2_tls.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"thread-utils.h\"\n #include \"trace.h\"\n #include \"trace2/tr2_tls.h\"\ndiff --git a/trailer.c b/trailer.c\nindex a2c3ed6f28..2170e01f6a 100644\n--- a/trailer.c\n+++ b/trailer.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/transport.c b/transport.c\nindex 0a5794a944..219af8fd50 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"hex.h\"\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 42ed86ef58..6c07913f3f 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"tree-walk.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/userdiff.c b/userdiff.c\nindex 664c7c1402..e399543823 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"userdiff.h\"\n #include \"attr.h\"\ndiff --git a/worktree.c b/worktree.c\nindex 2018c127ca..7410dce811 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"path.h\"\n-- \n2.41.0.rc2.161.g9c6817b8e7-goog\n\n"},{"id":"478118","messageId":"25d47081-2096-bb8a-dca3-bd5ea931c879@ramsayjones.plus.com","threadId":"59752","inReplyTo":"20230606171002.914075-5-calvinwan@google.com","subject":"Re: [PATCH v3 5/8] common.h: move non-compat specific macros and functions","fromName":"Ramsay Jones","fromEmail":"ramsay@ramsayjones.plus.com","sentAt":"2023-06-06T22:45:59Z","receivedAt":"2023-06-06T22:49:16Z","isPatch":true,"sender":{"key":"ramsay@ramsayjones.plus.com","avatar":"https://avatars.githubusercontent.com/u/33702710?v=4"},"body":"\n\nOn 06/06/2023 18:09, Calvin Wan wrote:\n> git-compat-util.h has grown to a large and difficult to read file partly\n> because its set of functionality is overloaded. Besides being a\n> compatibility file that ensures Git's operation across different\n> operating systems, it has also become a dumping ground for commonly used\n> macros and static inline functions.\n> \n> This commit separates out macros and static inline functions that are\n> compatible across operating systems into common.h. common.h is\n> reincluded back into git-compat-util.h so that other files do not also\n> have to include it. The eventual goal is for common.h to be separated\n> out into more reasonable boundaries, but for now this should be a good\n> first step towards that goal.\n> \n> Signed-off-by: Calvin Wan <calvinwan@google.com>\n> ---\n>  common.h          | 410 ++++++++++++++++++++++++++++++++++++++++++++++\n>  git-compat-util.h | 402 +--------------------------------------------\n>  2 files changed, 412 insertions(+), 400 deletions(-)\n>  create mode 100644 common.h\n> \n> diff --git a/common.h b/common.h\n> new file mode 100644\n> index 0000000000..0f164c1071\n> --- /dev/null\n> +++ b/common.h\n> @@ -0,0 +1,410 @@\n> +#ifndef COMMON_H\n> +#define COMMON_H\n> +\n> +#include \"git-compat-util.h\"\n\nHmm, ... So, \"common.h\" includes \"git-compat-util.h\", which\nin turn includes \"common.h\" ?\n\nSomething is not right here! ;)\n\n(Sorry, I have not been following this series, it just floated\npast on the ML and looked odd ...)\n\nATB,\nRamsay Jones\n\n"},{"id":"478147","messageId":"CAFySSZBZVn=7gBB19_uNxeUwS9Y8Q6ZZiCT=AwfuBy4+d34piw@mail.gmail.com","threadId":"59752","inReplyTo":"25d47081-2096-bb8a-dca3-bd5ea931c879@ramsayjones.plus.com","subject":"Re: [PATCH v3 5/8] common.h: move non-compat specific macros and functions","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-07T17:02:02Z","receivedAt":"2023-06-07T17:02:19Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Is there a particular problem here? common.h includes\ngit-compat-util.h at the top so that it has access to standard\nlibraries and possibly other compat utilities. git-compat-util.h\nincludes common.h at the bottom so that other files don't have to also\ninclude common.h as well. Imagine if instead of having git-compat-util\ninclude common.h, we had a third file here: git-compat-common.h. It\nincludes common.h and git-compat-util.h and every file includes that\ninstead of git-compat-util.h. Now git-compat-util.h wouldn't include\ncommon.h, but this change can be circumvented by including common.h at\nthe bottom.\n"},{"id":"478301","messageId":"xmqq8rco9zkl.fsf@gitster.g","threadId":"59752","inReplyTo":"CAFySSZBZVn=7gBB19_uNxeUwS9Y8Q6ZZiCT=AwfuBy4+d34piw@mail.gmail.com","subject":"Re: [PATCH v3 5/8] common.h: move non-compat specific macros and functions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-06-12T20:48:42Z","receivedAt":"2023-06-12T20:53:49Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Calvin Wan <calvinwan@google.com> writes:\n\n> Is there a particular problem here?\n\nDoesn't it defeat the notion that each header file is safe to\ninclude twice via \"#ifndef FOO/#define FOO/#endif\" safeguard and\nmakes anybody who sees the recursive inclusion to think twice before\nthey can convince themselves that it is OK for this particular pair?\n\n\n"},{"id":"478345","messageId":"CAFySSZBf51JFAY5fYRsYvk2RkZ8rDmoQOHKrCte4ERkBeoiJWA@mail.gmail.com","threadId":"59752","inReplyTo":"xmqq8rco9zkl.fsf@gitster.g","subject":"Re: [PATCH v3 5/8] common.h: move non-compat specific macros and functions","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-13T22:42:25Z","receivedAt":"2023-06-13T22:42:41Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"> > Is there a particular problem here?\n>\n> Doesn't it defeat the notion that each header file is safe to\n> include twice via \"#ifndef FOO/#define FOO/#endif\" safeguard and\n> makes anybody who sees the recursive inclusion to think twice before\n> they can convince themselves that it is OK for this particular pair?\n\nIn that case do you have any recommendations as to how I can make\nclear that this recursive inclusion isn't problematic or refactor away\nthe recursive inclusion without having to change the header inclusions\nof every other Git file?\n"},{"id":"478346","messageId":"xmqqy1kn2c1p.fsf@gitster.g","threadId":"59752","inReplyTo":"CAFySSZBf51JFAY5fYRsYvk2RkZ8rDmoQOHKrCte4ERkBeoiJWA@mail.gmail.com","subject":"Re: [PATCH v3 5/8] common.h: move non-compat specific macros and functions","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-06-13T23:10:58Z","receivedAt":"2023-06-13T23:11:06Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Calvin Wan <calvinwan@google.com> writes:\n\n> In that case do you have any recommendations as to how I can make\n> clear that this recursive inclusion isn't problematic or refactor away\n> the recursive inclusion without having to change the header inclusions\n> of every other Git file?\n\n\"Without having to\" is an unfair restrition, given that you do not\nhave to create common.h and move things around in the first place\n;-)\n"},{"id":"478356","messageId":"CAFySSZArxayE6VF-T1WpkcFpBwauJAE7PB7ionWpBwOURfrKOA@mail.gmail.com","threadId":"59752","inReplyTo":"xmqqy1kn2c1p.fsf@gitster.g","subject":"Re: [PATCH v3 5/8] common.h: move non-compat specific macros and functions","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-14T01:58:59Z","receivedAt":"2023-06-14T01:59:19Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"> \"Without having to\" is an unfair restrition, given that you do not\n> have to create common.h and move things around in the first place\n> ;-)\n\nthat's a good point...part of this change was motivated by having a\nmore natural location to move the general ALLOC functions in alloc.h.\nThought I would clean up git-compat-util.h along the way, but I can\nthrow this patch on the back burner until there's more of a need for\nit (maybe just having a separate section in git-compat-util.h for\ncommon functions/macros also works).\n"},{"id":"479062","messageId":"20230630202237.3069327-1-calvinwan@google.com","threadId":"59752","inReplyTo":"20230606170711.912972-1-calvinwan@google.com","subject":"[PATCH v4 0/6] git-compat-util cleanups","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-30T20:22:37Z","receivedAt":"2023-06-30T20:22:52Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Changes since v3:\n - Dropped patches 5 and 6 since removing the circular dependency in\n   common.h turns out to be quite difficult\n - Patch 8 moves the alloc macros to git-compat-util.h rather than\n   common.h since that does not exist anymore\n\nNote for the maintainer:\n\nI rebased this series onto both seen and next and they rebased cleanly.\nAs currently submitted, it is rebased onto next at (38632f3da).\nHopefully this series now doesn't cause any issues with other inflight\nseries.\n\nCalvin Wan (6):\n  git-compat-util: move strbuf.c funcs to its header\n  git-compat-util: move wrapper.c funcs to its header\n  sane-ctype.h: create header for sane-ctype macros\n  kwset: move translation table from ctype\n  treewide: remove unnecessary includes for wrapper.h\n  common: move alloc macros to common.h\n\n add-patch.c                        |   1 -\n alias.c                            |   1 -\n alloc.h                            |  75 --------\n apply.c                            |   2 -\n archive-tar.c                      |   1 -\n archive.c                          |   1 -\n attr.c                             |   1 -\n builtin/am.c                       |   1 -\n builtin/bisect.c                   |   1 -\n builtin/blame.c                    |   1 -\n builtin/branch.c                   |   1 -\n builtin/bugreport.c                |   1 -\n builtin/cat-file.c                 |   1 -\n builtin/checkout--worker.c         |   1 -\n builtin/clone.c                    |   1 -\n builtin/config.c                   |   2 -\n builtin/credential-cache--daemon.c |   1 -\n builtin/credential-cache.c         |   1 -\n builtin/difftool.c                 |   1 -\n builtin/fast-import.c              |   1 -\n builtin/fetch-pack.c               |   1 -\n builtin/fmt-merge-msg.c            |   1 -\n builtin/fsmonitor--daemon.c        |   1 -\n builtin/gc.c                       |   1 -\n builtin/get-tar-commit-id.c        |   1 -\n builtin/grep.c                     |   1 -\n builtin/index-pack.c               |   2 -\n builtin/init-db.c                  |   1 -\n builtin/log.c                      |   1 -\n builtin/merge.c                    |   2 -\n builtin/mktree.c                   |   1 -\n builtin/mv.c                       |   1 -\n builtin/name-rev.c                 |   1 -\n builtin/pack-objects.c             |   2 -\n builtin/rebase.c                   |   1 -\n builtin/receive-pack.c             |   1 -\n builtin/repack.c                   |   1 -\n builtin/rerere.c                   |   1 -\n builtin/rev-parse.c                |   1 -\n builtin/revert.c                   |   1 -\n builtin/rm.c                       |   1 -\n builtin/submodule--helper.c        |   1 -\n builtin/symbolic-ref.c             |   1 +\n builtin/unpack-file.c              |   1 -\n builtin/unpack-objects.c           |   1 +\n builtin/worktree.c                 |   1 -\n bulk-checkin.c                     |   2 -\n cache-tree.c                       |   1 -\n chunk-format.c                     |   1 -\n combine-diff.c                     |   1 -\n commit-graph.c                     |   1 -\n commit-reach.c                     |   1 -\n compat/terminal.c                  |   1 -\n config.c                           |   2 -\n convert.c                          |   1 -\n copy.c                             |   1 -\n csum-file.c                        |   1 -\n ctype.c                            |  36 ----\n daemon.c                           |   2 -\n delta-islands.c                    |   1 -\n diff.c                             |   2 -\n diffcore-rename.c                  |   1 -\n dir-iterator.c                     |   1 -\n dir.c                              |   2 -\n editor.c                           |   1 -\n entry.c                            |   1 -\n environment.c                      |   1 -\n ewah/bitmap.c                      |   1 -\n ewah/ewah_bitmap.c                 |   1 -\n fetch-pack.c                       |   2 -\n fmt-merge-msg.c                    |   1 -\n fsck.c                             |   1 -\n git-compat-util.h                  | 284 ++++++++---------------------\n gpg-interface.c                    |   1 -\n grep.c                             |   1 -\n help.c                             |   1 -\n http-backend.c                     |   2 -\n imap-send.c                        |   1 -\n kwset.c                            |  36 ++++\n kwset.h                            |   2 +\n line-log.c                         |   1 -\n list-objects-filter-options.c      |   1 -\n list-objects-filter.c              |   1 -\n merge-ll.c                         |   1 -\n merge-recursive.c                  |   1 -\n midx.c                             |   1 -\n notes-merge.c                      |   1 -\n object-file.c                      |   2 -\n oid-array.c                        |   1 -\n oidtree.c                          |   1 -\n pack-bitmap-write.c                |   1 -\n pack-bitmap.c                      |   1 -\n pack-objects.c                     |   1 -\n pack-write.c                       |   1 -\n packfile.c                         |   2 -\n parallel-checkout.c                |   2 -\n path.c                             |   1 -\n pkt-line.c                         |   1 -\n pretty.c                           |   1 -\n prio-queue.c                       |   1 -\n quote.c                            |   1 -\n read-cache.c                       |   2 -\n rebase-interactive.c               |   1 -\n ref-filter.c                       |   1 -\n reflog-walk.c                      |   1 -\n refs.c                             |   2 -\n refspec.c                          |   1 -\n remote-curl.c                      |   1 -\n remote.c                           |   1 -\n rerere.c                           |   2 -\n revision.c                         |   1 -\n sane-ctype.h                       |  66 +++++++\n send-pack.c                        |   1 -\n sequencer.c                        |   2 -\n server-info.c                      |   2 -\n setup.c                            |   1 -\n shallow.c                          |   2 -\n sigchain.c                         |   1 -\n sparse-index.c                     |   1 -\n split-index.c                      |   1 -\n strbuf.c                           |   2 -\n strbuf.h                           |  32 ++++\n streaming.c                        |   1 -\n string-list.c                      |   1 -\n strvec.c                           |   1 -\n submodule-config.c                 |   1 -\n submodule.c                        |   1 -\n t/helper/test-delta.c              |   1 -\n t/helper/test-fsmonitor-client.c   |   1 -\n t/helper/test-reach.c              |   1 -\n t/helper/test-read-cache.c         |   1 -\n tag.c                              |   1 -\n tempfile.c                         |   1 -\n trace.c                            |   1 -\n trace2/tr2_tls.c                   |   1 -\n trailer.c                          |   1 -\n transport-helper.c                 |   1 -\n transport.c                        |   2 -\n tree-walk.c                        |   1 -\n upload-pack.c                      |   1 -\n usage.c                            |   1 -\n userdiff.c                         |   1 -\n versioncmp.c                       |   1 +\n worktree.c                         |   2 -\n wrapper.c                          |   1 -\n wrapper.h                          | 111 +++++++++++\n write-or-die.c                     |   1 -\n 147 files changed, 327 insertions(+), 478 deletions(-)\n create mode 100644 sane-ctype.h\n\nRange-diff against v3:\n 1:  03efb2c4b3 <  -:  ---------- init-db: document existing bug with core.bare in template config\n 2:  020191c84e <  -:  ---------- init-db: remove unnecessary global variable\n 3:  4f2631b200 <  -:  ---------- init-db, clone: change unnecessary global into passed parameter\n 4:  40e8349c97 <  -:  ---------- setup: adopt shared init-db & clone code\n 5:  8ce842e5e4 <  -:  ---------- read-cache: move shared commit and ls-files code\n 6:  9a435193b6 <  -:  ---------- add: modify add_files_to_cache() to avoid globals\n 7:  f9fb1ec0c5 <  -:  ---------- read-cache: move shared add/checkout/commit code\n 8:  193ccad5dd <  -:  ---------- statinfo: move stat_{data,validity} functions from cache/read-cache\n 9:  8fb86883ed <  -:  ---------- run-command.h: move declarations for run-command.c from cache.h\n10:  5e579aeeb5 <  -:  ---------- name-hash.h: move declarations for name-hash.c from cache.h\n11:  5c0c5257a6 <  -:  ---------- sparse-index.h: move declarations for sparse-index.c from cache.h\n12:  230b0e9968 <  -:  ---------- preload-index.h: move declarations for preload-index.c from elsewhere\n13:  66327b7465 <  -:  ---------- diff.h: move declaration for global in diff.c from cache.h\n14:  61830c7bfa <  -:  ---------- merge.h: move declarations for merge.c from cache.h\n15:  0979c990b1 <  -:  ---------- repository.h: move declaration of the_index from cache.h\n16:  eb2fac9a86 <  -:  ---------- read-cache*.h: move declarations for read-cache.c functions from cache.h\n17:  0cda8f7c94 <  -:  ---------- cache.h: remove this no-longer-used header\n18:  82ce975a19 <  -:  ---------- log-tree: replace include of revision.h with simple forward declaration\n19:  75334a2bc0 <  -:  ---------- repository: remove unnecessary include of path.h\n20:  940ebf92de <  -:  ---------- diff.h: remove unnecessary include of oidset.h\n21:  fc12c810dc <  -:  ---------- list-objects-filter-options.h: remove unneccessary include\n22:  8985e07940 <  -:  ---------- builtin.h: remove unneccessary includes\n23:  af118e7cf0 <  -:  ---------- git-compat-util.h: remove unneccessary include of wildmatch.h\n24:  7e33c8f9b1 <  -:  ---------- merge-ll: rename from ll-merge\n25:  5e96b1b130 <  -:  ---------- khash: name the structs that khash declares\n26:  2d6aa61e78 <  -:  ---------- object-store-ll.h: split this header out of object-store.h\n27:  f6927dd57c <  -:  ---------- hash-ll, hashmap: move oidhash() to hash-ll\n28:  482d3c671e <  -:  ---------- fsmonitor-ll.h: split this header out of fsmonitor.h\n29:  aa680f395a <  -:  ---------- strbuf: clarify API boundary\n30:  44b977d1b0 <  -:  ---------- abspath: move related functions to abspath\n31:  99852416e8 <  -:  ---------- credential-store: move related functions to credential-store file\n32:  09aef95f30 <  -:  ---------- object-name: move related functions to object-name\n33:  36048bca4c <  -:  ---------- path: move related function to path\n34:  02a02faf12 <  -:  ---------- strbuf: clarify dependency\n35:  63a933ff2f <  -:  ---------- strbuf: remove global variable\n36:  d352eae308 =  1:  144284a8f1 git-compat-util: move strbuf.c funcs to its header\n37:  fe4fd6f92a =  2:  39913c44e8 git-compat-util: move wrapper.c funcs to its header\n38:  ec7ea12f7c =  3:  c495762940 sane-ctype.h: create header for sane-ctype macros\n39:  4f95b4121e =  4:  2750d35e6d kwset: move translation table from ctype\n40:  36525e39d5 <  -:  ---------- common.h: move non-compat specific macros and functions\n41:  21f0f31ff3 <  -:  ---------- git-compat-util: move usage.c funcs to its header\n42:  531db31c5c !  5:  b5fb55d235 treewide: remove unnecessary includes for wrapper.h\n    @@ gpg-interface.c\n     -#include \"wrapper.h\"\n      #include \"environment.h\"\n      \n    - static int git_gpg_config(const char *, const char *, void *);\n    + static int git_gpg_config(const char *, const char *,\n     \n      ## grep.c ##\n     @@\n43:  98694f7add !  6:  140d98111f common: move alloc macros to common.h\n    @@ Commit message\n         common: move alloc macros to common.h\n     \n         alloc_nr, ALLOC_GROW, and ALLOC_GROW_BY are commonly used macros for\n    -    dynamic array allocation. Moving these macros to common.h focuses\n    -    alloc.[ch] to allocation for Git objects and additionally allows us to\n    -    remove inclusions to alloc.h from files that solely used the above\n    -    macros.\n    +    dynamic array allocation. Moving these macros to git-compat-util.h with\n    +    the other alloc macros focuses alloc.[ch] to allocation for Git objects\n    +    and additionally allows us to remove inclusions to alloc.h from files\n    +    that solely used the above macros.\n     \n      ## add-patch.c ##\n     @@\n    @@ commit-reach.c\n      #include \"commit-graph.h\"\n      #include \"decorate.h\"\n     \n    - ## common.h ##\n    -@@ common.h: static inline int cast_size_t_to_int(size_t a)\n    -  */\n    - #define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)\n    - \n    -+#define alloc_nr(x) (((x)+16)*3/2)\n    -+\n    -+/**\n    -+ * Dynamically growing an array using realloc() is error prone and boring.\n    -+ *\n    -+ * Define your array with:\n    -+ *\n    -+ * - a pointer (`item`) that points at the array, initialized to `NULL`\n    -+ *   (although please name the variable based on its contents, not on its\n    -+ *   type);\n    -+ *\n    -+ * - an integer variable (`alloc`) that keeps track of how big the current\n    -+ *   allocation is, initialized to `0`;\n    -+ *\n    -+ * - another integer variable (`nr`) to keep track of how many elements the\n    -+ *   array currently has, initialized to `0`.\n    -+ *\n    -+ * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,\n    -+ * alloc)`.  This ensures that the array can hold at least `n` elements by\n    -+ * calling `realloc(3)` and adjusting `alloc` variable.\n    -+ *\n    -+ * ------------\n    -+ * sometype *item;\n    -+ * size_t nr;\n    -+ * size_t alloc\n    -+ *\n    -+ * for (i = 0; i < nr; i++)\n    -+ * \tif (we like item[i] already)\n    -+ * \t\treturn;\n    -+ *\n    -+ * // we did not like any existing one, so add one\n    -+ * ALLOC_GROW(item, nr + 1, alloc);\n    -+ * item[nr++] = value you like;\n    -+ * ------------\n    -+ *\n    -+ * You are responsible for updating the `nr` variable.\n    -+ *\n    -+ * If you need to specify the number of elements to allocate explicitly\n    -+ * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.\n    -+ *\n    -+ * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some\n    -+ * added niceties.\n    -+ *\n    -+ * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.\n    -+ */\n    -+#define ALLOC_GROW(x, nr, alloc) \\\n    -+\tdo { \\\n    -+\t\tif ((nr) > alloc) { \\\n    -+\t\t\tif (alloc_nr(alloc) < (nr)) \\\n    -+\t\t\t\talloc = (nr); \\\n    -+\t\t\telse \\\n    -+\t\t\t\talloc = alloc_nr(alloc); \\\n    -+\t\t\tREALLOC_ARRAY(x, alloc); \\\n    -+\t\t} \\\n    -+\t} while (0)\n    -+\n    -+/*\n    -+ * Similar to ALLOC_GROW but handles updating of the nr value and\n    -+ * zeroing the bytes of the newly-grown array elements.\n    -+ *\n    -+ * DO NOT USE any expression with side-effect for any of the\n    -+ * arguments.\n    -+ */\n    -+#define ALLOC_GROW_BY(x, nr, increase, alloc) \\\n    -+\tdo { \\\n    -+\t\tif (increase) { \\\n    -+\t\t\tsize_t new_nr = nr + (increase); \\\n    -+\t\t\tif (new_nr < nr) \\\n    -+\t\t\t\tBUG(\"negative growth in ALLOC_GROW_BY\"); \\\n    -+\t\t\tALLOC_GROW(x, new_nr, alloc); \\\n    -+\t\t\tmemset((x) + nr, 0, sizeof(*(x)) * (increase)); \\\n    -+\t\t\tnr = new_nr; \\\n    -+\t\t} \\\n    -+\t} while (0)\n    -+\n    - #define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))\n    - #define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))\n    - #define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))\n    -\n      ## config.c ##\n     @@\n      #include \"git-compat-util.h\"\n    @@ fsck.c\n      #include \"dir.h\"\n      #include \"hex.h\"\n     \n    + ## git-compat-util.h ##\n    +@@ git-compat-util.h: static inline void move_array(void *dst, const void *src, size_t n, size_t size)\n    + #define FLEXPTR_ALLOC_STR(x, ptrname, str) \\\n    + \tFLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))\n    + \n    ++#define alloc_nr(x) (((x)+16)*3/2)\n    ++\n    ++/**\n    ++ * Dynamically growing an array using realloc() is error prone and boring.\n    ++ *\n    ++ * Define your array with:\n    ++ *\n    ++ * - a pointer (`item`) that points at the array, initialized to `NULL`\n    ++ *   (although please name the variable based on its contents, not on its\n    ++ *   type);\n    ++ *\n    ++ * - an integer variable (`alloc`) that keeps track of how big the current\n    ++ *   allocation is, initialized to `0`;\n    ++ *\n    ++ * - another integer variable (`nr`) to keep track of how many elements the\n    ++ *   array currently has, initialized to `0`.\n    ++ *\n    ++ * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,\n    ++ * alloc)`.  This ensures that the array can hold at least `n` elements by\n    ++ * calling `realloc(3)` and adjusting `alloc` variable.\n    ++ *\n    ++ * ------------\n    ++ * sometype *item;\n    ++ * size_t nr;\n    ++ * size_t alloc\n    ++ *\n    ++ * for (i = 0; i < nr; i++)\n    ++ * \tif (we like item[i] already)\n    ++ * \t\treturn;\n    ++ *\n    ++ * // we did not like any existing one, so add one\n    ++ * ALLOC_GROW(item, nr + 1, alloc);\n    ++ * item[nr++] = value you like;\n    ++ * ------------\n    ++ *\n    ++ * You are responsible for updating the `nr` variable.\n    ++ *\n    ++ * If you need to specify the number of elements to allocate explicitly\n    ++ * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.\n    ++ *\n    ++ * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some\n    ++ * added niceties.\n    ++ *\n    ++ * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.\n    ++ */\n    ++#define ALLOC_GROW(x, nr, alloc) \\\n    ++\tdo { \\\n    ++\t\tif ((nr) > alloc) { \\\n    ++\t\t\tif (alloc_nr(alloc) < (nr)) \\\n    ++\t\t\t\talloc = (nr); \\\n    ++\t\t\telse \\\n    ++\t\t\t\talloc = alloc_nr(alloc); \\\n    ++\t\t\tREALLOC_ARRAY(x, alloc); \\\n    ++\t\t} \\\n    ++\t} while (0)\n    ++\n    ++/*\n    ++ * Similar to ALLOC_GROW but handles updating of the nr value and\n    ++ * zeroing the bytes of the newly-grown array elements.\n    ++ *\n    ++ * DO NOT USE any expression with side-effect for any of the\n    ++ * arguments.\n    ++ */\n    ++#define ALLOC_GROW_BY(x, nr, increase, alloc) \\\n    ++\tdo { \\\n    ++\t\tif (increase) { \\\n    ++\t\t\tsize_t new_nr = nr + (increase); \\\n    ++\t\t\tif (new_nr < nr) \\\n    ++\t\t\t\tBUG(\"negative growth in ALLOC_GROW_BY\"); \\\n    ++\t\t\tALLOC_GROW(x, new_nr, alloc); \\\n    ++\t\t\tmemset((x) + nr, 0, sizeof(*(x)) * (increase)); \\\n    ++\t\t\tnr = new_nr; \\\n    ++\t\t} \\\n    ++\t} while (0)\n    ++\n    + static inline char *xstrdup_or_null(const char *str)\n    + {\n    + \treturn str ? xstrdup(str) : NULL;\n    +\n      ## help.c ##\n     @@\n      #include \"git-compat-util.h\"\n-- \n2.41.0.255.g8b1d071c50-goog\n\n"},{"id":"479063","messageId":"20230630202346.3069950-1-calvinwan@google.com","threadId":"59752","inReplyTo":"20230630202237.3069327-1-calvinwan@google.com","subject":"[PATCH v4 1/6] git-compat-util: move strbuf.c funcs to its header","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-30T20:23:41Z","receivedAt":"2023-06-30T20:24:03Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"While functions like starts_with() probably should not belong in the\nboundaries of the strbuf library, this commit focuses on first splitting\nout headers from git-compat-util.h.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n builtin/symbolic-ref.c   |  1 +\n builtin/unpack-objects.c |  1 +\n git-compat-util.h        | 32 --------------------------------\n strbuf.h                 | 32 ++++++++++++++++++++++++++++++++\n versioncmp.c             |  1 +\n 5 files changed, 35 insertions(+), 32 deletions(-)\n\ndiff --git a/builtin/symbolic-ref.c b/builtin/symbolic-ref.c\nindex a61fa3c0f8..c9defe4d2e 100644\n--- a/builtin/symbolic-ref.c\n+++ b/builtin/symbolic-ref.c\n@@ -3,6 +3,7 @@\n #include \"gettext.h\"\n #include \"refs.h\"\n #include \"parse-options.h\"\n+#include \"strbuf.h\"\n \n static const char * const git_symbolic_ref_usage[] = {\n \tN_(\"git symbolic-ref [-m <reason>] <name> <ref>\"),\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex 1979532a9d..84b68304ed 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -12,6 +12,7 @@\n #include \"blob.h\"\n #include \"commit.h\"\n #include \"replace-object.h\"\n+#include \"strbuf.h\"\n #include \"tag.h\"\n #include \"tree.h\"\n #include \"tree-walk.h\"\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex ae88291976..78a993c604 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -679,9 +679,6 @@ void set_warn_routine(report_fn routine);\n report_fn get_warn_routine(void);\n void set_die_is_recursing_routine(int (*routine)(void));\n \n-int starts_with(const char *str, const char *prefix);\n-int istarts_with(const char *str, const char *prefix);\n-\n /*\n  * If the string \"str\" begins with the string found in \"prefix\", return 1.\n  * The \"out\" parameter is set to \"str + strlen(prefix)\" (i.e., to the point in\n@@ -710,29 +707,6 @@ static inline int skip_prefix(const char *str, const char *prefix,\n \treturn 0;\n }\n \n-/*\n- * If the string \"str\" is the same as the string in \"prefix\", then the \"arg\"\n- * parameter is set to the \"def\" parameter and 1 is returned.\n- * If the string \"str\" begins with the string found in \"prefix\" and then a\n- * \"=\" sign, then the \"arg\" parameter is set to \"str + strlen(prefix) + 1\"\n- * (i.e., to the point in the string right after the prefix and the \"=\" sign),\n- * and 1 is returned.\n- *\n- * Otherwise, return 0 and leave \"arg\" untouched.\n- *\n- * When we accept both a \"--key\" and a \"--key=<val>\" option, this function\n- * can be used instead of !strcmp(arg, \"--key\") and then\n- * skip_prefix(arg, \"--key=\", &arg) to parse such an option.\n- */\n-int skip_to_optional_arg_default(const char *str, const char *prefix,\n-\t\t\t\t const char **arg, const char *def);\n-\n-static inline int skip_to_optional_arg(const char *str, const char *prefix,\n-\t\t\t\t       const char **arg)\n-{\n-\treturn skip_to_optional_arg_default(str, prefix, arg, \"\");\n-}\n-\n /*\n  * Like skip_prefix, but promises never to read past \"len\" bytes of the input\n  * buffer, and returns the remaining number of bytes in \"out\" via \"outlen\".\n@@ -777,12 +751,6 @@ static inline int strip_suffix(const char *str, const char *suffix, size_t *len)\n \treturn strip_suffix_mem(str, len, suffix);\n }\n \n-static inline int ends_with(const char *str, const char *suffix)\n-{\n-\tsize_t len;\n-\treturn strip_suffix(str, suffix, &len);\n-}\n-\n #define SWAP(a, b) do {\t\t\t\t\t\t\\\n \tvoid *_swap_a_ptr = &(a);\t\t\t\t\\\n \tvoid *_swap_b_ptr = &(b);\t\t\t\t\\\ndiff --git a/strbuf.h b/strbuf.h\nindex 0528ab5010..fd43c46433 100644\n--- a/strbuf.h\n+++ b/strbuf.h\n@@ -671,4 +671,36 @@ char *xstrvfmt(const char *fmt, va_list ap);\n __attribute__((format (printf, 1, 2)))\n char *xstrfmt(const char *fmt, ...);\n \n+int starts_with(const char *str, const char *prefix);\n+int istarts_with(const char *str, const char *prefix);\n+\n+/*\n+ * If the string \"str\" is the same as the string in \"prefix\", then the \"arg\"\n+ * parameter is set to the \"def\" parameter and 1 is returned.\n+ * If the string \"str\" begins with the string found in \"prefix\" and then a\n+ * \"=\" sign, then the \"arg\" parameter is set to \"str + strlen(prefix) + 1\"\n+ * (i.e., to the point in the string right after the prefix and the \"=\" sign),\n+ * and 1 is returned.\n+ *\n+ * Otherwise, return 0 and leave \"arg\" untouched.\n+ *\n+ * When we accept both a \"--key\" and a \"--key=<val>\" option, this function\n+ * can be used instead of !strcmp(arg, \"--key\") and then\n+ * skip_prefix(arg, \"--key=\", &arg) to parse such an option.\n+ */\n+int skip_to_optional_arg_default(const char *str, const char *prefix,\n+\t\t\t\t const char **arg, const char *def);\n+\n+static inline int skip_to_optional_arg(const char *str, const char *prefix,\n+\t\t\t\t       const char **arg)\n+{\n+\treturn skip_to_optional_arg_default(str, prefix, arg, \"\");\n+}\n+\n+static inline int ends_with(const char *str, const char *suffix)\n+{\n+\tsize_t len;\n+\treturn strip_suffix(str, suffix, &len);\n+}\n+\n #endif /* STRBUF_H */\ndiff --git a/versioncmp.c b/versioncmp.c\nindex 74cc7c43f0..45e676cbca 100644\n--- a/versioncmp.c\n+++ b/versioncmp.c\n@@ -1,5 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"config.h\"\n+#include \"strbuf.h\"\n #include \"string-list.h\"\n #include \"versioncmp.h\"\n \n-- \n2.41.0.255.g8b1d071c50-goog\n\n"},{"id":"479064","messageId":"20230630202346.3069950-2-calvinwan@google.com","threadId":"59752","inReplyTo":"20230630202237.3069327-1-calvinwan@google.com","subject":"[PATCH v4 2/6] git-compat-util: move wrapper.c funcs to its header","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-30T20:23:42Z","receivedAt":"2023-06-30T20:24:08Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Since the functions in wrapper.c are widely used across the codebase,\ninclude it by default in git-compat-util.h. A future patch will remove\nnow unnecessary inclusions of wrapper.h from other files.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n git-compat-util.h | 112 +---------------------------------------------\n wrapper.h         | 111 +++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 112 insertions(+), 111 deletions(-)\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 78a993c604..9140f43bbf 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -627,7 +627,7 @@ static inline int git_has_dir_sep(const char *path)\n \n #include \"compat/bswap.h\"\n \n-struct strbuf;\n+#include \"wrapper.h\"\n \n /* General helper functions */\n NORETURN void usage(const char *err);\n@@ -1047,36 +1047,6 @@ static inline int cast_size_t_to_int(size_t a)\n # define xalloca(size)      (xmalloc(size))\n # define xalloca_free(p)    (free(p))\n #endif\n-char *xstrdup(const char *str);\n-void *xmalloc(size_t size);\n-void *xmallocz(size_t size);\n-void *xmallocz_gently(size_t size);\n-void *xmemdupz(const void *data, size_t len);\n-char *xstrndup(const char *str, size_t len);\n-void *xrealloc(void *ptr, size_t size);\n-void *xcalloc(size_t nmemb, size_t size);\n-void xsetenv(const char *name, const char *value, int overwrite);\n-void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n-const char *mmap_os_err(void);\n-void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n-int xopen(const char *path, int flags, ...);\n-ssize_t xread(int fd, void *buf, size_t len);\n-ssize_t xwrite(int fd, const void *buf, size_t len);\n-ssize_t xpread(int fd, void *buf, size_t len, off_t offset);\n-int xdup(int fd);\n-FILE *xfopen(const char *path, const char *mode);\n-FILE *xfdopen(int fd, const char *mode);\n-int xmkstemp(char *temp_filename);\n-int xmkstemp_mode(char *temp_filename, int mode);\n-char *xgetcwd(void);\n-FILE *fopen_for_writing(const char *path);\n-FILE *fopen_or_warn(const char *path, const char *mode);\n-\n-/*\n- * Like strncmp, but only return zero if s is NUL-terminated and exactly len\n- * characters long.  If it is not, consider it greater than t.\n- */\n-int xstrncmpz(const char *s, const char *t, size_t len);\n \n /*\n  * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note\n@@ -1178,15 +1148,10 @@ static inline size_t xsize_t(off_t len)\n \treturn (size_t) len;\n }\n \n-__attribute__((format (printf, 3, 4)))\n-int xsnprintf(char *dst, size_t max, const char *fmt, ...);\n-\n #ifndef HOST_NAME_MAX\n #define HOST_NAME_MAX 256\n #endif\n \n-int xgethostname(char *buf, size_t len);\n-\n /* in ctype.c, for kwset users */\n extern const unsigned char tolower_trans_tbl[256];\n \n@@ -1427,72 +1392,6 @@ void bug_fl(const char *file, int line, const char *fmt, ...);\n #endif\n #endif\n \n-enum fsync_action {\n-\tFSYNC_WRITEOUT_ONLY,\n-\tFSYNC_HARDWARE_FLUSH\n-};\n-\n-/*\n- * Issues an fsync against the specified file according to the specified mode.\n- *\n- * FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating\n- * systems to flush the OS cache without issuing a flush command to the storage\n- * controller. If those interfaces are unavailable, the function fails with\n- * ENOSYS.\n- *\n- * FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that\n- * changes are durable. It is not expected to fail.\n- */\n-int git_fsync(int fd, enum fsync_action action);\n-\n-/*\n- * Writes out trace statistics for fsync using the trace2 API.\n- */\n-void trace_git_fsync_stats(void);\n-\n-/*\n- * Preserves errno, prints a message, but gives no warning for ENOENT.\n- * Returns 0 on success, which includes trying to unlink an object that does\n- * not exist.\n- */\n-int unlink_or_warn(const char *path);\n- /*\n-  * Tries to unlink file.  Returns 0 if unlink succeeded\n-  * or the file already didn't exist.  Returns -1 and\n-  * appends a message to err suitable for\n-  * 'error(\"%s\", err->buf)' on error.\n-  */\n-int unlink_or_msg(const char *file, struct strbuf *err);\n-/*\n- * Preserves errno, prints a message, but gives no warning for ENOENT.\n- * Returns 0 on success, which includes trying to remove a directory that does\n- * not exist.\n- */\n-int rmdir_or_warn(const char *path);\n-/*\n- * Calls the correct function out of {unlink,rmdir}_or_warn based on\n- * the supplied file mode.\n- */\n-int remove_or_warn(unsigned int mode, const char *path);\n-\n-/*\n- * Call access(2), but warn for any error except \"missing file\"\n- * (ENOENT or ENOTDIR).\n- */\n-#define ACCESS_EACCES_OK (1U << 0)\n-int access_or_warn(const char *path, int mode, unsigned flag);\n-int access_or_die(const char *path, int mode, unsigned flag);\n-\n-/* Warn on an inaccessible file if errno indicates this is an error */\n-int warn_on_fopen_errors(const char *path);\n-\n-/*\n- * Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent\n- * may be racy. Do not use this as protection against an attacker who can\n- * simultaneously create paths.\n- */\n-int open_nofollow(const char *path, int flags);\n-\n #ifndef SHELL_PATH\n # define SHELL_PATH \"/bin/sh\"\n #endif\n@@ -1632,13 +1531,4 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset)\n \t((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))\n #endif /* !__GNUC__ */\n \n-void sleep_millisec(int millisec);\n-\n-/*\n- * Generate len bytes from the system cryptographically secure PRNG.\n- * Returns 0 on success and -1 on error, setting errno.  The inability to\n- * satisfy the full request is an error.\n- */\n-int csprng_bytes(void *buf, size_t len);\n-\n #endif\ndiff --git a/wrapper.h b/wrapper.h\nindex f0c7d0616d..c85b1328d1 100644\n--- a/wrapper.h\n+++ b/wrapper.h\n@@ -1,6 +1,42 @@\n #ifndef WRAPPER_H\n #define WRAPPER_H\n \n+char *xstrdup(const char *str);\n+void *xmalloc(size_t size);\n+void *xmallocz(size_t size);\n+void *xmallocz_gently(size_t size);\n+void *xmemdupz(const void *data, size_t len);\n+char *xstrndup(const char *str, size_t len);\n+void *xrealloc(void *ptr, size_t size);\n+void *xcalloc(size_t nmemb, size_t size);\n+void xsetenv(const char *name, const char *value, int overwrite);\n+void *xmmap(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n+const char *mmap_os_err(void);\n+void *xmmap_gently(void *start, size_t length, int prot, int flags, int fd, off_t offset);\n+int xopen(const char *path, int flags, ...);\n+ssize_t xread(int fd, void *buf, size_t len);\n+ssize_t xwrite(int fd, const void *buf, size_t len);\n+ssize_t xpread(int fd, void *buf, size_t len, off_t offset);\n+int xdup(int fd);\n+FILE *xfopen(const char *path, const char *mode);\n+FILE *xfdopen(int fd, const char *mode);\n+int xmkstemp(char *temp_filename);\n+int xmkstemp_mode(char *temp_filename, int mode);\n+char *xgetcwd(void);\n+FILE *fopen_for_writing(const char *path);\n+FILE *fopen_or_warn(const char *path, const char *mode);\n+\n+/*\n+ * Like strncmp, but only return zero if s is NUL-terminated and exactly len\n+ * characters long.  If it is not, consider it greater than t.\n+ */\n+int xstrncmpz(const char *s, const char *t, size_t len);\n+\n+__attribute__((format (printf, 3, 4)))\n+int xsnprintf(char *dst, size_t max, const char *fmt, ...);\n+\n+int xgethostname(char *buf, size_t len);\n+\n /* set default permissions by passing mode arguments to open(2) */\n int git_mkstemps_mode(char *pattern, int suffix_len, int mode);\n int git_mkstemp_mode(char *pattern, int mode);\n@@ -33,4 +69,79 @@ void write_file(const char *path, const char *fmt, ...);\n /* Return 1 if the file is empty or does not exists, 0 otherwise. */\n int is_empty_or_missing_file(const char *filename);\n \n+enum fsync_action {\n+\tFSYNC_WRITEOUT_ONLY,\n+\tFSYNC_HARDWARE_FLUSH\n+};\n+\n+/*\n+ * Issues an fsync against the specified file according to the specified mode.\n+ *\n+ * FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating\n+ * systems to flush the OS cache without issuing a flush command to the storage\n+ * controller. If those interfaces are unavailable, the function fails with\n+ * ENOSYS.\n+ *\n+ * FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that\n+ * changes are durable. It is not expected to fail.\n+ */\n+int git_fsync(int fd, enum fsync_action action);\n+\n+/*\n+ * Writes out trace statistics for fsync using the trace2 API.\n+ */\n+void trace_git_fsync_stats(void);\n+\n+/*\n+ * Preserves errno, prints a message, but gives no warning for ENOENT.\n+ * Returns 0 on success, which includes trying to unlink an object that does\n+ * not exist.\n+ */\n+int unlink_or_warn(const char *path);\n+ /*\n+  * Tries to unlink file.  Returns 0 if unlink succeeded\n+  * or the file already didn't exist.  Returns -1 and\n+  * appends a message to err suitable for\n+  * 'error(\"%s\", err->buf)' on error.\n+  */\n+int unlink_or_msg(const char *file, struct strbuf *err);\n+/*\n+ * Preserves errno, prints a message, but gives no warning for ENOENT.\n+ * Returns 0 on success, which includes trying to remove a directory that does\n+ * not exist.\n+ */\n+int rmdir_or_warn(const char *path);\n+/*\n+ * Calls the correct function out of {unlink,rmdir}_or_warn based on\n+ * the supplied file mode.\n+ */\n+int remove_or_warn(unsigned int mode, const char *path);\n+\n+/*\n+ * Call access(2), but warn for any error except \"missing file\"\n+ * (ENOENT or ENOTDIR).\n+ */\n+#define ACCESS_EACCES_OK (1U << 0)\n+int access_or_warn(const char *path, int mode, unsigned flag);\n+int access_or_die(const char *path, int mode, unsigned flag);\n+\n+/* Warn on an inaccessible file if errno indicates this is an error */\n+int warn_on_fopen_errors(const char *path);\n+\n+/*\n+ * Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent\n+ * may be racy. Do not use this as protection against an attacker who can\n+ * simultaneously create paths.\n+ */\n+int open_nofollow(const char *path, int flags);\n+\n+void sleep_millisec(int millisec);\n+\n+/*\n+ * Generate len bytes from the system cryptographically secure PRNG.\n+ * Returns 0 on success and -1 on error, setting errno.  The inability to\n+ * satisfy the full request is an error.\n+ */\n+int csprng_bytes(void *buf, size_t len);\n+\n #endif /* WRAPPER_H */\n-- \n2.41.0.255.g8b1d071c50-goog\n\n"},{"id":"479065","messageId":"20230630202346.3069950-3-calvinwan@google.com","threadId":"59752","inReplyTo":"20230630202237.3069327-1-calvinwan@google.com","subject":"[PATCH v4 3/6] sane-ctype.h: create header for sane-ctype macros","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-30T20:23:43Z","receivedAt":"2023-06-30T20:24:20Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Splitting these macros from git-compat-util.h cleans up the file and\nallows future third-party sources to not use these overrides if they do\nnot wish to.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n git-compat-util.h | 62 +-------------------------------------------\n sane-ctype.h      | 66 +++++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 67 insertions(+), 61 deletions(-)\n create mode 100644 sane-ctype.h\n\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 9140f43bbf..5f916e1094 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -1155,67 +1155,7 @@ static inline size_t xsize_t(off_t len)\n /* in ctype.c, for kwset users */\n extern const unsigned char tolower_trans_tbl[256];\n \n-/* Sane ctype - no locale, and works with signed chars */\n-#undef isascii\n-#undef isspace\n-#undef isdigit\n-#undef isalpha\n-#undef isalnum\n-#undef isprint\n-#undef islower\n-#undef isupper\n-#undef tolower\n-#undef toupper\n-#undef iscntrl\n-#undef ispunct\n-#undef isxdigit\n-\n-extern const unsigned char sane_ctype[256];\n-extern const signed char hexval_table[256];\n-#define GIT_SPACE 0x01\n-#define GIT_DIGIT 0x02\n-#define GIT_ALPHA 0x04\n-#define GIT_GLOB_SPECIAL 0x08\n-#define GIT_REGEX_SPECIAL 0x10\n-#define GIT_PATHSPEC_MAGIC 0x20\n-#define GIT_CNTRL 0x40\n-#define GIT_PUNCT 0x80\n-#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n-#define isascii(x) (((x) & ~0x7f) == 0)\n-#define isspace(x) sane_istest(x,GIT_SPACE)\n-#define isdigit(x) sane_istest(x,GIT_DIGIT)\n-#define isalpha(x) sane_istest(x,GIT_ALPHA)\n-#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)\n-#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)\n-#define islower(x) sane_iscase(x, 1)\n-#define isupper(x) sane_iscase(x, 0)\n-#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)\n-#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)\n-#define iscntrl(x) (sane_istest(x,GIT_CNTRL))\n-#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \\\n-\t\tGIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)\n-#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n-#define tolower(x) sane_case((unsigned char)(x), 0x20)\n-#define toupper(x) sane_case((unsigned char)(x), 0)\n-#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)\n-\n-static inline int sane_case(int x, int high)\n-{\n-\tif (sane_istest(x, GIT_ALPHA))\n-\t\tx = (x & ~0x20) | high;\n-\treturn x;\n-}\n-\n-static inline int sane_iscase(int x, int is_lower)\n-{\n-\tif (!sane_istest(x, GIT_ALPHA))\n-\t\treturn 0;\n-\n-\tif (is_lower)\n-\t\treturn (x & 0x20) != 0;\n-\telse\n-\t\treturn (x & 0x20) == 0;\n-}\n+#include \"sane-ctype.h\"\n \n /*\n  * Like skip_prefix, but compare case-insensitively. Note that the comparison\ndiff --git a/sane-ctype.h b/sane-ctype.h\nnew file mode 100644\nindex 0000000000..cbea1b299b\n--- /dev/null\n+++ b/sane-ctype.h\n@@ -0,0 +1,66 @@\n+#ifndef SANE_CTYPE_H\n+#define SANE_CTYPE_H\n+\n+/* Sane ctype - no locale, and works with signed chars */\n+#undef isascii\n+#undef isspace\n+#undef isdigit\n+#undef isalpha\n+#undef isalnum\n+#undef isprint\n+#undef islower\n+#undef isupper\n+#undef tolower\n+#undef toupper\n+#undef iscntrl\n+#undef ispunct\n+#undef isxdigit\n+\n+extern const unsigned char sane_ctype[256];\n+extern const signed char hexval_table[256];\n+#define GIT_SPACE 0x01\n+#define GIT_DIGIT 0x02\n+#define GIT_ALPHA 0x04\n+#define GIT_GLOB_SPECIAL 0x08\n+#define GIT_REGEX_SPECIAL 0x10\n+#define GIT_PATHSPEC_MAGIC 0x20\n+#define GIT_CNTRL 0x40\n+#define GIT_PUNCT 0x80\n+#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)\n+#define isascii(x) (((x) & ~0x7f) == 0)\n+#define isspace(x) sane_istest(x,GIT_SPACE)\n+#define isdigit(x) sane_istest(x,GIT_DIGIT)\n+#define isalpha(x) sane_istest(x,GIT_ALPHA)\n+#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)\n+#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)\n+#define islower(x) sane_iscase(x, 1)\n+#define isupper(x) sane_iscase(x, 0)\n+#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)\n+#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)\n+#define iscntrl(x) (sane_istest(x,GIT_CNTRL))\n+#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \\\n+\t\tGIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)\n+#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)\n+#define tolower(x) sane_case((unsigned char)(x), 0x20)\n+#define toupper(x) sane_case((unsigned char)(x), 0)\n+#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)\n+\n+static inline int sane_case(int x, int high)\n+{\n+\tif (sane_istest(x, GIT_ALPHA))\n+\t\tx = (x & ~0x20) | high;\n+\treturn x;\n+}\n+\n+static inline int sane_iscase(int x, int is_lower)\n+{\n+\tif (!sane_istest(x, GIT_ALPHA))\n+\t\treturn 0;\n+\n+\tif (is_lower)\n+\t\treturn (x & 0x20) != 0;\n+\telse\n+\t\treturn (x & 0x20) == 0;\n+}\n+\n+#endif\n-- \n2.41.0.255.g8b1d071c50-goog\n\n"},{"id":"479066","messageId":"20230630202346.3069950-4-calvinwan@google.com","threadId":"59752","inReplyTo":"20230630202237.3069327-1-calvinwan@google.com","subject":"[PATCH v4 4/6] kwset: move translation table from ctype","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-30T20:23:44Z","receivedAt":"2023-06-30T20:24:26Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"This table was originally introduced to solely be used with kwset\nmachinery (0f871cf56e), so it would make sense for it to belong in\nkwset.[ch] rather than ctype.c and git-compat-util.h. It is only used in\ndiffcore-pickaxe.c, which already includes kwset.h so no other headers\nhave to be modified.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n ctype.c           | 36 ------------------------------------\n git-compat-util.h |  3 ---\n kwset.c           | 36 ++++++++++++++++++++++++++++++++++++\n kwset.h           |  2 ++\n 4 files changed, 38 insertions(+), 39 deletions(-)\n\ndiff --git a/ctype.c b/ctype.c\nindex fc0225cebd..3451745550 100644\n--- a/ctype.c\n+++ b/ctype.c\n@@ -28,39 +28,3 @@ const unsigned char sane_ctype[256] = {\n \tA, A, A, A, A, A, A, A, A, A, A, R, R, U, P, X,\t\t/* 112..127 */\n \t/* Nothing in the 128.. range */\n };\n-\n-/* For case-insensitive kwset */\n-const unsigned char tolower_trans_tbl[256] = {\n-\t0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n-\t0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n-\t0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n-\t0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n-\t ' ',  '!',  '\"',  '#',  '$',  '%',  '&', 0x27,\n-\t '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',\n-\t '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',\n-\t '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',\n-\t '@',  'a',  'b',  'c',  'd',  'e',  'f',  'g',\n-\t 'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',\n-\t 'p',  'q',  'r',  's',  't',  'u',  'v',  'w',\n-\t 'x',  'y',  'z',  '[', 0x5c,  ']',  '^',  '_',\n-\t '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',\n-\t 'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',\n-\t 'p',  'q',  'r',  's',  't',  'u',  'v',  'w',\n-\t 'x',  'y',  'z',  '{',  '|',  '}',  '~', 0x7f,\n-\t0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n-\t0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n-\t0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n-\t0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n-\t0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n-\t0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n-\t0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n-\t0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n-\t0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n-\t0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n-\t0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n-\t0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n-\t0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n-\t0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n-\t0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n-\t0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n-};\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 5f916e1094..1832444fa2 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -1152,9 +1152,6 @@ static inline size_t xsize_t(off_t len)\n #define HOST_NAME_MAX 256\n #endif\n \n-/* in ctype.c, for kwset users */\n-extern const unsigned char tolower_trans_tbl[256];\n-\n #include \"sane-ctype.h\"\n \n /*\ndiff --git a/kwset.c b/kwset.c\nindex 4b14d4f86b..bbfcf815a5 100644\n--- a/kwset.c\n+++ b/kwset.c\n@@ -49,6 +49,42 @@ static void *obstack_chunk_alloc(long size)\n \n #define U(c) ((unsigned char) (c))\n \n+/* For case-insensitive kwset */\n+const unsigned char tolower_trans_tbl[256] = {\n+\t0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,\n+\t0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,\n+\t0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,\n+\t0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,\n+\t ' ',  '!',  '\"',  '#',  '$',  '%',  '&', 0x27,\n+\t '(',  ')',  '*',  '+',  ',',  '-',  '.',  '/',\n+\t '0',  '1',  '2',  '3',  '4',  '5',  '6',  '7',\n+\t '8',  '9',  ':',  ';',  '<',  '=',  '>',  '?',\n+\t '@',  'a',  'b',  'c',  'd',  'e',  'f',  'g',\n+\t 'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',\n+\t 'p',  'q',  'r',  's',  't',  'u',  'v',  'w',\n+\t 'x',  'y',  'z',  '[', 0x5c,  ']',  '^',  '_',\n+\t '`',  'a',  'b',  'c',  'd',  'e',  'f',  'g',\n+\t 'h',  'i',  'j',  'k',  'l',  'm',  'n',  'o',\n+\t 'p',  'q',  'r',  's',  't',  'u',  'v',  'w',\n+\t 'x',  'y',  'z',  '{',  '|',  '}',  '~', 0x7f,\n+\t0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,\n+\t0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,\n+\t0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,\n+\t0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,\n+\t0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,\n+\t0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,\n+\t0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,\n+\t0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,\n+\t0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,\n+\t0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,\n+\t0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,\n+\t0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,\n+\t0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7,\n+\t0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,\n+\t0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,\n+\t0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,\n+};\n+\n /* Balanced tree of edges and labels leaving a given trie node. */\n struct tree\n {\ndiff --git a/kwset.h b/kwset.h\nindex f50ecae573..d42a793a30 100644\n--- a/kwset.h\n+++ b/kwset.h\n@@ -26,6 +26,8 @@\n    The author may be reached (Email) at the address mike@ai.mit.edu,\n    or (US mail) as Mike Haertel c/o Free Software Foundation. */\n \n+extern const unsigned char tolower_trans_tbl[256];\n+\n struct kwsmatch\n {\n   int index;\t\t\t/* Index number of matching keyword. */\n-- \n2.41.0.255.g8b1d071c50-goog\n\n"},{"id":"479067","messageId":"20230630202346.3069950-5-calvinwan@google.com","threadId":"59752","inReplyTo":"20230630202237.3069327-1-calvinwan@google.com","subject":"[PATCH v4 5/6] treewide: remove unnecessary includes for wrapper.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-30T20:23:45Z","receivedAt":"2023-06-30T20:24:35Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"Signed-off-by: Calvin Wan <calvinwan@google.com>\n---\n apply.c                          | 1 -\n builtin/am.c                     | 1 -\n builtin/bisect.c                 | 1 -\n builtin/branch.c                 | 1 -\n builtin/bugreport.c              | 1 -\n builtin/clone.c                  | 1 -\n builtin/config.c                 | 1 -\n builtin/credential-cache.c       | 1 -\n builtin/difftool.c               | 1 -\n builtin/fast-import.c            | 1 -\n builtin/fmt-merge-msg.c          | 1 -\n builtin/gc.c                     | 1 -\n builtin/get-tar-commit-id.c      | 1 -\n builtin/index-pack.c             | 1 -\n builtin/init-db.c                | 1 -\n builtin/merge.c                  | 1 -\n builtin/pack-objects.c           | 1 -\n builtin/rebase.c                 | 1 -\n builtin/receive-pack.c           | 1 -\n builtin/rerere.c                 | 1 -\n builtin/unpack-file.c            | 1 -\n builtin/worktree.c               | 1 -\n bulk-checkin.c                   | 1 -\n combine-diff.c                   | 1 -\n commit-graph.c                   | 1 -\n compat/terminal.c                | 1 -\n config.c                         | 1 -\n convert.c                        | 1 -\n copy.c                           | 1 -\n csum-file.c                      | 1 -\n daemon.c                         | 1 -\n diff.c                           | 1 -\n dir.c                            | 1 -\n editor.c                         | 1 -\n entry.c                          | 1 -\n environment.c                    | 1 -\n fetch-pack.c                     | 1 -\n gpg-interface.c                  | 1 -\n grep.c                           | 1 -\n http-backend.c                   | 1 -\n imap-send.c                      | 1 -\n merge-ll.c                       | 1 -\n merge-recursive.c                | 1 -\n notes-merge.c                    | 1 -\n object-file.c                    | 1 -\n pack-write.c                     | 1 -\n packfile.c                       | 1 -\n parallel-checkout.c              | 1 -\n path.c                           | 1 -\n pkt-line.c                       | 1 -\n read-cache.c                     | 1 -\n rebase-interactive.c             | 1 -\n refs.c                           | 1 -\n rerere.c                         | 1 -\n send-pack.c                      | 1 -\n sequencer.c                      | 1 -\n server-info.c                    | 1 -\n setup.c                          | 1 -\n shallow.c                        | 1 -\n strbuf.c                         | 1 -\n streaming.c                      | 1 -\n t/helper/test-delta.c            | 1 -\n t/helper/test-fsmonitor-client.c | 1 -\n t/helper/test-read-cache.c       | 1 -\n tag.c                            | 1 -\n tempfile.c                       | 1 -\n trace.c                          | 1 -\n transport-helper.c               | 1 -\n transport.c                      | 1 -\n upload-pack.c                    | 1 -\n usage.c                          | 1 -\n worktree.c                       | 1 -\n wrapper.c                        | 1 -\n write-or-die.c                   | 1 -\n 74 files changed, 74 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 45dcd645e6..dde124066b 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -37,7 +37,6 @@\n #include \"symlinks.h\"\n #include \"wildmatch.h\"\n #include \"ws.h\"\n-#include \"wrapper.h\"\n \n struct gitdiff_data {\n \tstruct strbuf *root;\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 5fab159599..dcb89439b1 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -44,7 +44,6 @@\n #include \"path.h\"\n #include \"repository.h\"\n #include \"pretty.h\"\n-#include \"wrapper.h\"\n \n /**\n  * Returns the length of the first line of msg.\ndiff --git a/builtin/bisect.c b/builtin/bisect.c\nindex 6478df3489..65478ef40f 100644\n--- a/builtin/bisect.c\n+++ b/builtin/bisect.c\n@@ -15,7 +15,6 @@\n #include \"prompt.h\"\n #include \"quote.h\"\n #include \"revision.h\"\n-#include \"wrapper.h\"\n \n static GIT_PATH_FUNC(git_path_bisect_terms, \"BISECT_TERMS\")\n static GIT_PATH_FUNC(git_path_bisect_expected_rev, \"BISECT_EXPECTED_REV\")\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex e8ff3ecc07..a27bc0a3df 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -28,7 +28,6 @@\n #include \"worktree.h\"\n #include \"help.h\"\n #include \"commit-reach.h\"\n-#include \"wrapper.h\"\n \n static const char * const builtin_branch_usage[] = {\n \tN_(\"git branch [<options>] [-r | -a] [--merged] [--no-merged]\"),\ndiff --git a/builtin/bugreport.c b/builtin/bugreport.c\nindex daf6c23657..d2ae5c305d 100644\n--- a/builtin/bugreport.c\n+++ b/builtin/bugreport.c\n@@ -11,7 +11,6 @@\n #include \"diagnose.h\"\n #include \"object-file.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n static void get_system_info(struct strbuf *sys_info)\n {\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex da35f1a6b4..c65378b3d2 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -45,7 +45,6 @@\n #include \"hook.h\"\n #include \"bundle.h\"\n #include \"bundle-uri.h\"\n-#include \"wrapper.h\"\n \n /*\n  * Overall FIXMEs:\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 1c75cbc43d..787d85edac 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -15,7 +15,6 @@\n #include \"setup.h\"\n #include \"strbuf.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n \n static const char *const builtin_config_usage[] = {\n \tN_(\"git config [<options>]\"),\ndiff --git a/builtin/credential-cache.c b/builtin/credential-cache.c\nindex ff3a47badb..43b9d0e5b1 100644\n--- a/builtin/credential-cache.c\n+++ b/builtin/credential-cache.c\n@@ -3,7 +3,6 @@\n #include \"parse-options.h\"\n #include \"path.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n #ifndef NO_UNIX_SOCKETS\ndiff --git a/builtin/difftool.c b/builtin/difftool.c\nindex 24d88f88ba..0f5eae9cd4 100644\n--- a/builtin/difftool.c\n+++ b/builtin/difftool.c\n@@ -32,7 +32,6 @@\n #include \"dir.h\"\n #include \"entry.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n static int trust_exit_code;\n \ndiff --git a/builtin/fast-import.c b/builtin/fast-import.c\nindex 2ee19c7373..4dbb10aff3 100644\n--- a/builtin/fast-import.c\n+++ b/builtin/fast-import.c\n@@ -26,7 +26,6 @@\n #include \"commit-reach.h\"\n #include \"khash.h\"\n #include \"date.h\"\n-#include \"wrapper.h\"\n \n #define PACK_ID_BITS 16\n #define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex cc81241642..0f9855b680 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -3,7 +3,6 @@\n #include \"fmt-merge-msg.h\"\n #include \"gettext.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n \n static const char * const fmt_merge_msg_usage[] = {\n \tN_(\"git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]\"),\ndiff --git a/builtin/gc.c b/builtin/gc.c\nindex 91eec7703a..19d73067aa 100644\n--- a/builtin/gc.c\n+++ b/builtin/gc.c\n@@ -41,7 +41,6 @@\n #include \"hook.h\"\n #include \"setup.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n #define FAILED_RUN \"failed to run %s\"\n \ndiff --git a/builtin/get-tar-commit-id.c b/builtin/get-tar-commit-id.c\nindex 9303e386cc..20d0dfe9cf 100644\n--- a/builtin/get-tar-commit-id.c\n+++ b/builtin/get-tar-commit-id.c\n@@ -5,7 +5,6 @@\n #include \"commit.h\"\n #include \"tar.h\"\n #include \"quote.h\"\n-#include \"wrapper.h\"\n \n static const char builtin_get_tar_commit_id_usage[] =\n \"git get-tar-commit-id\";\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex e280180cac..66202b304d 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -25,7 +25,6 @@\n #include \"replace-object.h\"\n #include \"promisor-remote.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n static const char index_pack_usage[] =\n \"git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])\";\ndiff --git a/builtin/init-db.c b/builtin/init-db.c\nindex 0d8bd4d721..cb727c826f 100644\n--- a/builtin/init-db.c\n+++ b/builtin/init-db.c\n@@ -13,7 +13,6 @@\n #include \"path.h\"\n #include \"setup.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n static int guess_repository_type(const char *git_dir)\n {\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 06cf6afdcb..404700a35c 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -53,7 +53,6 @@\n #include \"commit-reach.h\"\n #include \"wt-status.h\"\n #include \"commit-graph.h\"\n-#include \"wrapper.h\"\n \n #define DEFAULT_TWOHEAD (1<<0)\n #define DEFAULT_OCTOPUS (1<<1)\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 8e77638145..8251961042 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -43,7 +43,6 @@\n #include \"promisor-remote.h\"\n #include \"pack-mtimes.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n \n /*\n  * Objects we are going to pack are collected in the `to_pack` structure.\ndiff --git a/builtin/rebase.c b/builtin/rebase.c\nindex 1b3f68d9b0..50cb85751f 100644\n--- a/builtin/rebase.c\n+++ b/builtin/rebase.c\n@@ -37,7 +37,6 @@\n #include \"reset.h\"\n #include \"trace2.h\"\n #include \"hook.h\"\n-#include \"wrapper.h\"\n \n static char const * const builtin_rebase_usage[] = {\n \tN_(\"git rebase [-i] [options] [--exec <cmd>] \"\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex faa8f84c5a..a7fe8c4d9a 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -40,7 +40,6 @@\n #include \"worktree.h\"\n #include \"shallow.h\"\n #include \"parse-options.h\"\n-#include \"wrapper.h\"\n \n static const char * const receive_pack_usage[] = {\n \tN_(\"git receive-pack <git-dir>\"),\ndiff --git a/builtin/rerere.c b/builtin/rerere.c\nindex 0458db9cad..07a9d37275 100644\n--- a/builtin/rerere.c\n+++ b/builtin/rerere.c\n@@ -6,7 +6,6 @@\n #include \"repository.h\"\n #include \"string-list.h\"\n #include \"rerere.h\"\n-#include \"wrapper.h\"\n #include \"xdiff/xdiff.h\"\n #include \"xdiff-interface.h\"\n #include \"pathspec.h\"\ndiff --git a/builtin/unpack-file.c b/builtin/unpack-file.c\nindex 6842a6c499..c129e2bb6c 100644\n--- a/builtin/unpack-file.c\n+++ b/builtin/unpack-file.c\n@@ -3,7 +3,6 @@\n #include \"hex.h\"\n #include \"object-name.h\"\n #include \"object-store-ll.h\"\n-#include \"wrapper.h\"\n \n static char *create_temp_file(struct object_id *oid)\n {\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex 7c114d56a3..2ce39b593c 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -24,7 +24,6 @@\n #include \"submodule.h\"\n #include \"utf8.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n #include \"quote.h\"\n \n #define BUILTIN_WORKTREE_ADD_USAGE \\\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex e2f71db0f6..fec6816259 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -17,7 +17,6 @@\n #include \"packfile.h\"\n #include \"object-file.h\"\n #include \"object-store-ll.h\"\n-#include \"wrapper.h\"\n \n static int odb_transaction_nesting;\n \ndiff --git a/combine-diff.c b/combine-diff.c\nindex 11e9d7494a..f90f442482 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -17,7 +17,6 @@\n #include \"userdiff.h\"\n #include \"oid-array.h\"\n #include \"revision.h\"\n-#include \"wrapper.h\"\n \n static int compare_paths(const struct combine_diff_path *one,\n \t\t\t  const struct diff_filespec *two)\ndiff --git a/commit-graph.c b/commit-graph.c\nindex f70afccada..38185c8529 100644\n--- a/commit-graph.c\n+++ b/commit-graph.c\n@@ -26,7 +26,6 @@\n #include \"trace2.h\"\n #include \"tree.h\"\n #include \"chunk-format.h\"\n-#include \"wrapper.h\"\n \n void git_test_write_commit_graph_or_die(void)\n {\ndiff --git a/compat/terminal.c b/compat/terminal.c\nindex d87e321189..83d95e8656 100644\n--- a/compat/terminal.c\n+++ b/compat/terminal.c\n@@ -6,7 +6,6 @@\n #include \"run-command.h\"\n #include \"string-list.h\"\n #include \"hashmap.h\"\n-#include \"wrapper.h\"\n \n #if defined(HAVE_DEV_TTY) || defined(GIT_WINDOWS_NATIVE)\n \ndiff --git a/config.c b/config.c\nindex 85c5f35132..59fad84eb7 100644\n--- a/config.c\n+++ b/config.c\n@@ -39,7 +39,6 @@\n #include \"wildmatch.h\"\n #include \"worktree.h\"\n #include \"ws.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n struct config_source {\ndiff --git a/convert.c b/convert.c\nindex cb64117cc0..a8870baff3 100644\n--- a/convert.c\n+++ b/convert.c\n@@ -16,7 +16,6 @@\n #include \"trace.h\"\n #include \"utf8.h\"\n #include \"merge-ll.h\"\n-#include \"wrapper.h\"\n \n /*\n  * convert.c - convert a file when checking it out and checking it in.\ndiff --git a/copy.c b/copy.c\nindex 882c79cffb..23d84c6c1d 100644\n--- a/copy.c\n+++ b/copy.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"copy.h\"\n #include \"path.h\"\n-#include \"wrapper.h\"\n \n int copy_fd(int ifd, int ofd)\n {\ndiff --git a/csum-file.c b/csum-file.c\nindex daf9b06dff..cd01713244 100644\n--- a/csum-file.c\n+++ b/csum-file.c\n@@ -11,7 +11,6 @@\n #include \"progress.h\"\n #include \"csum-file.h\"\n #include \"hash.h\"\n-#include \"wrapper.h\"\n \n static void verify_buffer_or_die(struct hashfile *f,\n \t\t\t\t const void *buf,\ndiff --git a/daemon.c b/daemon.c\nindex 3682bfdd08..a7fe89cd2d 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -10,7 +10,6 @@\n #include \"setup.h\"\n #include \"strbuf.h\"\n #include \"string-list.h\"\n-#include \"wrapper.h\"\n \n #ifdef NO_INITGROUPS\n #define initgroups(x, y) (0) /* nothing */\ndiff --git a/diff.c b/diff.c\nindex f265afa6c4..9e4d87a8db 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -43,7 +43,6 @@\n #include \"setup.h\"\n #include \"strmap.h\"\n #include \"ws.h\"\n-#include \"wrapper.h\"\n \n #ifdef NO_FAST_WORKING_DIRECTORY\n #define FAST_WORKING_DIRECTORY 0\ndiff --git a/dir.c b/dir.c\nindex 3acac7beb1..d270a1be36 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -32,7 +32,6 @@\n #include \"symlinks.h\"\n #include \"trace2.h\"\n #include \"tree.h\"\n-#include \"wrapper.h\"\n \n /*\n  * Tells read_directory_recursive how a file or directory should be treated.\ndiff --git a/editor.c b/editor.c\nindex 38c5dbbb79..b67b802ddf 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -11,7 +11,6 @@\n #include \"strvec.h\"\n #include \"run-command.h\"\n #include \"sigchain.h\"\n-#include \"wrapper.h\"\n \n #ifndef DEFAULT_EDITOR\n #define DEFAULT_EDITOR \"vi\"\ndiff --git a/entry.c b/entry.c\nindex f9a7c726a4..43767f9043 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -14,7 +14,6 @@\n #include \"fsmonitor.h\"\n #include \"entry.h\"\n #include \"parallel-checkout.h\"\n-#include \"wrapper.h\"\n \n static void create_directories(const char *path, int path_len,\n \t\t\t       const struct checkout *state)\ndiff --git a/environment.c b/environment.c\nindex 8128104373..a0d1d070d1 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -28,7 +28,6 @@\n #include \"setup.h\"\n #include \"shallow.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n int trust_executable_bit = 1;\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 1e0313a0a6..bb288d47f3 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -34,7 +34,6 @@\n #include \"commit-graph.h\"\n #include \"sigchain.h\"\n #include \"mergesort.h\"\n-#include \"wrapper.h\"\n \n static int transfer_unpack_limit = -1;\n static int fetch_unpack_limit = -1;\ndiff --git a/gpg-interface.c b/gpg-interface.c\nindex f7c1d385c1..48f43c5a21 100644\n--- a/gpg-interface.c\n+++ b/gpg-interface.c\n@@ -12,7 +12,6 @@\n #include \"sigchain.h\"\n #include \"tempfile.h\"\n #include \"alias.h\"\n-#include \"wrapper.h\"\n #include \"environment.h\"\n \n static int git_gpg_config(const char *, const char *,\ndiff --git a/grep.c b/grep.c\nindex ea38687c8a..0904d55b24 100644\n--- a/grep.c\n+++ b/grep.c\n@@ -12,7 +12,6 @@\n #include \"commit.h\"\n #include \"quote.h\"\n #include \"help.h\"\n-#include \"wrapper.h\"\n \n static int grep_source_load(struct grep_source *gs);\n static int grep_source_is_binary(struct grep_source *gs,\ndiff --git a/http-backend.c b/http-backend.c\nindex e1969c05dc..25a19c21b9 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -19,7 +19,6 @@\n #include \"object-store-ll.h\"\n #include \"protocol.h\"\n #include \"date.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n static const char content_type[] = \"Content-Type\";\ndiff --git a/imap-send.c b/imap-send.c\nindex 3518a4ace6..23c807fced 100644\n--- a/imap-send.c\n+++ b/imap-send.c\n@@ -30,7 +30,6 @@\n #include \"parse-options.h\"\n #include \"setup.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n #if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)\n typedef void *SSL;\n #endif\ndiff --git a/merge-ll.c b/merge-ll.c\nindex 95795b70f5..8fcf2d3710 100644\n--- a/merge-ll.c\n+++ b/merge-ll.c\n@@ -13,7 +13,6 @@\n #include \"merge-ll.h\"\n #include \"quote.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n struct ll_merge_driver;\n \ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 43f6b2d036..6a4081bb0f 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -38,7 +38,6 @@\n #include \"tag.h\"\n #include \"tree-walk.h\"\n #include \"unpack-trees.h\"\n-#include \"wrapper.h\"\n #include \"xdiff-interface.h\"\n \n struct merge_options_internal {\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 071947894e..8799b522a5 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -20,7 +20,6 @@\n #include \"trace.h\"\n #include \"notes-utils.h\"\n #include \"commit-reach.h\"\n-#include \"wrapper.h\"\n \n struct notes_merge_pair {\n \tstruct object_id obj, base, local, remote;\ndiff --git a/object-file.c b/object-file.c\nindex 8d87720dd5..527b740018 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -44,7 +44,6 @@\n #include \"setup.h\"\n #include \"submodule.h\"\n #include \"fsck.h\"\n-#include \"wrapper.h\"\n \n /* The maximum size for an object header. */\n #define MAX_HEADER_LEN 32\ndiff --git a/pack-write.c b/pack-write.c\nindex af48813a9b..b19ddf15b2 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -12,7 +12,6 @@\n #include \"pack-revindex.h\"\n #include \"path.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n void reset_pack_idx_option(struct pack_idx_option *opts)\n {\ndiff --git a/packfile.c b/packfile.c\nindex c2e753ef8f..9126274b37 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -24,7 +24,6 @@\n #include \"commit-graph.h\"\n #include \"pack-revindex.h\"\n #include \"promisor-remote.h\"\n-#include \"wrapper.h\"\n \n char *odb_pack_name(struct strbuf *buf,\n \t\t    const unsigned char *hash,\ndiff --git a/parallel-checkout.c b/parallel-checkout.c\nindex 602fbf19d3..8637723461 100644\n--- a/parallel-checkout.c\n+++ b/parallel-checkout.c\n@@ -15,7 +15,6 @@\n #include \"symlinks.h\"\n #include \"thread-utils.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n struct pc_worker {\n \tstruct child_process cp;\ndiff --git a/path.c b/path.c\nindex 044a50bad0..67e2690efe 100644\n--- a/path.c\n+++ b/path.c\n@@ -18,7 +18,6 @@\n #include \"object-store-ll.h\"\n #include \"lockfile.h\"\n #include \"exec-cmd.h\"\n-#include \"wrapper.h\"\n \n static int get_st_mode_bits(const char *path, int *mode)\n {\ndiff --git a/pkt-line.c b/pkt-line.c\nindex 62b4208b66..6e4166132d 100644\n--- a/pkt-line.c\n+++ b/pkt-line.c\n@@ -5,7 +5,6 @@\n #include \"hex.h\"\n #include \"run-command.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n char packet_buffer[LARGE_PACKET_MAX];\ndiff --git a/read-cache.c b/read-cache.c\nindex b9a995e5a1..140b4f96a0 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -46,7 +46,6 @@\n #include \"csum-file.h\"\n #include \"promisor-remote.h\"\n #include \"hook.h\"\n-#include \"wrapper.h\"\n \n /* Mask for the name length in ce_flags in the on-disk index */\n \ndiff --git a/rebase-interactive.c b/rebase-interactive.c\nindex f286404d4b..d9718409b3 100644\n--- a/rebase-interactive.c\n+++ b/rebase-interactive.c\n@@ -11,7 +11,6 @@\n #include \"config.h\"\n #include \"dir.h\"\n #include \"object-name.h\"\n-#include \"wrapper.h\"\n \n static const char edit_todo_list_advice[] =\n N_(\"You can fix this with 'git rebase --edit-todo' \"\ndiff --git a/refs.c b/refs.c\nindex c029f64982..d5e0184ca5 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -30,7 +30,6 @@\n #include \"date.h\"\n #include \"commit.h\"\n #include \"wildmatch.h\"\n-#include \"wrapper.h\"\n \n /*\n  * List of all available backends\ndiff --git a/rerere.c b/rerere.c\nindex e2b8597f88..4227c9612a 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -20,7 +20,6 @@\n #include \"object-store-ll.h\"\n #include \"hash-lookup.h\"\n #include \"strmap.h\"\n-#include \"wrapper.h\"\n \n #define RESOLVED 0\n #define PUNTED 1\ndiff --git a/send-pack.c b/send-pack.c\nindex 9510bef856..89aca9d829 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -15,7 +15,6 @@\n #include \"quote.h\"\n #include \"transport.h\"\n #include \"version.h\"\n-#include \"wrapper.h\"\n #include \"oid-array.h\"\n #include \"gpg-interface.h\"\n #include \"shallow.h\"\ndiff --git a/sequencer.c b/sequencer.c\nindex 7e6c556e0a..993dd8efbc 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -49,7 +49,6 @@\n #include \"rebase-interactive.h\"\n #include \"reset.h\"\n #include \"branch.h\"\n-#include \"wrapper.h\"\n \n #define GIT_REFLOG_ACTION \"GIT_REFLOG_ACTION\"\n \ndiff --git a/server-info.c b/server-info.c\nindex 382e481a2b..f350713ecf 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -14,7 +14,6 @@\n #include \"object-store-ll.h\"\n #include \"server-info.h\"\n #include \"strbuf.h\"\n-#include \"wrapper.h\"\n \n struct update_info_ctx {\n \tFILE *cur_fp;\ndiff --git a/setup.c b/setup.c\nindex 8e4b2cd2c3..18927a847b 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -17,7 +17,6 @@\n #include \"quote.h\"\n #include \"trace2.h\"\n #include \"worktree.h\"\n-#include \"wrapper.h\"\n \n static int inside_git_dir = -1;\n static int inside_work_tree = -1;\ndiff --git a/shallow.c b/shallow.c\nindex f3ef94d4c9..2fad3504b7 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -20,7 +20,6 @@\n #include \"shallow.h\"\n #include \"statinfo.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n \n void set_alternate_shallow_file(struct repository *r, const char *path, int override)\n {\ndiff --git a/strbuf.c b/strbuf.c\nindex b41d343ed0..ab8e52e9b4 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -6,7 +6,6 @@\n #include \"string-list.h\"\n #include \"utf8.h\"\n #include \"date.h\"\n-#include \"wrapper.h\"\n \n int starts_with(const char *str, const char *prefix)\n {\ndiff --git a/streaming.c b/streaming.c\nindex 49791ab958..10adf625b2 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -10,7 +10,6 @@\n #include \"object-store-ll.h\"\n #include \"replace-object.h\"\n #include \"packfile.h\"\n-#include \"wrapper.h\"\n \n typedef int (*open_istream_fn)(struct git_istream *,\n \t\t\t       struct repository *,\ndiff --git a/t/helper/test-delta.c b/t/helper/test-delta.c\nindex e7d134ec25..6bc787a474 100644\n--- a/t/helper/test-delta.c\n+++ b/t/helper/test-delta.c\n@@ -11,7 +11,6 @@\n #include \"test-tool.h\"\n #include \"git-compat-util.h\"\n #include \"delta.h\"\n-#include \"wrapper.h\"\n \n static const char usage_str[] =\n \t\"test-tool delta (-d|-p) <from_file> <data_file> <out_file>\";\ndiff --git a/t/helper/test-fsmonitor-client.c b/t/helper/test-fsmonitor-client.c\nindex 58d1dc5fc8..8280984d08 100644\n--- a/t/helper/test-fsmonitor-client.c\n+++ b/t/helper/test-fsmonitor-client.c\n@@ -11,7 +11,6 @@\n #include \"setup.h\"\n #include \"thread-utils.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n #ifndef HAVE_FSMONITOR_DAEMON_BACKEND\n int cmd__fsmonitor_client(int argc UNUSED, const char **argv UNUSED)\ndiff --git a/t/helper/test-read-cache.c b/t/helper/test-read-cache.c\nindex 56c2d25f35..1acd362346 100644\n--- a/t/helper/test-read-cache.c\n+++ b/t/helper/test-read-cache.c\n@@ -4,7 +4,6 @@\n #include \"read-cache-ll.h\"\n #include \"repository.h\"\n #include \"setup.h\"\n-#include \"wrapper.h\"\n \n int cmd__read_cache(int argc, const char **argv)\n {\ndiff --git a/tag.c b/tag.c\nindex c5426484b2..fc3834db46 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -10,7 +10,6 @@\n #include \"gpg-interface.h\"\n #include \"hex.h\"\n #include \"packfile.h\"\n-#include \"wrapper.h\"\n \n const char *tag_type = \"tag\";\n \ndiff --git a/tempfile.c b/tempfile.c\nindex 6c88a63b42..ecdebf1afb 100644\n--- a/tempfile.c\n+++ b/tempfile.c\n@@ -47,7 +47,6 @@\n #include \"path.h\"\n #include \"tempfile.h\"\n #include \"sigchain.h\"\n-#include \"wrapper.h\"\n \n static VOLATILE_LIST_HEAD(tempfile_list);\n \ndiff --git a/trace.c b/trace.c\nindex 592c141d78..971a68abe8 100644\n--- a/trace.c\n+++ b/trace.c\n@@ -27,7 +27,6 @@\n #include \"quote.h\"\n #include \"setup.h\"\n #include \"trace.h\"\n-#include \"wrapper.h\"\n \n struct trace_key trace_default_key = { \"GIT_TRACE\", 0, 0, 0 };\n struct trace_key trace_perf_key = TRACE_KEY_INIT(PERFORMANCE);\ndiff --git a/transport-helper.c b/transport-helper.c\nindex 5c0bc6a896..49811ef176 100644\n--- a/transport-helper.c\n+++ b/transport-helper.c\n@@ -19,7 +19,6 @@\n #include \"refspec.h\"\n #include \"transport-internal.h\"\n #include \"protocol.h\"\n-#include \"wrapper.h\"\n \n static int debug;\n \ndiff --git a/transport.c b/transport.c\nindex 4dc187a388..0a5794a944 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -30,7 +30,6 @@\n #include \"object-store-ll.h\"\n #include \"color.h\"\n #include \"bundle-uri.h\"\n-#include \"wrapper.h\"\n \n static int transport_use_color = -1;\n static char transport_colors[][COLOR_MAXLEN] = {\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 946074920a..0970392b41 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -32,7 +32,6 @@\n #include \"commit-graph.h\"\n #include \"commit-reach.h\"\n #include \"shallow.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n /* Remember to update object flag allocation in object.h */\ndiff --git a/usage.c b/usage.c\nindex 46d99f8bd4..09f0ed509b 100644\n--- a/usage.c\n+++ b/usage.c\n@@ -6,7 +6,6 @@\n #include \"git-compat-util.h\"\n #include \"gettext.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n static void vreportf(const char *prefix, const char *err, va_list params)\n {\ndiff --git a/worktree.c b/worktree.c\nindex 1b84e3a34d..2ea5d45e1e 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -12,7 +12,6 @@\n #include \"dir.h\"\n #include \"wt-status.h\"\n #include \"config.h\"\n-#include \"wrapper.h\"\n \n void free_worktrees(struct worktree **worktrees)\n {\ndiff --git a/wrapper.c b/wrapper.c\nindex 67f5f5dbe1..22be9812a7 100644\n--- a/wrapper.c\n+++ b/wrapper.c\n@@ -9,7 +9,6 @@\n #include \"repository.h\"\n #include \"strbuf.h\"\n #include \"trace2.h\"\n-#include \"wrapper.h\"\n \n static intmax_t count_fsync_writeout_only;\n static intmax_t count_fsync_hardware_flush;\ndiff --git a/write-or-die.c b/write-or-die.c\nindex cc9e0787a1..d8355c0c3e 100644\n--- a/write-or-die.c\n+++ b/write-or-die.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"config.h\"\n #include \"run-command.h\"\n-#include \"wrapper.h\"\n #include \"write-or-die.h\"\n \n /*\n-- \n2.41.0.255.g8b1d071c50-goog\n\n"},{"id":"479068","messageId":"20230630202346.3069950-6-calvinwan@google.com","threadId":"59752","inReplyTo":"20230630202237.3069327-1-calvinwan@google.com","subject":"[PATCH v4 6/6] common: move alloc macros to common.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-06-30T20:23:46Z","receivedAt":"2023-06-30T20:24:38Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"alloc_nr, ALLOC_GROW, and ALLOC_GROW_BY are commonly used macros for\ndynamic array allocation. Moving these macros to git-compat-util.h with\nthe other alloc macros focuses alloc.[ch] to allocation for Git objects\nand additionally allows us to remove inclusions to alloc.h from files\nthat solely used the above macros.\n\nSigned-off-by: Calvin Wan <calvinwan@google.com>\n---\n add-patch.c                        |  1 -\n alias.c                            |  1 -\n alloc.h                            | 75 ------------------------------\n apply.c                            |  1 -\n archive-tar.c                      |  1 -\n archive.c                          |  1 -\n attr.c                             |  1 -\n builtin/blame.c                    |  1 -\n builtin/cat-file.c                 |  1 -\n builtin/checkout--worker.c         |  1 -\n builtin/config.c                   |  1 -\n builtin/credential-cache--daemon.c |  1 -\n builtin/fetch-pack.c               |  1 -\n builtin/fsmonitor--daemon.c        |  1 -\n builtin/grep.c                     |  1 -\n builtin/index-pack.c               |  1 -\n builtin/log.c                      |  1 -\n builtin/merge.c                    |  1 -\n builtin/mktree.c                   |  1 -\n builtin/mv.c                       |  1 -\n builtin/name-rev.c                 |  1 -\n builtin/pack-objects.c             |  1 -\n builtin/repack.c                   |  1 -\n builtin/rev-parse.c                |  1 -\n builtin/revert.c                   |  1 -\n builtin/rm.c                       |  1 -\n builtin/submodule--helper.c        |  1 -\n bulk-checkin.c                     |  1 -\n cache-tree.c                       |  1 -\n chunk-format.c                     |  1 -\n commit-reach.c                     |  1 -\n config.c                           |  1 -\n daemon.c                           |  1 -\n delta-islands.c                    |  1 -\n diff.c                             |  1 -\n diffcore-rename.c                  |  1 -\n dir-iterator.c                     |  1 -\n dir.c                              |  1 -\n ewah/bitmap.c                      |  1 -\n ewah/ewah_bitmap.c                 |  1 -\n fetch-pack.c                       |  1 -\n fmt-merge-msg.c                    |  1 -\n fsck.c                             |  1 -\n git-compat-util.h                  | 75 ++++++++++++++++++++++++++++++\n help.c                             |  1 -\n http-backend.c                     |  1 -\n line-log.c                         |  1 -\n list-objects-filter-options.c      |  1 -\n list-objects-filter.c              |  1 -\n midx.c                             |  1 -\n object-file.c                      |  1 -\n oid-array.c                        |  1 -\n oidtree.c                          |  1 -\n pack-bitmap-write.c                |  1 -\n pack-bitmap.c                      |  1 -\n pack-objects.c                     |  1 -\n packfile.c                         |  1 -\n parallel-checkout.c                |  1 -\n pretty.c                           |  1 -\n prio-queue.c                       |  1 -\n quote.c                            |  1 -\n read-cache.c                       |  1 -\n ref-filter.c                       |  1 -\n reflog-walk.c                      |  1 -\n refs.c                             |  1 -\n refspec.c                          |  1 -\n remote-curl.c                      |  1 -\n remote.c                           |  1 -\n rerere.c                           |  1 -\n revision.c                         |  1 -\n sequencer.c                        |  1 -\n server-info.c                      |  1 -\n shallow.c                          |  1 -\n sigchain.c                         |  1 -\n sparse-index.c                     |  1 -\n split-index.c                      |  1 -\n strbuf.c                           |  1 -\n string-list.c                      |  1 -\n strvec.c                           |  1 -\n submodule-config.c                 |  1 -\n submodule.c                        |  1 -\n t/helper/test-reach.c              |  1 -\n trace2/tr2_tls.c                   |  1 -\n trailer.c                          |  1 -\n transport.c                        |  1 -\n tree-walk.c                        |  1 -\n userdiff.c                         |  1 -\n worktree.c                         |  1 -\n 88 files changed, 75 insertions(+), 161 deletions(-)\n\ndiff --git a/add-patch.c b/add-patch.c\nindex ba629add62..bfe19876cd 100644\n--- a/add-patch.c\n+++ b/add-patch.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"add-interactive.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"editor.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/alias.c b/alias.c\nindex 910dd252a0..5a238f2e30 100644\n--- a/alias.c\n+++ b/alias.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"alias.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n #include \"strbuf.h\"\ndiff --git a/alloc.h b/alloc.h\nindex 4312db4bd0..3f4a0ad310 100644\n--- a/alloc.h\n+++ b/alloc.h\n@@ -17,79 +17,4 @@ void *alloc_object_node(struct repository *r);\n struct alloc_state *allocate_alloc_state(void);\n void clear_alloc_state(struct alloc_state *s);\n \n-#define alloc_nr(x) (((x)+16)*3/2)\n-\n-/**\n- * Dynamically growing an array using realloc() is error prone and boring.\n- *\n- * Define your array with:\n- *\n- * - a pointer (`item`) that points at the array, initialized to `NULL`\n- *   (although please name the variable based on its contents, not on its\n- *   type);\n- *\n- * - an integer variable (`alloc`) that keeps track of how big the current\n- *   allocation is, initialized to `0`;\n- *\n- * - another integer variable (`nr`) to keep track of how many elements the\n- *   array currently has, initialized to `0`.\n- *\n- * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,\n- * alloc)`.  This ensures that the array can hold at least `n` elements by\n- * calling `realloc(3)` and adjusting `alloc` variable.\n- *\n- * ------------\n- * sometype *item;\n- * size_t nr;\n- * size_t alloc\n- *\n- * for (i = 0; i < nr; i++)\n- * \tif (we like item[i] already)\n- * \t\treturn;\n- *\n- * // we did not like any existing one, so add one\n- * ALLOC_GROW(item, nr + 1, alloc);\n- * item[nr++] = value you like;\n- * ------------\n- *\n- * You are responsible for updating the `nr` variable.\n- *\n- * If you need to specify the number of elements to allocate explicitly\n- * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.\n- *\n- * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some\n- * added niceties.\n- *\n- * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.\n- */\n-#define ALLOC_GROW(x, nr, alloc) \\\n-\tdo { \\\n-\t\tif ((nr) > alloc) { \\\n-\t\t\tif (alloc_nr(alloc) < (nr)) \\\n-\t\t\t\talloc = (nr); \\\n-\t\t\telse \\\n-\t\t\t\talloc = alloc_nr(alloc); \\\n-\t\t\tREALLOC_ARRAY(x, alloc); \\\n-\t\t} \\\n-\t} while (0)\n-\n-/*\n- * Similar to ALLOC_GROW but handles updating of the nr value and\n- * zeroing the bytes of the newly-grown array elements.\n- *\n- * DO NOT USE any expression with side-effect for any of the\n- * arguments.\n- */\n-#define ALLOC_GROW_BY(x, nr, increase, alloc) \\\n-\tdo { \\\n-\t\tif (increase) { \\\n-\t\t\tsize_t new_nr = nr + (increase); \\\n-\t\t\tif (new_nr < nr) \\\n-\t\t\t\tBUG(\"negative growth in ALLOC_GROW_BY\"); \\\n-\t\t\tALLOC_GROW(x, new_nr, alloc); \\\n-\t\t\tmemset((x) + nr, 0, sizeof(*(x)) * (increase)); \\\n-\t\t\tnr = new_nr; \\\n-\t\t} \\\n-\t} while (0)\n-\n #endif\ndiff --git a/apply.c b/apply.c\nindex dde124066b..3d69fec836 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -9,7 +9,6 @@\n \n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"base85.h\"\n #include \"config.h\"\n #include \"object-store-ll.h\"\ndiff --git a/archive-tar.c b/archive-tar.c\nindex 218c901ec7..0726996839 100644\n--- a/archive-tar.c\n+++ b/archive-tar.c\n@@ -2,7 +2,6 @@\n  * Copyright (c) 2005, 2006 Rene Scharfe\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"gettext.h\"\n #include \"git-zlib.h\"\ndiff --git a/archive.c b/archive.c\nindex 1817cca9f4..ca11db185b 100644\n--- a/archive.c\n+++ b/archive.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"environment.h\"\ndiff --git a/attr.c b/attr.c\nindex e5785c55db..ff0a3e7b61 100644\n--- a/attr.c\n+++ b/attr.c\n@@ -7,7 +7,6 @@\n  */\n \n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"exec-cmd.h\"\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex f9d316a7bf..9c987d6567 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -6,7 +6,6 @@\n  */\n \n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"color.h\"\n #include \"builtin.h\"\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex c9c93b80fc..694c8538df 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -5,7 +5,6 @@\n  */\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"diff.h\"\ndiff --git a/builtin/checkout--worker.c b/builtin/checkout--worker.c\nindex c655dc4b13..6b62b5375b 100644\n--- a/builtin/checkout--worker.c\n+++ b/builtin/checkout--worker.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"entry.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/config.c b/builtin/config.c\nindex 787d85edac..11a4d4ef14 100644\n--- a/builtin/config.c\n+++ b/builtin/config.c\n@@ -1,6 +1,5 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"color.h\"\n #include \"editor.h\"\ndiff --git a/builtin/credential-cache--daemon.c b/builtin/credential-cache--daemon.c\nindex dc1cf2d25f..3a6a750a8e 100644\n--- a/builtin/credential-cache--daemon.c\n+++ b/builtin/credential-cache--daemon.c\n@@ -1,6 +1,5 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"object-file.h\"\n #include \"parse-options.h\"\ndiff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c\nindex 3ba0fe5a39..44c05ee86c 100644\n--- a/builtin/fetch-pack.c\n+++ b/builtin/fetch-pack.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"object-file.h\"\ndiff --git a/builtin/fsmonitor--daemon.c b/builtin/fsmonitor--daemon.c\nindex b5796b4a4a..7e99c4d61b 100644\n--- a/builtin/fsmonitor--daemon.c\n+++ b/builtin/fsmonitor--daemon.c\n@@ -1,6 +1,5 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 22645c6244..ce866523e2 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -4,7 +4,6 @@\n  * Copyright (c) 2006 Junio C Hamano\n  */\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"repository.h\"\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 66202b304d..3da879d138 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"delta.h\"\n #include \"environment.h\"\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 1aca560ec3..1b119eaf0b 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -6,7 +6,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 404700a35c..de68910177 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -10,7 +10,6 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"editor.h\"\n #include \"environment.h\"\ndiff --git a/builtin/mktree.c b/builtin/mktree.c\nindex 0eea810c7e..9a22d4e277 100644\n--- a/builtin/mktree.c\n+++ b/builtin/mktree.c\n@@ -4,7 +4,6 @@\n  * Copyright (c) Junio C Hamano, 2006, 2009\n  */\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"quote.h\"\ndiff --git a/builtin/mv.c b/builtin/mv.c\nindex ae462bd7d4..fa84fcb20d 100644\n--- a/builtin/mv.c\n+++ b/builtin/mv.c\n@@ -7,7 +7,6 @@\n #include \"builtin.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/builtin/name-rev.c b/builtin/name-rev.c\nindex c3b722b36f..c706fa3720 100644\n--- a/builtin/name-rev.c\n+++ b/builtin/name-rev.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 8251961042..06b33d49e9 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 51698e3c68..f913e9a8a2 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -1,5 +1,4 @@\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"dir.h\"\n #include \"environment.h\"\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 3e2ee44177..434646b074 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -6,7 +6,6 @@\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"commit.h\"\n #include \"environment.h\"\ndiff --git a/builtin/revert.c b/builtin/revert.c\nindex f6f07d9b53..e6f9a1ad26 100644\n--- a/builtin/revert.c\n+++ b/builtin/revert.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"builtin.h\"\n #include \"parse-options.h\"\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex 463eeabcea..dff819ae50 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -5,7 +5,6 @@\n  */\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n-#include \"alloc.h\"\n #include \"advice.h\"\n #include \"config.h\"\n #include \"lockfile.h\"\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 42706150cf..f6871efd95 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -1,7 +1,6 @@\n #define USE_THE_INDEX_VARIABLE\n #include \"builtin.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex fec6816259..73bff3a23d 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -2,7 +2,6 @@\n  * Copyright (c) 2011, Google Inc.\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"bulk-checkin.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/cache-tree.c b/cache-tree.c\nindex 84d7491420..641427ed41 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"hex.h\"\n #include \"lockfile.h\"\ndiff --git a/chunk-format.c b/chunk-format.c\nindex e7d613c907..140dfa0dcc 100644\n--- a/chunk-format.c\n+++ b/chunk-format.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"chunk-format.h\"\n #include \"csum-file.h\"\n #include \"gettext.h\"\ndiff --git a/commit-reach.c b/commit-reach.c\nindex f15d84566b..4b7c233fd4 100644\n--- a/commit-reach.c\n+++ b/commit-reach.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"commit-graph.h\"\n #include \"decorate.h\"\ndiff --git a/config.c b/config.c\nindex 59fad84eb7..3846a37be9 100644\n--- a/config.c\n+++ b/config.c\n@@ -8,7 +8,6 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"date.h\"\n #include \"branch.h\"\n #include \"config.h\"\ndiff --git a/daemon.c b/daemon.c\nindex a7fe89cd2d..f5e597114b 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"path.h\"\ndiff --git a/delta-islands.c b/delta-islands.c\nindex 5fc6ea6ff5..5de5759f3f 100644\n--- a/delta-islands.c\n+++ b/delta-islands.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"attr.h\"\n #include \"object.h\"\n #include \"blob.h\"\ndiff --git a/diff.c b/diff.c\nindex 9e4d87a8db..ee3eb629e3 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -3,7 +3,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"base85.h\"\n #include \"config.h\"\n #include \"convert.h\"\ndiff --git a/diffcore-rename.c b/diffcore-rename.c\nindex 926b554bd5..5a6e2bcac7 100644\n--- a/diffcore-rename.c\n+++ b/diffcore-rename.c\n@@ -3,7 +3,6 @@\n  * Copyright (C) 2005 Junio C Hamano\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"diff.h\"\n #include \"diffcore.h\"\n #include \"object-store-ll.h\"\ndiff --git a/dir-iterator.c b/dir-iterator.c\nindex fb7c47f0e8..278b04243a 100644\n--- a/dir-iterator.c\n+++ b/dir-iterator.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"iterator.h\"\n #include \"dir-iterator.h\"\ndiff --git a/dir.c b/dir.c\nindex d270a1be36..c9dc69fc24 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -7,7 +7,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"dir.h\"\ndiff --git a/ewah/bitmap.c b/ewah/bitmap.c\nindex 12d6aa398e..7b525b1ecd 100644\n--- a/ewah/bitmap.c\n+++ b/ewah/bitmap.c\n@@ -17,7 +17,6 @@\n  * along with this program; if not, see <http://www.gnu.org/licenses/>.\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"ewok.h\"\n \n #define EWAH_MASK(x) ((eword_t)1 << (x % BITS_IN_EWORD))\ndiff --git a/ewah/ewah_bitmap.c b/ewah/ewah_bitmap.c\nindex c6d4ffc87c..8785cbc54a 100644\n--- a/ewah/ewah_bitmap.c\n+++ b/ewah/ewah_bitmap.c\n@@ -17,7 +17,6 @@\n  * along with this program; if not, see <http://www.gnu.org/licenses/>.\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"ewok.h\"\n #include \"ewok_rlw.h\"\n \ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex bb288d47f3..65c1ff4bb4 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"repository.h\"\n #include \"config.h\"\n #include \"date.h\"\ndiff --git a/fmt-merge-msg.c b/fmt-merge-msg.c\nindex 4239594ad8..66e47449a0 100644\n--- a/fmt-merge-msg.c\n+++ b/fmt-merge-msg.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"refs.h\"\ndiff --git a/fsck.c b/fsck.c\nindex 3be86616c5..b160b6f9d0 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"date.h\"\n #include \"dir.h\"\n #include \"hex.h\"\ndiff --git a/git-compat-util.h b/git-compat-util.h\nindex 1832444fa2..d32aa754ae 100644\n--- a/git-compat-util.h\n+++ b/git-compat-util.h\n@@ -1136,6 +1136,81 @@ static inline void move_array(void *dst, const void *src, size_t n, size_t size)\n #define FLEXPTR_ALLOC_STR(x, ptrname, str) \\\n \tFLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))\n \n+#define alloc_nr(x) (((x)+16)*3/2)\n+\n+/**\n+ * Dynamically growing an array using realloc() is error prone and boring.\n+ *\n+ * Define your array with:\n+ *\n+ * - a pointer (`item`) that points at the array, initialized to `NULL`\n+ *   (although please name the variable based on its contents, not on its\n+ *   type);\n+ *\n+ * - an integer variable (`alloc`) that keeps track of how big the current\n+ *   allocation is, initialized to `0`;\n+ *\n+ * - another integer variable (`nr`) to keep track of how many elements the\n+ *   array currently has, initialized to `0`.\n+ *\n+ * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,\n+ * alloc)`.  This ensures that the array can hold at least `n` elements by\n+ * calling `realloc(3)` and adjusting `alloc` variable.\n+ *\n+ * ------------\n+ * sometype *item;\n+ * size_t nr;\n+ * size_t alloc\n+ *\n+ * for (i = 0; i < nr; i++)\n+ * \tif (we like item[i] already)\n+ * \t\treturn;\n+ *\n+ * // we did not like any existing one, so add one\n+ * ALLOC_GROW(item, nr + 1, alloc);\n+ * item[nr++] = value you like;\n+ * ------------\n+ *\n+ * You are responsible for updating the `nr` variable.\n+ *\n+ * If you need to specify the number of elements to allocate explicitly\n+ * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.\n+ *\n+ * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some\n+ * added niceties.\n+ *\n+ * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.\n+ */\n+#define ALLOC_GROW(x, nr, alloc) \\\n+\tdo { \\\n+\t\tif ((nr) > alloc) { \\\n+\t\t\tif (alloc_nr(alloc) < (nr)) \\\n+\t\t\t\talloc = (nr); \\\n+\t\t\telse \\\n+\t\t\t\talloc = alloc_nr(alloc); \\\n+\t\t\tREALLOC_ARRAY(x, alloc); \\\n+\t\t} \\\n+\t} while (0)\n+\n+/*\n+ * Similar to ALLOC_GROW but handles updating of the nr value and\n+ * zeroing the bytes of the newly-grown array elements.\n+ *\n+ * DO NOT USE any expression with side-effect for any of the\n+ * arguments.\n+ */\n+#define ALLOC_GROW_BY(x, nr, increase, alloc) \\\n+\tdo { \\\n+\t\tif (increase) { \\\n+\t\t\tsize_t new_nr = nr + (increase); \\\n+\t\t\tif (new_nr < nr) \\\n+\t\t\t\tBUG(\"negative growth in ALLOC_GROW_BY\"); \\\n+\t\t\tALLOC_GROW(x, new_nr, alloc); \\\n+\t\t\tmemset((x) + nr, 0, sizeof(*(x)) * (increase)); \\\n+\t\t\tnr = new_nr; \\\n+\t\t} \\\n+\t} while (0)\n+\n static inline char *xstrdup_or_null(const char *str)\n {\n \treturn str ? xstrdup(str) : NULL;\ndiff --git a/help.c b/help.c\nindex 389382b148..6d2ebfbd2a 100644\n--- a/help.c\n+++ b/help.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"builtin.h\"\n #include \"exec-cmd.h\"\ndiff --git a/http-backend.c b/http-backend.c\nindex 25a19c21b9..e24399ed10 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"git-zlib.h\"\ndiff --git a/line-log.c b/line-log.c\nindex 2eff914bf3..790ab73212 100644\n--- a/line-log.c\n+++ b/line-log.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"line-range.h\"\n #include \"hex.h\"\n #include \"tag.h\"\ndiff --git a/list-objects-filter-options.c b/list-objects-filter-options.c\nindex 2a3b7881af..8a08b7af49 100644\n--- a/list-objects-filter-options.c\n+++ b/list-objects-filter-options.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"config.h\"\n #include \"gettext.h\"\ndiff --git a/list-objects-filter.c b/list-objects-filter.c\nindex e075a66c99..9327ccd505 100644\n--- a/list-objects-filter.c\n+++ b/list-objects-filter.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/midx.c b/midx.c\nindex db459e448b..3a16acabbc 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"csum-file.h\"\n #include \"dir.h\"\ndiff --git a/object-file.c b/object-file.c\nindex 527b740018..5ebe1b00c5 100644\n--- a/object-file.c\n+++ b/object-file.c\n@@ -8,7 +8,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"convert.h\"\n #include \"environment.h\"\ndiff --git a/oid-array.c b/oid-array.c\nindex e8228c777b..8e4717746c 100644\n--- a/oid-array.c\n+++ b/oid-array.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"oid-array.h\"\n #include \"hash-lookup.h\"\n \ndiff --git a/oidtree.c b/oidtree.c\nindex 7d57b7b19e..daef175dc7 100644\n--- a/oidtree.c\n+++ b/oidtree.c\n@@ -4,7 +4,6 @@\n  */\n #include \"git-compat-util.h\"\n #include \"oidtree.h\"\n-#include \"alloc.h\"\n #include \"hash.h\"\n \n struct oidtree_iter_data {\ndiff --git a/pack-bitmap-write.c b/pack-bitmap-write.c\nindex d86f4e739a..f6757c3cbf 100644\n--- a/pack-bitmap-write.c\n+++ b/pack-bitmap-write.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/pack-bitmap.c b/pack-bitmap.c\nindex 7367f62bb6..01fbc0a657 100644\n--- a/pack-bitmap.c\n+++ b/pack-bitmap.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/pack-objects.c b/pack-objects.c\nindex ccab09fe65..1b8052bece 100644\n--- a/pack-objects.c\n+++ b/pack-objects.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"object.h\"\n #include \"pack.h\"\n #include \"pack-objects.h\"\ndiff --git a/packfile.c b/packfile.c\nindex 9126274b37..030b7ec7a8 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/parallel-checkout.c b/parallel-checkout.c\nindex 8637723461..b5a714c711 100644\n--- a/parallel-checkout.c\n+++ b/parallel-checkout.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"entry.h\"\n #include \"gettext.h\"\ndiff --git a/pretty.c b/pretty.c\nindex 7862be105d..4df716686f 100644\n--- a/pretty.c\n+++ b/pretty.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"commit.h\"\n #include \"environment.h\"\ndiff --git a/prio-queue.c b/prio-queue.c\nindex dc2476be53..450775a374 100644\n--- a/prio-queue.c\n+++ b/prio-queue.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"prio-queue.h\"\n \n static inline int compare(struct prio_queue *queue, int i, int j)\ndiff --git a/quote.c b/quote.c\nindex 43c739671e..3c05194496 100644\n--- a/quote.c\n+++ b/quote.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"path.h\"\n #include \"quote.h\"\n #include \"strbuf.h\"\ndiff --git a/read-cache.c b/read-cache.c\nindex 140b4f96a0..53d71134e2 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -4,7 +4,6 @@\n  * Copyright (C) Linus Torvalds, 2005\n  */\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"bulk-checkin.h\"\n #include \"config.h\"\n #include \"date.h\"\ndiff --git a/ref-filter.c b/ref-filter.c\nindex e0d03a9f8e..2ed0ecf260 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"gpg-interface.h\"\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex d337e64431..d216f6f966 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"refs.h\"\n #include \"diff.h\"\ndiff --git a/refs.c b/refs.c\nindex d5e0184ca5..c1b3d1f13f 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -4,7 +4,6 @@\n \n #include \"git-compat-util.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"hashmap.h\"\ndiff --git a/refspec.c b/refspec.c\nindex 57f6c2aaf9..d60932f4de 100644\n--- a/refspec.c\n+++ b/refspec.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hash.h\"\n #include \"hex.h\"\ndiff --git a/remote-curl.c b/remote-curl.c\nindex acf7b2bb40..8a976a0253 100644\n--- a/remote-curl.c\n+++ b/remote-curl.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/remote.c b/remote.c\nindex 6e13993bdc..55e7d22a00 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/rerere.c b/rerere.c\nindex 4227c9612a..7070f75014 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"copy.h\"\n #include \"gettext.h\"\ndiff --git a/revision.c b/revision.c\nindex d66857ecc0..0976d41404 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/sequencer.c b/sequencer.c\nindex 993dd8efbc..cc9821ece2 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -1,7 +1,6 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"copy.h\"\n #include \"environment.h\"\ndiff --git a/server-info.c b/server-info.c\nindex f350713ecf..e2fe0f9143 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"environment.h\"\n #include \"hex.h\"\ndiff --git a/shallow.c b/shallow.c\nindex 2fad3504b7..5413719fd4 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"hex.h\"\n #include \"repository.h\"\n #include \"tempfile.h\"\ndiff --git a/sigchain.c b/sigchain.c\nindex ee778c0580..66123bdbab 100644\n--- a/sigchain.c\n+++ b/sigchain.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"sigchain.h\"\n \n #define SIGCHAIN_MAX_SIGNALS 32\ndiff --git a/sparse-index.c b/sparse-index.c\nindex 90d0462256..1fdb07a9e6 100644\n--- a/sparse-index.c\n+++ b/sparse-index.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"name-hash.h\"\ndiff --git a/split-index.c b/split-index.c\nindex 0ee3865a55..8c38687c04 100644\n--- a/split-index.c\n+++ b/split-index.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hash.h\"\n #include \"mem-pool.h\"\ndiff --git a/strbuf.c b/strbuf.c\nindex ab8e52e9b4..f65d7bee4c 100644\n--- a/strbuf.c\n+++ b/strbuf.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\n #include \"strbuf.h\"\ndiff --git a/string-list.c b/string-list.c\nindex 0f8ac117fd..954569f381 100644\n--- a/string-list.c\n+++ b/string-list.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"string-list.h\"\n-#include \"alloc.h\"\n \n void string_list_init_nodup(struct string_list *list)\n {\ndiff --git a/strvec.c b/strvec.c\nindex 17d54b6c3b..89dc9e7e75 100644\n--- a/strvec.c\n+++ b/strvec.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"strvec.h\"\n-#include \"alloc.h\"\n #include \"hex.h\"\n #include \"strbuf.h\"\n \ndiff --git a/submodule-config.c b/submodule-config.c\nindex b6908e295f..6a48fd12f6 100644\n--- a/submodule-config.c\n+++ b/submodule-config.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/submodule.c b/submodule.c\nindex f0f8788d2e..e603a19a87 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"repository.h\"\n #include \"config.h\"\n #include \"submodule-config.h\"\ndiff --git a/t/helper/test-reach.c b/t/helper/test-reach.c\nindex 5b6f217441..119f4908cf 100644\n--- a/t/helper/test-reach.c\n+++ b/t/helper/test-reach.c\n@@ -1,5 +1,4 @@\n #include \"test-tool.h\"\n-#include \"alloc.h\"\n #include \"commit.h\"\n #include \"commit-reach.h\"\n #include \"config.h\"\ndiff --git a/trace2/tr2_tls.c b/trace2/tr2_tls.c\nindex 9f46ae12f5..601c9e5036 100644\n--- a/trace2/tr2_tls.c\n+++ b/trace2/tr2_tls.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"thread-utils.h\"\n #include \"trace.h\"\n #include \"trace2/tr2_tls.h\"\ndiff --git a/trailer.c b/trailer.c\nindex 06dc0b7f68..f408f9b058 100644\n--- a/trailer.c\n+++ b/trailer.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\ndiff --git a/transport.c b/transport.c\nindex 0a5794a944..219af8fd50 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"advice.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"environment.h\"\n #include \"hex.h\"\ndiff --git a/tree-walk.c b/tree-walk.c\nindex 42ed86ef58..6c07913f3f 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"tree-walk.h\"\n-#include \"alloc.h\"\n #include \"dir.h\"\n #include \"gettext.h\"\n #include \"hex.h\"\ndiff --git a/userdiff.c b/userdiff.c\nindex 664c7c1402..e399543823 100644\n--- a/userdiff.c\n+++ b/userdiff.c\n@@ -1,5 +1,4 @@\n #include \"git-compat-util.h\"\n-#include \"alloc.h\"\n #include \"config.h\"\n #include \"userdiff.h\"\n #include \"attr.h\"\ndiff --git a/worktree.c b/worktree.c\nindex 2ea5d45e1e..b8cf29e6a1 100644\n--- a/worktree.c\n+++ b/worktree.c\n@@ -1,6 +1,5 @@\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n-#include \"alloc.h\"\n #include \"environment.h\"\n #include \"gettext.h\"\n #include \"path.h\"\n-- \n2.41.0.255.g8b1d071c50-goog\n\n"},{"id":"479071","messageId":"xmqqjzvk62cw.fsf@gitster.g","threadId":"59752","inReplyTo":"20230630202237.3069327-1-calvinwan@google.com","subject":"Re: [PATCH v4 0/6] git-compat-util cleanups","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-06-30T21:56:31Z","receivedAt":"2023-06-30T21:56:40Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Calvin Wan <calvinwan@google.com> writes:\n\n> Changes since v3:\n>  - Dropped patches 5 and 6 since removing the circular dependency in\n>    common.h turns out to be quite difficult\n>  - Patch 8 moves the alloc macros to git-compat-util.h rather than\n>    common.h since that does not exist anymore\n\nWill queue.\n\n> Note for the maintainer:\n>\n> I rebased this series onto both seen and next and they rebased cleanly.\n\nThanks.  It is a very indirect way to ensure if the topic is usable,\nthough.  What we want is:\n\n * A series of patches that applies cleanly to 'master'.  Call the\n   result of applying them $T (topic).\n\n * \"git checkout next && git merge $T\" should give at most trivial\n   conflicts.\n\n * The same for 'seen'.\n\nIf the conflicts with topics in 'seen' are only with topics in the\nstalled category and/or expecting a reroll category, we may discard\nthe other topic have _their_ reroll worry about adjusting for this\ntopic.\n\nFWIW, I did\n\n (1) tentatively applied these patches to 'next^0', and discarded\n     the result.\n\n (2) applied these patches with \"-3\" to 'master^0', which saw a bit\n     of conflicts in gpg-interface.c (with cw/strbuf-cleanup topic)\n     and in strbuf.c (again with cw/strbuf-cleanup topic).\n\n (3) to cross check the result, merged (2) into 'next^0' to make\n     sure that it matches (1).\n\n (4) merged (2) into 'seen^0'.\n\nAs this round has been rebased to a more recent codebase, even with\nthe conflicts with cw/strbuf-cleanup, (4) indeed merged fairly\ncleanly, with the same set of conflicts as (3).\n\nThanks for rebasing the patches.\n\nHopefully people will be able to review and give feedback to the\nseries this time.\n"},{"id":"479074","messageId":"xmqqfs685zw1.fsf@gitster.g","threadId":"59752","inReplyTo":"20230630202346.3069950-6-calvinwan@google.com","subject":"Re: [PATCH v4 6/6] common: move alloc macros to common.h","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-06-30T22:49:50Z","receivedAt":"2023-06-30T22:49:57Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Calvin Wan <calvinwan@google.com> writes:\n\n> alloc_nr, ALLOC_GROW, and ALLOC_GROW_BY are commonly used macros for\n> dynamic array allocation. Moving these macros to git-compat-util.h with\n> the other alloc macros focuses alloc.[ch] to allocation for Git objects\n> and additionally allows us to remove inclusions to alloc.h from files\n> that solely used the above macros.\n\nIs this step mistitled?  There is no \"common.h\" in this round.\n\nFor that matter, when the series makes a big change like this round,\nplease update the cover letter so that those who are reading it\nwithout having seen the prior rounds can understand what the series\nis about.  It will equally help those who have seen prior rounds,\ntoo. what is going on.  E.g. The cover letter of v1 emphasized why\nmoving many things to common.h was a great thing (and promised to\ntalk about it more in patch 3), but that focus certainly has shifted\nin this iteration that no longer even creates \"common.h\", right?\n\nThanks.\n"},{"id":"479200","messageId":"CAFySSZBDur-1+XG2AetS6jZ=mkv0esFFT5HgQnQ-SVsrpgKXew@mail.gmail.com","threadId":"59752","inReplyTo":"xmqqfs685zw1.fsf@gitster.g","subject":"Re: [PATCH v4 6/6] common: move alloc macros to common.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-07-05T16:25:57Z","receivedAt":"2023-07-05T16:26:12Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"> Is this step mistitled?  There is no \"common.h\" in this round.\n\nAhhhh my pre-vacation brain managed to correctly edit the commit\nmessage, but not the header\n\n> For that matter, when the series makes a big change like this round,\n> please update the cover letter so that those who are reading it\n> without having seen the prior rounds can understand what the series\n> is about.  It will equally help those who have seen prior rounds,\n> too. what is going on.  E.g. The cover letter of v1 emphasized why\n> moving many things to common.h was a great thing (and promised to\n> talk about it more in patch 3), but that focus certainly has shifted\n> in this iteration that no longer even creates \"common.h\", right?\n\nThat's correct. I'll reroll this series with an updated cover letter\nand fixed commit header.\n"},{"id":"479214","messageId":"xmqqpm561cw0.fsf@gitster.g","threadId":"59752","inReplyTo":"CAFySSZBDur-1+XG2AetS6jZ=mkv0esFFT5HgQnQ-SVsrpgKXew@mail.gmail.com","subject":"Re: [PATCH v4 6/6] common: move alloc macros to common.h","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-07-05T17:33:51Z","receivedAt":"2023-07-05T17:35:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Calvin Wan <calvinwan@google.com> writes:\n\n>> Is this step mistitled?  There is no \"common.h\" in this round.\n>\n> Ahhhh my pre-vacation brain managed to correctly edit the commit\n> message, but not the header\n>\n>> For that matter, when the series makes a big change like this round,\n>> please update the cover letter so that those who are reading it\n>> without having seen the prior rounds can understand what the series\n>> is about.  It will equally help those who have seen prior rounds,\n>> too. what is going on.  E.g. The cover letter of v1 emphasized why\n>> moving many things to common.h was a great thing (and promised to\n>> talk about it more in patch 3), but that focus certainly has shifted\n>> in this iteration that no longer even creates \"common.h\", right?\n>\n> That's correct. I'll reroll this series with an updated cover letter\n> and fixed commit header.\n\nThat will help others, but in the meantime I'll just tweak the\ncommit log message to say \"to common.h\" -> \"to git-compat-util.h\";\notherwise the series is ready for 'next', right?\n\nTHanks.\n"},{"id":"479217","messageId":"CAFySSZBv+2tg6rOUJvtF7A0DUkxZtHQ-UJDLD8T_HMKKqBh8Eg@mail.gmail.com","threadId":"59752","inReplyTo":"xmqqpm561cw0.fsf@gitster.g","subject":"Re: [PATCH v4 6/6] common: move alloc macros to common.h","fromName":"Calvin Wan","fromEmail":"calvinwan@google.com","sentAt":"2023-07-05T17:58:28Z","receivedAt":"2023-07-05T17:58:42Z","isPatch":true,"sender":{"key":"calvinwan@google.com","avatar":"https://avatars.githubusercontent.com/u/92547554?v=4"},"body":"> That will help others, but in the meantime I'll just tweak the\n> commit log message to say \"to common.h\" -> \"to git-compat-util.h\";\n> otherwise the series is ready for 'next', right?\n\nCorrect, I have it as \"git-compat-util: move alloc macros to\ngit-compat-util.h\". Thanks!\n"}]}