git-compat-util cleanups
cover git-compat-util cleanups
This series focuses on cleaning up and reducing the scope of git-compat-util.h by moving headers to their respective files and separating out functionality from git-compat-util.h to a new file, common.h. I go into more detail in patch 3 as to why I believe this separation is useful.
By the end of this series, git-compat-util.h includes common.h which includes wrapper.h and usage.h. Since virtually every file includes git-compat-util.h and the large majority of files use functions defined in common.h, wrapper.h, and usage.h, I believe it makes sense that those are also automatically included with git-compat-util.h.
While this series does not intend to draw clearer boundaries for common.h, I am open to ideas for how it can be cleaned up more and if there is a better name for the file.
Calvin Wan (6):
strbuf.h: move declarations for strbuf.c functions from
git-compat-util.h
wrapper.h: move declarations for wrapper.c functions from
git-compat-util.h
common.h: move non-compat specific macros and functions from
git-compat-util.h
usage.h: move declarations for usage.c functions from
git-compat-util.h
treewide: remove unnecessary includes for wrapper.h
common: move alloc macros to common.h
add-patch.c | 1 - alias.c | 1 - alloc.h | 75 ---- apply.c | 2 - archive-tar.c | 1 - archive.c | 1 - attr.c | 1 - builtin/am.c | 1 - builtin/bisect.c | 1 - builtin/blame.c | 1 - builtin/branch.c | 1 - builtin/bugreport.c | 1 - builtin/cat-file.c | 1 - builtin/checkout--worker.c | 1 - builtin/clone.c | 1 - builtin/config.c | 2 - builtin/credential-cache--daemon.c | 1 - builtin/credential-cache.c | 1 - builtin/difftool.c | 1 - builtin/fast-import.c | 1 - builtin/fetch-pack.c | 1 - builtin/fmt-merge-msg.c | 1 - builtin/fsmonitor--daemon.c | 1 - builtin/gc.c | 1 - builtin/get-tar-commit-id.c | 1 - builtin/grep.c | 1 - builtin/index-pack.c | 2 - builtin/init-db.c | 1 - builtin/log.c | 1 - builtin/merge.c | 2 - builtin/mktree.c | 1 - builtin/mv.c | 1 - builtin/name-rev.c | 1 - builtin/pack-objects.c | 2 - builtin/rebase.c | 1 - builtin/receive-pack.c | 1 - builtin/repack.c | 1 - builtin/rerere.c | 1 - builtin/rev-parse.c | 1 - builtin/revert.c | 1 - builtin/rm.c | 1 - builtin/submodule--helper.c | 1 - builtin/unpack-file.c | 1 - builtin/worktree.c | 1 - bulk-checkin.c | 2 - cache-tree.c | 1 - chunk-format.c | 1 - combine-diff.c | 1 - commit-graph.c | 1 - commit-reach.c | 1 - common.h | 551 ++++++++++++++++++++++++ compat/terminal.c | 1 - config.c | 2 - convert.c | 1 - copy.c | 1 - csum-file.c | 1 - daemon.c | 2 - delta-islands.c | 1 - diff.c | 2 - diffcore-rename.c | 1 - dir-iterator.c | 1 - dir.c | 2 - editor.c | 1 - entry.c | 1 - environment.c | 1 - ewah/bitmap.c | 1 - ewah/ewah_bitmap.c | 1 - fetch-pack.c | 2 - fmt-merge-msg.c | 1 - fsck.c | 1 - git-compat-util.h | 664 +---------------------------- gpg-interface.c | 1 - grep.c | 1 - help.c | 1 - http-backend.c | 2 - imap-send.c | 1 - line-log.c | 1 - list-objects-filter-options.c | 1 - list-objects-filter.c | 1 - ll-merge.c | 1 - merge-recursive.c | 1 - midx.c | 1 - notes-merge.c | 1 - object-file.c | 2 - oid-array.c | 1 - oidtree.c | 1 - pack-bitmap-write.c | 1 - pack-bitmap.c | 1 - pack-objects.c | 1 - pack-write.c | 1 - packfile.c | 2 - parallel-checkout.c | 2 - path.c | 1 - pkt-line.c | 1 - pretty.c | 1 - prio-queue.c | 1 - quote.c | 1 - read-cache.c | 2 - rebase-interactive.c | 1 - ref-filter.c | 1 - reflog-walk.c | 1 - refs.c | 2 - refspec.c | 1 - remote-curl.c | 1 - remote.c | 1 - rerere.c | 2 - revision.c | 1 - send-pack.c | 1 - sequencer.c | 2 - server-info.c | 2 - setup.c | 1 - shallow.c | 2 - sigchain.c | 1 - sparse-index.c | 1 - split-index.c | 1 - strbuf.c | 2 - strbuf.h | 32 ++ streaming.c | 1 - string-list.c | 1 - strvec.c | 1 - submodule-config.c | 1 - submodule.c | 1 - t/helper/test-delta.c | 1 - t/helper/test-fsmonitor-client.c | 1 - t/helper/test-reach.c | 1 - t/helper/test-read-cache.c | 1 - tag.c | 1 - tempfile.c | 1 - trace.c | 1 - trace2/tr2_tls.c | 1 - trailer.c | 1 - transport-helper.c | 1 - transport.c | 2 - tree-walk.c | 1 - upload-pack.c | 1 - usage.c | 1 - usage.h | 60 +++ userdiff.c | 1 - worktree.c | 2 - wrapper.c | 1 - wrapper.h | 111 +++++ write-or-die.c | 1 - 142 files changed, 756 insertions(+), 897 deletions(-) create mode 100644 common.h create mode 100644 usage.h
Signature · 1 line
2.40.1.606.ga4b1b128d6-goog
PATCH 1/6 strbuf.h: move declarations for strbuf.c functions from git-compat-util.h
While functions like starts_with() probably should not belong in the boundaries of the strbuf library, this commit focuses on first splitting out headers from git-compat-util.h.
--- git-compat-util.h | 32 -------------------------------- strbuf.h | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 32 deletions(-)
git-compat-util.h +0 -32
@@ -679,9 +679,6 @@ void set_warn_routine(report_fn routine);report_fn get_warn_routine (void );void set_die_is_recursing_routine (int (*routine)(void )); -int starts_with (const char *str,const char *prefix); -int istarts_with (const char *str,const char *prefix); -/* * If the string "str" begins with the string found in "prefix", return 1. * The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in
@@ -710,29 +707,6 @@ static inline int skip_prefix(const char *str, const char *prefix,return 0 ; } -/* -* If the string "str" is the same as the string in "prefix", then the "arg" -* parameter is set to the "def" parameter and 1 is returned. -* If the string "str" begins with the string found in "prefix" and then a -* "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1" -* (i.e., to the point in the string right after the prefix and the "=" sign), -* and 1 is returned. -* -* Otherwise, return 0 and leave "arg" untouched. -* -* When we accept both a "--key" and a "--key=<val>" option, this function -* can be used instead of !strcmp(arg, "--key") and then -* skip_prefix(arg, "--key=", &arg) to parse such an option. -*/ -int skip_to_optional_arg_default (const char *str,const char *prefix, -const char **arg,const char *def); - -static inline int skip_to_optional_arg (const char *str,const char *prefix, -const char **arg) -{ -return skip_to_optional_arg_default (str, prefix, arg,"" ); -} -/* * Like skip_prefix, but promises never to read past "len" bytes of the input * buffer, and returns the remaining number of bytes in "out" via "outlen".
@@ -777,12 +751,6 @@ static inline int strip_suffix(const char *str, const char *suffix, size_t *len)return strip_suffix_mem (str, len, suffix); } -static inline int ends_with (const char *str,const char *suffix) -{ -size_t len; -return strip_suffix (str, suffix, &len); -} -#define SWAP (a, b) do { \ void *_swap_a_ptr = &(a); \ void *_swap_b_ptr = &(b); \
strbuf.h +32 -0
@@ -727,4 +727,36 @@ char *xstrvfmt(const char *fmt, va_list ap); __attribute__((format (printf,1 ,2 )))char *xstrfmt (const char *fmt, ...); +int starts_with (const char *str,const char *prefix); +int istarts_with (const char *str,const char *prefix); + +/* +* If the string "str" is the same as the string in "prefix", then the "arg" +* parameter is set to the "def" parameter and 1 is returned. +* If the string "str" begins with the string found in "prefix" and then a +* "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1" +* (i.e., to the point in the string right after the prefix and the "=" sign), +* and 1 is returned. +* +* Otherwise, return 0 and leave "arg" untouched. +* +* When we accept both a "--key" and a "--key=<val>" option, this function +* can be used instead of !strcmp(arg, "--key") and then +* skip_prefix(arg, "--key=", &arg) to parse such an option. +*/ +int skip_to_optional_arg_default (const char *str,const char *prefix, +const char **arg,const char *def); + +static inline int skip_to_optional_arg (const char *str,const char *prefix, +const char **arg) +{ +return skip_to_optional_arg_default (str, prefix, arg,"" ); +} + +static inline int ends_with (const char *str,const char *suffix) +{ +size_t len; +return strip_suffix (str, suffix, &len); +} +#endif /* STRBUF_H */
Signature · 1 line
2.40.1.606.ga4b1b128d6-goog
Re: [PATCH 1/6] strbuf.h: move declarations for strbuf.c functions from git-compat-util.h
Quoted 3 lines · Calvin Wan
While functions like
starts_with()probably should not belong in the boundaries of the strbuf library, this commit focuses on first splitting out headers fromgit-compat-util.h.
Yeah, compat-util.h started out as a (surprise) "compatibility aid" that isolates the knowledge of platform specific inclusion order, what feature macros to define before including which system header file, etc. but over the years, it accumulated some common niceties that are too small to deserve their own header files.
starts_with() and skip_prefix() are two examples of such.
It is hard to imagine skip_to_optional_arg_default() should belong to strbuf API, but if you are booting it out of compat-util, declaring it in strbuf.h may be the least bad choice, as the implementation sits in strbuf.c (which is a strange place, but that is not the fault of this series).
PATCH 2/6 wrapper.h: move declarations for wrapper.c functions from git-compat-util.h
In reply to Calvin WanSince the functions in wrapper.c are widely used across the codebase, include it by default in git-compat-util.h. A future patch will remove now unnecessary inclusions of wrapper.h from other files.
--- git-compat-util.h | 113 +--------------------------------------------- wrapper.h | 111 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 112 deletions(-)
git-compat-util.h +1 -112
@@ -626,8 +626,7 @@ static inline int git_has_dir_sep(const char *path)#include "compat/bswap.h" #include "wildmatch.h" - -struct strbuf ; +#include "wrapper.h" /* General helper functions */ NORETURN void usage(const char *err);
@@ -1047,36 +1046,6 @@ static inline int cast_size_t_to_int(size_t a)# define xalloca (size) (xmalloc(size))# define xalloca_free (p) (free(p))#endif -char *xstrdup (const char *str); -void *xmalloc (size_t size); -void *xmallocz (size_t size); -void *xmallocz_gently (size_t size); -void *xmemdupz (const void *data,size_t len); -char *xstrndup (const char *str,size_t len); -void *xrealloc (void *ptr,size_t size); -void *xcalloc (size_t nmemb,size_t size); -void xsetenv (const char *name,const char *value,int overwrite); -void *xmmap (void *start,size_t length,int prot,int flags,int fd,off_t offset); -const char *mmap_os_err (void ); -void *xmmap_gently (void *start,size_t length,int prot,int flags,int fd,off_t offset); -int xopen (const char *path,int flags, ...); -ssize_t xread (int fd,void *buf,size_t len); -ssize_t xwrite (int fd,const void *buf,size_t len); -ssize_t xpread (int fd,void *buf,size_t len,off_t offset); -int xdup (int fd); -FILE *xfopen (const char *path,const char *mode); -FILE *xfdopen (int fd,const char *mode); -int xmkstemp (char *temp_filename); -int xmkstemp_mode (char *temp_filename,int mode); -char *xgetcwd (void ); -FILE *fopen_for_writing (const char *path); -FILE *fopen_or_warn (const char *path,const char *mode); - -/* -* Like strncmp, but only return zero if s is NUL-terminated and exactly len -* characters long. If it is not, consider it greater than t. -*/ -int xstrncmpz (const char *s,const char *t,size_t len);/* * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note
@@ -1178,15 +1147,10 @@ static inline size_t xsize_t(off_t len)return (size_t ) len; } -__attribute__((format (printf,3 ,4 ))) -int xsnprintf (char *dst,size_t max,const char *fmt, ...); -#ifndef HOST_NAME_MAX #define HOST_NAME_MAX 256#endif -int xgethostname (char *buf,size_t len); -/* in ctype.c, for kwset users */ extern const unsigned char tolower_trans_tbl[256 ];
@@ -1427,72 +1391,6 @@ void bug_fl(const char *file, int line, const char *fmt, ...);#endif #endif -enum fsync_action { -FSYNC_WRITEOUT_ONLY , -FSYNC_HARDWARE_FLUSH -}; - -/* -* Issues an fsync against the specified file according to the specified mode. -* -* FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating -* systems to flush the OS cache without issuing a flush command to the storage -* controller. If those interfaces are unavailable, the function fails with -* ENOSYS. -* -* FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that -* changes are durable. It is not expected to fail. -*/ -int git_fsync (int fd,enum fsync_action action); - -/* -* Writes out trace statistics for fsync using the trace2 API. -*/ -void trace_git_fsync_stats (void ); - -/* -* Preserves errno, prints a message, but gives no warning for ENOENT. -* Returns 0 on success, which includes trying to unlink an object that does -* not exist. -*/ -int unlink_or_warn (const char *path); -/* -* Tries to unlink file. Returns 0 if unlink succeeded -* or the file already didn't exist. Returns -1 and -* appends a message to err suitable for -* 'error("%s", err->buf)' on error. -*/ -int unlink_or_msg (const char *file,struct strbuf *err); -/* -* Preserves errno, prints a message, but gives no warning for ENOENT. -* Returns 0 on success, which includes trying to remove a directory that does -* not exist. -*/ -int rmdir_or_warn (const char *path); -/* -* Calls the correct function out of {unlink,rmdir}_or_warn based on -* the supplied file mode. -*/ -int remove_or_warn (unsigned int mode,const char *path); - -/* -* Call access(2), but warn for any error except "missing file" -* (ENOENT or ENOTDIR). -*/ -#define ACCESS_EACCES_OK (1U << 0) -int access_or_warn (const char *path,int mode,unsigned flag); -int access_or_die (const char *path,int mode,unsigned flag); - -/* Warn on an inaccessible file if errno indicates this is an error */ -int warn_on_fopen_errors (const char *path); - -/* -* Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent -* may be racy. Do not use this as protection against an attacker who can -* simultaneously create paths. -*/ -int open_nofollow (const char *path,int flags); -#ifndef SHELL_PATH # define SHELL_PATH "/bin/sh"#endif
@@ -1632,13 +1530,4 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset) ((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))#endif /* !__GNUC__ */ -void sleep_millisec (int millisec); - -/* -* Generate len bytes from the system cryptographically secure PRNG. -* Returns 0 on success and -1 on error, setting errno. The inability to -* satisfy the full request is an error. -*/ -int csprng_bytes (void *buf,size_t len); -#endif
wrapper.h +111 -0
121 lines not on this page · raw message
Signature · 1 line
2.40.1.606.ga4b1b128d6-goog
Re: [PATCH 2/6] wrapper.h: move declarations for wrapper.c functions from git-compat-util.h
Quoted 3 lines · Calvin Wan
Since the functions in
wrapper.care widely used across the codebase, include it by default ingit-compat-util.h. A future patch will remove now unnecessary inclusions ofwrapper.hfrom other files.
The description taken alone implies the move in the other direction (i.e. taking decls from wrapper.h and moving them to git-compat-util.h), but that the patch actually does makes sense. Slim compat-util.h by moving decls for wrapper functions that are defined in wrapper.c to wrapper.h, but to avoid impacting the users right away, include wrapper.h in the compat-util.h that these users expect to find these decls in.
Quoted 287 lines
Signed-off-by Calvin Wan <[email protected]>--- git-compat-util.h | 113 +--------------------------------------------- wrapper.h | 111 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 112 deletions(-)git-compat-util.h +1
-112@@ -626,8 +626,7 @@ static inline int git_has_dir_sep(const char *path)#include "compat/bswap.h" #include "wildmatch.h" - -struct strbuf ; +#include "wrapper.h" /* General helper functions */ NORETURN void usage(const char *err);@@ -1047,36 +1046,6 @@ static inline int cast_size_t_to_int(size_t a)# define xalloca (size) (xmalloc(size))# define xalloca_free (p) (free(p))#endif -char *xstrdup (const char *str); -void *xmalloc (size_t size); -void *xmallocz (size_t size); -void *xmallocz_gently (size_t size); -void *xmemdupz (const void *data,size_t len); -char *xstrndup (const char *str,size_t len); -void *xrealloc (void *ptr,size_t size); -void *xcalloc (size_t nmemb,size_t size); -void xsetenv (const char *name,const char *value,int overwrite); -void *xmmap (void *start,size_t length,int prot,int flags,int fd,off_t offset); -const char *mmap_os_err (void ); -void *xmmap_gently (void *start,size_t length,int prot,int flags,int fd,off_t offset); -int xopen (const char *path,int flags, ...); -ssize_t xread (int fd,void *buf,size_t len); -ssize_t xwrite (int fd,const void *buf,size_t len); -ssize_t xpread (int fd,void *buf,size_t len,off_t offset); -int xdup (int fd); -FILE *xfopen (const char *path,const char *mode); -FILE *xfdopen (int fd,const char *mode); -int xmkstemp (char *temp_filename); -int xmkstemp_mode (char *temp_filename,int mode); -char *xgetcwd (void ); -FILE *fopen_for_writing (const char *path); -FILE *fopen_or_warn (const char *path,const char *mode); - -/* -* Like strncmp, but only return zero if s is NUL-terminated and exactly len -* characters long. If it is not, consider it greater than t. -*/ -int xstrncmpz (const char *s,const char *t,size_t len);/* * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note @@ -1178,15 +1147,10 @@ static inline size_t xsize_t(off_t len)return (size_t ) len; } -__attribute__((format (printf,3 ,4 ))) -int xsnprintf (char *dst,size_t max,const char *fmt, ...); -#ifndef HOST_NAME_MAX #define HOST_NAME_MAX 256#endif -int xgethostname (char *buf,size_t len); -/* in ctype.c, for kwset users */ extern const unsigned char tolower_trans_tbl[256 ];@@ -1427,72 +1391,6 @@ void bug_fl(const char *file, int line, const char *fmt, ...);#endif #endif -enum fsync_action { -FSYNC_WRITEOUT_ONLY , -FSYNC_HARDWARE_FLUSH -}; - -/* -* Issues an fsync against the specified file according to the specified mode. -* -* FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating -* systems to flush the OS cache without issuing a flush command to the storage -* controller. If those interfaces are unavailable, the function fails with -* ENOSYS. -* -* FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that -* changes are durable. It is not expected to fail. -*/ -int git_fsync (int fd,enum fsync_action action); - -/* -* Writes out trace statistics for fsync using the trace2 API. -*/ -void trace_git_fsync_stats (void ); - -/* -* Preserves errno, prints a message, but gives no warning for ENOENT. -* Returns 0 on success, which includes trying to unlink an object that does -* not exist. -*/ -int unlink_or_warn (const char *path); -/* -* Tries to unlink file. Returns 0 if unlink succeeded -* or the file already didn't exist. Returns -1 and -* appends a message to err suitable for -* 'error("%s", err->buf)' on error. -*/ -int unlink_or_msg (const char *file,struct strbuf *err); -/* -* Preserves errno, prints a message, but gives no warning for ENOENT. -* Returns 0 on success, which includes trying to remove a directory that does -* not exist. -*/ -int rmdir_or_warn (const char *path); -/* -* Calls the correct function out of {unlink,rmdir}_or_warn based on -* the supplied file mode. -*/ -int remove_or_warn (unsigned int mode,const char *path); - -/* -* Call access(2), but warn for any error except "missing file" -* (ENOENT or ENOTDIR). -*/ -#define ACCESS_EACCES_OK (1U << 0) -int access_or_warn (const char *path,int mode,unsigned flag); -int access_or_die (const char *path,int mode,unsigned flag); - -/* Warn on an inaccessible file if errno indicates this is an error */ -int warn_on_fopen_errors (const char *path); - -/* -* Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent -* may be racy. Do not use this as protection against an attacker who can -* simultaneously create paths. -*/ -int open_nofollow (const char *path,int flags); -#ifndef SHELL_PATH # define SHELL_PATH "/bin/sh"#endif @@ -1632,13 +1530,4 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset) ((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))#endif /* !__GNUC__ */ -void sleep_millisec (int millisec); - -/* -* Generate len bytes from the system cryptographically secure PRNG. -* Returns 0 on success and -1 on error, setting errno. The inability to -* satisfy the full request is an error. -*/ -int csprng_bytes (void *buf,size_t len); -#endif wrapper.h +111
-0@@ -1,6 +1,42 @@#ifndef WRAPPER_H #define WRAPPER_H +char *xstrdup (const char *str); +void *xmalloc (size_t size); +void *xmallocz (size_t size); +void *xmallocz_gently (size_t size); +void *xmemdupz (const void *data,size_t len); +char *xstrndup (const char *str,size_t len); +void *xrealloc (void *ptr,size_t size); +void *xcalloc (size_t nmemb,size_t size); +void xsetenv (const char *name,const char *value,int overwrite); +void *xmmap (void *start,size_t length,int prot,int flags,int fd,off_t offset); +const char *mmap_os_err (void ); +void *xmmap_gently (void *start,size_t length,int prot,int flags,int fd,off_t offset); +int xopen (const char *path,int flags, ...); +ssize_t xread (int fd,void *buf,size_t len); +ssize_t xwrite (int fd,const void *buf,size_t len); +ssize_t xpread (int fd,void *buf,size_t len,off_t offset); +int xdup (int fd); +FILE *xfopen (const char *path,const char *mode); +FILE *xfdopen (int fd,const char *mode); +int xmkstemp (char *temp_filename); +int xmkstemp_mode (char *temp_filename,int mode); +char *xgetcwd (void ); +FILE *fopen_for_writing (const char *path); +FILE *fopen_or_warn (const char *path,const char *mode); + +/* +* Like strncmp, but only return zero if s is NUL-terminated and exactly len +* characters long. If it is not, consider it greater than t. +*/ +int xstrncmpz (const char *s,const char *t,size_t len); + +__attribute__((format (printf,3 ,4 ))) +int xsnprintf (char *dst,size_t max,const char *fmt, ...); + +int xgethostname (char *buf,size_t len); +/* set default permissions by passing mode arguments to open(2) */ int git_mkstemps_mode (char *pattern,int suffix_len,int mode);int git_mkstemp_mode (char *pattern,int mode);@@ -33,4 +69,79 @@ void write_file(const char *path, const char *fmt, ...);/* Return 1 if the file is empty or does not exists, 0 otherwise. */ int is_empty_or_missing_file (const char *filename); +enum fsync_action { +FSYNC_WRITEOUT_ONLY , +FSYNC_HARDWARE_FLUSH +}; + +/* +* Issues an fsync against the specified file according to the specified mode. +* +* FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating +* systems to flush the OS cache without issuing a flush command to the storage +* controller. If those interfaces are unavailable, the function fails with +* ENOSYS. +* +* FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that +* changes are durable. It is not expected to fail. +*/ +int git_fsync (int fd,enum fsync_action action); + +/* +* Writes out trace statistics for fsync using the trace2 API. +*/ +void trace_git_fsync_stats (void ); + +/* +* Preserves errno, prints a message, but gives no warning for ENOENT. +* Returns 0 on success, which includes trying to unlink an object that does +* not exist. +*/ +int unlink_or_warn (const char *path); +/* +* Tries to unlink file. Returns 0 if unlink succeeded +* or the file already didn't exist. Returns -1 and +* appends a message to err suitable for +* 'error("%s", err->buf)' on error. +*/ +int unlink_or_msg (const char *file,struct strbuf *err); +/* +* Preserves errno, prints a message, but gives no warning for ENOENT. +* Returns 0 on success, which includes trying to remove a directory that does +* not exist. +*/ +int rmdir_or_warn (const char *path); +/* +* Calls the correct function out of {unlink,rmdir}_or_warn based on +* the supplied file mode. +*/ +int remove_or_warn (unsigned int mode,const char *path); + +/* +* Call access(2), but warn for any error except "missing file" +* (ENOENT or ENOTDIR). +*/ +#define ACCESS_EACCES_OK (1U << 0) +int access_or_warn (const char *path,int mode,unsigned flag); +int access_or_die (const char *path,int mode,unsigned flag); + +/* Warn on an inaccessible file if errno indicates this is an error */ +int warn_on_fopen_errors (const char *path); + +/* +* Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent +* may be racy. Do not use this as protection against an attacker who can +* simultaneously create paths. +*/ +int open_nofollow (const char *path,int flags); + +void sleep_millisec (int millisec); + +/* +* Generate len bytes from the system cryptographically secure PRNG. +* Returns 0 on success and -1 on error, setting errno. The inability to +* satisfy the full request is an error. +*/ +int csprng_bytes (void *buf,size_t len); +#endif /* WRAPPER_H */
PATCH 3/6 common.h: move non-compat specific macros and functions from git-compat-util.h
In reply to Calvin Wangit-compat-util.h has grown to a large and difficult to read file partly because its set of functionality is overloaded. Besides being a compatibility file that ensures Git's operation across different operating systems, it has also become a dumping ground for commonly used macros and static inline functions.
This commit separates out macros and static inline functions that are compatible across operating systems into common.h. common.h is reincluded back into git-compat-util.h so that other files do not also have to include it. The eventual goal is for common.h to be separated out into more reasonable boundaries, but for now this should be a good first step towards that goal.
--- common.h | 475 ++++++++++++++++++++++++++++++++++++++++++++++ git-compat-util.h | 467 +-------------------------------------------- 2 files changed, 477 insertions(+), 465 deletions(-) create mode 100644 common.h
common.h new file +475 -0
@@ -0,0 +1,475 @@ +#ifndef COMMON_H +#define COMMON_H + +#include "git-compat-util.h" +#include "wrapper.h" + +/* +* ARRAY_SIZE - get the number of elements in a visible array +* @x: the array whose size you want. +* +* This does not work on pointers, or arrays declared as [], or +* function parameters. With correct compiler support, such usage +* will cause a build error (see the build_assert_or_zero macro). +*/ +#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]) + BARF_UNLESS_AN_ARRAY(x)) + +#define bitsizeof (x) (CHAR_BIT * sizeof(x)) + +#define maximum_signed_value_of_type (a) \ + (INTMAX_MAX >> (bitsizeof(intmax_t) - bitsizeof(a))) + +#define maximum_unsigned_value_of_type (a) \ + (UINTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a))) + +/* +* Signed integer overflow is undefined in C, so here's a helper macro +* to detect if the sum of two integers will overflow. +* +* Requires: a >= 0, typeof(a) equals typeof(b) +*/ +#define signed_add_overflows (a, b) \ + ((b) > maximum_signed_value_of_type(a) - (a)) + +#define unsigned_add_overflows (a, b) \ + ((b) > maximum_unsigned_value_of_type(a) - (a)) + +/* +* Returns true if the multiplication of "a" and "b" will +* overflow. The types of "a" and "b" must match and must be unsigned. +* Note that this macro evaluates "a" twice! +*/ +#define unsigned_mult_overflows (a, b) \ + ((a) && (b) > maximum_unsigned_value_of_type(a) / (a)) + +/* +* Returns true if the left shift of "a" by "shift" bits will +* overflow. The type of "a" must be unsigned. +*/ +#define unsigned_left_shift_overflows (a, shift) \ + ((shift) < bitsizeof(a) && \ + (a) > maximum_unsigned_value_of_type(a) >> (shift)) + +#define MSB (x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits)))) +#define HAS_MULTI_BITS (i) ((i) & ((i) - 1))/* checks if an integer has more than 1 bit set */ + +#define DIV_ROUND_UP (n,d) (((n) + (d) - 1) / (d)) + +/* Approximation of the length of the decimal representation of this type. */ +#define decimal_length (x) ((int)(sizeof(x) * 2.56 + 0.5) + 1) + +/* +* If the string "str" begins with the string found in "prefix", return 1. +* The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in +* the string right after the prefix). +* +* Otherwise, return 0 and leave "out" untouched. +* +* Examples: +* +* [extract branch name, fail if not a branch] +* if (!skip_prefix(ref, "refs/heads/", &branch) +* return -1; +* +* [skip prefix if present, otherwise use whole string] +* skip_prefix(name, "refs/heads/", &name); +*/ +static inline int skip_prefix (const char *str,const char *prefix, +const char **out) +{ +do { +if (!*prefix) { + *out = str; +return 1 ; + } + }while (*str++ == *prefix++); +return 0 ; +} + +/* +* Like skip_prefix, but promises never to read past "len" bytes of the input +* buffer, and returns the remaining number of bytes in "out" via "outlen". +*/ +static inline int skip_prefix_mem (const char *buf,size_t len, +const char *prefix, +const char **out,size_t *outlen) +{ +size_t prefix_len =strlen (prefix); +if (prefix_len <= len && !memcmp (buf, prefix, prefix_len)) { + *out = buf + prefix_len; + *outlen = len - prefix_len; +return 1 ; + } +return 0 ; +} + +/* +* If buf ends with suffix, return 1 and subtract the length of the suffix +* from *len. Otherwise, return 0 and leave *len untouched. +*/ +static inline int strip_suffix_mem (const char *buf,size_t *len, +const char *suffix) +{ +size_t suflen =strlen (suffix); +if (*len < suflen ||memcmp (buf + (*len - suflen), suffix, suflen)) +return 0 ; + *len -= suflen; +return 1 ; +} + +/* +* If str ends with suffix, return 1 and set *len to the size of the string +* without the suffix. Otherwise, return 0 and set *len to the size of the +* string. +* +* Note that we do _not_ NUL-terminate str to the new length. +*/ +static inline int strip_suffix (const char *str,const char *suffix,size_t *len) +{ + *len =strlen (str); +return strip_suffix_mem (str, len, suffix); +} + +#define SWAP (a, b) do { \ + void *_swap_a_ptr = &(a); \ + void *_swap_b_ptr = &(b); \ + unsigned char _swap_buffer[sizeof(a)]; \ + memcpy(_swap_buffer, _swap_a_ptr, sizeof(a)); \ + memcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a) + \ + BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b))); \ + memcpy(_swap_b_ptr, _swap_buffer, sizeof(a)); \ +} while (0) + +static inline size_t st_add (size_t a,size_t b) +{ +if (unsigned_add_overflows (a, b)) +die ("size_t overflow: %" PRIuMAX" + %" PRIuMAX, + (uintmax_t )a, (uintmax_t )b); +return a + b; +} +#define st_add3 (a,b,c) st_add(st_add((a),(b)),(c)) +#define st_add4 (a,b,c,d) st_add(st_add3((a),(b),(c)),(d)) + +static inline size_t st_mult (size_t a,size_t b) +{ +if (unsigned_mult_overflows (a, b)) +die ("size_t overflow: %" PRIuMAX" * %" PRIuMAX, + (uintmax_t )a, (uintmax_t )b); +return a * b; +} + +static inline size_t st_sub (size_t a,size_t b) +{ +if (a < b) +die ("size_t underflow: %" PRIuMAX" - %" PRIuMAX, + (uintmax_t )a, (uintmax_t )b); +return a - b; +} + +static inline size_t st_left_shift (size_t a,unsigned shift) +{ +if (unsigned_left_shift_overflows (a, shift)) +die ("size_t overflow: %" PRIuMAX" << %u" , + (uintmax_t )a, shift); +return a << shift; +} + +static inline unsigned long cast_size_t_to_ulong (size_t a) +{ +if (a != (unsigned long )a) +die ("object too large to read on this platform: %" + PRIuMAX" is cut off to %lu" , + (uintmax_t )a, (unsigned long )a); +return (unsigned long )a; +} + +static inline int cast_size_t_to_int (size_t a) +{ +if (a >INT_MAX ) +die ("number too large to represent as int on this platform: %" PRIuMAX, + (uintmax_t )a); +return (int )a; +} + + +/* +* FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note +* that ptr is used twice, so don't pass e.g. ptr++. +*/ +#define FREE_AND_NULL (p) do { free(p); (p) = NULL; } while (0) + +#define ALLOC_ARRAY (x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc))) +#define CALLOC_ARRAY (x, alloc) (x) = xcalloc((alloc), sizeof(*(x))) +#define REALLOC_ARRAY (x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc))) + +#define COPY_ARRAY (dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \ + BARF_UNLESS_COPYABLE((dst), (src))) +static inline void copy_array (void *dst,const void *src,size_t n,size_t size) +{ +if (n) +memcpy (dst, src,st_mult (size, n)); +} + +#define MOVE_ARRAY (dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \ + BARF_UNLESS_COPYABLE((dst), (src))) +static inline void move_array (void *dst,const void *src,size_t n,size_t size) +{ +if (n) +memmove (dst, src,st_mult (size, n)); +} + +#define DUP_ARRAY (dst, src, n) do { \ + size_t dup_array_n_ = (n); \ + COPY_ARRAY(ALLOC_ARRAY((dst), dup_array_n_), (src), dup_array_n_); \ +} while (0) + +/* +* These functions help you allocate structs with flex arrays, and copy +* the data directly into the array. For example, if you had: +* +* struct foo { +* int bar; +* char name[FLEX_ARRAY]; +* }; +* +* you can do: +* +* struct foo *f; +* FLEX_ALLOC_MEM(f, name, src, len); +* +* to allocate a "foo" with the contents of "src" in the "name" field. +* The resulting struct is automatically zero'd, and the flex-array field +* is NUL-terminated (whether the incoming src buffer was or not). +* +* The FLEXPTR_* variants operate on structs that don't use flex-arrays, +* but do want to store a pointer to some extra data in the same allocated +* block. For example, if you have: +* +* struct foo { +* char *name; +* int bar; +* }; +* +* you can do: +* +* struct foo *f; +* FLEXPTR_ALLOC_STR(f, name, src); +* +* and "name" will point to a block of memory after the struct, which will be +* freed along with the struct (but the pointer can be repointed anywhere). +* +* The *_STR variants accept a string parameter rather than a ptr/len +* combination. +* +* Note that these macros will evaluate the first parameter multiple +* times, and it must be assignable as an lvalue. +*/ +#define FLEX_ALLOC_MEM (x, flexname, buf, len) do { \ + size_t flex_array_len_ = (len); \ + (x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \ + memcpy((void *)(x)->flexname, (buf), flex_array_len_); \ +} while (0) +#define FLEXPTR_ALLOC_MEM (x, ptrname, buf, len) do { \ + size_t flex_array_len_ = (len); \ + (x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \ + memcpy((x) + 1, (buf), flex_array_len_); \ + (x)->ptrname = (void *)((x)+1); \ +} while(0) +#define FLEX_ALLOC_STR (x, flexname, str) \ + FLEX_ALLOC_MEM((x), flexname, (str), strlen(str)) +#define FLEXPTR_ALLOC_STR (x, ptrname, str) \ + FLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str)) + +static inline char *xstrdup_or_null (const char *str) +{ +return str ?xstrdup (str) :NULL ; +} + +static inline size_t xsize_t (off_t len) +{ +if (len <0 || (uintmax_t ) len >SIZE_MAX ) +die ("Cannot handle files this big" ); +return (size_t ) len; +} + +/* in ctype.c, for kwset users */ +extern const unsigned char tolower_trans_tbl[256 ]; + +/* Sane ctype - no locale, and works with signed chars */ +#undef isascii +#undef isspace +#undef isdigit +#undef isalpha +#undef isalnum +#undef isprint +#undef islower +#undef isupper +#undef tolower +#undef toupper +#undef iscntrl +#undef ispunct +#undef isxdigit + +extern const unsigned char sane_ctype[256 ]; +extern const signed char hexval_table[256 ]; +#define GIT_SPACE 0x01 +#define GIT_DIGIT 0x02 +#define GIT_ALPHA 0x04 +#define GIT_GLOB_SPECIAL 0x08 +#define GIT_REGEX_SPECIAL 0x10 +#define GIT_PATHSPEC_MAGIC 0x20 +#define GIT_CNTRL 0x40 +#define GIT_PUNCT 0x80 +#define sane_istest (x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) +#define isascii (x) (((x) & ~0x7f) == 0) +#define isspace (x) sane_istest(x,GIT_SPACE) +#define isdigit (x) sane_istest(x,GIT_DIGIT) +#define isalpha (x) sane_istest(x,GIT_ALPHA) +#define isalnum (x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) +#define isprint (x) ((x) >= 0x20 && (x) <= 0x7e) +#define islower (x) sane_iscase(x, 1) +#define isupper (x) sane_iscase(x, 0) +#define is_glob_special (x) sane_istest(x,GIT_GLOB_SPECIAL) +#define is_regex_special (x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL) +#define iscntrl (x) (sane_istest(x,GIT_CNTRL)) +#define ispunct (x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \ + GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC) +#define isxdigit (x) (hexval_table[(unsigned char)(x)] != -1) +#define tolower (x) sane_case((unsigned char)(x), 0x20) +#define toupper (x) sane_case((unsigned char)(x), 0) +#define is_pathspec_magic (x) sane_istest(x,GIT_PATHSPEC_MAGIC) + +static inline int sane_case (int x,int high) +{ +if (sane_istest (x,GIT_ALPHA )) + x = (x & ~0x20 ) | high; +return x; +} + +static inline int sane_iscase (int x,int is_lower) +{ +if (!sane_istest (x,GIT_ALPHA )) +return 0 ; + +if (is_lower) +return (x &0x20 ) !=0 ; +else +return (x &0x20 ) ==0 ; +} + +/* +* Like skip_prefix, but compare case-insensitively. Note that the comparison +* is done via tolower(), so it is strictly ASCII (no multi-byte characters or +* locale-specific conversions). +*/ +static inline int skip_iprefix (const char *str,const char *prefix, +const char **out) +{ +do { +if (!*prefix) { + *out = str; +return 1 ; + } + }while (tolower (*str++) ==tolower (*prefix++)); +return 0 ; +} + +/* +* Like skip_prefix_mem, but compare case-insensitively. Note that the +* comparison is done via tolower(), so it is strictly ASCII (no multi-byte +* characters or locale-specific conversions). +*/ +static inline int skip_iprefix_mem (const char *buf,size_t len, +const char *prefix, +const char **out,size_t *outlen) +{ +do { +if (!*prefix) { + *out = buf; + *outlen = len; +return 1 ; + } + }while (len-- >0 &&tolower (*buf++) ==tolower (*prefix++)); +return 0 ; +} + +static inline int strtoul_ui (char const *s,int base,unsigned int *result) +{ +unsigned long ul; +char *p; + + errno =0 ; +/* negative values would be accepted by strtoul */ +if (strchr (s,'-' )) +return -1 ; + ul =strtoul (s, &p, base); +if (errno || *p || p == s || (unsigned int ) ul != ul) +return -1 ; + *result = ul; +return 0 ; +} + +static inline int strtol_i (char const *s,int base,int *result) +{ +long ul; +char *p; + + errno =0 ; + ul =strtol (s, &p, base); +if (errno || *p || p == s || (int ) ul != ul) +return -1 ; + *result = ul; +return 0 ; +} + +static inline int regexec_buf (const regex_t *preg,const char *buf,size_t size, +size_t nmatch,regmatch_t pmatch[],int eflags) +{ +assert (nmatch >0 && pmatch); + pmatch[0 ].rm_so =0 ; + pmatch[0 ].rm_eo = size; +return regexec (preg, buf, nmatch, pmatch, eflags |REG_STARTEND ); +} + +/* +* Our code often opens a path to an optional file, to work on its +* contents when we can successfully open it. We can ignore a failure +* to open if such an optional file does not exist, but we do want to +* report a failure in opening for other reasons (e.g. we got an I/O +* error, or the file is there, but we lack the permission to open). +* +* Call this function after seeing an error from open() or fopen() to +* see if the errno indicates a missing file that we can safely ignore. +*/ +static inline int is_missing_file_error (int errno_) +{ +return (errno_ ==ENOENT || errno_ ==ENOTDIR ); +} + +/* +* container_of - Get the address of an object containing a field. +* +* @ptr: pointer to the field. +* @type: type of the object. +* @member: name of the field within the object. +*/ +#define container_of (ptr, type, member) \ + ((type *) ((char *)(ptr) - offsetof(type, member))) + +/* +* helper function for `container_of_or_null' to avoid multiple +* evaluation of @ptr +*/ +static inline void *container_of_or_null_offset (void *ptr,size_t offset) +{ +return ptr ? (char *)ptr - offset :NULL ; +} + +/* +* like `container_of', but allows returned value to be NULL +*/ +#define container_of_or_null (ptr, type, member) \ + (type *)container_of_or_null_offset(ptr, offsetof(type, member)) + + +#endif
git-compat-util.h +2 -465
525 lines not on this page · raw message
Signature · 1 line
2.40.1.606.ga4b1b128d6-goog
Re: [PATCH 3/6] common.h: move non-compat specific macros and functions from git-compat-util.h
Quoted 5 lines · Calvin Wan
git-compat-util.hhas grown to a large and difficult to read file partly because its set of functionality is overloaded. Besides being a compatibility file that ensures Git's operation across different operating systems, it has also become a dumping ground for commonly used macros and static inline functions.
Yeah, compat-util.h started out as a (surprise) "compatibility aid" that isolates the knowledge of platform specific inclusion order, what feature macros to define before including which system header file, etc. "A dumping ground for common stuff"---aptly put ;-).
Quoted 2 lines
This commit separates out macros and static inline functions that are compatible across operating systems into
common.h.
It sounds a bit too generic a name to me, but OK.
At some level I am more or less indifferent, in the sense that both compat-util and common need to be included by a .c file anyway, whether it is _our_ source, or in a future third-party source that wants to link with the libified part of Git, so it does notreally make much of a difference if ARRAY_SIZE() is defined in which one of these two headers. But presumably such a future third-party source may arrange their own system support using their own counterpart to compat-util without using ours, and if that is what motivates this change, I could understand why a more-or-less git-agnostic common.h could be a good idea.
Everything, other than sane-ctype macros, does look like a generally useful git-agnostic helper functions. If we were to move in this direction, I probably would prefer to separate sane-ctype macros in a separate header, simply because they are _designed_ to override system supplied ones and some third-party source may not want to use such a "feature".
Re: [PATCH 3/6] common.h: move non-compat specific macros and functions from git-compat-util.h
Quoted 10 lines
At some level I am more or less indifferent, in the sense that both compat-util and common need to be included by a .c file anyway, whether it is _our_ source, or in a future third-party source that wants to link with the libified part of Git, so it does notreally make much of a difference if
ARRAY_SIZE()is defined in which one of these two headers. But presumably such a future third-party source may arrange their own system support using their own counterpart to compat-util without using ours, and if that is what motivates this change, I could understand why a more-or-less git-agnosticcommon.hcould be a good idea.
Also, a later patch moves ALLOC_GROW and other macros from alloc.h to common.h. I thought it would make more sense to have a common file for these macros to be moved to rather than adding to git-compat-util for the sake of only removing the alloc.h dependency from certain files.
Quoted 6 lines
Everything, other than sane-ctype macros, does look like a generally useful git-agnostic helper functions. If we were to move in this direction, I probably would prefer to separate sane-ctype macros in a separate header, simply because they are _designed_ to override system supplied ones and some third-party source may not want to use such a "feature".
Ah that makes sense that they would belong in a separate file like ctype.h -- I can split those macros out.
PATCH 4/6 usage.h: move declarations for usage.c functions from git-compat-util.h
In reply to Calvin Wan--- common.h | 1 + git-compat-util.h | 54 ------------------------------------------ usage.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 54 deletions(-) create mode 100644 usage.h
common.h +1 -0
@@ -3,6 +3,7 @@#include "git-compat-util.h" #include "wrapper.h" +#include "usage.h" /* * ARRAY_SIZE - get the number of elements in a visible array
git-compat-util.h +0 -54
72 lines not on this page · raw message
usage.h new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.40.1.606.ga4b1b128d6-goog
PATCH 5/6 treewide: remove unnecessary includes for wrapper.h
In reply to Calvin Wan--- apply.c | 1 - builtin/am.c | 1 - builtin/bisect.c | 1 - builtin/branch.c | 1 - builtin/bugreport.c | 1 - builtin/clone.c | 1 - builtin/config.c | 1 - builtin/credential-cache.c | 1 - builtin/difftool.c | 1 - builtin/fast-import.c | 1 - builtin/fmt-merge-msg.c | 1 - builtin/gc.c | 1 - builtin/get-tar-commit-id.c | 1 - builtin/index-pack.c | 1 - builtin/init-db.c | 1 - builtin/merge.c | 1 - builtin/pack-objects.c | 1 - builtin/rebase.c | 1 - builtin/receive-pack.c | 1 - builtin/rerere.c | 1 - builtin/unpack-file.c | 1 - builtin/worktree.c | 1 - bulk-checkin.c | 1 - combine-diff.c | 1 - commit-graph.c | 1 - compat/terminal.c | 1 - config.c | 1 - convert.c | 1 - copy.c | 1 - csum-file.c | 1 - daemon.c | 1 - diff.c | 1 - dir.c | 1 - editor.c | 1 - entry.c | 1 - environment.c | 1 - fetch-pack.c | 1 - gpg-interface.c | 1 - grep.c | 1 - http-backend.c | 1 - imap-send.c | 1 - ll-merge.c | 1 - merge-recursive.c | 1 - notes-merge.c | 1 - object-file.c | 1 - pack-write.c | 1 - packfile.c | 1 - parallel-checkout.c | 1 - path.c | 1 - pkt-line.c | 1 - read-cache.c | 1 - rebase-interactive.c | 1 - refs.c | 1 - rerere.c | 1 - send-pack.c | 1 - sequencer.c | 1 - server-info.c | 1 - setup.c | 1 - shallow.c | 1 - strbuf.c | 1 - streaming.c | 1 - t/helper/test-delta.c | 1 - t/helper/test-fsmonitor-client.c | 1 - t/helper/test-read-cache.c | 1 - tag.c | 1 - tempfile.c | 1 - trace.c | 1 - transport-helper.c | 1 - transport.c | 1 - upload-pack.c | 1 - usage.c | 1 - worktree.c | 1 - wrapper.c | 1 - write-or-die.c | 1 - 74 files changed, 74 deletions(-)
apply.c +0 -1
@@ -30,7 +30,6 @@#include "apply.h" #include "entry.h" #include "setup.h" -#include "wrapper.h" struct gitdiff_data {struct strbuf *root;
builtin/am.c +0 -1
@@ -43,7 +43,6 @@#include "pager.h" #include "repository.h" #include "pretty.h" -#include "wrapper.h" /** * Returns the length of the first line of msg.
builtin/bisect.c +0 -1
@@ -14,7 +14,6 @@#include "prompt.h" #include "quote.h" #include "revision.h" -#include "wrapper.h" static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS") static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
builtin/branch.c +0 -1
@@ -28,7 +28,6 @@#include "worktree.h" #include "help.h" #include "commit-reach.h" -#include "wrapper.h" static const char *const builtin_branch_usage[] = {N_ ("git branch [<options>] [-r | -a] [--merged] [--no-merged]" ),
builtin/bugreport.c +0 -1
@@ -11,7 +11,6 @@#include "diagnose.h" #include "object-file.h" #include "setup.h" -#include "wrapper.h" static void get_system_info (struct strbuf *sys_info) {
builtin/clone.c +0 -1
@@ -42,7 +42,6 @@#include "hook.h" #include "bundle.h" #include "bundle-uri.h" -#include "wrapper.h" /* * Overall FIXMEs:
builtin/config.c +0 -1
@@ -12,7 +12,6 @@#include "quote.h" #include "setup.h" #include "worktree.h" -#include "wrapper.h" static const char *const builtin_config_usage[] = {N_ ("git config [<options>]" ),
builtin/credential-cache.c +0 -1
@@ -1,7 +1,6 @@#include "builtin.h" #include "gettext.h" #include "parse-options.h" -#include "wrapper.h" #include "write-or-die.h" #ifndef NO_UNIX_SOCKETS
builtin/difftool.c +0 -1
@@ -30,7 +30,6 @@#include "dir.h" #include "entry.h" #include "setup.h" -#include "wrapper.h" static int trust_exit_code;
builtin/fast-import.c +0 -1
@@ -26,7 +26,6 @@#include "commit-reach.h" #include "khash.h" #include "date.h" -#include "wrapper.h" #define PACK_ID_BITS 16#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
builtin/fmt-merge-msg.c +0 -1
@@ -3,7 +3,6 @@#include "fmt-merge-msg.h" #include "gettext.h" #include "parse-options.h" -#include "wrapper.h" static const char *const fmt_merge_msg_usage[] = {N_ ("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]" ),
builtin/gc.c +0 -1
@@ -39,7 +39,6 @@#include "hook.h" #include "setup.h" #include "trace2.h" -#include "wrapper.h" #define FAILED_RUN "failed to run %s"
builtin/get-tar-commit-id.c +0 -1
@@ -6,7 +6,6 @@#include "tar.h" #include "builtin.h" #include "quote.h" -#include "wrapper.h" static const char builtin_get_tar_commit_id_usage[] ="git get-tar-commit-id" ;
builtin/index-pack.c +0 -1
@@ -24,7 +24,6 @@#include "replace-object.h" #include "promisor-remote.h" #include "setup.h" -#include "wrapper.h" static const char index_pack_usage[] ="git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])" ;
builtin/init-db.c +0 -1
@@ -15,7 +15,6 @@#include "parse-options.h" #include "setup.h" #include "worktree.h" -#include "wrapper.h" #ifndef DEFAULT_GIT_TEMPLATE_DIR #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
builtin/merge.c +0 -1
@@ -52,7 +52,6 @@#include "commit-reach.h" #include "wt-status.h" #include "commit-graph.h" -#include "wrapper.h" #define DEFAULT_TWOHEAD (1<<0)#define DEFAULT_OCTOPUS (1<<1)
builtin/pack-objects.c +0 -1
@@ -43,7 +43,6 @@#include "promisor-remote.h" #include "pack-mtimes.h" #include "parse-options.h" -#include "wrapper.h" /* * Objects we are going to pack are collected in the `to_pack` structure.
builtin/rebase.c +0 -1
@@ -36,7 +36,6 @@#include "reset.h" #include "trace2.h" #include "hook.h" -#include "wrapper.h" static char const *const builtin_rebase_usage[] = { N_("git rebase [-i] [options] [--exec <cmd>] "
builtin/receive-pack.c +0 -1
@@ -38,7 +38,6 @@#include "worktree.h" #include "shallow.h" #include "parse-options.h" -#include "wrapper.h" static const char *const receive_pack_usage[] = {N_ ("git receive-pack <git-dir>" ),
builtin/rerere.c +0 -1
@@ -6,7 +6,6 @@#include "parse-options.h" #include "string-list.h" #include "rerere.h" -#include "wrapper.h" #include "xdiff/xdiff.h" #include "xdiff-interface.h" #include "pathspec.h"
builtin/unpack-file.c +0 -1
@@ -3,7 +3,6 @@#include "hex.h" #include "object-name.h" #include "object-store.h" -#include "wrapper.h" static char *create_temp_file (struct object_id *oid) {
builtin/worktree.c +0 -1
@@ -19,7 +19,6 @@#include "submodule.h" #include "utf8.h" #include "worktree.h" -#include "wrapper.h" #include "quote.h" #define BUILTIN_WORKTREE_ADD_USAGE \
bulk-checkin.c +0 -1
@@ -17,7 +17,6 @@#include "packfile.h" #include "object-file.h" #include "object-store.h" -#include "wrapper.h" static int odb_transaction_nesting;
combine-diff.c +0 -1
@@ -16,7 +16,6 @@#include "userdiff.h" #include "oid-array.h" #include "revision.h" -#include "wrapper.h" static int compare_paths (const struct combine_diff_path *one,const struct diff_filespec *two)
commit-graph.c +0 -1
@@ -24,7 +24,6 @@#include "json-writer.h" #include "trace2.h" #include "chunk-format.h" -#include "wrapper.h" void git_test_write_commit_graph_or_die (void ) {
compat/terminal.c +0 -1
@@ -6,7 +6,6 @@#include "run-command.h" #include "string-list.h" #include "hashmap.h" -#include "wrapper.h" #if defined(HAVE_DEV_TTY ) || defined(GIT_WINDOWS_NATIVE )
config.c +0 -1
@@ -35,7 +35,6 @@#include "setup.h" #include "trace2.h" #include "worktree.h" -#include "wrapper.h" #include "write-or-die.h" struct config_source {
convert.c +0 -1
@@ -14,7 +14,6 @@#include "trace.h" #include "utf8.h" #include "ll-merge.h" -#include "wrapper.h" /* * convert.c - convert a file when checking it out and checking it in.
copy.c +0 -1
@@ -1,5 +1,4 @@#include "cache.h" -#include "wrapper.h" int copy_fd (int ifd,int ofd) {
csum-file.c +0 -1
@@ -10,7 +10,6 @@#include "git-compat-util.h" #include "progress.h" #include "csum-file.h" -#include "wrapper.h" static void verify_buffer_or_die(struct hashfile *f, const void *buf,
daemon.c +0 -1
@@ -9,7 +9,6 @@#include "setup.h" #include "strbuf.h" #include "string-list.h" -#include "wrapper.h" #ifdef NO_INITGROUPS #define initgroups (x, y) (0)/* nothing */
diff.c +0 -1
@@ -40,7 +40,6 @@#include "object-name.h" #include "setup.h" #include "strmap.h" -#include "wrapper.h" #ifdef NO_FAST_WORKING_DIRECTORY #define FAST_WORKING_DIRECTORY 0
dir.c +0 -1
@@ -26,7 +26,6 @@#include "setup.h" #include "submodule-config.h" #include "trace2.h" -#include "wrapper.h" /* * Tells read_directory_recursive how a file or directory should be treated.
editor.c +0 -1
@@ -10,7 +10,6 @@#include "strvec.h" #include "run-command.h" #include "sigchain.h" -#include "wrapper.h" #ifndef DEFAULT_EDITOR #define DEFAULT_EDITOR "vi"
entry.c +0 -1
@@ -11,7 +11,6 @@#include "fsmonitor.h" #include "entry.h" #include "parallel-checkout.h" -#include "wrapper.h" static void create_directories (const char *path,int path_len,const struct checkout *state)
environment.c +0 -1
@@ -27,7 +27,6 @@#include "setup.h" #include "shallow.h" #include "trace.h" -#include "wrapper.h" #include "write-or-die.h" int trust_executable_bit =1 ;
fetch-pack.c +0 -1
@@ -32,7 +32,6 @@#include "commit-graph.h" #include "sigchain.h" #include "mergesort.h" -#include "wrapper.h" static int transfer_unpack_limit =-1 ;static int fetch_unpack_limit =-1 ;
gpg-interface.c +0 -1
@@ -10,7 +10,6 @@#include "sigchain.h" #include "tempfile.h" #include "alias.h" -#include "wrapper.h" static int git_gpg_config (const char *,const char *,void *);
grep.c +0 -1
@@ -11,7 +11,6 @@#include "commit.h" #include "quote.h" #include "help.h" -#include "wrapper.h" static int grep_source_load (struct grep_source *gs); static int grep_source_is_binary(struct grep_source *gs,
http-backend.c +0 -1
@@ -18,7 +18,6 @@#include "object-store.h" #include "protocol.h" #include "date.h" -#include "wrapper.h" #include "write-or-die.h" static const char content_type[] ="Content-Type" ;
imap-send.c +0 -1
@@ -29,7 +29,6 @@#include "run-command.h" #include "parse-options.h" #include "setup.h" -#include "wrapper.h" #if defined(NO_OPENSSL ) && !defined(HAVE_OPENSSL_CSPRNG )typedef void *SSL ;#endif
ll-merge.c +0 -1
@@ -12,7 +12,6 @@#include "run-command.h" #include "ll-merge.h" #include "quote.h" -#include "wrapper.h" struct ll_merge_driver ;
merge-recursive.c +0 -1
@@ -33,7 +33,6 @@#include "tag.h" #include "tree-walk.h" #include "unpack-trees.h" -#include "wrapper.h" #include "xdiff-interface.h" struct merge_options_internal {
notes-merge.c +0 -1
@@ -19,7 +19,6 @@#include "trace.h" #include "notes-utils.h" #include "commit-reach.h" -#include "wrapper.h" struct notes_merge_pair {struct object_id obj, base, local, remote;
object-file.c +0 -1
@@ -42,7 +42,6 @@#include "setup.h" #include "submodule.h" #include "fsck.h" -#include "wrapper.h" /* The maximum size for an object header. */ #define MAX_HEADER_LEN 32
pack-write.c +0 -1
@@ -10,7 +10,6 @@#include "oidmap.h" #include "pack-objects.h" #include "pack-revindex.h" -#include "wrapper.h" void reset_pack_idx_option (struct pack_idx_option *opts) {
packfile.c +0 -1
@@ -24,7 +24,6 @@#include "commit-graph.h" #include "pack-revindex.h" #include "promisor-remote.h" -#include "wrapper.h" char *odb_pack_name(struct strbuf *buf, const unsigned char *hash,
parallel-checkout.c +0 -1
@@ -12,7 +12,6 @@#include "streaming.h" #include "thread-utils.h" #include "trace2.h" -#include "wrapper.h" struct pc_worker {struct child_process cp;
path.c +0 -1
@@ -18,7 +18,6 @@#include "object-store.h" #include "lockfile.h" #include "exec-cmd.h" -#include "wrapper.h" static int get_st_mode_bits (const char *path,int *mode) {
pkt-line.c +0 -1
@@ -4,7 +4,6 @@#include "hex.h" #include "run-command.h" #include "trace.h" -#include "wrapper.h" #include "write-or-die.h" char packet_buffer[LARGE_PACKET_MAX ];
read-cache.c +0 -1
@@ -38,7 +38,6 @@#include "csum-file.h" #include "promisor-remote.h" #include "hook.h" -#include "wrapper.h" /* Mask for the name length in ce_flags in the on-disk index */
rebase-interactive.c +0 -1
@@ -10,7 +10,6 @@#include "config.h" #include "dir.h" #include "object-name.h" -#include "wrapper.h" static const char edit_todo_list_advice[] = N_("You can fix this with 'git rebase --edit-todo' "
refs.c +0 -1
@@ -28,7 +28,6 @@#include "sigchain.h" #include "date.h" #include "commit.h" -#include "wrapper.h" /* * List of all available backends
rerere.c +0 -1
@@ -17,7 +17,6 @@#include "object-store.h" #include "hash-lookup.h" #include "strmap.h" -#include "wrapper.h" #define RESOLVED 0#define PUNTED 1
send-pack.c +0 -1
@@ -14,7 +14,6 @@#include "quote.h" #include "transport.h" #include "version.h" -#include "wrapper.h" #include "oid-array.h" #include "gpg-interface.h" #include "shallow.h"
sequencer.c +0 -1
@@ -45,7 +45,6 @@#include "rebase-interactive.h" #include "reset.h" #include "branch.h" -#include "wrapper.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
server-info.c +0 -1
@@ -12,7 +12,6 @@#include "object-file.h" #include "object-store.h" #include "strbuf.h" -#include "wrapper.h" struct update_info_ctx {FILE *cur_fp;
setup.c +0 -1
@@ -12,7 +12,6 @@#include "promisor-remote.h" #include "quote.h" #include "trace2.h" -#include "wrapper.h" static int inside_git_dir =-1 ;static int inside_work_tree =-1 ;
shallow.c +0 -1
@@ -18,7 +18,6 @@#include "commit-reach.h" #include "shallow.h" #include "trace.h" -#include "wrapper.h" void set_alternate_shallow_file (struct repository *r,const char *path,int override) {
strbuf.c +0 -1
@@ -9,7 +9,6 @@#include "string-list.h" #include "utf8.h" #include "date.h" -#include "wrapper.h" int starts_with (const char *str,const char *prefix) {
streaming.c +0 -1
@@ -10,7 +10,6 @@#include "object-store.h" #include "replace-object.h" #include "packfile.h" -#include "wrapper.h" typedef int (*open_istream_fn)(struct git_istream *, struct repository *,
t/helper/test-delta.c +0 -1
@@ -11,7 +11,6 @@#include "test-tool.h" #include "git-compat-util.h" #include "delta.h" -#include "wrapper.h" static const char usage_str[] ="test-tool delta (-d|-p) <from_file> <data_file> <out_file>" ;
t/helper/test-fsmonitor-client.c +0 -1
@@ -10,7 +10,6 @@#include "setup.h" #include "thread-utils.h" #include "trace2.h" -#include "wrapper.h" #ifndef HAVE_FSMONITOR_DAEMON_BACKEND int cmd__fsmonitor_client(int argc UNUSED, const char **argv UNUSED)
t/helper/test-read-cache.c +0 -1
@@ -3,7 +3,6 @@#include "cache.h" #include "config.h" #include "setup.h" -#include "wrapper.h" int cmd__read_cache (int argc,const char **argv) {
tag.c +0 -1
@@ -10,7 +10,6 @@#include "gpg-interface.h" #include "hex.h" #include "packfile.h" -#include "wrapper.h" const char *tag_type ="tag" ;
tempfile.c +0 -1
@@ -46,7 +46,6 @@#include "path.h" #include "tempfile.h" #include "sigchain.h" -#include "wrapper.h" static VOLATILE_LIST_HEAD (tempfile_list);
trace.c +0 -1
@@ -27,7 +27,6 @@#include "quote.h" #include "setup.h" #include "trace.h" -#include "wrapper.h" struct trace_key trace_default_key = {"GIT_TRACE" ,0 ,0 ,0 };struct trace_key trace_perf_key =TRACE_KEY_INIT (PERFORMANCE );
transport-helper.c +0 -1
@@ -18,7 +18,6 @@#include "refspec.h" #include "transport-internal.h" #include "protocol.h" -#include "wrapper.h" static int debug;
transport.c +0 -1
@@ -30,7 +30,6 @@#include "object-store.h" #include "color.h" #include "bundle-uri.h" -#include "wrapper.h" static int transport_use_color =-1 ;static char transport_colors[][COLOR_MAXLEN ] = {
upload-pack.c +0 -1
@@ -32,7 +32,6 @@#include "commit-graph.h" #include "commit-reach.h" #include "shallow.h" -#include "wrapper.h" #include "write-or-die.h" /* Remember to update object flag allocation in object.h */
usage.c +0 -1
@@ -6,7 +6,6 @@#include "git-compat-util.h" #include "gettext.h" #include "trace2.h" -#include "wrapper.h" static void vreportf (const char *prefix,const char *err,va_list params) {
worktree.c +0 -1
@@ -11,7 +11,6 @@#include "dir.h" #include "wt-status.h" #include "config.h" -#include "wrapper.h" void free_worktrees (struct worktree **worktrees) {
wrapper.c +0 -1
@@ -6,7 +6,6 @@#include "config.h" #include "gettext.h" #include "trace2.h" -#include "wrapper.h" static intmax_t count_fsync_writeout_only;static intmax_t count_fsync_hardware_flush;
write-or-die.c +0 -1
@@ -1,7 +1,6 @@#include "git-compat-util.h" #include "config.h" #include "run-command.h" -#include "wrapper.h" #include "write-or-die.h" /*
Signature · 1 line
2.40.1.606.ga4b1b128d6-goog
PATCH 6/6 common: move alloc macros to common.h
In reply to Calvin Wanalloc_nr, ALLOC_GROW, and ALLOC_GROW_BY are commonly used macros for dynamic array allocation. Moving these macros to common.h focuses alloc.[ch] to allocation for Git objects and additionally allows us to remove inclusions to alloc.h from files that solely used the above macros.
--- add-patch.c | 1 - alias.c | 1 - alloc.h | 75 ------------------------------ apply.c | 1 - archive-tar.c | 1 - archive.c | 1 - attr.c | 1 - builtin/blame.c | 1 - builtin/cat-file.c | 1 - builtin/checkout--worker.c | 1 - builtin/config.c | 1 - builtin/credential-cache--daemon.c | 1 - builtin/fetch-pack.c | 1 - builtin/fsmonitor--daemon.c | 1 - builtin/grep.c | 1 - builtin/index-pack.c | 1 - builtin/log.c | 1 - builtin/merge.c | 1 - builtin/mktree.c | 1 - builtin/mv.c | 1 - builtin/name-rev.c | 1 - builtin/pack-objects.c | 1 - builtin/repack.c | 1 - builtin/rev-parse.c | 1 - builtin/revert.c | 1 - builtin/rm.c | 1 - builtin/submodule--helper.c | 1 - bulk-checkin.c | 1 - cache-tree.c | 1 - chunk-format.c | 1 - commit-reach.c | 1 - common.h | 75 ++++++++++++++++++++++++++++++ config.c | 1 - daemon.c | 1 - delta-islands.c | 1 - diff.c | 1 - diffcore-rename.c | 1 - dir-iterator.c | 1 - dir.c | 1 - ewah/bitmap.c | 1 - ewah/ewah_bitmap.c | 1 - fetch-pack.c | 1 - fmt-merge-msg.c | 1 - fsck.c | 1 - help.c | 1 - http-backend.c | 1 - line-log.c | 1 - list-objects-filter-options.c | 1 - list-objects-filter.c | 1 - midx.c | 1 - object-file.c | 1 - oid-array.c | 1 - oidtree.c | 1 - pack-bitmap-write.c | 1 - pack-bitmap.c | 1 - pack-objects.c | 1 - packfile.c | 1 - parallel-checkout.c | 1 - pretty.c | 1 - prio-queue.c | 1 - quote.c | 1 - read-cache.c | 1 - ref-filter.c | 1 - reflog-walk.c | 1 - refs.c | 1 - refspec.c | 1 - remote-curl.c | 1 - remote.c | 1 - rerere.c | 1 - revision.c | 1 - sequencer.c | 1 - server-info.c | 1 - shallow.c | 1 - sigchain.c | 1 - sparse-index.c | 1 - split-index.c | 1 - strbuf.c | 1 - string-list.c | 1 - strvec.c | 1 - submodule-config.c | 1 - submodule.c | 1 - t/helper/test-reach.c | 1 - trace2/tr2_tls.c | 1 - trailer.c | 1 - transport.c | 1 - tree-walk.c | 1 - userdiff.c | 1 - worktree.c | 1 - 88 files changed, 75 insertions(+), 161 deletions(-)
add-patch.c +0 -1
@@ -1,7 +1,6 @@#include "cache.h" #include "add-interactive.h" #include "advice.h" -#include "alloc.h" #include "editor.h" #include "environment.h" #include "gettext.h"
alias.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "alias.h" -#include "alloc.h" #include "config.h" #include "gettext.h" #include "strbuf.h"
alloc.h +0 -75
79 lines not on this page · raw message
apply.c +0 -1
@@ -9,7 +9,6 @@#include "cache.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "object-store.h" #include "blob.h"
archive-tar.c +0 -1
@@ -2,7 +2,6 @@* Copyright (c) 2005, 2006 Rene Scharfe */ #include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "gettext.h" #include "git-zlib.h"
archive.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "environment.h"
attr.c +0 -1
@@ -7,7 +7,6 @@*/ #include "cache.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "exec-cmd.h"
builtin/blame.c +0 -1
@@ -6,7 +6,6 @@*/ #include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "color.h" #include "builtin.h"
builtin/cat-file.c +0 -1
@@ -5,7 +5,6 @@*/ #define USE_THE_INDEX_VARIABLE #include "cache.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "builtin.h"
builtin/checkout--worker.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "config.h" #include "entry.h" #include "gettext.h"
builtin/config.c +0 -1
@@ -1,6 +1,5 @@#include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "color.h" #include "editor.h"
builtin/credential-cache--daemon.c +0 -1
@@ -1,6 +1,5 @@#include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "gettext.h" #include "object-file.h" #include "parse-options.h"
builtin/fetch-pack.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "gettext.h" #include "hex.h" #include "object-file.h"
builtin/fsmonitor--daemon.c +0 -1
@@ -1,6 +1,5 @@#include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
builtin/grep.c +0 -1
@@ -4,7 +4,6 @@* Copyright (c) 2006 Junio C Hamano */ #include "cache.h" -#include "alloc.h" #include "gettext.h" #include "hex.h" #include "repository.h"
builtin/index-pack.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "config.h" #include "delta.h" #include "environment.h"
builtin/log.c +0 -1
@@ -6,7 +6,6 @@*/ #include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
builtin/merge.c +0 -1
@@ -10,7 +10,6 @@#include "cache.h" #include "abspath.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "editor.h" #include "environment.h"
builtin/mktree.c +0 -1
@@ -4,7 +4,6 @@* Copyright (c) Junio C Hamano, 2006, 2009 */ #include "builtin.h" -#include "alloc.h" #include "gettext.h" #include "hex.h" #include "quote.h"
builtin/mv.c +0 -1
@@ -7,7 +7,6 @@#include "builtin.h" #include "abspath.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
builtin/name-rev.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
builtin/pack-objects.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
builtin/repack.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "config.h" #include "dir.h" #include "environment.h"
builtin/rev-parse.c +0 -1
@@ -6,7 +6,6 @@#define USE_THE_INDEX_VARIABLE #include "cache.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "commit.h" #include "environment.h"
builtin/revert.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "builtin.h" #include "parse-options.h"
builtin/rm.c +0 -1
@@ -5,7 +5,6 @@*/ #define USE_THE_INDEX_VARIABLE #include "builtin.h" -#include "alloc.h" #include "advice.h" #include "config.h" #include "lockfile.h"
builtin/submodule--helper.c +0 -1
@@ -1,7 +1,6 @@#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
bulk-checkin.c +0 -1
@@ -2,7 +2,6 @@* Copyright (c) 2011, Google Inc. */ #include "git-compat-util.h" -#include "alloc.h" #include "bulk-checkin.h" #include "environment.h" #include "gettext.h"
cache-tree.c +0 -1
@@ -1,5 +1,4 @@#include "cache.h" -#include "alloc.h" #include "environment.h" #include "hex.h" #include "lockfile.h"
chunk-format.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "chunk-format.h" #include "csum-file.h" #include "gettext.h"
commit-reach.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "commit.h" #include "commit-graph.h" #include "decorate.h"
common.h +75 -0
81 lines not on this page · raw message
config.c +0 -1
@@ -8,7 +8,6 @@#include "cache.h" #include "abspath.h" #include "advice.h" -#include "alloc.h" #include "date.h" #include "branch.h" #include "config.h"
daemon.c +0 -1
@@ -1,6 +1,5 @@#include "cache.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "pkt-line.h"
delta-islands.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "attr.h" #include "object.h" #include "blob.h"
diff.c +0 -1
@@ -3,7 +3,6 @@*/ #include "cache.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "environment.h"
diffcore-rename.c +0 -1
@@ -3,7 +3,6 @@* Copyright (C) 2005 Junio C Hamano */ #include "git-compat-util.h" -#include "alloc.h" #include "diff.h" #include "diffcore.h" #include "object-store.h"
dir-iterator.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "dir.h" #include "iterator.h" #include "dir-iterator.h"
dir.c +0 -1
@@ -7,7 +7,6 @@*/ #include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "dir.h"
ewah/bitmap.c +0 -1
@@ -17,7 +17,6 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ #include "git-compat-util.h" -#include "alloc.h" #include "ewok.h" #define EWAH_MASK (x) ((eword_t)1 << (x % BITS_IN_EWORD))
ewah/ewah_bitmap.c +0 -1
@@ -17,7 +17,6 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ #include "git-compat-util.h" -#include "alloc.h" #include "ewok.h" #include "ewok_rlw.h"
fetch-pack.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "repository.h" #include "config.h" #include "environment.h"
fmt-merge-msg.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "refs.h"
fsck.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "hex.h" #include "object-store.h" #include "repository.h"
help.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "builtin.h" #include "exec-cmd.h"
http-backend.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "git-zlib.h"
line-log.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "line-range.h" #include "hex.h" #include "tag.h"
list-objects-filter-options.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "commit.h" #include "config.h" #include "gettext.h"
list-objects-filter.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "dir.h" #include "gettext.h" #include "hex.h"
midx.c +0 -1
@@ -1,6 +1,5 @@#include "cache.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "csum-file.h" #include "dir.h"
object-file.c +0 -1
@@ -8,7 +8,6 @@*/ #include "cache.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "environment.h"
oid-array.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "oid-array.h" #include "hash-lookup.h"
oidtree.c +0 -1
@@ -4,7 +4,6 @@*/ #include "git-compat-util.h" #include "oidtree.h" -#include "alloc.h" #include "hash.h" struct oidtree_iter_data {
pack-bitmap-write.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
pack-bitmap.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "commit.h" #include "gettext.h" #include "hex.h"
pack-objects.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "object.h" #include "pack.h" #include "pack-objects.h"
packfile.c +0 -1
@@ -1,5 +1,4 @@#include "cache.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
parallel-checkout.c +0 -1
@@ -1,5 +1,4 @@#include "cache.h" -#include "alloc.h" #include "config.h" #include "entry.h" #include "gettext.h"
pretty.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "commit.h" #include "environment.h"
prio-queue.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "prio-queue.h" static inline int compare (struct prio_queue *queue,int i,int j)
quote.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "path.h" #include "quote.h" #include "strbuf.h"
read-cache.c +0 -1
@@ -4,7 +4,6 @@* Copyright (C) Linus Torvalds, 2005 */ #include "cache.h" -#include "alloc.h" #include "config.h" #include "diff.h" #include "diffcore.h"
ref-filter.c +0 -1
@@ -1,5 +1,4 @@#include "cache.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
reflog-walk.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "commit.h" #include "refs.h" #include "diff.h"
refs.c +0 -1
@@ -4,7 +4,6 @@#include "git-compat-util.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "hashmap.h"
refspec.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "gettext.h" #include "hex.h" #include "strvec.h"
remote-curl.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
remote.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
rerere.c +0 -1
@@ -1,6 +1,5 @@#include "cache.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "gettext.h" #include "hex.h"
revision.c +0 -1
@@ -1,5 +1,4 @@#include "cache.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
sequencer.c +0 -1
@@ -1,7 +1,6 @@#include "cache.h" #include "abspath.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
server-info.c +0 -1
@@ -1,5 +1,4 @@#include "cache.h" -#include "alloc.h" #include "dir.h" #include "environment.h" #include "hex.h"
shallow.c +0 -1
@@ -1,5 +1,4 @@#include "cache.h" -#include "alloc.h" #include "hex.h" #include "repository.h" #include "tempfile.h"
sigchain.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "sigchain.h" #define SIGCHAIN_MAX_SIGNALS 32
sparse-index.c +0 -1
@@ -1,5 +1,4 @@#include "cache.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "repository.h"
split-index.c +0 -1
@@ -1,5 +1,4 @@#include "cache.h" -#include "alloc.h" #include "gettext.h" #include "mem-pool.h" #include "split-index.h"
strbuf.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
string-list.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "string-list.h" -#include "alloc.h" void string_list_init_nodup (struct string_list *list) {
strvec.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "strvec.h" -#include "alloc.h" #include "hex.h" #include "strbuf.h"
submodule-config.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "dir.h" #include "environment.h" #include "gettext.h"
submodule.c +0 -1
@@ -1,6 +1,5 @@#include "cache.h" #include "abspath.h" -#include "alloc.h" #include "repository.h" #include "config.h" #include "submodule-config.h"
t/helper/test-reach.c +0 -1
@@ -1,5 +1,4 @@#include "test-tool.h" -#include "alloc.h" #include "commit.h" #include "commit-reach.h" #include "config.h"
trace2/tr2_tls.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "thread-utils.h" #include "trace.h" #include "trace2/tr2_tls.h"
trailer.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
transport.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "hex.h"
tree-walk.c +0 -1
@@ -1,6 +1,5 @@#include "cache.h" #include "tree-walk.h" -#include "alloc.h" #include "dir.h" #include "gettext.h" #include "hex.h"
userdiff.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "userdiff.h" #include "attr.h"
worktree.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "repository.h"
Signature · 1 line
2.40.1.606.ga4b1b128d6-goog
Quoted 12 lines · Calvin Wan
This series focuses on cleaning up and reducing the scope of
git-compat-util.hby moving headers to their respective files and separating out functionality fromgit-compat-util.hto a new file,common.h. I go into more detail in patch 3 as to why I believe this separation is useful.By the end of this series,
git-compat-util.hincludescommon.hwhich includeswrapper.handusage.h. Since virtually every file includesgit-compat-util.hand the large majority of files use functions defined incommon.h,wrapper.h, andusage.h, I believe it makes sense that those are also automatically included withgit-compat-util.h.
Quoted 3 lines
While this series does not intend to draw clearer boundaries for
common.h, I am open to ideas for how it can be cleaned up more and if there is a better name for the file.
This seems to have been based on 'master' around Apr 25th of this year, like 0807e578 (Merge branch 'en/header-split-cache-h', 2023-04-25). If this were written some time ago and have been tested internally at $WORK or something, *not* rebasing on a later tip of 'master' (which you did) is good, but at the same time, it would be nice to hear on which commit the series is designed to be applied. To prepare for the start of the next cycle, however, it may be even better to rebase it on the tip of more recent 'master' and test it internally (again), and sending the result out as v2 would very much be appreciated ;-)
Thanks.
Quoted 10 lines · Junio C Hamano
This seems to have been based on 'master' around Apr 25th of this year, like
0807e578(Merge branch 'en/header-split-cache-h', 2023-04-25). If this were written some time ago and have been tested internally at $WORK or something, *not* rebasing on a later tip of 'master' (which you did) is good, but at the same time, it would be nice to hear on which commit the series is designed to be applied. To prepare for the start of the next cycle, however, it may be even better to rebase it on the tip of more recent 'master' and test it internally (again), and sending the result out as v2 would very much be appreciated ;-)
ok I'll go ahead and do that
v2 cover git-compat-util cleanups
In reply to Calvin WanChanges since v1:
- rebased onto 8afb38ac80f6
- add a patch to split up sane-ctype macros into a separate file rather than into common.h as suggested by Junio
===
This series focuses on cleaning up and reducing the scope of git-compat-util.h by moving headers to their respective files and separating out functionality from git-compat-util.h to a new file, common.h. I go into more detail in patch 4 as to why I believe this separation is useful.
By the end of this series, git-compat-util.h includes common.h which includes wrapper.h, and usage.h. Since virtually every file includes git-compat-util.h and the large majority of files use functions defined in common.h, wrapper.h, and usage.h, I believe it makes sense that those are also automatically included with git-compat-util.h.
While this series does not intend to draw clearer boundaries for common.h, I am open to ideas for how it can be cleaned up more and if there is a better name for the file.
Calvin Wan (7):
strbuf.h: move declarations for strbuf.c functions from
git-compat-util.h
wrapper.h: move declarations for wrapper.c functions from
git-compat-util.h
sane-ctype.h: move sane-ctype macros from git-compat-util.h common.h: move non-compat specific macros and functions from
git-compat-util.h
usage.h: move declarations for usage.c functions from
git-compat-util.h
treewide: remove unnecessary includes for wrapper.h
common: move alloc macros to common.h
add-patch.c | 1 - alias.c | 1 - alloc.h | 75 ---- apply.c | 2 - archive-tar.c | 1 - archive.c | 1 - attr.c | 1 - builtin/am.c | 1 - builtin/bisect.c | 1 - builtin/blame.c | 1 - builtin/branch.c | 1 - builtin/bugreport.c | 1 - builtin/cat-file.c | 1 - builtin/checkout--worker.c | 1 - builtin/clone.c | 1 - builtin/config.c | 2 - builtin/credential-cache--daemon.c | 1 - builtin/credential-cache.c | 1 - builtin/difftool.c | 1 - builtin/fast-import.c | 1 - builtin/fetch-pack.c | 1 - builtin/fmt-merge-msg.c | 1 - builtin/fsmonitor--daemon.c | 1 - builtin/gc.c | 1 - builtin/get-tar-commit-id.c | 1 - builtin/grep.c | 1 - builtin/index-pack.c | 2 - builtin/init-db.c | 1 - builtin/log.c | 1 - builtin/merge.c | 2 - builtin/mktree.c | 1 - builtin/mv.c | 1 - builtin/name-rev.c | 1 - builtin/pack-objects.c | 2 - builtin/rebase.c | 1 - builtin/receive-pack.c | 1 - builtin/repack.c | 1 - builtin/rerere.c | 1 - builtin/rev-parse.c | 1 - builtin/revert.c | 1 - builtin/rm.c | 1 - builtin/submodule--helper.c | 1 - builtin/symbolic-ref.c | 1 + builtin/unpack-file.c | 1 - builtin/unpack-objects.c | 1 + builtin/worktree.c | 1 - bulk-checkin.c | 2 - cache-tree.c | 1 - chunk-format.c | 1 - combine-diff.c | 1 - commit-graph.c | 1 - commit-reach.c | 1 - common.h | 486 +++++++++++++++++++++ compat/terminal.c | 1 - config.c | 2 - convert.c | 1 - copy.c | 1 - csum-file.c | 1 - daemon.c | 2 - delta-islands.c | 1 - diff.c | 2 - diffcore-rename.c | 1 - dir-iterator.c | 1 - dir.c | 2 - editor.c | 1 - entry.c | 1 - environment.c | 1 - ewah/bitmap.c | 1 - ewah/ewah_bitmap.c | 1 - fetch-pack.c | 2 - fmt-merge-msg.c | 1 - fsck.c | 1 - git-compat-util.h | 664 +---------------------------- gpg-interface.c | 1 - grep.c | 1 - help.c | 1 - http-backend.c | 2 - imap-send.c | 1 - line-log.c | 1 - list-objects-filter-options.c | 1 - list-objects-filter.c | 1 - merge-ll.c | 1 - merge-recursive.c | 1 - midx.c | 1 - notes-merge.c | 1 - object-file.c | 2 - oid-array.c | 1 - oidtree.c | 1 - pack-bitmap-write.c | 1 - pack-bitmap.c | 1 - pack-objects.c | 1 - pack-write.c | 1 - packfile.c | 2 - parallel-checkout.c | 2 - path.c | 1 - pkt-line.c | 1 - pretty.c | 1 - prio-queue.c | 1 - quote.c | 1 - read-cache.c | 2 - rebase-interactive.c | 1 - ref-filter.c | 1 - reflog-walk.c | 1 - refs.c | 2 - refspec.c | 1 - remote-curl.c | 1 - remote.c | 1 - rerere.c | 2 - revision.c | 1 - sane-ctype.h | 69 +++ send-pack.c | 1 - sequencer.c | 2 - server-info.c | 2 - setup.c | 1 - shallow.c | 2 - sigchain.c | 1 - sparse-index.c | 1 - split-index.c | 1 - strbuf.c | 2 - strbuf.h | 32 ++ streaming.c | 1 - string-list.c | 1 - strvec.c | 1 - submodule-config.c | 1 - submodule.c | 1 - t/helper/test-delta.c | 1 - t/helper/test-fsmonitor-client.c | 1 - t/helper/test-reach.c | 1 - t/helper/test-read-cache.c | 1 - tag.c | 1 - tempfile.c | 1 - trace.c | 1 - trace2/tr2_tls.c | 1 - trailer.c | 1 - transport-helper.c | 1 - transport.c | 2 - tree-walk.c | 1 - upload-pack.c | 1 - usage.c | 1 - usage.h | 60 +++ userdiff.c | 1 - versioncmp.c | 1 + worktree.c | 2 - wrapper.c | 1 - wrapper.h | 111 +++++ write-or-die.c | 1 - 146 files changed, 764 insertions(+), 896 deletions(-) create mode 100644 common.h create mode 100644 sane-ctype.h create mode 100644 usage.h
Range-diff against v1:
1: c3f998df91 ! 1: a2b7a28e6e strbuf.h: move declarations for strbuf.c functions from git-compat-util.h
@@ Commit message
boundaries of the strbuf library, this commit focuses on first splitting
out headers from git-compat-util.h.
+ ## builtin/symbolic-ref.c ##
+@@
+ #include "gettext.h"
+ #include "refs.h"
+ #include "parse-options.h"
++#include "strbuf.h"
+
+ static const char * const git_symbolic_ref_usage[] = {
+ N_("git symbolic-ref [-m <reason>] <name> <ref>"),
+
+ ## builtin/unpack-objects.c ##
+@@
+ #include "blob.h"
+ #include "commit.h"
+ #include "replace-object.h"
++#include "strbuf.h"
+ #include "tag.h"
+ #include "tree.h"
+ #include "tree-walk.h"
+
## git-compat-util.h ##
@@ git-compat-util.h: void set_warn_routine(report_fn routine);
report_fn get_warn_routine(void);
@@ strbuf.h: char *xstrvfmt(const char *fmt, va_list ap);
+}
+
#endif /* STRBUF_H */
+
+ ## versioncmp.c ##
+@@
+ #include "git-compat-util.h"
+ #include "config.h"
++#include "strbuf.h"
+ #include "string-list.h"
+ #include "versioncmp.h"
+
2: 71176763ff ! 2: b12fb0e2ff wrapper.h: move declarations for wrapper.c functions from git-compat-util.h
@@ Commit message
## git-compat-util.h ##
@@ git-compat-util.h: static inline int git_has_dir_sep(const char *path)
+
#include "compat/bswap.h"
- #include "wildmatch.h"
--
-struct strbuf;
+#include "wrapper.h"-: ---------- > 3: 016f671836 sane-ctype.h: move sane-ctype macros from git-compat-util.h
3: 6c905444cd ! 4: 244650e5c9 common.h: move non-compat specific macros and functions from git-compat-util.h
@@ common.h (new)
+ return (size_t) len;
+}
+
-+/* in ctype.c, for kwset users */
-+extern const unsigned char tolower_trans_tbl[256];
-+
-+/* Sane ctype - no locale, and works with signed chars */
-+#undef isascii
-+#undef isspace
-+#undef isdigit
-+#undef isalpha
-+#undef isalnum
-+#undef isprint
-+#undef islower
-+#undef isupper
-+#undef tolower
-+#undef toupper
-+#undef iscntrl
-+#undef ispunct
-+#undef isxdigit
-+
-+extern const unsigned char sane_ctype[256];
-+extern const signed char hexval_table[256];
-+#define GIT_SPACE 0x01
-+#define GIT_DIGIT 0x02
-+#define GIT_ALPHA 0x04
-+#define GIT_GLOB_SPECIAL 0x08
-+#define GIT_REGEX_SPECIAL 0x10
-+#define GIT_PATHSPEC_MAGIC 0x20
-+#define GIT_CNTRL 0x40
-+#define GIT_PUNCT 0x80
-+#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
-+#define isascii(x) (((x) & ~0x7f) == 0)
-+#define isspace(x) sane_istest(x,GIT_SPACE)
-+#define isdigit(x) sane_istest(x,GIT_DIGIT)
-+#define isalpha(x) sane_istest(x,GIT_ALPHA)
-+#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
-+#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)
-+#define islower(x) sane_iscase(x, 1)
-+#define isupper(x) sane_iscase(x, 0)
-+#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
-+#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)
-+#define iscntrl(x) (sane_istest(x,GIT_CNTRL))
-+#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \
-+ GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)
-+#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)
-+#define tolower(x) sane_case((unsigned char)(x), 0x20)
-+#define toupper(x) sane_case((unsigned char)(x), 0)
-+#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)
-+
-+static inline int sane_case(int x, int high)
-+{
-+ if (sane_istest(x, GIT_ALPHA))
-+ x = (x & ~0x20) | high;
-+ return x;
-+}
-+
-+static inline int sane_iscase(int x, int is_lower)
-+{
-+ if (!sane_istest(x, GIT_ALPHA))
-+ return 0;
-+
-+ if (is_lower)
-+ return (x & 0x20) != 0;
-+ else
-+ return (x & 0x20) == 0;
-+}
-+
+/*
+ * Like skip_prefix, but compare case-insensitively. Note that the comparison
+ * is done via tolower(), so it is strictly ASCII (no multi-byte characters or
@@ git-compat-util.h: static inline int cast_size_t_to_int(size_t a)
#define HOST_NAME_MAX 256
#endif
--/* in ctype.c, for kwset users */
--extern const unsigned char tolower_trans_tbl[256];
--
--/* Sane ctype - no locale, and works with signed chars */
--#undef isascii
--#undef isspace
--#undef isdigit
--#undef isalpha
--#undef isalnum
--#undef isprint
--#undef islower
--#undef isupper
--#undef tolower
--#undef toupper
--#undef iscntrl
--#undef ispunct
--#undef isxdigit
--
--extern const unsigned char sane_ctype[256];
--extern const signed char hexval_table[256];
--#define GIT_SPACE 0x01
--#define GIT_DIGIT 0x02
--#define GIT_ALPHA 0x04
--#define GIT_GLOB_SPECIAL 0x08
--#define GIT_REGEX_SPECIAL 0x10
--#define GIT_PATHSPEC_MAGIC 0x20
--#define GIT_CNTRL 0x40
--#define GIT_PUNCT 0x80
--#define sane_istest(x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0)
--#define isascii(x) (((x) & ~0x7f) == 0)
--#define isspace(x) sane_istest(x,GIT_SPACE)
--#define isdigit(x) sane_istest(x,GIT_DIGIT)
--#define isalpha(x) sane_istest(x,GIT_ALPHA)
--#define isalnum(x) sane_istest(x,GIT_ALPHA | GIT_DIGIT)
--#define isprint(x) ((x) >= 0x20 && (x) <= 0x7e)
--#define islower(x) sane_iscase(x, 1)
--#define isupper(x) sane_iscase(x, 0)
--#define is_glob_special(x) sane_istest(x,GIT_GLOB_SPECIAL)
--#define is_regex_special(x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL)
--#define iscntrl(x) (sane_istest(x,GIT_CNTRL))
--#define ispunct(x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \
-- GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC)
--#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)
--#define tolower(x) sane_case((unsigned char)(x), 0x20)
--#define toupper(x) sane_case((unsigned char)(x), 0)
--#define is_pathspec_magic(x) sane_istest(x,GIT_PATHSPEC_MAGIC)
--
--static inline int sane_case(int x, int high)
--{
-- if (sane_istest(x, GIT_ALPHA))
-- x = (x & ~0x20) | high;
-- return x;
--}
--
--static inline int sane_iscase(int x, int is_lower)
--{
-- if (!sane_istest(x, GIT_ALPHA))
-- return 0;
--
-- if (is_lower)
-- return (x & 0x20) != 0;
-- else
-- return (x & 0x20) == 0;
--}
--
+ #include "sane-ctype.h"
+
-/*
- * Like skip_prefix, but compare case-insensitively. Note that the comparison
- * is done via tolower(), so it is strictly ASCII (no multi-byte characters or
4: 280a7492ec ! 5: 91a1253ee6 usage.h: move declarations for usage.c functions from git-compat-util.h
@@ common.h
## git-compat-util.h ##
@@ git-compat-util.h: static inline int git_has_dir_sep(const char *path)
+
#include "compat/bswap.h"
- #include "wildmatch.h"
-#include "wrapper.h"
-
-/* General helper functions */
@@ git-compat-util.h: static inline int git_has_dir_sep(const char *path)
-int error_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
-void warning(const char *err, ...) __attribute__((format (printf, 1, 2)));
-void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
-
+-
#ifndef NO_OPENSSL
#ifdef APPLE_COMMON_CRYPTO
+ #include "compat/apple-common-crypto.h"
@@ git-compat-util.h: void warning_errno(const char *err, ...) __attribute__((format (printf, 1, 2)));
#include <openssl/rand.h>
#endif
5: 9b29a77a90 ! 6: c9850a7c18 treewide: remove unnecessary includes for wrapper.h
@@ Commit message
## apply.c ##
@@
- #include "apply.h"
- #include "entry.h"
- #include "setup.h"
+ #include "symlinks.h"
+ #include "wildmatch.h"
+ #include "ws.h"
-#include "wrapper.h"
struct gitdiff_data {
@@ apply.c
## builtin/am.c ##
@@
- #include "pager.h"
+ #include "path.h"
#include "repository.h"
#include "pretty.h"
-#include "wrapper.h"
@@ builtin/clone.c
## builtin/config.c ##
@@
- #include "quote.h"
#include "setup.h"
+ #include "strbuf.h"
#include "worktree.h"
-#include "wrapper.h"
@@ builtin/config.c
## builtin/credential-cache.c ##
@@
- #include "builtin.h"
- #include "gettext.h"
#include "parse-options.h"
+ #include "path.h"
+ #include "strbuf.h"
-#include "wrapper.h"
#include "write-or-die.h"
@@ builtin/gc.c
## builtin/get-tar-commit-id.c ##
@@
+ #include "commit.h"
#include "tar.h"
- #include "builtin.h"
#include "quote.h"
-#include "wrapper.h"
@@ builtin/index-pack.c
## builtin/init-db.c ##
@@
- #include "parse-options.h"
+ #include "path.h"
#include "setup.h"
- #include "worktree.h"
+ #include "strbuf.h"
-#include "wrapper.h"
- #ifndef DEFAULT_GIT_TEMPLATE_DIR
- #define DEFAULT_GIT_TEMPLATE_DIR "/usr/share/git-core/templates"
+ static int guess_repository_type(const char *git_dir)
+ {
## builtin/merge.c ##
@@
@@ builtin/receive-pack.c
## builtin/rerere.c ##
@@
- #include "parse-options.h"
+ #include "repository.h"
#include "string-list.h"
#include "rerere.h"
-#include "wrapper.h"
@@ builtin/unpack-file.c
@@
#include "hex.h"
#include "object-name.h"
- #include "object-store.h"
+ #include "object-store-ll.h"
-#include "wrapper.h"
static char *create_temp_file(struct object_id *oid)
@@ bulk-checkin.c
@@
#include "packfile.h"
#include "object-file.h"
- #include "object-store.h"
+ #include "object-store-ll.h"
-#include "wrapper.h"
static int odb_transaction_nesting;
@@ combine-diff.c
## commit-graph.c ##
@@
- #include "json-writer.h"
#include "trace2.h"
+ #include "tree.h"
#include "chunk-format.h"
-#include "wrapper.h"
@@ compat/terminal.c
## config.c ##
@@
- #include "setup.h"
- #include "trace2.h"
+ #include "wildmatch.h"
#include "worktree.h"
+ #include "ws.h"
-#include "wrapper.h"
#include "write-or-die.h"
@@ convert.c
@@
#include "trace.h"
#include "utf8.h"
- #include "ll-merge.h"
+ #include "merge-ll.h"
-#include "wrapper.h"
/*
@@ convert.c
## copy.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
+ #include "copy.h"
+ #include "path.h"
-#include "wrapper.h"
int copy_fd(int ifd, int ofd)
@@ copy.c
## csum-file.c ##
@@
- #include "git-compat-util.h"
#include "progress.h"
#include "csum-file.h"
+ #include "hash.h"
-#include "wrapper.h"
static void verify_buffer_or_die(struct hashfile *f,
@@ daemon.c
## diff.c ##
@@
- #include "object-name.h"
#include "setup.h"
#include "strmap.h"
+ #include "ws.h"
-#include "wrapper.h"
#ifdef NO_FAST_WORKING_DIRECTORY
@@ diff.c
## dir.c ##
@@
- #include "setup.h"
- #include "submodule-config.h"
+ #include "symlinks.h"
#include "trace2.h"
+ #include "tree.h"
-#include "wrapper.h"
/*
@@ gpg-interface.c
#include "tempfile.h"
#include "alias.h"
-#include "wrapper.h"
+ #include "environment.h"
static int git_gpg_config(const char *, const char *, void *);
-
## grep.c ##
@@
@@ grep.c
## http-backend.c ##
@@
- #include "object-store.h"
+ #include "object-store-ll.h"
#include "protocol.h"
#include "date.h"
-#include "wrapper.h"
@@ http-backend.c
## imap-send.c ##
@@
- #include "run-command.h"
#include "parse-options.h"
#include "setup.h"
+ #include "strbuf.h"
-#include "wrapper.h"
#if defined(NO_OPENSSL) && !defined(HAVE_OPENSSL_CSPRNG)
typedef void *SSL;
#endif
- ## ll-merge.c ##
+ ## merge-ll.c ##
@@
- #include "run-command.h"
- #include "ll-merge.h"
+ #include "merge-ll.h"
#include "quote.h"
+ #include "strbuf.h"
-#include "wrapper.h"
struct ll_merge_driver;
@@ object-file.c
## pack-write.c ##
@@
- #include "oidmap.h"
- #include "pack-objects.h"
#include "pack-revindex.h"
+ #include "path.h"
+ #include "strbuf.h"
-#include "wrapper.h"
void reset_pack_idx_option(struct pack_idx_option *opts)
@@ packfile.c
## parallel-checkout.c ##
@@
- #include "streaming.h"
+ #include "symlinks.h"
#include "thread-utils.h"
#include "trace2.h"
-#include "wrapper.h"
@@ parallel-checkout.c
## path.c ##
@@
- #include "object-store.h"
+ #include "object-store-ll.h"
#include "lockfile.h"
#include "exec-cmd.h"
-#include "wrapper.h"
@@ rebase-interactive.c
## refs.c ##
@@
- #include "sigchain.h"
#include "date.h"
#include "commit.h"
+ #include "wildmatch.h"
-#include "wrapper.h"
/*
@@ refs.c
## rerere.c ##
@@
- #include "object-store.h"
+ #include "object-store-ll.h"
#include "hash-lookup.h"
#include "strmap.h"
-#include "wrapper.h"
@@ sequencer.c
## server-info.c ##
@@
- #include "object-file.h"
- #include "object-store.h"
+ #include "object-store-ll.h"
+ #include "server-info.h"
#include "strbuf.h"
-#include "wrapper.h"
@@ server-info.c
## setup.c ##
@@
- #include "promisor-remote.h"
#include "quote.h"
#include "trace2.h"
+ #include "worktree.h"
-#include "wrapper.h"
static int inside_git_dir = -1;
@@ setup.c
## shallow.c ##
@@
- #include "commit-reach.h"
#include "shallow.h"
+ #include "statinfo.h"
#include "trace.h"
-#include "wrapper.h"
@@ strbuf.c
## streaming.c ##
@@
- #include "object-store.h"
+ #include "object-store-ll.h"
#include "replace-object.h"
#include "packfile.h"
-#include "wrapper.h"
@@ t/helper/test-fsmonitor-client.c
## t/helper/test-read-cache.c ##
@@
- #include "cache.h"
- #include "config.h"
+ #include "read-cache-ll.h"
+ #include "repository.h"
#include "setup.h"
-#include "wrapper.h"
@@ transport-helper.c
## transport.c ##
@@
- #include "object-store.h"
+ #include "object-store-ll.h"
#include "color.h"
#include "bundle-uri.h"
-#include "wrapper.h"
@@ worktree.c
## wrapper.c ##
@@
- #include "config.h"
- #include "gettext.h"
+ #include "repository.h"
+ #include "strbuf.h"
#include "trace2.h"
-#include "wrapper.h"6: 9604b66c72 ! 7: 067b28ec09 common: move alloc macros to common.h
@@ Commit message
## add-patch.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
#include "add-interactive.h"
#include "advice.h"
-#include "alloc.h"
@@ alloc.h: void *alloc_object_node(struct repository *r);
## apply.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
+ #include "base85.h"
#include "config.h"
- #include "object-store.h"
- #include "blob.h"
+ #include "object-store-ll.h"
## archive-tar.c ##
@@
@@ attr.c
@@
*/
- #include "cache.h"
+ #include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
@@ builtin/cat-file.c
@@
*/
#define USE_THE_INDEX_VARIABLE
- #include "cache.h"
+ #include "builtin.h"
-#include "alloc.h"
#include "config.h"
#include "convert.h"
- #include "builtin.h"
+ #include "diff.h"
## builtin/checkout--worker.c ##
@@
@@ builtin/grep.c
@@
* Copyright (c) 2006 Junio C Hamano
*/
- #include "cache.h"
+ #include "builtin.h"
-#include "alloc.h"
#include "gettext.h"
#include "hex.h"
@@ builtin/log.c
## builtin/merge.c ##
@@
- #include "cache.h"
+ #include "builtin.h"
#include "abspath.h"
#include "advice.h"
-#include "alloc.h"
@@ builtin/repack.c
## builtin/rev-parse.c ##
@@
#define USE_THE_INDEX_VARIABLE
- #include "cache.h"
+ #include "builtin.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
@@ bulk-checkin.c
## cache-tree.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
-#include "alloc.h"
#include "environment.h"
#include "hex.h"
@@ common.h: static inline int cast_size_t_to_int(size_t a)
## config.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
-#include "alloc.h"
@@ config.c
## daemon.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
- #include "pkt-line.h"
+ #include "path.h"
## delta-islands.c ##
@@
@@ delta-islands.c
## diff.c ##
@@
*/
- #include "cache.h"
+ #include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
+ #include "base85.h"
#include "config.h"
#include "convert.h"
- #include "environment.h"
## diffcore-rename.c ##
@@
@@ diffcore-rename.c
-#include "alloc.h"
#include "diff.h"
#include "diffcore.h"
- #include "object-store.h"
+ #include "object-store-ll.h"
## dir-iterator.c ##
@@
@@ fetch-pack.c
-#include "alloc.h"
#include "repository.h"
#include "config.h"
- #include "environment.h"
+ #include "date.h"
## fmt-merge-msg.c ##
@@
@@ fsck.c
@@
#include "git-compat-util.h"
-#include "alloc.h"
+ #include "date.h"
+ #include "dir.h"
#include "hex.h"
- #include "object-store.h"
- #include "repository.h"
## help.c ##
@@
@@ list-objects-filter.c
## midx.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
@@ midx.c
## object-file.c ##
@@
*/
- #include "cache.h"
+ #include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
@@ pack-objects.c
## packfile.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
@@ packfile.c
## parallel-checkout.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "entry.h"
@@ read-cache.c
@@
* Copyright (C) Linus Torvalds, 2005
*/
- #include "cache.h"
+ #include "git-compat-util.h"
-#include "alloc.h"
+ #include "bulk-checkin.h"
#include "config.h"
- #include "diff.h"
- #include "diffcore.h"
+ #include "date.h"
## ref-filter.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
- #include "hex.h"
+ #include "gpg-interface.h"
## reflog-walk.c ##
@@
@@ refspec.c
#include "git-compat-util.h"
-#include "alloc.h"
#include "gettext.h"
+ #include "hash.h"
#include "hex.h"
- #include "strvec.h"
## remote-curl.c ##
@@
@@ remote.c
## rerere.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "config.h"
+ #include "copy.h"
#include "gettext.h"
- #include "hex.h"
## revision.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
-#include "alloc.h"
#include "config.h"
#include "environment.h"
@@ revision.c
## sequencer.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
#include "abspath.h"
#include "advice.h"
-#include "alloc.h"
#include "config.h"
+ #include "copy.h"
#include "environment.h"
- #include "gettext.h"
## server-info.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
-#include "alloc.h"
#include "dir.h"
#include "environment.h"
@@ server-info.c
## shallow.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
-#include "alloc.h"
#include "hex.h"
#include "repository.h"
@@ sigchain.c
## sparse-index.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
- #include "repository.h"
+ #include "name-hash.h"
## split-index.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
-#include "alloc.h"
#include "gettext.h"
+ #include "hash.h"
#include "mem-pool.h"
- #include "split-index.h"
## strbuf.c ##
@@
#include "git-compat-util.h"
- #include "abspath.h"
-#include "alloc.h"
- #include "environment.h"
#include "gettext.h"
#include "hex.h"
+ #include "path.h"
## string-list.c ##
@@
@@ submodule-config.c
## submodule.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
#include "abspath.h"
-#include "alloc.h"
#include "repository.h"
@@ transport.c
## tree-walk.c ##
@@
- #include "cache.h"
+ #include "git-compat-util.h"
#include "tree-walk.h"
-#include "alloc.h"
#include "dir.h"
@@ worktree.c
-#include "alloc.h"
#include "environment.h"
#include "gettext.h"
- #include "repository.h"
+ #include "path.h"Signature · 1 line
2.40.1.698.g37aff9b760-goog
PATCH v2 1/7 strbuf.h: move declarations for strbuf.c functions from git-compat-util.h
While functions like starts_with() probably should not belong in the boundaries of the strbuf library, this commit focuses on first splitting out headers from git-compat-util.h.
--- builtin/symbolic-ref.c | 1 + builtin/unpack-objects.c | 1 + git-compat-util.h | 32 -------------------------------- strbuf.h | 32 ++++++++++++++++++++++++++++++++ versioncmp.c | 1 + 5 files changed, 35 insertions(+), 32 deletions(-)
builtin/symbolic-ref.c +1 -0
@@ -3,6 +3,7 @@#include "gettext.h" #include "refs.h" #include "parse-options.h" +#include "strbuf.h" static const char *const git_symbolic_ref_usage[] = {N_ ("git symbolic-ref [-m <reason>] <name> <ref>" ),
builtin/unpack-objects.c +1 -0
@@ -12,6 +12,7 @@#include "blob.h" #include "commit.h" #include "replace-object.h" +#include "strbuf.h" #include "tag.h" #include "tree.h" #include "tree-walk.h"
git-compat-util.h +0 -32
@@ -677,9 +677,6 @@ void set_warn_routine(report_fn routine);report_fn get_warn_routine (void );void set_die_is_recursing_routine (int (*routine)(void )); -int starts_with (const char *str,const char *prefix); -int istarts_with (const char *str,const char *prefix); -/* * If the string "str" begins with the string found in "prefix", return 1. * The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in
@@ -708,29 +705,6 @@ static inline int skip_prefix(const char *str, const char *prefix,return 0 ; } -/* -* If the string "str" is the same as the string in "prefix", then the "arg" -* parameter is set to the "def" parameter and 1 is returned. -* If the string "str" begins with the string found in "prefix" and then a -* "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1" -* (i.e., to the point in the string right after the prefix and the "=" sign), -* and 1 is returned. -* -* Otherwise, return 0 and leave "arg" untouched. -* -* When we accept both a "--key" and a "--key=<val>" option, this function -* can be used instead of !strcmp(arg, "--key") and then -* skip_prefix(arg, "--key=", &arg) to parse such an option. -*/ -int skip_to_optional_arg_default (const char *str,const char *prefix, -const char **arg,const char *def); - -static inline int skip_to_optional_arg (const char *str,const char *prefix, -const char **arg) -{ -return skip_to_optional_arg_default (str, prefix, arg,"" ); -} -/* * Like skip_prefix, but promises never to read past "len" bytes of the input * buffer, and returns the remaining number of bytes in "out" via "outlen".
@@ -775,12 +749,6 @@ static inline int strip_suffix(const char *str, const char *suffix, size_t *len)return strip_suffix_mem (str, len, suffix); } -static inline int ends_with (const char *str,const char *suffix) -{ -size_t len; -return strip_suffix (str, suffix, &len); -} -#define SWAP (a, b) do { \ void *_swap_a_ptr = &(a); \ void *_swap_b_ptr = &(b); \
strbuf.h +32 -0
@@ -698,4 +698,36 @@ char *xstrvfmt(const char *fmt, va_list ap); __attribute__((format (printf,1 ,2 )))char *xstrfmt (const char *fmt, ...); +int starts_with (const char *str,const char *prefix); +int istarts_with (const char *str,const char *prefix); + +/* +* If the string "str" is the same as the string in "prefix", then the "arg" +* parameter is set to the "def" parameter and 1 is returned. +* If the string "str" begins with the string found in "prefix" and then a +* "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1" +* (i.e., to the point in the string right after the prefix and the "=" sign), +* and 1 is returned. +* +* Otherwise, return 0 and leave "arg" untouched. +* +* When we accept both a "--key" and a "--key=<val>" option, this function +* can be used instead of !strcmp(arg, "--key") and then +* skip_prefix(arg, "--key=", &arg) to parse such an option. +*/ +int skip_to_optional_arg_default (const char *str,const char *prefix, +const char **arg,const char *def); + +static inline int skip_to_optional_arg (const char *str,const char *prefix, +const char **arg) +{ +return skip_to_optional_arg_default (str, prefix, arg,"" ); +} + +static inline int ends_with (const char *str,const char *suffix) +{ +size_t len; +return strip_suffix (str, suffix, &len); +} +#endif /* STRBUF_H */
versioncmp.c +1 -0
@@ -1,5 +1,6 @@#include "git-compat-util.h" #include "config.h" +#include "strbuf.h" #include "string-list.h" #include "versioncmp.h"
Signature · 1 line
2.40.1.698.g37aff9b760-goog
Re: [PATCH v2 1/7] strbuf.h: move declarations for strbuf.c functions from git-compat-util.h
Quoted 5 lines · Calvin Wan
While functions like
starts_with()probably should not belong in the boundaries of the strbuf library, this commit focuses on first splitting out headers fromgit-compat-util.h.Signed-off-by Calvin Wan <[email protected]>
I know we don't follow the 50-character rule for commit message headers all the time, but I don't think it's necessary to break it here for a relatively simple-to-explain change. Maybe "git-compat-util: move strbuf.c funcs to its header". Same for the other patches.
The patch itself looks good.
PATCH v2 2/7 wrapper.h: move declarations for wrapper.c functions from git-compat-util.h
In reply to Calvin WanSince the functions in wrapper.c are widely used across the codebase, include it by default in git-compat-util.h. A future patch will remove now unnecessary inclusions of wrapper.h from other files.
--- git-compat-util.h | 112 +--------------------------------------------- wrapper.h | 111 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 111 deletions(-)
git-compat-util.h +1 -111
@@ -625,7 +625,7 @@ static inline int git_has_dir_sep(const char *path)#include "compat/bswap.h" -struct strbuf ; +#include "wrapper.h" /* General helper functions */ NORETURN void usage(const char *err);
@@ -1045,36 +1045,6 @@ static inline int cast_size_t_to_int(size_t a)# define xalloca (size) (xmalloc(size))# define xalloca_free (p) (free(p))#endif -char *xstrdup (const char *str); -void *xmalloc (size_t size); -void *xmallocz (size_t size); -void *xmallocz_gently (size_t size); -void *xmemdupz (const void *data,size_t len); -char *xstrndup (const char *str,size_t len); -void *xrealloc (void *ptr,size_t size); -void *xcalloc (size_t nmemb,size_t size); -void xsetenv (const char *name,const char *value,int overwrite); -void *xmmap (void *start,size_t length,int prot,int flags,int fd,off_t offset); -const char *mmap_os_err (void ); -void *xmmap_gently (void *start,size_t length,int prot,int flags,int fd,off_t offset); -int xopen (const char *path,int flags, ...); -ssize_t xread (int fd,void *buf,size_t len); -ssize_t xwrite (int fd,const void *buf,size_t len); -ssize_t xpread (int fd,void *buf,size_t len,off_t offset); -int xdup (int fd); -FILE *xfopen (const char *path,const char *mode); -FILE *xfdopen (int fd,const char *mode); -int xmkstemp (char *temp_filename); -int xmkstemp_mode (char *temp_filename,int mode); -char *xgetcwd (void ); -FILE *fopen_for_writing (const char *path); -FILE *fopen_or_warn (const char *path,const char *mode); - -/* -* Like strncmp, but only return zero if s is NUL-terminated and exactly len -* characters long. If it is not, consider it greater than t. -*/ -int xstrncmpz (const char *s,const char *t,size_t len);/* * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note
@@ -1176,15 +1146,10 @@ static inline size_t xsize_t(off_t len)return (size_t ) len; } -__attribute__((format (printf,3 ,4 ))) -int xsnprintf (char *dst,size_t max,const char *fmt, ...); -#ifndef HOST_NAME_MAX #define HOST_NAME_MAX 256#endif -int xgethostname (char *buf,size_t len); -/* in ctype.c, for kwset users */ extern const unsigned char tolower_trans_tbl[256 ];
@@ -1425,72 +1390,6 @@ void bug_fl(const char *file, int line, const char *fmt, ...);#endif #endif -enum fsync_action { -FSYNC_WRITEOUT_ONLY , -FSYNC_HARDWARE_FLUSH -}; - -/* -* Issues an fsync against the specified file according to the specified mode. -* -* FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating -* systems to flush the OS cache without issuing a flush command to the storage -* controller. If those interfaces are unavailable, the function fails with -* ENOSYS. -* -* FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that -* changes are durable. It is not expected to fail. -*/ -int git_fsync (int fd,enum fsync_action action); - -/* -* Writes out trace statistics for fsync using the trace2 API. -*/ -void trace_git_fsync_stats (void ); - -/* -* Preserves errno, prints a message, but gives no warning for ENOENT. -* Returns 0 on success, which includes trying to unlink an object that does -* not exist. -*/ -int unlink_or_warn (const char *path); -/* -* Tries to unlink file. Returns 0 if unlink succeeded -* or the file already didn't exist. Returns -1 and -* appends a message to err suitable for -* 'error("%s", err->buf)' on error. -*/ -int unlink_or_msg (const char *file,struct strbuf *err); -/* -* Preserves errno, prints a message, but gives no warning for ENOENT. -* Returns 0 on success, which includes trying to remove a directory that does -* not exist. -*/ -int rmdir_or_warn (const char *path); -/* -* Calls the correct function out of {unlink,rmdir}_or_warn based on -* the supplied file mode. -*/ -int remove_or_warn (unsigned int mode,const char *path); - -/* -* Call access(2), but warn for any error except "missing file" -* (ENOENT or ENOTDIR). -*/ -#define ACCESS_EACCES_OK (1U << 0) -int access_or_warn (const char *path,int mode,unsigned flag); -int access_or_die (const char *path,int mode,unsigned flag); - -/* Warn on an inaccessible file if errno indicates this is an error */ -int warn_on_fopen_errors (const char *path); - -/* -* Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent -* may be racy. Do not use this as protection against an attacker who can -* simultaneously create paths. -*/ -int open_nofollow (const char *path,int flags); -#ifndef SHELL_PATH # define SHELL_PATH "/bin/sh"#endif
@@ -1630,13 +1529,4 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset) ((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))#endif /* !__GNUC__ */ -void sleep_millisec (int millisec); - -/* -* Generate len bytes from the system cryptographically secure PRNG. -* Returns 0 on success and -1 on error, setting errno. The inability to -* satisfy the full request is an error. -*/ -int csprng_bytes (void *buf,size_t len); -#endif
wrapper.h +111 -0
121 lines not on this page · raw message
Signature · 1 line
2.40.1.698.g37aff9b760-goog
Re: [PATCH v2 2/7] wrapper.h: move declarations for wrapper.c functions from git-compat-util.h
Quoted 5 lines · Calvin Wan
Since the functions in
wrapper.care widely used across the codebase, include it by default ingit-compat-util.h. A future patch will remove now unnecessary inclusions ofwrapper.hfrom other files.Signed-off-by Calvin Wan <[email protected]>
Thanks. So currently, if you wanted to xmmap, you don't have to include wrapper.h, but if you wanted to read_in_full, you do. Making Git code treat functions like those 2 in the same way makes sense to me.
PATCH v2 3/7 sane-ctype.h: move sane-ctype macros from git-compat-util.h
In reply to Calvin WanSplitting these macros from git-compat-util.h cleans up the file and allows future third-party sources to not use these overrides if they do not wish to.
--- git-compat-util.h | 65 +------------------------------------------- sane-ctype.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 64 deletions(-) create mode 100644 sane-ctype.h
git-compat-util.h +1 -64
@@ -1150,70 +1150,7 @@ static inline size_t xsize_t(off_t len)#define HOST_NAME_MAX 256#endif -/* in ctype.c, for kwset users */ -extern const unsigned char tolower_trans_tbl[256 ]; - -/* Sane ctype - no locale, and works with signed chars */ -#undef isascii -#undef isspace -#undef isdigit -#undef isalpha -#undef isalnum -#undef isprint -#undef islower -#undef isupper -#undef tolower -#undef toupper -#undef iscntrl -#undef ispunct -#undef isxdigit - -extern const unsigned char sane_ctype[256 ]; -extern const signed char hexval_table[256 ]; -#define GIT_SPACE 0x01 -#define GIT_DIGIT 0x02 -#define GIT_ALPHA 0x04 -#define GIT_GLOB_SPECIAL 0x08 -#define GIT_REGEX_SPECIAL 0x10 -#define GIT_PATHSPEC_MAGIC 0x20 -#define GIT_CNTRL 0x40 -#define GIT_PUNCT 0x80 -#define sane_istest (x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) -#define isascii (x) (((x) & ~0x7f) == 0) -#define isspace (x) sane_istest(x,GIT_SPACE) -#define isdigit (x) sane_istest(x,GIT_DIGIT) -#define isalpha (x) sane_istest(x,GIT_ALPHA) -#define isalnum (x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) -#define isprint (x) ((x) >= 0x20 && (x) <= 0x7e) -#define islower (x) sane_iscase(x, 1) -#define isupper (x) sane_iscase(x, 0) -#define is_glob_special (x) sane_istest(x,GIT_GLOB_SPECIAL) -#define is_regex_special (x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL) -#define iscntrl (x) (sane_istest(x,GIT_CNTRL)) -#define ispunct (x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \ - GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC) -#define isxdigit (x) (hexval_table[(unsigned char)(x)] != -1) -#define tolower (x) sane_case((unsigned char)(x), 0x20) -#define toupper (x) sane_case((unsigned char)(x), 0) -#define is_pathspec_magic (x) sane_istest(x,GIT_PATHSPEC_MAGIC) - -static inline int sane_case (int x,int high) -{ -if (sane_istest (x,GIT_ALPHA )) - x = (x & ~0x20 ) | high; -return x; -} - -static inline int sane_iscase (int x,int is_lower) -{ -if (!sane_istest (x,GIT_ALPHA )) -return 0 ; - -if (is_lower) -return (x &0x20 ) !=0 ; -else -return (x &0x20 ) ==0 ; -} +#include "sane-ctype.h" /* * Like skip_prefix, but compare case-insensitively. Note that the comparison
sane-ctype.h new file +69 -0
69 lines not on this page · raw message
Signature · 1 line
2.40.1.698.g37aff9b760-goog
Re: [PATCH v2 3/7] sane-ctype.h: move sane-ctype macros from git-compat-util.h
Quoted 8 lines · Calvin Wan
Splitting these macros from
git-compat-util.hcleans up the file and allows future third-party sources to not use these overrides if they do not wish to.Signed-off-by Calvin Wan <[email protected]>--- git-compat-util.h | 65 +------------------------------------------- sane-ctype.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++
Any specific reason for the "sane-" prefix? I think it would make more sense if it was just named ctype.h: see below.
git-compat-util.h static inline size_t xsize_t(off_t len) · line 1154
Quoted 2 lines
git-compat-util.h +0
-2-/* in ctype.c, for kwset users */ -extern const unsigned char tolower_trans_tbl[256 ];
I'm not sure what this has to do with sanity, but this is indeed defined in ctype.c, so it's easier to justify moving this out if the criterion was "what's in ctype.c" rather than "what's related to sane ctypes".
Quoted 1 line
-extern const signed char hexval_table[256];
And this one has nothing to do with ctypes or sanity, but rather, what's considered to be a hex character. I think we need another patch to move this to hex.h.
Quoted 1 line
-#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)
Same for this one.
With the above suggestions, I think we do get what we want - a split between things that make ctype more sane and between other compat stuff, and also a split between those two and more platform-agnostic things like what a hex character is.
Re: [PATCH v2 3/7] sane-ctype.h: move sane-ctype macros from git-compat-util.h
Hi Calvin and Jonathan
Quoted 4 lines · Jonathan Tan
Quoted 3 lines · Calvin Wan
Splitting these macros from
git-compat-util.hcleans up the file and allows future third-party sources to not use these overrides if they do not wish to.
I think splitting these out makes sense. If you have time to add a comment highlighting the differences from the standard library versions that would be really helpful. As far as I know the differences are
- our versions are locale independent
- our isspace() does not consider '\v' or '\f' to be space
- our versions expect a signed or unsigned char rather than an int as their argument
- our versions do not accept EOF
- our versions do not require an explicit cast to avoid undefined behavior when passing char on systems where char is signed
Quoted 7 lines
Quoted 4 lines
Signed-off-by Calvin Wan <[email protected]>--- git-compat-util.h | 65 +------------------------------------------- sane-ctype.h | 69 +++++++++++++++++++++++++++++++++++++++++++++++Any specific reason for the "sane-" prefix? I think it would make more sense if it was just named
ctype.h: see below.
I don't have a strong opinion either way but "sane-ctype.h" makes it clearer why we're doing something different to the standard library.
Quoted 6 lines
git-compat-util.h static inline size_t xsize_t(off_t len) · line 1154
Quoted 2 lines
git-compat-util.h +0
-2-/* in ctype.c, for kwset users */ -extern const unsigned char tolower_trans_tbl[256 ];I'm not sure what this has to do with sanity, but this is indeed defined in
ctype.c, so it's easier to justify moving this out if the criterion was "what's inctype.c" rather than "what's related to sane ctypes".
There is only one user of this so it could be moved to diffcore-pickaxe.c or kwset.c where it would be more discoverable if anyone needs to add another user in the future.
Quoted 5 lines
Quoted 1 line
-extern const signed char hexval_table[256];
And this one has nothing to do with ctypes or sanity, but rather, what's considered to be a hex character. I think we need another patch to move this to
hex.h.
Isn't "what's considered to be a hex character" related to ctypes and sanity though as it is used by the "sane" definition of isxdigit().
Quoted 3 lines
Quoted 1 line
-#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)
Same for this one.
I'd much rather keep all of our "sane" ctype replacements in one place as Calvin is proposing. isxdigit() is defined in <ctype.h> so it should be in our "sane" version of that header.
Best Wishes
Phillip
Quoted 4 lines
With the above suggestions, I think we do get what we want - a split between things that make ctype more sane and between other compat stuff, and also a split between those two and more platform-agnostic things like what a hex character is.
Re: [PATCH v2 3/7] sane-ctype.h: move sane-ctype macros from git-compat-util.h
Quoted 5 lines · Phillip Wood
Quoted 2 lines
Any specific reason for the "sane-" prefix? I think it would make more sense if it was just named
ctype.h: see below.I don't have a strong opinion either way but "
sane-ctype.h" makes it clearer why we're doing something different to the standard library.
Ah...that's true.
Quoted 9 lines
Quoted 5 lines
Quoted 1 line
-extern const signed char hexval_table[256];
And this one has nothing to do with ctypes or sanity, but rather, what's considered to be a hex character. I think we need another patch to move this to
hex.h.Isn't "what's considered to be a hex character" related to ctypes and sanity though as it is used by the "sane" definition of
isxdigit().
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
-#define isxdigit(x) (hexval_table[(unsigned char)(x)] != -1)
Same for this one.
I'd much rather keep all of our "sane" ctype replacements in one place as Calvin is proposing.
isxdigit()is defined in <ctype.h> so it should be in our "sane" version of that header.
Good point.
Re: [PATCH v2 3/7] sane-ctype.h: move sane-ctype macros from git-compat-util.h
In reply to Jonathan TanQuoted 2 lines · Jonathan Tan
Any specific reason for the "sane-" prefix? I think it would make more sense if it was just named
ctype.h: see below.
I think it is a good idea to keep the sane prefix for two reasons that were described in 4546738b (Unlocalized isspace and friends, 2005-10-13):
Do our own ctype.h, just to get the sane semantics: we want locale-independence, _and_ we want the right signed behaviour. Plus we only use a very small subset of ctype.h anyway (isspace, isalpha, isdigit and isalnum).
PATCH v2 4/7 common.h: move non-compat specific macros and functions from git-compat-util.h
In reply to Calvin Wangit-compat-util.h has grown to a large and difficult to read file partly because its set of functionality is overloaded. Besides being a compatibility file that ensures Git's operation across different operating systems, it has also become a dumping ground for commonly used macros and static inline functions.
This commit separates out macros and static inline functions that are compatible across operating systems into common.h. common.h is reincluded back into git-compat-util.h so that other files do not also have to include it. The eventual goal is for common.h to be separated out into more reasonable boundaries, but for now this should be a good first step towards that goal.
--- common.h | 410 ++++++++++++++++++++++++++++++++++++++++++++++ git-compat-util.h | 402 +-------------------------------------------- 2 files changed, 412 insertions(+), 400 deletions(-) create mode 100644 common.h
common.h new file +410 -0
@@ -0,0 +1,410 @@ +#ifndef COMMON_H +#define COMMON_H + +#include "git-compat-util.h" +#include "wrapper.h" + +/* +* ARRAY_SIZE - get the number of elements in a visible array +* @x: the array whose size you want. +* +* This does not work on pointers, or arrays declared as [], or +* function parameters. With correct compiler support, such usage +* will cause a build error (see the build_assert_or_zero macro). +*/ +#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]) + BARF_UNLESS_AN_ARRAY(x)) + +#define bitsizeof (x) (CHAR_BIT * sizeof(x)) + +#define maximum_signed_value_of_type (a) \ + (INTMAX_MAX >> (bitsizeof(intmax_t) - bitsizeof(a))) + +#define maximum_unsigned_value_of_type (a) \ + (UINTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a))) + +/* +* Signed integer overflow is undefined in C, so here's a helper macro +* to detect if the sum of two integers will overflow. +* +* Requires: a >= 0, typeof(a) equals typeof(b) +*/ +#define signed_add_overflows (a, b) \ + ((b) > maximum_signed_value_of_type(a) - (a)) + +#define unsigned_add_overflows (a, b) \ + ((b) > maximum_unsigned_value_of_type(a) - (a)) + +/* +* Returns true if the multiplication of "a" and "b" will +* overflow. The types of "a" and "b" must match and must be unsigned. +* Note that this macro evaluates "a" twice! +*/ +#define unsigned_mult_overflows (a, b) \ + ((a) && (b) > maximum_unsigned_value_of_type(a) / (a)) + +/* +* Returns true if the left shift of "a" by "shift" bits will +* overflow. The type of "a" must be unsigned. +*/ +#define unsigned_left_shift_overflows (a, shift) \ + ((shift) < bitsizeof(a) && \ + (a) > maximum_unsigned_value_of_type(a) >> (shift)) + +#define MSB (x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits)))) +#define HAS_MULTI_BITS (i) ((i) & ((i) - 1))/* checks if an integer has more than 1 bit set */ + +#define DIV_ROUND_UP (n,d) (((n) + (d) - 1) / (d)) + +/* Approximation of the length of the decimal representation of this type. */ +#define decimal_length (x) ((int)(sizeof(x) * 2.56 + 0.5) + 1) + +/* +* If the string "str" begins with the string found in "prefix", return 1. +* The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in +* the string right after the prefix). +* +* Otherwise, return 0 and leave "out" untouched. +* +* Examples: +* +* [extract branch name, fail if not a branch] +* if (!skip_prefix(ref, "refs/heads/", &branch) +* return -1; +* +* [skip prefix if present, otherwise use whole string] +* skip_prefix(name, "refs/heads/", &name); +*/ +static inline int skip_prefix (const char *str,const char *prefix, +const char **out) +{ +do { +if (!*prefix) { + *out = str; +return 1 ; + } + }while (*str++ == *prefix++); +return 0 ; +} + +/* +* Like skip_prefix, but promises never to read past "len" bytes of the input +* buffer, and returns the remaining number of bytes in "out" via "outlen". +*/ +static inline int skip_prefix_mem (const char *buf,size_t len, +const char *prefix, +const char **out,size_t *outlen) +{ +size_t prefix_len =strlen (prefix); +if (prefix_len <= len && !memcmp (buf, prefix, prefix_len)) { + *out = buf + prefix_len; + *outlen = len - prefix_len; +return 1 ; + } +return 0 ; +} + +/* +* If buf ends with suffix, return 1 and subtract the length of the suffix +* from *len. Otherwise, return 0 and leave *len untouched. +*/ +static inline int strip_suffix_mem (const char *buf,size_t *len, +const char *suffix) +{ +size_t suflen =strlen (suffix); +if (*len < suflen ||memcmp (buf + (*len - suflen), suffix, suflen)) +return 0 ; + *len -= suflen; +return 1 ; +} + +/* +* If str ends with suffix, return 1 and set *len to the size of the string +* without the suffix. Otherwise, return 0 and set *len to the size of the +* string. +* +* Note that we do _not_ NUL-terminate str to the new length. +*/ +static inline int strip_suffix (const char *str,const char *suffix,size_t *len) +{ + *len =strlen (str); +return strip_suffix_mem (str, len, suffix); +} + +#define SWAP (a, b) do { \ + void *_swap_a_ptr = &(a); \ + void *_swap_b_ptr = &(b); \ + unsigned char _swap_buffer[sizeof(a)]; \ + memcpy(_swap_buffer, _swap_a_ptr, sizeof(a)); \ + memcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a) + \ + BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b))); \ + memcpy(_swap_b_ptr, _swap_buffer, sizeof(a)); \ +} while (0) + +static inline size_t st_add (size_t a,size_t b) +{ +if (unsigned_add_overflows (a, b)) +die ("size_t overflow: %" PRIuMAX" + %" PRIuMAX, + (uintmax_t )a, (uintmax_t )b); +return a + b; +} +#define st_add3 (a,b,c) st_add(st_add((a),(b)),(c)) +#define st_add4 (a,b,c,d) st_add(st_add3((a),(b),(c)),(d)) + +static inline size_t st_mult (size_t a,size_t b) +{ +if (unsigned_mult_overflows (a, b)) +die ("size_t overflow: %" PRIuMAX" * %" PRIuMAX, + (uintmax_t )a, (uintmax_t )b); +return a * b; +} + +static inline size_t st_sub (size_t a,size_t b) +{ +if (a < b) +die ("size_t underflow: %" PRIuMAX" - %" PRIuMAX, + (uintmax_t )a, (uintmax_t )b); +return a - b; +} + +static inline size_t st_left_shift (size_t a,unsigned shift) +{ +if (unsigned_left_shift_overflows (a, shift)) +die ("size_t overflow: %" PRIuMAX" << %u" , + (uintmax_t )a, shift); +return a << shift; +} + +static inline unsigned long cast_size_t_to_ulong (size_t a) +{ +if (a != (unsigned long )a) +die ("object too large to read on this platform: %" + PRIuMAX" is cut off to %lu" , + (uintmax_t )a, (unsigned long )a); +return (unsigned long )a; +} + +static inline int cast_size_t_to_int (size_t a) +{ +if (a >INT_MAX ) +die ("number too large to represent as int on this platform: %" PRIuMAX, + (uintmax_t )a); +return (int )a; +} + + +/* +* FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note +* that ptr is used twice, so don't pass e.g. ptr++. +*/ +#define FREE_AND_NULL (p) do { free(p); (p) = NULL; } while (0) + +#define ALLOC_ARRAY (x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc))) +#define CALLOC_ARRAY (x, alloc) (x) = xcalloc((alloc), sizeof(*(x))) +#define REALLOC_ARRAY (x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc))) + +#define COPY_ARRAY (dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \ + BARF_UNLESS_COPYABLE((dst), (src))) +static inline void copy_array (void *dst,const void *src,size_t n,size_t size) +{ +if (n) +memcpy (dst, src,st_mult (size, n)); +} + +#define MOVE_ARRAY (dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \ + BARF_UNLESS_COPYABLE((dst), (src))) +static inline void move_array (void *dst,const void *src,size_t n,size_t size) +{ +if (n) +memmove (dst, src,st_mult (size, n)); +} + +#define DUP_ARRAY (dst, src, n) do { \ + size_t dup_array_n_ = (n); \ + COPY_ARRAY(ALLOC_ARRAY((dst), dup_array_n_), (src), dup_array_n_); \ +} while (0) + +/* +* These functions help you allocate structs with flex arrays, and copy +* the data directly into the array. For example, if you had: +* +* struct foo { +* int bar; +* char name[FLEX_ARRAY]; +* }; +* +* you can do: +* +* struct foo *f; +* FLEX_ALLOC_MEM(f, name, src, len); +* +* to allocate a "foo" with the contents of "src" in the "name" field. +* The resulting struct is automatically zero'd, and the flex-array field +* is NUL-terminated (whether the incoming src buffer was or not). +* +* The FLEXPTR_* variants operate on structs that don't use flex-arrays, +* but do want to store a pointer to some extra data in the same allocated +* block. For example, if you have: +* +* struct foo { +* char *name; +* int bar; +* }; +* +* you can do: +* +* struct foo *f; +* FLEXPTR_ALLOC_STR(f, name, src); +* +* and "name" will point to a block of memory after the struct, which will be +* freed along with the struct (but the pointer can be repointed anywhere). +* +* The *_STR variants accept a string parameter rather than a ptr/len +* combination. +* +* Note that these macros will evaluate the first parameter multiple +* times, and it must be assignable as an lvalue. +*/ +#define FLEX_ALLOC_MEM (x, flexname, buf, len) do { \ + size_t flex_array_len_ = (len); \ + (x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \ + memcpy((void *)(x)->flexname, (buf), flex_array_len_); \ +} while (0) +#define FLEXPTR_ALLOC_MEM (x, ptrname, buf, len) do { \ + size_t flex_array_len_ = (len); \ + (x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \ + memcpy((x) + 1, (buf), flex_array_len_); \ + (x)->ptrname = (void *)((x)+1); \ +} while(0) +#define FLEX_ALLOC_STR (x, flexname, str) \ + FLEX_ALLOC_MEM((x), flexname, (str), strlen(str)) +#define FLEXPTR_ALLOC_STR (x, ptrname, str) \ + FLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str)) + +static inline char *xstrdup_or_null (const char *str) +{ +return str ?xstrdup (str) :NULL ; +} + +static inline size_t xsize_t (off_t len) +{ +if (len <0 || (uintmax_t ) len >SIZE_MAX ) +die ("Cannot handle files this big" ); +return (size_t ) len; +} + +/* +* Like skip_prefix, but compare case-insensitively. Note that the comparison +* is done via tolower(), so it is strictly ASCII (no multi-byte characters or +* locale-specific conversions). +*/ +static inline int skip_iprefix (const char *str,const char *prefix, +const char **out) +{ +do { +if (!*prefix) { + *out = str; +return 1 ; + } + }while (tolower (*str++) ==tolower (*prefix++)); +return 0 ; +} + +/* +* Like skip_prefix_mem, but compare case-insensitively. Note that the +* comparison is done via tolower(), so it is strictly ASCII (no multi-byte +* characters or locale-specific conversions). +*/ +static inline int skip_iprefix_mem (const char *buf,size_t len, +const char *prefix, +const char **out,size_t *outlen) +{ +do { +if (!*prefix) { + *out = buf; + *outlen = len; +return 1 ; + } + }while (len-- >0 &&tolower (*buf++) ==tolower (*prefix++)); +return 0 ; +} + +static inline int strtoul_ui (char const *s,int base,unsigned int *result) +{ +unsigned long ul; +char *p; + + errno =0 ; +/* negative values would be accepted by strtoul */ +if (strchr (s,'-' )) +return -1 ; + ul =strtoul (s, &p, base); +if (errno || *p || p == s || (unsigned int ) ul != ul) +return -1 ; + *result = ul; +return 0 ; +} + +static inline int strtol_i (char const *s,int base,int *result) +{ +long ul; +char *p; + + errno =0 ; + ul =strtol (s, &p, base); +if (errno || *p || p == s || (int ) ul != ul) +return -1 ; + *result = ul; +return 0 ; +} + +static inline int regexec_buf (const regex_t *preg,const char *buf,size_t size, +size_t nmatch,regmatch_t pmatch[],int eflags) +{ +assert (nmatch >0 && pmatch); + pmatch[0 ].rm_so =0 ; + pmatch[0 ].rm_eo = size; +return regexec (preg, buf, nmatch, pmatch, eflags |REG_STARTEND ); +} + +/* +* Our code often opens a path to an optional file, to work on its +* contents when we can successfully open it. We can ignore a failure +* to open if such an optional file does not exist, but we do want to +* report a failure in opening for other reasons (e.g. we got an I/O +* error, or the file is there, but we lack the permission to open). +* +* Call this function after seeing an error from open() or fopen() to +* see if the errno indicates a missing file that we can safely ignore. +*/ +static inline int is_missing_file_error (int errno_) +{ +return (errno_ ==ENOENT || errno_ ==ENOTDIR ); +} + +/* +* container_of - Get the address of an object containing a field. +* +* @ptr: pointer to the field. +* @type: type of the object. +* @member: name of the field within the object. +*/ +#define container_of (ptr, type, member) \ + ((type *) ((char *)(ptr) - offsetof(type, member))) + +/* +* helper function for `container_of_or_null' to avoid multiple +* evaluation of @ptr +*/ +static inline void *container_of_or_null_offset (void *ptr,size_t offset) +{ +return ptr ? (char *)ptr - offset :NULL ; +} + +/* +* like `container_of', but allows returned value to be NULL +*/ +#define container_of_or_null (ptr, type, member) \ + (type *)container_of_or_null_offset(ptr, offsetof(type, member)) + + +#endif
git-compat-util.h +2 -400
462 lines not on this page · raw message
Signature · 1 line
2.40.1.698.g37aff9b760-goog
PATCH v2 5/7 usage.h: move declarations for usage.c functions from git-compat-util.h
In reply to Calvin Wan--- common.h | 1 + git-compat-util.h | 55 ------------------------------------------- usage.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 55 deletions(-) create mode 100644 usage.h
common.h +1 -0
@@ -3,6 +3,7 @@#include "git-compat-util.h" #include "wrapper.h" +#include "usage.h" /* * ARRAY_SIZE - get the number of elements in a visible array
git-compat-util.h +0 -55
73 lines not on this page · raw message
usage.h new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.40.1.698.g37aff9b760-goog
PATCH v2 6/7 treewide: remove unnecessary includes for wrapper.h
In reply to Calvin Wan--- apply.c | 1 - builtin/am.c | 1 - builtin/bisect.c | 1 - builtin/branch.c | 1 - builtin/bugreport.c | 1 - builtin/clone.c | 1 - builtin/config.c | 1 - builtin/credential-cache.c | 1 - builtin/difftool.c | 1 - builtin/fast-import.c | 1 - builtin/fmt-merge-msg.c | 1 - builtin/gc.c | 1 - builtin/get-tar-commit-id.c | 1 - builtin/index-pack.c | 1 - builtin/init-db.c | 1 - builtin/merge.c | 1 - builtin/pack-objects.c | 1 - builtin/rebase.c | 1 - builtin/receive-pack.c | 1 - builtin/rerere.c | 1 - builtin/unpack-file.c | 1 - builtin/worktree.c | 1 - bulk-checkin.c | 1 - combine-diff.c | 1 - commit-graph.c | 1 - compat/terminal.c | 1 - config.c | 1 - convert.c | 1 - copy.c | 1 - csum-file.c | 1 - daemon.c | 1 - diff.c | 1 - dir.c | 1 - editor.c | 1 - entry.c | 1 - environment.c | 1 - fetch-pack.c | 1 - gpg-interface.c | 1 - grep.c | 1 - http-backend.c | 1 - imap-send.c | 1 - merge-ll.c | 1 - merge-recursive.c | 1 - notes-merge.c | 1 - object-file.c | 1 - pack-write.c | 1 - packfile.c | 1 - parallel-checkout.c | 1 - path.c | 1 - pkt-line.c | 1 - read-cache.c | 1 - rebase-interactive.c | 1 - refs.c | 1 - rerere.c | 1 - send-pack.c | 1 - sequencer.c | 1 - server-info.c | 1 - setup.c | 1 - shallow.c | 1 - strbuf.c | 1 - streaming.c | 1 - t/helper/test-delta.c | 1 - t/helper/test-fsmonitor-client.c | 1 - t/helper/test-read-cache.c | 1 - tag.c | 1 - tempfile.c | 1 - trace.c | 1 - transport-helper.c | 1 - transport.c | 1 - upload-pack.c | 1 - usage.c | 1 - worktree.c | 1 - wrapper.c | 1 - write-or-die.c | 1 - 74 files changed, 74 deletions(-)
apply.c +0 -1
@@ -37,7 +37,6 @@#include "symlinks.h" #include "wildmatch.h" #include "ws.h" -#include "wrapper.h" struct gitdiff_data {struct strbuf *root;
builtin/am.c +0 -1
@@ -44,7 +44,6 @@#include "path.h" #include "repository.h" #include "pretty.h" -#include "wrapper.h" /** * Returns the length of the first line of msg.
builtin/bisect.c +0 -1
@@ -15,7 +15,6 @@#include "prompt.h" #include "quote.h" #include "revision.h" -#include "wrapper.h" static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS") static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
builtin/branch.c +0 -1
@@ -28,7 +28,6 @@#include "worktree.h" #include "help.h" #include "commit-reach.h" -#include "wrapper.h" static const char *const builtin_branch_usage[] = {N_ ("git branch [<options>] [-r | -a] [--merged] [--no-merged]" ),
builtin/bugreport.c +0 -1
@@ -11,7 +11,6 @@#include "diagnose.h" #include "object-file.h" #include "setup.h" -#include "wrapper.h" static void get_system_info (struct strbuf *sys_info) {
builtin/clone.c +0 -1
@@ -45,7 +45,6 @@#include "hook.h" #include "bundle.h" #include "bundle-uri.h" -#include "wrapper.h" /* * Overall FIXMEs:
builtin/config.c +0 -1
@@ -14,7 +14,6 @@#include "setup.h" #include "strbuf.h" #include "worktree.h" -#include "wrapper.h" static const char *const builtin_config_usage[] = {N_ ("git config [<options>]" ),
builtin/credential-cache.c +0 -1
@@ -3,7 +3,6 @@#include "parse-options.h" #include "path.h" #include "strbuf.h" -#include "wrapper.h" #include "write-or-die.h" #ifndef NO_UNIX_SOCKETS
builtin/difftool.c +0 -1
@@ -32,7 +32,6 @@#include "dir.h" #include "entry.h" #include "setup.h" -#include "wrapper.h" static int trust_exit_code;
builtin/fast-import.c +0 -1
@@ -26,7 +26,6 @@#include "commit-reach.h" #include "khash.h" #include "date.h" -#include "wrapper.h" #define PACK_ID_BITS 16#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
builtin/fmt-merge-msg.c +0 -1
@@ -3,7 +3,6 @@#include "fmt-merge-msg.h" #include "gettext.h" #include "parse-options.h" -#include "wrapper.h" static const char *const fmt_merge_msg_usage[] = {N_ ("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]" ),
builtin/gc.c +0 -1
@@ -41,7 +41,6 @@#include "hook.h" #include "setup.h" #include "trace2.h" -#include "wrapper.h" #define FAILED_RUN "failed to run %s"
builtin/get-tar-commit-id.c +0 -1
@@ -5,7 +5,6 @@#include "commit.h" #include "tar.h" #include "quote.h" -#include "wrapper.h" static const char builtin_get_tar_commit_id_usage[] ="git get-tar-commit-id" ;
builtin/index-pack.c +0 -1
@@ -25,7 +25,6 @@#include "replace-object.h" #include "promisor-remote.h" #include "setup.h" -#include "wrapper.h" static const char index_pack_usage[] ="git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])" ;
builtin/init-db.c +0 -1
@@ -13,7 +13,6 @@#include "path.h" #include "setup.h" #include "strbuf.h" -#include "wrapper.h" static int guess_repository_type (const char *git_dir) {
builtin/merge.c +0 -1
@@ -53,7 +53,6 @@#include "commit-reach.h" #include "wt-status.h" #include "commit-graph.h" -#include "wrapper.h" #define DEFAULT_TWOHEAD (1<<0)#define DEFAULT_OCTOPUS (1<<1)
builtin/pack-objects.c +0 -1
@@ -43,7 +43,6 @@#include "promisor-remote.h" #include "pack-mtimes.h" #include "parse-options.h" -#include "wrapper.h" /* * Objects we are going to pack are collected in the `to_pack` structure.
builtin/rebase.c +0 -1
@@ -37,7 +37,6 @@#include "reset.h" #include "trace2.h" #include "hook.h" -#include "wrapper.h" static char const *const builtin_rebase_usage[] = { N_("git rebase [-i] [options] [--exec <cmd>] "
builtin/receive-pack.c +0 -1
@@ -40,7 +40,6 @@#include "worktree.h" #include "shallow.h" #include "parse-options.h" -#include "wrapper.h" static const char *const receive_pack_usage[] = {N_ ("git receive-pack <git-dir>" ),
builtin/rerere.c +0 -1
@@ -6,7 +6,6 @@#include "repository.h" #include "string-list.h" #include "rerere.h" -#include "wrapper.h" #include "xdiff/xdiff.h" #include "xdiff-interface.h" #include "pathspec.h"
builtin/unpack-file.c +0 -1
@@ -3,7 +3,6 @@#include "hex.h" #include "object-name.h" #include "object-store-ll.h" -#include "wrapper.h" static char *create_temp_file (struct object_id *oid) {
builtin/worktree.c +0 -1
@@ -24,7 +24,6 @@#include "submodule.h" #include "utf8.h" #include "worktree.h" -#include "wrapper.h" #include "quote.h" #define BUILTIN_WORKTREE_ADD_USAGE \
bulk-checkin.c +0 -1
@@ -17,7 +17,6 @@#include "packfile.h" #include "object-file.h" #include "object-store-ll.h" -#include "wrapper.h" static int odb_transaction_nesting;
combine-diff.c +0 -1
@@ -17,7 +17,6 @@#include "userdiff.h" #include "oid-array.h" #include "revision.h" -#include "wrapper.h" static int compare_paths (const struct combine_diff_path *one,const struct diff_filespec *two)
commit-graph.c +0 -1
@@ -26,7 +26,6 @@#include "trace2.h" #include "tree.h" #include "chunk-format.h" -#include "wrapper.h" void git_test_write_commit_graph_or_die (void ) {
compat/terminal.c +0 -1
@@ -6,7 +6,6 @@#include "run-command.h" #include "string-list.h" #include "hashmap.h" -#include "wrapper.h" #if defined(HAVE_DEV_TTY ) || defined(GIT_WINDOWS_NATIVE )
config.c +0 -1
@@ -39,7 +39,6 @@#include "wildmatch.h" #include "worktree.h" #include "ws.h" -#include "wrapper.h" #include "write-or-die.h" struct config_source {
convert.c +0 -1
@@ -16,7 +16,6 @@#include "trace.h" #include "utf8.h" #include "merge-ll.h" -#include "wrapper.h" /* * convert.c - convert a file when checking it out and checking it in.
copy.c +0 -1
@@ -1,7 +1,6 @@#include "git-compat-util.h" #include "copy.h" #include "path.h" -#include "wrapper.h" int copy_fd (int ifd,int ofd) {
csum-file.c +0 -1
@@ -11,7 +11,6 @@#include "progress.h" #include "csum-file.h" #include "hash.h" -#include "wrapper.h" static void verify_buffer_or_die(struct hashfile *f, const void *buf,
daemon.c +0 -1
@@ -10,7 +10,6 @@#include "setup.h" #include "strbuf.h" #include "string-list.h" -#include "wrapper.h" #ifdef NO_INITGROUPS #define initgroups (x, y) (0)/* nothing */
diff.c +0 -1
@@ -43,7 +43,6 @@#include "setup.h" #include "strmap.h" #include "ws.h" -#include "wrapper.h" #ifdef NO_FAST_WORKING_DIRECTORY #define FAST_WORKING_DIRECTORY 0
dir.c +0 -1
@@ -32,7 +32,6 @@#include "symlinks.h" #include "trace2.h" #include "tree.h" -#include "wrapper.h" /* * Tells read_directory_recursive how a file or directory should be treated.
editor.c +0 -1
@@ -11,7 +11,6 @@#include "strvec.h" #include "run-command.h" #include "sigchain.h" -#include "wrapper.h" #ifndef DEFAULT_EDITOR #define DEFAULT_EDITOR "vi"
entry.c +0 -1
@@ -14,7 +14,6 @@#include "fsmonitor.h" #include "entry.h" #include "parallel-checkout.h" -#include "wrapper.h" static void create_directories (const char *path,int path_len,const struct checkout *state)
environment.c +0 -1
@@ -28,7 +28,6 @@#include "setup.h" #include "shallow.h" #include "trace.h" -#include "wrapper.h" #include "write-or-die.h" int trust_executable_bit =1 ;
fetch-pack.c +0 -1
@@ -34,7 +34,6 @@#include "commit-graph.h" #include "sigchain.h" #include "mergesort.h" -#include "wrapper.h" static int transfer_unpack_limit =-1 ;static int fetch_unpack_limit =-1 ;
gpg-interface.c +0 -1
@@ -12,7 +12,6 @@#include "sigchain.h" #include "tempfile.h" #include "alias.h" -#include "wrapper.h" #include "environment.h" static int git_gpg_config (const char *,const char *,void *);
grep.c +0 -1
@@ -12,7 +12,6 @@#include "commit.h" #include "quote.h" #include "help.h" -#include "wrapper.h" static int grep_source_load (struct grep_source *gs); static int grep_source_is_binary(struct grep_source *gs,
http-backend.c +0 -1
@@ -19,7 +19,6 @@#include "object-store-ll.h" #include "protocol.h" #include "date.h" -#include "wrapper.h" #include "write-or-die.h" static const char content_type[] ="Content-Type" ;
imap-send.c +0 -1
@@ -30,7 +30,6 @@#include "parse-options.h" #include "setup.h" #include "strbuf.h" -#include "wrapper.h" #if defined(NO_OPENSSL ) && !defined(HAVE_OPENSSL_CSPRNG )typedef void *SSL ;#endif
merge-ll.c +0 -1
@@ -13,7 +13,6 @@#include "merge-ll.h" #include "quote.h" #include "strbuf.h" -#include "wrapper.h" struct ll_merge_driver ;
merge-recursive.c +0 -1
@@ -38,7 +38,6 @@#include "tag.h" #include "tree-walk.h" #include "unpack-trees.h" -#include "wrapper.h" #include "xdiff-interface.h" struct merge_options_internal {
notes-merge.c +0 -1
@@ -20,7 +20,6 @@#include "trace.h" #include "notes-utils.h" #include "commit-reach.h" -#include "wrapper.h" struct notes_merge_pair {struct object_id obj, base, local, remote;
object-file.c +0 -1
@@ -44,7 +44,6 @@#include "setup.h" #include "submodule.h" #include "fsck.h" -#include "wrapper.h" /* The maximum size for an object header. */ #define MAX_HEADER_LEN 32
pack-write.c +0 -1
@@ -12,7 +12,6 @@#include "pack-revindex.h" #include "path.h" #include "strbuf.h" -#include "wrapper.h" void reset_pack_idx_option (struct pack_idx_option *opts) {
packfile.c +0 -1
@@ -24,7 +24,6 @@#include "commit-graph.h" #include "pack-revindex.h" #include "promisor-remote.h" -#include "wrapper.h" char *odb_pack_name(struct strbuf *buf, const unsigned char *hash,
parallel-checkout.c +0 -1
@@ -15,7 +15,6 @@#include "symlinks.h" #include "thread-utils.h" #include "trace2.h" -#include "wrapper.h" struct pc_worker {struct child_process cp;
path.c +0 -1
@@ -18,7 +18,6 @@#include "object-store-ll.h" #include "lockfile.h" #include "exec-cmd.h" -#include "wrapper.h" static int get_st_mode_bits (const char *path,int *mode) {
pkt-line.c +0 -1
@@ -5,7 +5,6 @@#include "hex.h" #include "run-command.h" #include "trace.h" -#include "wrapper.h" #include "write-or-die.h" char packet_buffer[LARGE_PACKET_MAX ];
read-cache.c +0 -1
@@ -46,7 +46,6 @@#include "csum-file.h" #include "promisor-remote.h" #include "hook.h" -#include "wrapper.h" /* Mask for the name length in ce_flags in the on-disk index */
rebase-interactive.c +0 -1
@@ -11,7 +11,6 @@#include "config.h" #include "dir.h" #include "object-name.h" -#include "wrapper.h" static const char edit_todo_list_advice[] = N_("You can fix this with 'git rebase --edit-todo' "
refs.c +0 -1
@@ -30,7 +30,6 @@#include "date.h" #include "commit.h" #include "wildmatch.h" -#include "wrapper.h" /* * List of all available backends
rerere.c +0 -1
@@ -20,7 +20,6 @@#include "object-store-ll.h" #include "hash-lookup.h" #include "strmap.h" -#include "wrapper.h" #define RESOLVED 0#define PUNTED 1
send-pack.c +0 -1
@@ -15,7 +15,6 @@#include "quote.h" #include "transport.h" #include "version.h" -#include "wrapper.h" #include "oid-array.h" #include "gpg-interface.h" #include "shallow.h"
sequencer.c +0 -1
@@ -49,7 +49,6 @@#include "rebase-interactive.h" #include "reset.h" #include "branch.h" -#include "wrapper.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
server-info.c +0 -1
@@ -14,7 +14,6 @@#include "object-store-ll.h" #include "server-info.h" #include "strbuf.h" -#include "wrapper.h" struct update_info_ctx {FILE *cur_fp;
setup.c +0 -1
@@ -17,7 +17,6 @@#include "quote.h" #include "trace2.h" #include "worktree.h" -#include "wrapper.h" static int inside_git_dir =-1 ;static int inside_work_tree =-1 ;
shallow.c +0 -1
@@ -20,7 +20,6 @@#include "shallow.h" #include "statinfo.h" #include "trace.h" -#include "wrapper.h" void set_alternate_shallow_file (struct repository *r,const char *path,int override) {
strbuf.c +0 -1
@@ -7,7 +7,6 @@#include "string-list.h" #include "utf8.h" #include "date.h" -#include "wrapper.h" int starts_with (const char *str,const char *prefix) {
streaming.c +0 -1
@@ -10,7 +10,6 @@#include "object-store-ll.h" #include "replace-object.h" #include "packfile.h" -#include "wrapper.h" typedef int (*open_istream_fn)(struct git_istream *, struct repository *,
t/helper/test-delta.c +0 -1
@@ -11,7 +11,6 @@#include "test-tool.h" #include "git-compat-util.h" #include "delta.h" -#include "wrapper.h" static const char usage_str[] ="test-tool delta (-d|-p) <from_file> <data_file> <out_file>" ;
t/helper/test-fsmonitor-client.c +0 -1
@@ -11,7 +11,6 @@#include "setup.h" #include "thread-utils.h" #include "trace2.h" -#include "wrapper.h" #ifndef HAVE_FSMONITOR_DAEMON_BACKEND int cmd__fsmonitor_client(int argc UNUSED, const char **argv UNUSED)
t/helper/test-read-cache.c +0 -1
@@ -4,7 +4,6 @@#include "read-cache-ll.h" #include "repository.h" #include "setup.h" -#include "wrapper.h" int cmd__read_cache (int argc,const char **argv) {
tag.c +0 -1
@@ -11,7 +11,6 @@#include "gpg-interface.h" #include "hex.h" #include "packfile.h" -#include "wrapper.h" const char *tag_type ="tag" ;
tempfile.c +0 -1
@@ -47,7 +47,6 @@#include "path.h" #include "tempfile.h" #include "sigchain.h" -#include "wrapper.h" static VOLATILE_LIST_HEAD (tempfile_list);
trace.c +0 -1
@@ -27,7 +27,6 @@#include "quote.h" #include "setup.h" #include "trace.h" -#include "wrapper.h" struct trace_key trace_default_key = {"GIT_TRACE" ,0 ,0 ,0 };struct trace_key trace_perf_key =TRACE_KEY_INIT (PERFORMANCE );
transport-helper.c +0 -1
@@ -19,7 +19,6 @@#include "refspec.h" #include "transport-internal.h" #include "protocol.h" -#include "wrapper.h" static int debug;
transport.c +0 -1
@@ -30,7 +30,6 @@#include "object-store-ll.h" #include "color.h" #include "bundle-uri.h" -#include "wrapper.h" static int transport_use_color =-1 ;static char transport_colors[][COLOR_MAXLEN ] = {
upload-pack.c +0 -1
@@ -32,7 +32,6 @@#include "commit-graph.h" #include "commit-reach.h" #include "shallow.h" -#include "wrapper.h" #include "write-or-die.h" /* Remember to update object flag allocation in object.h */
usage.c +0 -1
@@ -6,7 +6,6 @@#include "git-compat-util.h" #include "gettext.h" #include "trace2.h" -#include "wrapper.h" static void vreportf (const char *prefix,const char *err,va_list params) {
worktree.c +0 -1
@@ -12,7 +12,6 @@#include "dir.h" #include "wt-status.h" #include "config.h" -#include "wrapper.h" void free_worktrees (struct worktree **worktrees) {
wrapper.c +0 -1
@@ -9,7 +9,6 @@#include "repository.h" #include "strbuf.h" #include "trace2.h" -#include "wrapper.h" static intmax_t count_fsync_writeout_only;static intmax_t count_fsync_hardware_flush;
write-or-die.c +0 -1
@@ -1,7 +1,6 @@#include "git-compat-util.h" #include "config.h" #include "run-command.h" -#include "wrapper.h" #include "write-or-die.h" /*
Signature · 1 line
2.40.1.698.g37aff9b760-goog
PATCH v2 7/7 common: move alloc macros to common.h
In reply to Calvin Wanalloc_nr, ALLOC_GROW, and ALLOC_GROW_BY are commonly used macros for dynamic array allocation. Moving these macros to common.h focuses alloc.[ch] to allocation for Git objects and additionally allows us to remove inclusions to alloc.h from files that solely used the above macros.
--- add-patch.c | 1 - alias.c | 1 - alloc.h | 75 ------------------------------ apply.c | 1 - archive-tar.c | 1 - archive.c | 1 - attr.c | 1 - builtin/blame.c | 1 - builtin/cat-file.c | 1 - builtin/checkout--worker.c | 1 - builtin/config.c | 1 - builtin/credential-cache--daemon.c | 1 - builtin/fetch-pack.c | 1 - builtin/fsmonitor--daemon.c | 1 - builtin/grep.c | 1 - builtin/index-pack.c | 1 - builtin/log.c | 1 - builtin/merge.c | 1 - builtin/mktree.c | 1 - builtin/mv.c | 1 - builtin/name-rev.c | 1 - builtin/pack-objects.c | 1 - builtin/repack.c | 1 - builtin/rev-parse.c | 1 - builtin/revert.c | 1 - builtin/rm.c | 1 - builtin/submodule--helper.c | 1 - bulk-checkin.c | 1 - cache-tree.c | 1 - chunk-format.c | 1 - commit-reach.c | 1 - common.h | 75 ++++++++++++++++++++++++++++++ config.c | 1 - daemon.c | 1 - delta-islands.c | 1 - diff.c | 1 - diffcore-rename.c | 1 - dir-iterator.c | 1 - dir.c | 1 - ewah/bitmap.c | 1 - ewah/ewah_bitmap.c | 1 - fetch-pack.c | 1 - fmt-merge-msg.c | 1 - fsck.c | 1 - help.c | 1 - http-backend.c | 1 - line-log.c | 1 - list-objects-filter-options.c | 1 - list-objects-filter.c | 1 - midx.c | 1 - object-file.c | 1 - oid-array.c | 1 - oidtree.c | 1 - pack-bitmap-write.c | 1 - pack-bitmap.c | 1 - pack-objects.c | 1 - packfile.c | 1 - parallel-checkout.c | 1 - pretty.c | 1 - prio-queue.c | 1 - quote.c | 1 - read-cache.c | 1 - ref-filter.c | 1 - reflog-walk.c | 1 - refs.c | 1 - refspec.c | 1 - remote-curl.c | 1 - remote.c | 1 - rerere.c | 1 - revision.c | 1 - sequencer.c | 1 - server-info.c | 1 - shallow.c | 1 - sigchain.c | 1 - sparse-index.c | 1 - split-index.c | 1 - strbuf.c | 1 - string-list.c | 1 - strvec.c | 1 - submodule-config.c | 1 - submodule.c | 1 - t/helper/test-reach.c | 1 - trace2/tr2_tls.c | 1 - trailer.c | 1 - transport.c | 1 - tree-walk.c | 1 - userdiff.c | 1 - worktree.c | 1 - 88 files changed, 75 insertions(+), 161 deletions(-)
add-patch.c +0 -1
@@ -1,7 +1,6 @@#include "git-compat-util.h" #include "add-interactive.h" #include "advice.h" -#include "alloc.h" #include "editor.h" #include "environment.h" #include "gettext.h"
alias.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "alias.h" -#include "alloc.h" #include "config.h" #include "gettext.h" #include "strbuf.h"
alloc.h +0 -75
79 lines not on this page · raw message
apply.c +0 -1
@@ -9,7 +9,6 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "base85.h" #include "config.h" #include "object-store-ll.h"
archive-tar.c +0 -1
@@ -2,7 +2,6 @@* Copyright (c) 2005, 2006 Rene Scharfe */ #include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "gettext.h" #include "git-zlib.h"
archive.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "environment.h"
attr.c +0 -1
@@ -7,7 +7,6 @@*/ #include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "exec-cmd.h"
builtin/blame.c +0 -1
@@ -6,7 +6,6 @@*/ #include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "color.h" #include "builtin.h"
builtin/cat-file.c +0 -1
@@ -5,7 +5,6 @@*/ #define USE_THE_INDEX_VARIABLE #include "builtin.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "diff.h"
builtin/checkout--worker.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "config.h" #include "entry.h" #include "gettext.h"
builtin/config.c +0 -1
@@ -1,6 +1,5 @@#include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "color.h" #include "editor.h"
builtin/credential-cache--daemon.c +0 -1
@@ -1,6 +1,5 @@#include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "gettext.h" #include "object-file.h" #include "parse-options.h"
builtin/fetch-pack.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "gettext.h" #include "hex.h" #include "object-file.h"
builtin/fsmonitor--daemon.c +0 -1
@@ -1,6 +1,5 @@#include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
builtin/grep.c +0 -1
@@ -4,7 +4,6 @@* Copyright (c) 2006 Junio C Hamano */ #include "builtin.h" -#include "alloc.h" #include "gettext.h" #include "hex.h" #include "repository.h"
builtin/index-pack.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "config.h" #include "delta.h" #include "environment.h"
builtin/log.c +0 -1
@@ -6,7 +6,6 @@*/ #include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
builtin/merge.c +0 -1
@@ -10,7 +10,6 @@#include "builtin.h" #include "abspath.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "editor.h" #include "environment.h"
builtin/mktree.c +0 -1
@@ -4,7 +4,6 @@* Copyright (c) Junio C Hamano, 2006, 2009 */ #include "builtin.h" -#include "alloc.h" #include "gettext.h" #include "hex.h" #include "quote.h"
builtin/mv.c +0 -1
@@ -7,7 +7,6 @@#include "builtin.h" #include "abspath.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
builtin/name-rev.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
builtin/pack-objects.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
builtin/repack.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "config.h" #include "dir.h" #include "environment.h"
builtin/rev-parse.c +0 -1
@@ -6,7 +6,6 @@#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "commit.h" #include "environment.h"
builtin/revert.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "builtin.h" #include "parse-options.h"
builtin/rm.c +0 -1
@@ -5,7 +5,6 @@*/ #define USE_THE_INDEX_VARIABLE #include "builtin.h" -#include "alloc.h" #include "advice.h" #include "config.h" #include "lockfile.h"
builtin/submodule--helper.c +0 -1
@@ -1,7 +1,6 @@#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
bulk-checkin.c +0 -1
@@ -2,7 +2,6 @@* Copyright (c) 2011, Google Inc. */ #include "git-compat-util.h" -#include "alloc.h" #include "bulk-checkin.h" #include "environment.h" #include "gettext.h"
cache-tree.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "environment.h" #include "hex.h" #include "lockfile.h"
chunk-format.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "chunk-format.h" #include "csum-file.h" #include "gettext.h"
commit-reach.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "commit.h" #include "commit-graph.h" #include "decorate.h"
common.h +75 -0
81 lines not on this page · raw message
config.c +0 -1
@@ -8,7 +8,6 @@#include "git-compat-util.h" #include "abspath.h" #include "advice.h" -#include "alloc.h" #include "date.h" #include "branch.h" #include "config.h"
daemon.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "path.h"
delta-islands.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "attr.h" #include "object.h" #include "blob.h"
diff.c +0 -1
@@ -3,7 +3,6 @@*/ #include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "base85.h" #include "config.h" #include "convert.h"
diffcore-rename.c +0 -1
@@ -3,7 +3,6 @@* Copyright (C) 2005 Junio C Hamano */ #include "git-compat-util.h" -#include "alloc.h" #include "diff.h" #include "diffcore.h" #include "object-store-ll.h"
dir-iterator.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "dir.h" #include "iterator.h" #include "dir-iterator.h"
dir.c +0 -1
@@ -7,7 +7,6 @@*/ #include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "dir.h"
ewah/bitmap.c +0 -1
@@ -17,7 +17,6 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ #include "git-compat-util.h" -#include "alloc.h" #include "ewok.h" #define EWAH_MASK (x) ((eword_t)1 << (x % BITS_IN_EWORD))
ewah/ewah_bitmap.c +0 -1
@@ -17,7 +17,6 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ #include "git-compat-util.h" -#include "alloc.h" #include "ewok.h" #include "ewok_rlw.h"
fetch-pack.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "repository.h" #include "config.h" #include "date.h"
fmt-merge-msg.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "refs.h"
fsck.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "date.h" #include "dir.h" #include "hex.h"
help.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "builtin.h" #include "exec-cmd.h"
http-backend.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "git-zlib.h"
line-log.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "line-range.h" #include "hex.h" #include "tag.h"
list-objects-filter-options.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "commit.h" #include "config.h" #include "gettext.h"
list-objects-filter.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "dir.h" #include "gettext.h" #include "hex.h"
midx.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "csum-file.h" #include "dir.h"
object-file.c +0 -1
@@ -8,7 +8,6 @@*/ #include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "environment.h"
oid-array.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "oid-array.h" #include "hash-lookup.h"
oidtree.c +0 -1
@@ -4,7 +4,6 @@*/ #include "git-compat-util.h" #include "oidtree.h" -#include "alloc.h" #include "hash.h" struct oidtree_iter_data {
pack-bitmap-write.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
pack-bitmap.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "commit.h" #include "gettext.h" #include "hex.h"
pack-objects.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "object.h" #include "pack.h" #include "pack-objects.h"
packfile.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
parallel-checkout.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "entry.h" #include "gettext.h"
pretty.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "commit.h" #include "environment.h"
prio-queue.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "prio-queue.h" static inline int compare (struct prio_queue *queue,int i,int j)
quote.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "path.h" #include "quote.h" #include "strbuf.h"
read-cache.c +0 -1
@@ -4,7 +4,6 @@* Copyright (C) Linus Torvalds, 2005 */ #include "git-compat-util.h" -#include "alloc.h" #include "bulk-checkin.h" #include "config.h" #include "date.h"
ref-filter.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "gpg-interface.h"
reflog-walk.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "commit.h" #include "refs.h" #include "diff.h"
refs.c +0 -1
@@ -4,7 +4,6 @@#include "git-compat-util.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "hashmap.h"
refspec.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "gettext.h" #include "hash.h" #include "hex.h"
remote-curl.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
remote.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
rerere.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "copy.h" #include "gettext.h"
revision.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
sequencer.c +0 -1
@@ -1,7 +1,6 @@#include "git-compat-util.h" #include "abspath.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "copy.h" #include "environment.h"
server-info.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "dir.h" #include "environment.h" #include "hex.h"
shallow.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "hex.h" #include "repository.h" #include "tempfile.h"
sigchain.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "sigchain.h" #define SIGCHAIN_MAX_SIGNALS 32
sparse-index.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "name-hash.h"
split-index.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "gettext.h" #include "hash.h" #include "mem-pool.h"
strbuf.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "gettext.h" #include "hex.h" #include "path.h"
string-list.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "string-list.h" -#include "alloc.h" void string_list_init_nodup (struct string_list *list) {
strvec.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "strvec.h" -#include "alloc.h" #include "hex.h" #include "strbuf.h"
submodule-config.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "dir.h" #include "environment.h" #include "gettext.h"
submodule.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "repository.h" #include "config.h" #include "submodule-config.h"
t/helper/test-reach.c +0 -1
@@ -1,5 +1,4 @@#include "test-tool.h" -#include "alloc.h" #include "commit.h" #include "commit-reach.h" #include "config.h"
trace2/tr2_tls.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "thread-utils.h" #include "trace.h" #include "trace2/tr2_tls.h"
trailer.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
transport.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "hex.h"
tree-walk.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "tree-walk.h" -#include "alloc.h" #include "dir.h" #include "gettext.h" #include "hex.h"
userdiff.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "userdiff.h" #include "attr.h"
worktree.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "path.h"
Signature · 1 line
2.40.1.698.g37aff9b760-goog
Re: [PATCH v2 7/7] common: move alloc macros to common.h
Quoted 7 lines · Calvin Wan
alloc_nr,ALLOC_GROW, andALLOC_GROW_BYare commonly used macros for dynamic array allocation. Moving these macros tocommon.hfocuses alloc.[ch] to allocation for Git objects and additionally allows us to remove inclusions toalloc.hfrom files that solely used the above macros.Signed-off-by Calvin Wan <[email protected]>
Ah, indeed, "alloc.h" was used for 2 different allocation-related things. This change makes sense, of course.
Thanks for this patch set. Overall, it looks good (except for some minor comments that I've given in other emails).
Quoted 2 lines · Calvin Wan
Changes since v1:
- rebased onto8afb38ac80f6
I couldn't find this object. Calvin and I resolved this off-list, so I can proceed with the review, but remember to rebase onto a more stable base in version 3.
v3 cover git-compat-util cleanups
In reply to Calvin WanChanges since v2:
- rebased on 2.41, en/header-split-cache-h-part-3, and cw/strbuf-cleanup (originally rebased onto seen which is why the range-diff is like that)
- moved tolower_trans_tbl to kwset rather than sane-ctype
- rewrote commit message headers to be shorter
This series focuses on cleaning up and reducing the scope of git-compat-util.h by moving headers to their respective files and separating out functionality from git-compat-util.h to a new file, common.h. I go into more detail in patch 5 as to why I believe this separation is useful.
By the end of this series, git-compat-util.h includes common.h which includes wrapper.h, and usage.h. Since virtually every file includes git-compat-util.h and the large majority of files use functions defined in common.h, wrapper.h, and usage.h, I believe it makes sense that those are also automatically included with git-compat-util.h.
Calvin Wan (8):
git-compat-util: move strbuf.c funcs to its header
git-compat-util: move wrapper.c funcs to its header sane-ctype.h: create header for sane-ctype macros
kwset: move translation table from ctype common.h: move non-compat specific macros and functions
git-compat-util: move usage.c funcs to its header
treewide: remove unnecessary includes for wrapper.h
common: move alloc macros to common.h
add-patch.c | 1 - alias.c | 1 - alloc.h | 75 ---- apply.c | 2 - archive-tar.c | 1 - archive.c | 1 - attr.c | 1 - builtin/am.c | 1 - builtin/bisect.c | 1 - builtin/blame.c | 1 - builtin/branch.c | 1 - builtin/bugreport.c | 1 - builtin/cat-file.c | 1 - builtin/checkout--worker.c | 1 - builtin/clone.c | 1 - builtin/config.c | 2 - builtin/credential-cache--daemon.c | 1 - builtin/credential-cache.c | 1 - builtin/difftool.c | 1 - builtin/fast-import.c | 1 - builtin/fetch-pack.c | 1 - builtin/fmt-merge-msg.c | 1 - builtin/fsmonitor--daemon.c | 1 - builtin/gc.c | 1 - builtin/get-tar-commit-id.c | 1 - builtin/grep.c | 1 - builtin/index-pack.c | 2 - builtin/init-db.c | 1 - builtin/log.c | 1 - builtin/merge.c | 2 - builtin/mktree.c | 1 - builtin/mv.c | 1 - builtin/name-rev.c | 1 - builtin/pack-objects.c | 2 - builtin/rebase.c | 1 - builtin/receive-pack.c | 1 - builtin/repack.c | 1 - builtin/rerere.c | 1 - builtin/rev-parse.c | 1 - builtin/revert.c | 1 - builtin/rm.c | 1 - builtin/submodule--helper.c | 1 - builtin/symbolic-ref.c | 1 + builtin/unpack-file.c | 1 - builtin/unpack-objects.c | 1 + builtin/worktree.c | 1 - bulk-checkin.c | 2 - cache-tree.c | 1 - chunk-format.c | 1 - combine-diff.c | 1 - commit-graph.c | 1 - commit-reach.c | 1 - common.h | 486 +++++++++++++++++++++ compat/terminal.c | 1 - config.c | 2 - convert.c | 1 - copy.c | 1 - csum-file.c | 1 - ctype.c | 36 -- daemon.c | 2 - delta-islands.c | 1 - diff.c | 2 - diffcore-rename.c | 1 - dir-iterator.c | 1 - dir.c | 2 - editor.c | 1 - entry.c | 1 - environment.c | 1 - ewah/bitmap.c | 1 - ewah/ewah_bitmap.c | 1 - fetch-pack.c | 2 - fmt-merge-msg.c | 1 - fsck.c | 1 - git-compat-util.h | 664 +---------------------------- gpg-interface.c | 1 - grep.c | 1 - help.c | 1 - http-backend.c | 2 - imap-send.c | 1 - kwset.c | 36 ++ kwset.h | 2 + line-log.c | 1 - list-objects-filter-options.c | 1 - list-objects-filter.c | 1 - merge-ll.c | 1 - merge-recursive.c | 1 - midx.c | 1 - notes-merge.c | 1 - object-file.c | 2 - oid-array.c | 1 - oidtree.c | 1 - pack-bitmap-write.c | 1 - pack-bitmap.c | 1 - pack-objects.c | 1 - pack-write.c | 1 - packfile.c | 2 - parallel-checkout.c | 2 - path.c | 1 - pkt-line.c | 1 - pretty.c | 1 - prio-queue.c | 1 - quote.c | 1 - read-cache.c | 2 - rebase-interactive.c | 1 - ref-filter.c | 1 - reflog-walk.c | 1 - refs.c | 2 - refspec.c | 1 - remote-curl.c | 1 - remote.c | 1 - rerere.c | 2 - revision.c | 1 - sane-ctype.h | 66 +++ send-pack.c | 1 - sequencer.c | 2 - server-info.c | 2 - setup.c | 1 - shallow.c | 2 - sigchain.c | 1 - sparse-index.c | 1 - split-index.c | 1 - strbuf.c | 2 - strbuf.h | 32 ++ streaming.c | 1 - string-list.c | 1 - strvec.c | 1 - submodule-config.c | 1 - submodule.c | 1 - t/helper/test-delta.c | 1 - t/helper/test-fsmonitor-client.c | 1 - t/helper/test-reach.c | 1 - t/helper/test-read-cache.c | 1 - tag.c | 1 - tempfile.c | 1 - trace.c | 1 - trace2/tr2_tls.c | 1 - trailer.c | 1 - transport-helper.c | 1 - transport.c | 2 - tree-walk.c | 1 - upload-pack.c | 1 - usage.c | 1 - usage.h | 60 +++ userdiff.c | 1 - versioncmp.c | 1 + worktree.c | 2 - wrapper.c | 1 - wrapper.h | 111 +++++ write-or-die.c | 1 - 149 files changed, 799 insertions(+), 932 deletions(-) create mode 100644 common.h create mode 100644 sane-ctype.h create mode 100644 usage.h
Range-diff against v2:
1: 08f55ec7b2 < -: ---------- diff-merges: implement [no-]hide option and log.diffMergesHide config
2: b9873596ec < -: ---------- diff-merges: implement log.diffMerges-m-imply-p config
3: 56c961db8d < -: ---------- diff-merges: support list of values for --diff-merges
4: 96f5dc2cfe < -: ---------- diff-merges: issue warning on lone '-m' option
5: 0200086346 < -: ---------- diff-merges: improve --diff-merges documentation
6: f216b8d143 < -: ---------- test-lib: allow storing counts with test harnesses
7: 78bb2515d6 < -: ---------- checkout/switch: disallow checking out same branch in multiple worktrees
8: f2111f451f < -: ---------- imap-send: note "auth_method", not "host" on auth method failure
9: f161e8fd64 < -: ---------- imap-send doc: the imap.sslVerify is used with imap.tunnel
10: ddfd0c2740 < -: ---------- imap-send: replace auto-probe libcurl with hard dependency
11: 647ddc1bf8 < -: ---------- imap-send: make --curl no-optional
12: bbf79fd38d < -: ---------- imap-send: remove old --no-curl codepath
13: ded420f1d1 < -: ---------- imap-send: correctly report "host" when using "tunnel"
14: 4bef181256 < -: ---------- pull: conflict hint pull.rebase suggestion should offer "merges" vs "true"
15: fe944b5c26 < -: ---------- run-command: add on_stderr_output_fn to run_processes_parallel_opts
16: 079d6eec74 < -: ---------- submodule: rename strbuf variable
17: c306d4ce36 < -: ---------- submodule: move status parsing into function
18: 7cce9de786 < -: ---------- submodule: refactor is_submodule_modified()
19: a8a6e3a99b < -: ---------- diff-lib: refactor out diff_change logic
20: ab60254a51 < -: ---------- diff-lib: parallelize run_diff_files for submodules
21: f8762b1cef < -: ---------- pack-bitmap.c: hide bitmap internals in `read_u8()`
22: 82d838ac61 < -: ---------- pack-bitmap.c: hide bitmap internals in `read_be32()`
23: 5abc4c1c89 < -: ---------- pack-bitmap.c: drop unnecessary 'inline's
24: 0e2a13eb16 < -: ---------- pack-bitmap.c: factor out manual `map_pos` manipulation
25: e535db7c69 < -: ---------- pack-bitmap.c: use `bitmap_index_seek()` where possible
26: 3acd24d42a < -: ---------- pack-bitmap.c: factor out `bitmap_index_seek_commit()`
27: 1cf6fbc4f7 < -: ---------- SQUASH??? the test marked to expect failure passes from day one
28: 3ff774e34f < -: ---------- fsmonitor: handle differences between Windows named pipe functions
29: fce46cf78e < -: ---------- diff-index: enable sparse index
30: f7cfd68b91 < -: ---------- usage: clarify --recurse-submodules as a boolean
31: 2739b3473a < -: ---------- rebase -i: move unlink() calls
32: 486312cec7 < -: ---------- rebase -i: remove patch file after conflict resolution
33: a2fbbcb270 < -: ---------- sequencer: factor out part of pick_commits()
34: 193623fd97 < -: ---------- rebase --continue: refuse to commit after failed command
35: cfc27593ab < -: ---------- rebase: fix rewritten list for failed pick
36: bf1932c2f3 < -: ---------- rebase -i: fix adding failed command to the todo list
37: bd111141aa < -: ---------- cocci: add headings to and reword README
38: 3bd0097cfc < -: ---------- cocci: codify authoring and reviewing practices
39: 62a8a36709 < -: ---------- notes.c: cleanup 'strbuf_grow' call in 'append_edit'
40: 39a609ec6c < -: ---------- notes.c: use designated initializers for clarity
41: e9a0a06d38 < -: ---------- t3321: add test cases about the notes stripspace behavior
42: 3993a53a13 < -: ---------- notes.c: introduce '--separator=<paragraph-break>' option
43: ad3d1f8feb < -: ---------- notes.c: append separator instead of insert by pos
44: aa382bf677 < -: ---------- notes.c: introduce "--[no-]stripspace" option
45: 8e9a6aa3f7 < -: ---------- sequencer: beautify subject of reverts of reverts
46: 9d484b92ed < -: ---------- diff: fix interaction between the "-s" option and other options
47: fe90355361 < -: ---------- object: add object_array initializer helper function
48: 47ff853f02 < -: ---------- pack-bitmap.c: extract `fill_in_bitmap()`
49: b0afdce5da < -: ---------- pack-bitmap.c: use commit boundary during bitmap traversal
50: 6ba979b352 < -: ---------- t6429: remove switching aspects of fast-rebase
51: cd85a8aab3 < -: ---------- replay: introduce new builtin
52: ff6b4688a7 < -: ---------- replay: start using parse_options API
53: d1e55ff4ab < -: ---------- replay: die() instead of failing assert()
54: 93461549f2 < -: ---------- replay: introduce pick_regular_commit()
55: 1bf61baa21 < -: ---------- replay: don't simplify history
56: 317ac15b14 < -: ---------- replay: add an important FIXME comment about gpg signing
57: a195c920d9 < -: ---------- replay: remove progress and info output
58: 20e96266a5 < -: ---------- replay: remove HEAD related sanity check
59: acf68154a0 < -: ---------- replay: make it a minimal server side command
60: e02064abfc < -: ---------- replay: use standard revision ranges
61: 33296b563c < -: ---------- replay: disallow revision specific options and pathspecs
62: e436c4e38f < -: ---------- replay: add --advance or 'cherry-pick' mode
63: 657ce1ace6 < -: ---------- replay: add --contained to rebase contained branches
64: 145695cc72 < -: ---------- replay: stop assuming replayed branches do not diverge
65: b37a7d7a8a < -: ---------- SQUASH???
66: ec664ab737 < -: ---------- cat-file: quote-format name in error when using -z
67: 982ff2c961 < -: ---------- object tests: add test for unexpected objects in tags
68: d5afcaa611 < -: ---------- tag: don't misreport type of tagged objects in errors
69: cdc90612fd < -: ---------- tag: don't emit potentially incorrect "object is a X, not a Y"
70: b745672f8d < -: ---------- doc: trailer: fix grammar
71: 354fc9157c < -: ---------- doc: trailer: swap verb order
72: 267aea4472 < -: ---------- doc: trailer: drop "commit message part" phrasing
73: 2d75fde295 < -: ---------- doc: trailer: examples: avoid the word "message" by itself
74: e2087e448a < -: ---------- doc: trailer: remove redundant phrasing
75: 479d93ea37 < -: ---------- doc: trailer: use angle brackets for <token> and <value>
76: 4361055f15 < -: ---------- doc: trailer.<token>.command: emphasize deprecation
77: 4fc3593f55 < -: ---------- doc: trailer: mention 'key' in DESCRIPTION
78: 05d3be026d < -: ---------- doc: trailer: add more examples in DESCRIPTION
79: d0ca92a7fe < -: ---------- strbuf: clarify API boundary
80: 689ece6602 < -: ---------- abspath: move related functions to abspath
81: eaec86fb92 < -: ---------- credential-store: move related functions to credential-store file
82: d1272d1469 < -: ---------- object-name: move related functions to object-name
83: 9a5bb4efa0 < -: ---------- path: move related function to path
84: 88da41d9ff < -: ---------- strbuf: clarify dependency
85: 6897be8f14 < -: ---------- strbuf: remove global variable
86: 283174b214 < -: ---------- docs: clarify git-pack-refs --all will pack all refs
87: 826ae79fca < -: ---------- pack-refs: teach --exclude option to exclude refs from being packed
88: 4fe42f326e < -: ---------- pack-refs: teach pack-refs --include option
89: 836ada9931 < -: ---------- refs.c: rename `ref_filter`
90: ccd9c98044 < -: ---------- ref-filter.h: provide `REF_FILTER_INIT`
91: 25d2495e4a < -: ---------- ref-filter: clear reachable list pointers after freeing
92: b10cd5c909 < -: ---------- ref-filter: add `ref_filter_clear()`
93: d3e45e84fd < -: ---------- ref-filter.c: parameterize match functions over patterns
94: 389f8c1827 < -: ---------- builtin/for-each-ref.c: add `--exclude` option
95: 60ccf68ae5 < -: ---------- refs: plumb `exclude_patterns` argument throughout
96: c5950cfc7b < -: ---------- refs/packed-backend.c: refactor `find_reference_location()`
97: d2be75e8d2 < -: ---------- refs/packed-backend.c: implement jump lists to avoid excluded pattern(s)
98: 9a66abb6ce < -: ---------- refs/packed-backend.c: add trace2 counters for jump list
99: 54b1444a51 < -: ---------- revision.h: store hidden refs in a `strvec`
100: fe10c7fe7a < -: ---------- refs/packed-backend.c: ignore complicated hidden refs rules
101: 3df995b8c5 < -: ---------- refs.h: let `for_each_namespaced_ref()` take excluded patterns
102: c41619ccdc < -: ---------- builtin/receive-pack.c: avoid enumerating hidden references
103: fb22f5bcea < -: ---------- upload-pack.c: avoid enumerating hidden refs where possible
104: bd3fabf816 < -: ---------- ls-refs.c: avoid enumerating hidden refs where possible
105: 342e04e6fd < -: ---------- reachable.c: extract `obj_is_recent()`
106: 8b19941a02 < -: ---------- gc: introduce `gc.recentObjectsHook`
107: 955ee54d92 < -: ---------- init-db: document existing bug with core.bare in template config
108: d404ac1027 < -: ---------- init-db: remove unnecessary global variable
109: 0a76a5fb02 < -: ---------- init-db, clone: change unnecessary global into passed parameter
110: 3f85c72fad < -: ---------- setup: adopt shared init-db & clone code
111: 4956a5ec86 < -: ---------- read-cache: move shared commit and ls-files code
112: c862a92083 < -: ---------- add: modify add_files_to_cache() to avoid globals
113: eb6220a10a < -: ---------- read-cache: move shared add/checkout/commit code
114: b5ee0a2bf4 < -: ---------- statinfo: move stat_{data,validity} functions from cache/read-cache
115: ccdfc96750 < -: ---------- run-command.h: move declarations for run-command.c from cache.h
116: 74eab62313 < -: ---------- name-hash.h: move declarations for name-hash.c from cache.h
117: 8ccc457fff < -: ---------- sparse-index.h: move declarations for sparse-index.c from cache.h
118: e1f4132af8 < -: ---------- preload-index.h: move declarations for preload-index.c from elsewhere
119: cea0ce693d < -: ---------- diff.h: move declaration for global in diff.c from cache.h
120: e114585b13 < -: ---------- merge.h: move declarations for merge.c from cache.h
121: dc45fab4e7 < -: ---------- repository.h: move declaration of the_index from cache.h
122: 433097258d < -: ---------- read-cache*.h: move declarations for read-cache.c functions from cache.h
123: 4275a22e16 < -: ---------- cache.h: remove this no-longer-used header
124: e1fcb3a534 < -: ---------- log-tree: replace include of revision.h with simple forward declaration
125: f6a61d3055 < -: ---------- repository: remove unnecessary include of path.h
126: 4666f5120d < -: ---------- diff.h: remove unnecessary include of oidset.h
127: 5e67baddca < -: ---------- list-objects-filter-options.h: remove unneccessary include
128: 64667610fc < -: ---------- builtin.h: remove unneccessary includes
129: 19c8e8012b < -: ---------- git-compat-util.h: remove unneccessary include of wildmatch.h
130: 50b5ecfaf0 < -: ---------- merge-ll: rename from ll-merge
131: aaf326e1cd < -: ---------- khash: name the structs that khash declares
132: 52c6131caa < -: ---------- object-store-ll.h: split this header out of object-store.h
133: 25547a5791 < -: ---------- hash-ll, hashmap: move oidhash() to hash-ll
134: d677f7e76a < -: ---------- fsmonitor-ll.h: split this header out of fsmonitor.h
135: 719515fdd0 < -: ---------- doc: tag: document `TAG_EDITMSG`
136: 669c11de85 < -: ---------- t/t7004-tag: add regression test for successful tag creation
137: 08c12ec1d0 < -: ---------- tag: keep the message file in case ref transaction fails
138: 2372aa4195 < -: ---------- credential/libsecret: store new attributes
139: a40449bcd4 < -: ---------- fetch: drop unused DISPLAY_FORMAT_UNKNOWN enum value
140: 6bc7a37e79 < -: ---------- fetch: drop unneeded NULL-check for `remote_ref`
141: d1adf85b0a < -: ---------- fetch: pass through `fetch_config` directly
142: b779a25e05 < -: ---------- fetch: use `fetch_config` to store "fetch.prune" value
143: 2b472cfeac < -: ---------- fetch: use `fetch_config` to store "fetch.pruneTags" value
144: ba28b2ca5d < -: ---------- fetch: use `fetch_config` to store "fetch.showForcedUpdates" value
145: 56e8bb4fb4 < -: ---------- fetch: use `fetch_config` to store "fetch.recurseSubmodules" value
146: ac197cc094 < -: ---------- fetch: use `fetch_config` to store "fetch.parallel" value
147: f7e063f326 < -: ---------- fetch: use `fetch_config` to store "submodule.fetchJobs" value
148: b71f919dda < -: ---------- worktree add: include -B in usage docs
149: 1b28fbd218 < -: ---------- t2400: cleanup created worktree in test
150: ed6db0e9ff < -: ---------- t2400: refactor "worktree add" opt exclusion tests
151: 9ccdace1e8 < -: ---------- t2400: add tests to verify --quiet
152: 7ab8918985 < -: ---------- worktree add: add --orphan flag
153: 35f0383ca6 < -: ---------- worktree add: introduce "try --orphan" hint
154: 128e5496b3 < -: ---------- worktree add: extend DWIM to infer --orphan
155: 926c40d04b < -: ---------- worktree add: emit warn when there is a bad HEAD
156: 48c5fbfb89 < -: ---------- diff-tree: integrate with sparse index
157: cfa120947e < -: ---------- format-patch: free rev.message_id when exiting
158: 00bf685975 < -: ---------- show-ref doc: update for internal consistency
159: 0f45b5bc32 < -: ---------- show-branch doc: say <ref>, not <reference>
160: 21c9bac2c7 < -: ---------- ls-remote doc: remove redundant --tags example
161: e959fa452f < -: ---------- ls-remote doc: show peeled tags in examples
162: a5b076321a < -: ---------- ls-remote doc: explain what each example does
163: 51f9d2e563 < -: ---------- ls-remote doc: document the output format
164: c6d26a9dda < -: ---------- format-patch: free elements of rev.ref_message_ids list
165: 2f68c99a3b < -: ---------- t0000-basic: modernize test format
166: 27990663f0 < -: ---------- t0030-stripspace: modernize test format
167: 3c2f5d26c0 < -: ---------- t3210-pack-refs: modernize test format
168: 58db6e450b < -: ---------- t1001-read-tree-m-2way: modernize test format
169: a10bb2ded5 < -: ---------- t1002-read-tree-m-u-2way: modernize test format
170: 350c484239 < -: ---------- t1006-cat-file: modernize test format
171: 0a6cb5c42f < -: ---------- t3500-cherry: modernize test format
172: 0aa0266c4b < -: ---------- t3700-add: modernize test format
173: a8fcc0ac89 < -: ---------- t3903-stash: modernize test format
174: 9cfcbcc095 < -: ---------- t4002-diff-basic: modernize test format
175: 9297229d15 < -: ---------- t4003-diff-rename-1: modernize test format
176: 93fc423e9a < -: ---------- t4004-diff-rename-symlink: modernize test format
177: 3da9be913a < -: ---------- t4202-log: modernize test format
178: 1afebc92ef < -: ---------- t4206-log-follow-harder-copies: modernize test format
179: e478a52087 < -: ---------- t5300-pack-object: modernize test format
180: cc0c1ad9ad < -: ---------- t5301-sliding-window: modernize test format
181: aac864059f < -: ---------- t5303-pack-corruption-resilience: modernize test format
182: a45bb750db < -: ---------- t5306-pack-nobase: modernize test format
183: 32942346aa < -: ---------- t6050-replace: modernize test format
184: 3b8724bce6 < -: ---------- t7101-reset-empty-subdirs: modernize test format
185: a32a724b03 < -: ---------- t7110-reset-merge: modernize test format
186: c970681f50 < -: ---------- t7111-reset-table: modernize test format
187: 10dae78533 < -: ---------- t7201-co: modernize test format
188: a6171e1478 < -: ---------- t7508-status: modernize test format
189: bd48dfad69 < -: ---------- t7600-merge: modernize test format
190: 3a3b98be91 < -: ---------- t7700-repack: modernize test format
191: be1fce6dae < -: ---------- t9100-git-svn-basic: modernize test format
192: 7d7097bf59 < -: ---------- t9104-git-svn-follow-parent: modernize test format
193: 7dac6347c5 < -: ---------- t9200-git-cvsexportcommit: modernize test format
194: 447a3b7331 < -: ---------- t9400-git-cvsserver-server: modernize test format
195: bc11bac329 < -: ---------- revisions.txt: use description list for special refs
196: 6ec5f46071 < -: ---------- revisions.txt: document more special refs
197: 1ef3c61b78 < -: ---------- completion: complete REVERT_HEAD and BISECT_HEAD
198: b7dd54a2c7 < -: ---------- git-merge.txt: modernize word choice in "True merge" section
199: 4fa1edb988 < -: ---------- Documentation: document AUTO_MERGE
200: 982ff3a649 < -: ---------- completion: complete AUTO_MERGE
201: 3a5d53d3c0 < -: ---------- t4216: test wrong bloom filter version rejection
202: 5a91f9682b < -: ---------- commit-graph: fix murmur3, bump filter ver. to 2
203: 3d3906ce28 < -: ---------- ### match next
204: 9d9c164d7e < -: ---------- cherry-pick: refuse cherry-pick sequence if index is dirty
205: d091928b02 < -: ---------- ls-files: aligin format atoms wtih ls-tree
206: a2b7a28e6e ! 1: d352eae308 strbuf.h: move declarations for strbuf.c functions from git-compat-util.h @@ Metadata
Author: Calvin Wan <[email protected]>
## Commit message ##
- strbuf.h: move declarations for strbuf.c functions from git-compat-util.h
+ git-compat-util: move strbuf.c funcs to its header
While functions like starts_with() probably should not belong in the boundaries of the strbuf library, this commit focuses on first splitting
207: b12fb0e2ff ! 2: fe4fd6f92a wrapper.h: move declarations for wrapper.c functions from git-compat-util.h
@@ Metadata
Author: Calvin Wan <[email protected]>
## Commit message ##
- wrapper.h: move declarations for wrapper.c functions from git-compat-util.h
+ git-compat-util: move wrapper.c funcs to its header
Since the functions in wrapper.c are widely used across the codebase, include it by default in git-compat-util.h. A future patch will remove
208: 016f671836 ! 3: ec7ea12f7c sane-ctype.h: move sane-ctype macros from git-compat-util.h
@@ Metadata
Author: Calvin Wan <[email protected]>
## Commit message ##
- sane-ctype.h: move sane-ctype macros from git-compat-util.h
+ sane-ctype.h: create header for sane-ctype macros
Splitting these macros from git-compat-util.h cleans up the file and allows future third-party sources to not use these overrides if they do
@@ Commit message
## git-compat-util.h ##
@@ git-compat-util.h: static inline size_t xsize_t(off_t len)
- #define HOST_NAME_MAX 256
- #endif
+ /* in ctype.c, for kwset users */
+ extern const unsigned char tolower_trans_tbl[256];
--/* in ctype.c, for kwset users */
--extern const unsigned char tolower_trans_tbl[256]; --
-/* Sane ctype - no locale, and works with signed chars */ -#undef isascii
-#undef isspace
@@ sane-ctype.h (new)
+#ifndef SANE_CTYPE_H
+#define SANE_CTYPE_H
+
-+/* in ctype.c, for kwset users */
-+extern const unsigned char tolower_trans_tbl[256]; -+
+/* Sane ctype - no locale, and works with signed chars */ +#undef isascii
+#undef isspace
-: ---------- > 4: 4f95b4121e kwset: move translation table from ctype 209: 244650e5c9 ! 5: 36525e39d5 common.h: move non-compat specific macros and functions from git-compat-util.h
@@ Metadata
Author: Calvin Wan <[email protected]>
## Commit message ##
- common.h: move non-compat specific macros and functions from git-compat-util.h
+ common.h: move non-compat specific macros and functions
git-compat-util.h has grown to a large and difficult to read file partly because its set of functionality is overloaded. Besides being a
210: 91a1253ee6 ! 6: 21f0f31ff3 usage.h: move declarations for usage.c functions from git-compat-util.h
@@ Metadata
Author: Calvin Wan <[email protected]>
## Commit message ##
- usage.h: move declarations for usage.c functions from git-compat-util.h
+ git-compat-util: move usage.c funcs to its header
## common.h ##
@@
211: c9850a7c18 = 7: 531db31c5c treewide: remove unnecessary includes for wrapper.h
212: 067b28ec09 ! 8: 98694f7add common: move alloc macros to common.h
@@ strbuf.c
-#include "alloc.h"
#include "gettext.h"
#include "hex.h"
- #include "path.h"
+ #include "strbuf.h"
## string-list.c ##
@@Signature · 1 line
2.41.0.rc2.161.g9c6817b8e7-goog
PATCH v3 1/8 git-compat-util: move strbuf.c funcs to its header
While functions like starts_with() probably should not belong in the boundaries of the strbuf library, this commit focuses on first splitting out headers from git-compat-util.h.
--- builtin/symbolic-ref.c | 1 + builtin/unpack-objects.c | 1 + git-compat-util.h | 32 -------------------------------- strbuf.h | 32 ++++++++++++++++++++++++++++++++ versioncmp.c | 1 + 5 files changed, 35 insertions(+), 32 deletions(-)
builtin/symbolic-ref.c +1 -0
@@ -3,6 +3,7 @@#include "gettext.h" #include "refs.h" #include "parse-options.h" +#include "strbuf.h" static const char *const git_symbolic_ref_usage[] = {N_ ("git symbolic-ref [-m <reason>] <name> <ref>" ),
builtin/unpack-objects.c +1 -0
@@ -12,6 +12,7 @@#include "blob.h" #include "commit.h" #include "replace-object.h" +#include "strbuf.h" #include "tag.h" #include "tree.h" #include "tree-walk.h"
git-compat-util.h +0 -32
@@ -677,9 +677,6 @@ void set_warn_routine(report_fn routine);report_fn get_warn_routine (void );void set_die_is_recursing_routine (int (*routine)(void )); -int starts_with (const char *str,const char *prefix); -int istarts_with (const char *str,const char *prefix); -/* * If the string "str" begins with the string found in "prefix", return 1. * The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in
@@ -708,29 +705,6 @@ static inline int skip_prefix(const char *str, const char *prefix,return 0 ; } -/* -* If the string "str" is the same as the string in "prefix", then the "arg" -* parameter is set to the "def" parameter and 1 is returned. -* If the string "str" begins with the string found in "prefix" and then a -* "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1" -* (i.e., to the point in the string right after the prefix and the "=" sign), -* and 1 is returned. -* -* Otherwise, return 0 and leave "arg" untouched. -* -* When we accept both a "--key" and a "--key=<val>" option, this function -* can be used instead of !strcmp(arg, "--key") and then -* skip_prefix(arg, "--key=", &arg) to parse such an option. -*/ -int skip_to_optional_arg_default (const char *str,const char *prefix, -const char **arg,const char *def); - -static inline int skip_to_optional_arg (const char *str,const char *prefix, -const char **arg) -{ -return skip_to_optional_arg_default (str, prefix, arg,"" ); -} -/* * Like skip_prefix, but promises never to read past "len" bytes of the input * buffer, and returns the remaining number of bytes in "out" via "outlen".
@@ -775,12 +749,6 @@ static inline int strip_suffix(const char *str, const char *suffix, size_t *len)return strip_suffix_mem (str, len, suffix); } -static inline int ends_with (const char *str,const char *suffix) -{ -size_t len; -return strip_suffix (str, suffix, &len); -} -#define SWAP (a, b) do { \ void *_swap_a_ptr = &(a); \ void *_swap_b_ptr = &(b); \
strbuf.h +32 -0
@@ -698,4 +698,36 @@ char *xstrvfmt(const char *fmt, va_list ap); __attribute__((format (printf,1 ,2 )))char *xstrfmt (const char *fmt, ...); +int starts_with (const char *str,const char *prefix); +int istarts_with (const char *str,const char *prefix); + +/* +* If the string "str" is the same as the string in "prefix", then the "arg" +* parameter is set to the "def" parameter and 1 is returned. +* If the string "str" begins with the string found in "prefix" and then a +* "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1" +* (i.e., to the point in the string right after the prefix and the "=" sign), +* and 1 is returned. +* +* Otherwise, return 0 and leave "arg" untouched. +* +* When we accept both a "--key" and a "--key=<val>" option, this function +* can be used instead of !strcmp(arg, "--key") and then +* skip_prefix(arg, "--key=", &arg) to parse such an option. +*/ +int skip_to_optional_arg_default (const char *str,const char *prefix, +const char **arg,const char *def); + +static inline int skip_to_optional_arg (const char *str,const char *prefix, +const char **arg) +{ +return skip_to_optional_arg_default (str, prefix, arg,"" ); +} + +static inline int ends_with (const char *str,const char *suffix) +{ +size_t len; +return strip_suffix (str, suffix, &len); +} +#endif /* STRBUF_H */
versioncmp.c +1 -0
@@ -1,5 +1,6 @@#include "git-compat-util.h" #include "config.h" +#include "strbuf.h" #include "string-list.h" #include "versioncmp.h"
Signature · 1 line
2.41.0.rc2.161.g9c6817b8e7-goog
PATCH v3 2/8 git-compat-util: move wrapper.c funcs to its header
In reply to Calvin WanSince the functions in wrapper.c are widely used across the codebase, include it by default in git-compat-util.h. A future patch will remove now unnecessary inclusions of wrapper.h from other files.
--- git-compat-util.h | 112 +--------------------------------------------- wrapper.h | 111 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 111 deletions(-)
git-compat-util.h +1 -111
@@ -625,7 +625,7 @@ static inline int git_has_dir_sep(const char *path)#include "compat/bswap.h" -struct strbuf ; +#include "wrapper.h" /* General helper functions */ NORETURN void usage(const char *err);
@@ -1045,36 +1045,6 @@ static inline int cast_size_t_to_int(size_t a)# define xalloca (size) (xmalloc(size))# define xalloca_free (p) (free(p))#endif -char *xstrdup (const char *str); -void *xmalloc (size_t size); -void *xmallocz (size_t size); -void *xmallocz_gently (size_t size); -void *xmemdupz (const void *data,size_t len); -char *xstrndup (const char *str,size_t len); -void *xrealloc (void *ptr,size_t size); -void *xcalloc (size_t nmemb,size_t size); -void xsetenv (const char *name,const char *value,int overwrite); -void *xmmap (void *start,size_t length,int prot,int flags,int fd,off_t offset); -const char *mmap_os_err (void ); -void *xmmap_gently (void *start,size_t length,int prot,int flags,int fd,off_t offset); -int xopen (const char *path,int flags, ...); -ssize_t xread (int fd,void *buf,size_t len); -ssize_t xwrite (int fd,const void *buf,size_t len); -ssize_t xpread (int fd,void *buf,size_t len,off_t offset); -int xdup (int fd); -FILE *xfopen (const char *path,const char *mode); -FILE *xfdopen (int fd,const char *mode); -int xmkstemp (char *temp_filename); -int xmkstemp_mode (char *temp_filename,int mode); -char *xgetcwd (void ); -FILE *fopen_for_writing (const char *path); -FILE *fopen_or_warn (const char *path,const char *mode); - -/* -* Like strncmp, but only return zero if s is NUL-terminated and exactly len -* characters long. If it is not, consider it greater than t. -*/ -int xstrncmpz (const char *s,const char *t,size_t len);/* * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note
@@ -1176,15 +1146,10 @@ static inline size_t xsize_t(off_t len)return (size_t ) len; } -__attribute__((format (printf,3 ,4 ))) -int xsnprintf (char *dst,size_t max,const char *fmt, ...); -#ifndef HOST_NAME_MAX #define HOST_NAME_MAX 256#endif -int xgethostname (char *buf,size_t len); -/* in ctype.c, for kwset users */ extern const unsigned char tolower_trans_tbl[256 ];
@@ -1425,72 +1390,6 @@ void bug_fl(const char *file, int line, const char *fmt, ...);#endif #endif -enum fsync_action { -FSYNC_WRITEOUT_ONLY , -FSYNC_HARDWARE_FLUSH -}; - -/* -* Issues an fsync against the specified file according to the specified mode. -* -* FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating -* systems to flush the OS cache without issuing a flush command to the storage -* controller. If those interfaces are unavailable, the function fails with -* ENOSYS. -* -* FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that -* changes are durable. It is not expected to fail. -*/ -int git_fsync (int fd,enum fsync_action action); - -/* -* Writes out trace statistics for fsync using the trace2 API. -*/ -void trace_git_fsync_stats (void ); - -/* -* Preserves errno, prints a message, but gives no warning for ENOENT. -* Returns 0 on success, which includes trying to unlink an object that does -* not exist. -*/ -int unlink_or_warn (const char *path); -/* -* Tries to unlink file. Returns 0 if unlink succeeded -* or the file already didn't exist. Returns -1 and -* appends a message to err suitable for -* 'error("%s", err->buf)' on error. -*/ -int unlink_or_msg (const char *file,struct strbuf *err); -/* -* Preserves errno, prints a message, but gives no warning for ENOENT. -* Returns 0 on success, which includes trying to remove a directory that does -* not exist. -*/ -int rmdir_or_warn (const char *path); -/* -* Calls the correct function out of {unlink,rmdir}_or_warn based on -* the supplied file mode. -*/ -int remove_or_warn (unsigned int mode,const char *path); - -/* -* Call access(2), but warn for any error except "missing file" -* (ENOENT or ENOTDIR). -*/ -#define ACCESS_EACCES_OK (1U << 0) -int access_or_warn (const char *path,int mode,unsigned flag); -int access_or_die (const char *path,int mode,unsigned flag); - -/* Warn on an inaccessible file if errno indicates this is an error */ -int warn_on_fopen_errors (const char *path); - -/* -* Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent -* may be racy. Do not use this as protection against an attacker who can -* simultaneously create paths. -*/ -int open_nofollow (const char *path,int flags); -#ifndef SHELL_PATH # define SHELL_PATH "/bin/sh"#endif
@@ -1630,13 +1529,4 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset) ((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))#endif /* !__GNUC__ */ -void sleep_millisec (int millisec); - -/* -* Generate len bytes from the system cryptographically secure PRNG. -* Returns 0 on success and -1 on error, setting errno. The inability to -* satisfy the full request is an error. -*/ -int csprng_bytes (void *buf,size_t len); -#endif
wrapper.h +111 -0
121 lines not on this page · raw message
Signature · 1 line
2.41.0.rc2.161.g9c6817b8e7-goog
PATCH v3 3/8 sane-ctype.h: create header for sane-ctype macros
In reply to Calvin WanSplitting these macros from git-compat-util.h cleans up the file and allows future third-party sources to not use these overrides if they do not wish to.
--- git-compat-util.h | 62 +------------------------------------------- sane-ctype.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 61 deletions(-) create mode 100644 sane-ctype.h
git-compat-util.h +1 -61
@@ -1153,67 +1153,7 @@ static inline size_t xsize_t(off_t len)/* in ctype.c, for kwset users */ extern const unsigned char tolower_trans_tbl[256 ]; -/* Sane ctype - no locale, and works with signed chars */ -#undef isascii -#undef isspace -#undef isdigit -#undef isalpha -#undef isalnum -#undef isprint -#undef islower -#undef isupper -#undef tolower -#undef toupper -#undef iscntrl -#undef ispunct -#undef isxdigit - -extern const unsigned char sane_ctype[256 ]; -extern const signed char hexval_table[256 ]; -#define GIT_SPACE 0x01 -#define GIT_DIGIT 0x02 -#define GIT_ALPHA 0x04 -#define GIT_GLOB_SPECIAL 0x08 -#define GIT_REGEX_SPECIAL 0x10 -#define GIT_PATHSPEC_MAGIC 0x20 -#define GIT_CNTRL 0x40 -#define GIT_PUNCT 0x80 -#define sane_istest (x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) -#define isascii (x) (((x) & ~0x7f) == 0) -#define isspace (x) sane_istest(x,GIT_SPACE) -#define isdigit (x) sane_istest(x,GIT_DIGIT) -#define isalpha (x) sane_istest(x,GIT_ALPHA) -#define isalnum (x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) -#define isprint (x) ((x) >= 0x20 && (x) <= 0x7e) -#define islower (x) sane_iscase(x, 1) -#define isupper (x) sane_iscase(x, 0) -#define is_glob_special (x) sane_istest(x,GIT_GLOB_SPECIAL) -#define is_regex_special (x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL) -#define iscntrl (x) (sane_istest(x,GIT_CNTRL)) -#define ispunct (x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \ - GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC) -#define isxdigit (x) (hexval_table[(unsigned char)(x)] != -1) -#define tolower (x) sane_case((unsigned char)(x), 0x20) -#define toupper (x) sane_case((unsigned char)(x), 0) -#define is_pathspec_magic (x) sane_istest(x,GIT_PATHSPEC_MAGIC) - -static inline int sane_case (int x,int high) -{ -if (sane_istest (x,GIT_ALPHA )) - x = (x & ~0x20 ) | high; -return x; -} - -static inline int sane_iscase (int x,int is_lower) -{ -if (!sane_istest (x,GIT_ALPHA )) -return 0 ; - -if (is_lower) -return (x &0x20 ) !=0 ; -else -return (x &0x20 ) ==0 ; -} +#include "sane-ctype.h" /* * Like skip_prefix, but compare case-insensitively. Note that the comparison
sane-ctype.h new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
2.41.0.rc2.161.g9c6817b8e7-goog
PATCH v3 4/8 kwset: move translation table from ctype
In reply to Calvin WanThis table was originally introduced to solely be used with kwset machinery (0f871cf56e), so it would make sense for it to belong in kwset.[ch] rather than ctype.c and git-compat-util.h. It is only used in diffcore-pickaxe.c, which already includes kwset.h so no other headers have to be modified.
--- ctype.c | 36 ------------------------------------ git-compat-util.h | 3 --- kwset.c | 36 ++++++++++++++++++++++++++++++++++++ kwset.h | 2 ++ 4 files changed, 38 insertions(+), 39 deletions(-)
ctype.c +0 -36
@@ -28,39 +28,3 @@ const unsigned char sane_ctype[256] = { A, A, A, A, A, A, A, A, A, A, A, R, R, U, P, X, /* 112..127 */ /* Nothing in the 128.. range */ }; - -/* For case-insensitive kwset */ -const unsigned char tolower_trans_tbl[256 ] = { -0x00 ,0x01 ,0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x07 , -0x08 ,0x09 ,0x0a ,0x0b ,0x0c ,0x0d ,0x0e ,0x0f , -0x10 ,0x11 ,0x12 ,0x13 ,0x14 ,0x15 ,0x16 ,0x17 , -0x18 ,0x19 ,0x1a ,0x1b ,0x1c ,0x1d ,0x1e ,0x1f , -' ' ,'!' ,'"' ,'#' ,'$' ,'%' ,'&' ,0x27 , -'(' ,')' ,'*' ,'+' ,',' ,'-' ,'.' ,'/' , -'0' ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' , -'8' ,'9' ,':' ,';' ,'<' ,'=' ,'>' ,'?' , -'@' ,'a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' , -'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o' , -'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' , -'x' ,'y' ,'z' ,'[' ,0x5c ,']' ,'^' ,'_' , -'`' ,'a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' , -'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o' , -'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' , -'x' ,'y' ,'z' ,'{' ,'|' ,'}' ,'~' ,0x7f , -0x80 ,0x81 ,0x82 ,0x83 ,0x84 ,0x85 ,0x86 ,0x87 , -0x88 ,0x89 ,0x8a ,0x8b ,0x8c ,0x8d ,0x8e ,0x8f , -0x90 ,0x91 ,0x92 ,0x93 ,0x94 ,0x95 ,0x96 ,0x97 , -0x98 ,0x99 ,0x9a ,0x9b ,0x9c ,0x9d ,0x9e ,0x9f , -0xa0 ,0xa1 ,0xa2 ,0xa3 ,0xa4 ,0xa5 ,0xa6 ,0xa7 , -0xa8 ,0xa9 ,0xaa ,0xab ,0xac ,0xad ,0xae ,0xaf , -0xb0 ,0xb1 ,0xb2 ,0xb3 ,0xb4 ,0xb5 ,0xb6 ,0xb7 , -0xb8 ,0xb9 ,0xba ,0xbb ,0xbc ,0xbd ,0xbe ,0xbf , -0xc0 ,0xc1 ,0xc2 ,0xc3 ,0xc4 ,0xc5 ,0xc6 ,0xc7 , -0xc8 ,0xc9 ,0xca ,0xcb ,0xcc ,0xcd ,0xce ,0xcf , -0xd0 ,0xd1 ,0xd2 ,0xd3 ,0xd4 ,0xd5 ,0xd6 ,0xd7 , -0xd8 ,0xd9 ,0xda ,0xdb ,0xdc ,0xdd ,0xde ,0xdf , -0xe0 ,0xe1 ,0xe2 ,0xe3 ,0xe4 ,0xe5 ,0xe6 ,0xe7 , -0xe8 ,0xe9 ,0xea ,0xeb ,0xec ,0xed ,0xee ,0xef , -0xf0 ,0xf1 ,0xf2 ,0xf3 ,0xf4 ,0xf5 ,0xf6 ,0xf7 , -0xf8 ,0xf9 ,0xfa ,0xfb ,0xfc ,0xfd ,0xfe ,0xff , -};
git-compat-util.h +0 -3
@@ -1150,9 +1150,6 @@ static inline size_t xsize_t(off_t len)#define HOST_NAME_MAX 256#endif -/* in ctype.c, for kwset users */ -extern const unsigned char tolower_trans_tbl[256 ]; -#include "sane-ctype.h" /*
kwset.c +36 -0
@@ -49,6 +49,42 @@ static void *obstack_chunk_alloc(long size)#define U (c) ((unsigned char) (c)) +/* For case-insensitive kwset */ +const unsigned char tolower_trans_tbl[256 ] = { +0x00 ,0x01 ,0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x07 , +0x08 ,0x09 ,0x0a ,0x0b ,0x0c ,0x0d ,0x0e ,0x0f , +0x10 ,0x11 ,0x12 ,0x13 ,0x14 ,0x15 ,0x16 ,0x17 , +0x18 ,0x19 ,0x1a ,0x1b ,0x1c ,0x1d ,0x1e ,0x1f , +' ' ,'!' ,'"' ,'#' ,'$' ,'%' ,'&' ,0x27 , +'(' ,')' ,'*' ,'+' ,',' ,'-' ,'.' ,'/' , +'0' ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' , +'8' ,'9' ,':' ,';' ,'<' ,'=' ,'>' ,'?' , +'@' ,'a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' , +'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o' , +'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' , +'x' ,'y' ,'z' ,'[' ,0x5c ,']' ,'^' ,'_' , +'`' ,'a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' , +'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o' , +'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' , +'x' ,'y' ,'z' ,'{' ,'|' ,'}' ,'~' ,0x7f , +0x80 ,0x81 ,0x82 ,0x83 ,0x84 ,0x85 ,0x86 ,0x87 , +0x88 ,0x89 ,0x8a ,0x8b ,0x8c ,0x8d ,0x8e ,0x8f , +0x90 ,0x91 ,0x92 ,0x93 ,0x94 ,0x95 ,0x96 ,0x97 , +0x98 ,0x99 ,0x9a ,0x9b ,0x9c ,0x9d ,0x9e ,0x9f , +0xa0 ,0xa1 ,0xa2 ,0xa3 ,0xa4 ,0xa5 ,0xa6 ,0xa7 , +0xa8 ,0xa9 ,0xaa ,0xab ,0xac ,0xad ,0xae ,0xaf , +0xb0 ,0xb1 ,0xb2 ,0xb3 ,0xb4 ,0xb5 ,0xb6 ,0xb7 , +0xb8 ,0xb9 ,0xba ,0xbb ,0xbc ,0xbd ,0xbe ,0xbf , +0xc0 ,0xc1 ,0xc2 ,0xc3 ,0xc4 ,0xc5 ,0xc6 ,0xc7 , +0xc8 ,0xc9 ,0xca ,0xcb ,0xcc ,0xcd ,0xce ,0xcf , +0xd0 ,0xd1 ,0xd2 ,0xd3 ,0xd4 ,0xd5 ,0xd6 ,0xd7 , +0xd8 ,0xd9 ,0xda ,0xdb ,0xdc ,0xdd ,0xde ,0xdf , +0xe0 ,0xe1 ,0xe2 ,0xe3 ,0xe4 ,0xe5 ,0xe6 ,0xe7 , +0xe8 ,0xe9 ,0xea ,0xeb ,0xec ,0xed ,0xee ,0xef , +0xf0 ,0xf1 ,0xf2 ,0xf3 ,0xf4 ,0xf5 ,0xf6 ,0xf7 , +0xf8 ,0xf9 ,0xfa ,0xfb ,0xfc ,0xfd ,0xfe ,0xff , +}; +/* Balanced tree of edges and labels leaving a given trie node. */ struct tree {
kwset.h +2 -0
@@ -26,6 +26,8 @@The author may be reached (Email) at the address [email protected], or (US mail) as Mike Haertel c/o Free Software Foundation. */ +extern const unsigned char tolower_trans_tbl[256 ]; +struct kwsmatch {int index;/* Index number of matching keyword. */
Signature · 1 line
2.41.0.rc2.161.g9c6817b8e7-goog
PATCH v3 5/8 common.h: move non-compat specific macros and functions
In reply to Calvin Wangit-compat-util.h has grown to a large and difficult to read file partly because its set of functionality is overloaded. Besides being a compatibility file that ensures Git's operation across different operating systems, it has also become a dumping ground for commonly used macros and static inline functions.
This commit separates out macros and static inline functions that are compatible across operating systems into common.h. common.h is reincluded back into git-compat-util.h so that other files do not also have to include it. The eventual goal is for common.h to be separated out into more reasonable boundaries, but for now this should be a good first step towards that goal.
--- common.h | 410 ++++++++++++++++++++++++++++++++++++++++++++++ git-compat-util.h | 402 +-------------------------------------------- 2 files changed, 412 insertions(+), 400 deletions(-) create mode 100644 common.h
common.h new file +410 -0
@@ -0,0 +1,410 @@ +#ifndef COMMON_H +#define COMMON_H + +#include "git-compat-util.h" +#include "wrapper.h" + +/* +* ARRAY_SIZE - get the number of elements in a visible array +* @x: the array whose size you want. +* +* This does not work on pointers, or arrays declared as [], or +* function parameters. With correct compiler support, such usage +* will cause a build error (see the build_assert_or_zero macro). +*/ +#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0]) + BARF_UNLESS_AN_ARRAY(x)) + +#define bitsizeof (x) (CHAR_BIT * sizeof(x)) + +#define maximum_signed_value_of_type (a) \ + (INTMAX_MAX >> (bitsizeof(intmax_t) - bitsizeof(a))) + +#define maximum_unsigned_value_of_type (a) \ + (UINTMAX_MAX >> (bitsizeof(uintmax_t) - bitsizeof(a))) + +/* +* Signed integer overflow is undefined in C, so here's a helper macro +* to detect if the sum of two integers will overflow. +* +* Requires: a >= 0, typeof(a) equals typeof(b) +*/ +#define signed_add_overflows (a, b) \ + ((b) > maximum_signed_value_of_type(a) - (a)) + +#define unsigned_add_overflows (a, b) \ + ((b) > maximum_unsigned_value_of_type(a) - (a)) + +/* +* Returns true if the multiplication of "a" and "b" will +* overflow. The types of "a" and "b" must match and must be unsigned. +* Note that this macro evaluates "a" twice! +*/ +#define unsigned_mult_overflows (a, b) \ + ((a) && (b) > maximum_unsigned_value_of_type(a) / (a)) + +/* +* Returns true if the left shift of "a" by "shift" bits will +* overflow. The type of "a" must be unsigned. +*/ +#define unsigned_left_shift_overflows (a, shift) \ + ((shift) < bitsizeof(a) && \ + (a) > maximum_unsigned_value_of_type(a) >> (shift)) + +#define MSB (x, bits) ((x) & TYPEOF(x)(~0ULL << (bitsizeof(x) - (bits)))) +#define HAS_MULTI_BITS (i) ((i) & ((i) - 1))/* checks if an integer has more than 1 bit set */ + +#define DIV_ROUND_UP (n,d) (((n) + (d) - 1) / (d)) + +/* Approximation of the length of the decimal representation of this type. */ +#define decimal_length (x) ((int)(sizeof(x) * 2.56 + 0.5) + 1) + +/* +* If the string "str" begins with the string found in "prefix", return 1. +* The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in +* the string right after the prefix). +* +* Otherwise, return 0 and leave "out" untouched. +* +* Examples: +* +* [extract branch name, fail if not a branch] +* if (!skip_prefix(ref, "refs/heads/", &branch) +* return -1; +* +* [skip prefix if present, otherwise use whole string] +* skip_prefix(name, "refs/heads/", &name); +*/ +static inline int skip_prefix (const char *str,const char *prefix, +const char **out) +{ +do { +if (!*prefix) { + *out = str; +return 1 ; + } + }while (*str++ == *prefix++); +return 0 ; +} + +/* +* Like skip_prefix, but promises never to read past "len" bytes of the input +* buffer, and returns the remaining number of bytes in "out" via "outlen". +*/ +static inline int skip_prefix_mem (const char *buf,size_t len, +const char *prefix, +const char **out,size_t *outlen) +{ +size_t prefix_len =strlen (prefix); +if (prefix_len <= len && !memcmp (buf, prefix, prefix_len)) { + *out = buf + prefix_len; + *outlen = len - prefix_len; +return 1 ; + } +return 0 ; +} + +/* +* If buf ends with suffix, return 1 and subtract the length of the suffix +* from *len. Otherwise, return 0 and leave *len untouched. +*/ +static inline int strip_suffix_mem (const char *buf,size_t *len, +const char *suffix) +{ +size_t suflen =strlen (suffix); +if (*len < suflen ||memcmp (buf + (*len - suflen), suffix, suflen)) +return 0 ; + *len -= suflen; +return 1 ; +} + +/* +* If str ends with suffix, return 1 and set *len to the size of the string +* without the suffix. Otherwise, return 0 and set *len to the size of the +* string. +* +* Note that we do _not_ NUL-terminate str to the new length. +*/ +static inline int strip_suffix (const char *str,const char *suffix,size_t *len) +{ + *len =strlen (str); +return strip_suffix_mem (str, len, suffix); +} + +#define SWAP (a, b) do { \ + void *_swap_a_ptr = &(a); \ + void *_swap_b_ptr = &(b); \ + unsigned char _swap_buffer[sizeof(a)]; \ + memcpy(_swap_buffer, _swap_a_ptr, sizeof(a)); \ + memcpy(_swap_a_ptr, _swap_b_ptr, sizeof(a) + \ + BUILD_ASSERT_OR_ZERO(sizeof(a) == sizeof(b))); \ + memcpy(_swap_b_ptr, _swap_buffer, sizeof(a)); \ +} while (0) + +static inline size_t st_add (size_t a,size_t b) +{ +if (unsigned_add_overflows (a, b)) +die ("size_t overflow: %" PRIuMAX" + %" PRIuMAX, + (uintmax_t )a, (uintmax_t )b); +return a + b; +} +#define st_add3 (a,b,c) st_add(st_add((a),(b)),(c)) +#define st_add4 (a,b,c,d) st_add(st_add3((a),(b),(c)),(d)) + +static inline size_t st_mult (size_t a,size_t b) +{ +if (unsigned_mult_overflows (a, b)) +die ("size_t overflow: %" PRIuMAX" * %" PRIuMAX, + (uintmax_t )a, (uintmax_t )b); +return a * b; +} + +static inline size_t st_sub (size_t a,size_t b) +{ +if (a < b) +die ("size_t underflow: %" PRIuMAX" - %" PRIuMAX, + (uintmax_t )a, (uintmax_t )b); +return a - b; +} + +static inline size_t st_left_shift (size_t a,unsigned shift) +{ +if (unsigned_left_shift_overflows (a, shift)) +die ("size_t overflow: %" PRIuMAX" << %u" , + (uintmax_t )a, shift); +return a << shift; +} + +static inline unsigned long cast_size_t_to_ulong (size_t a) +{ +if (a != (unsigned long )a) +die ("object too large to read on this platform: %" + PRIuMAX" is cut off to %lu" , + (uintmax_t )a, (unsigned long )a); +return (unsigned long )a; +} + +static inline int cast_size_t_to_int (size_t a) +{ +if (a >INT_MAX ) +die ("number too large to represent as int on this platform: %" PRIuMAX, + (uintmax_t )a); +return (int )a; +} + + +/* +* FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note +* that ptr is used twice, so don't pass e.g. ptr++. +*/ +#define FREE_AND_NULL (p) do { free(p); (p) = NULL; } while (0) + +#define ALLOC_ARRAY (x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc))) +#define CALLOC_ARRAY (x, alloc) (x) = xcalloc((alloc), sizeof(*(x))) +#define REALLOC_ARRAY (x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc))) + +#define COPY_ARRAY (dst, src, n) copy_array((dst), (src), (n), sizeof(*(dst)) + \ + BARF_UNLESS_COPYABLE((dst), (src))) +static inline void copy_array (void *dst,const void *src,size_t n,size_t size) +{ +if (n) +memcpy (dst, src,st_mult (size, n)); +} + +#define MOVE_ARRAY (dst, src, n) move_array((dst), (src), (n), sizeof(*(dst)) + \ + BARF_UNLESS_COPYABLE((dst), (src))) +static inline void move_array (void *dst,const void *src,size_t n,size_t size) +{ +if (n) +memmove (dst, src,st_mult (size, n)); +} + +#define DUP_ARRAY (dst, src, n) do { \ + size_t dup_array_n_ = (n); \ + COPY_ARRAY(ALLOC_ARRAY((dst), dup_array_n_), (src), dup_array_n_); \ +} while (0) + +/* +* These functions help you allocate structs with flex arrays, and copy +* the data directly into the array. For example, if you had: +* +* struct foo { +* int bar; +* char name[FLEX_ARRAY]; +* }; +* +* you can do: +* +* struct foo *f; +* FLEX_ALLOC_MEM(f, name, src, len); +* +* to allocate a "foo" with the contents of "src" in the "name" field. +* The resulting struct is automatically zero'd, and the flex-array field +* is NUL-terminated (whether the incoming src buffer was or not). +* +* The FLEXPTR_* variants operate on structs that don't use flex-arrays, +* but do want to store a pointer to some extra data in the same allocated +* block. For example, if you have: +* +* struct foo { +* char *name; +* int bar; +* }; +* +* you can do: +* +* struct foo *f; +* FLEXPTR_ALLOC_STR(f, name, src); +* +* and "name" will point to a block of memory after the struct, which will be +* freed along with the struct (but the pointer can be repointed anywhere). +* +* The *_STR variants accept a string parameter rather than a ptr/len +* combination. +* +* Note that these macros will evaluate the first parameter multiple +* times, and it must be assignable as an lvalue. +*/ +#define FLEX_ALLOC_MEM (x, flexname, buf, len) do { \ + size_t flex_array_len_ = (len); \ + (x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \ + memcpy((void *)(x)->flexname, (buf), flex_array_len_); \ +} while (0) +#define FLEXPTR_ALLOC_MEM (x, ptrname, buf, len) do { \ + size_t flex_array_len_ = (len); \ + (x) = xcalloc(1, st_add3(sizeof(*(x)), flex_array_len_, 1)); \ + memcpy((x) + 1, (buf), flex_array_len_); \ + (x)->ptrname = (void *)((x)+1); \ +} while(0) +#define FLEX_ALLOC_STR (x, flexname, str) \ + FLEX_ALLOC_MEM((x), flexname, (str), strlen(str)) +#define FLEXPTR_ALLOC_STR (x, ptrname, str) \ + FLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str)) + +static inline char *xstrdup_or_null (const char *str) +{ +return str ?xstrdup (str) :NULL ; +} + +static inline size_t xsize_t (off_t len) +{ +if (len <0 || (uintmax_t ) len >SIZE_MAX ) +die ("Cannot handle files this big" ); +return (size_t ) len; +} + +/* +* Like skip_prefix, but compare case-insensitively. Note that the comparison +* is done via tolower(), so it is strictly ASCII (no multi-byte characters or +* locale-specific conversions). +*/ +static inline int skip_iprefix (const char *str,const char *prefix, +const char **out) +{ +do { +if (!*prefix) { + *out = str; +return 1 ; + } + }while (tolower (*str++) ==tolower (*prefix++)); +return 0 ; +} + +/* +* Like skip_prefix_mem, but compare case-insensitively. Note that the +* comparison is done via tolower(), so it is strictly ASCII (no multi-byte +* characters or locale-specific conversions). +*/ +static inline int skip_iprefix_mem (const char *buf,size_t len, +const char *prefix, +const char **out,size_t *outlen) +{ +do { +if (!*prefix) { + *out = buf; + *outlen = len; +return 1 ; + } + }while (len-- >0 &&tolower (*buf++) ==tolower (*prefix++)); +return 0 ; +} + +static inline int strtoul_ui (char const *s,int base,unsigned int *result) +{ +unsigned long ul; +char *p; + + errno =0 ; +/* negative values would be accepted by strtoul */ +if (strchr (s,'-' )) +return -1 ; + ul =strtoul (s, &p, base); +if (errno || *p || p == s || (unsigned int ) ul != ul) +return -1 ; + *result = ul; +return 0 ; +} + +static inline int strtol_i (char const *s,int base,int *result) +{ +long ul; +char *p; + + errno =0 ; + ul =strtol (s, &p, base); +if (errno || *p || p == s || (int ) ul != ul) +return -1 ; + *result = ul; +return 0 ; +} + +static inline int regexec_buf (const regex_t *preg,const char *buf,size_t size, +size_t nmatch,regmatch_t pmatch[],int eflags) +{ +assert (nmatch >0 && pmatch); + pmatch[0 ].rm_so =0 ; + pmatch[0 ].rm_eo = size; +return regexec (preg, buf, nmatch, pmatch, eflags |REG_STARTEND ); +} + +/* +* Our code often opens a path to an optional file, to work on its +* contents when we can successfully open it. We can ignore a failure +* to open if such an optional file does not exist, but we do want to +* report a failure in opening for other reasons (e.g. we got an I/O +* error, or the file is there, but we lack the permission to open). +* +* Call this function after seeing an error from open() or fopen() to +* see if the errno indicates a missing file that we can safely ignore. +*/ +static inline int is_missing_file_error (int errno_) +{ +return (errno_ ==ENOENT || errno_ ==ENOTDIR ); +} + +/* +* container_of - Get the address of an object containing a field. +* +* @ptr: pointer to the field. +* @type: type of the object. +* @member: name of the field within the object. +*/ +#define container_of (ptr, type, member) \ + ((type *) ((char *)(ptr) - offsetof(type, member))) + +/* +* helper function for `container_of_or_null' to avoid multiple +* evaluation of @ptr +*/ +static inline void *container_of_or_null_offset (void *ptr,size_t offset) +{ +return ptr ? (char *)ptr - offset :NULL ; +} + +/* +* like `container_of', but allows returned value to be NULL +*/ +#define container_of_or_null (ptr, type, member) \ + (type *)container_of_or_null_offset(ptr, offsetof(type, member)) + + +#endif
git-compat-util.h +2 -400
462 lines not on this page · raw message
Signature · 1 line
2.41.0.rc2.161.g9c6817b8e7-goog
Re: [PATCH v3 5/8] common.h: move non-compat specific macros and functions
Quoted 26 lines · Calvin Wan
git-compat-util.hhas grown to a large and difficult to read file partly because its set of functionality is overloaded. Besides being a compatibility file that ensures Git's operation across different operating systems, it has also become a dumping ground for commonly used macros and static inline functions.This commit separates out macros and static inline functions that are compatible across operating systems into
common.h.common.his reincluded back intogit-compat-util.hso that other files do not also have to include it. The eventual goal is forcommon.hto be separated out into more reasonable boundaries, but for now this should be a good first step towards that goal.Signed-off-by Calvin Wan <[email protected]>--- common.h | 410 ++++++++++++++++++++++++++++++++++++++++++++++ git-compat-util.h | 402 +-------------------------------------------- 2 files changed, 412 insertions(+), 400 deletions(-) create mode 100644 common.hcommon.h new file +0
-0
common.h line 4
Quoted 4 lines
common.h new file +4
-0@@ -0,0 +1,410 @@ +#ifndef COMMON_H +#define COMMON_H + +#include "git-compat-util.h"
Hmm, ... So, "common.h" includes "git-compat-util.h", which in turn includes "common.h" ?
Something is not right here! ;)
(Sorry, I have not been following this series, it just floated past on the ML and looked odd ...)
ATB,
Ramsay Jones
Re: [PATCH v3 5/8] common.h: move non-compat specific macros and functions
Is there a particular problem here? common.h includes git-compat-util.h at the top so that it has access to standard libraries and possibly other compat utilities. git-compat-util.h includes common.h at the bottom so that other files don't have to also include common.h as well. Imagine if instead of having git-compat-util include common.h, we had a third file here: git-compat-common.h. It includes common.h and git-compat-util.h and every file includes that instead of git-compat-util.h. Now git-compat-util.h wouldn't include common.h, but this change can be circumvented by including common.h at the bottom.
Re: [PATCH v3 5/8] common.h: move non-compat specific macros and functions
Quoted 1 line · Calvin Wan
Is there a particular problem here?
Doesn't it defeat the notion that each header file is safe to include twice via "#ifndef FOO/#define FOO/#endif" safeguard and makes anybody who sees the recursive inclusion to think twice before they can convince themselves that it is OK for this particular pair?
Re: [PATCH v3 5/8] common.h: move non-compat specific macros and functions
Quoted 6 lines
Quoted 1 line
Is there a particular problem here?
Doesn't it defeat the notion that each header file is safe to include twice via "#ifndef FOO/#define FOO/#endif" safeguard and makes anybody who sees the recursive inclusion to think twice before they can convince themselves that it is OK for this particular pair?
In that case do you have any recommendations as to how I can make clear that this recursive inclusion isn't problematic or refactor away the recursive inclusion without having to change the header inclusions of every other Git file?
Re: [PATCH v3 5/8] common.h: move non-compat specific macros and functions
Quoted 4 lines · Calvin Wan
In that case do you have any recommendations as to how I can make clear that this recursive inclusion isn't problematic or refactor away the recursive inclusion without having to change the header inclusions of every other Git file?
"Without having to" is an unfair restrition, given that you do not have to create common.h and move things around in the first place ;-)
Re: [PATCH v3 5/8] common.h: move non-compat specific macros and functions
Quoted 3 lines
"Without having to" is an unfair restrition, given that you do not have to create
common.hand move things around in the first place ;-)
that's a good point...part of this change was motivated by having a more natural location to move the general ALLOC functions in alloc.h. Thought I would clean up git-compat-util.h along the way, but I can throw this patch on the back burner until there's more of a need for it (maybe just having a separate section in git-compat-util.h for common functions/macros also works).
PATCH v3 6/8 git-compat-util: move usage.c funcs to its header
In reply to Calvin Wan--- common.h | 1 + git-compat-util.h | 55 ------------------------------------------- usage.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 55 deletions(-) create mode 100644 usage.h
common.h +1 -0
@@ -3,6 +3,7 @@#include "git-compat-util.h" #include "wrapper.h" +#include "usage.h" /* * ARRAY_SIZE - get the number of elements in a visible array
git-compat-util.h +0 -55
73 lines not on this page · raw message
usage.h new file +60 -0
60 lines not on this page · raw message
Signature · 1 line
2.41.0.rc2.161.g9c6817b8e7-goog
PATCH v3 7/8 treewide: remove unnecessary includes for wrapper.h
In reply to Calvin Wan--- apply.c | 1 - builtin/am.c | 1 - builtin/bisect.c | 1 - builtin/branch.c | 1 - builtin/bugreport.c | 1 - builtin/clone.c | 1 - builtin/config.c | 1 - builtin/credential-cache.c | 1 - builtin/difftool.c | 1 - builtin/fast-import.c | 1 - builtin/fmt-merge-msg.c | 1 - builtin/gc.c | 1 - builtin/get-tar-commit-id.c | 1 - builtin/index-pack.c | 1 - builtin/init-db.c | 1 - builtin/merge.c | 1 - builtin/pack-objects.c | 1 - builtin/rebase.c | 1 - builtin/receive-pack.c | 1 - builtin/rerere.c | 1 - builtin/unpack-file.c | 1 - builtin/worktree.c | 1 - bulk-checkin.c | 1 - combine-diff.c | 1 - commit-graph.c | 1 - compat/terminal.c | 1 - config.c | 1 - convert.c | 1 - copy.c | 1 - csum-file.c | 1 - daemon.c | 1 - diff.c | 1 - dir.c | 1 - editor.c | 1 - entry.c | 1 - environment.c | 1 - fetch-pack.c | 1 - gpg-interface.c | 1 - grep.c | 1 - http-backend.c | 1 - imap-send.c | 1 - merge-ll.c | 1 - merge-recursive.c | 1 - notes-merge.c | 1 - object-file.c | 1 - pack-write.c | 1 - packfile.c | 1 - parallel-checkout.c | 1 - path.c | 1 - pkt-line.c | 1 - read-cache.c | 1 - rebase-interactive.c | 1 - refs.c | 1 - rerere.c | 1 - send-pack.c | 1 - sequencer.c | 1 - server-info.c | 1 - setup.c | 1 - shallow.c | 1 - strbuf.c | 1 - streaming.c | 1 - t/helper/test-delta.c | 1 - t/helper/test-fsmonitor-client.c | 1 - t/helper/test-read-cache.c | 1 - tag.c | 1 - tempfile.c | 1 - trace.c | 1 - transport-helper.c | 1 - transport.c | 1 - upload-pack.c | 1 - usage.c | 1 - worktree.c | 1 - wrapper.c | 1 - write-or-die.c | 1 - 74 files changed, 74 deletions(-)
apply.c +0 -1
@@ -37,7 +37,6 @@#include "symlinks.h" #include "wildmatch.h" #include "ws.h" -#include "wrapper.h" struct gitdiff_data {struct strbuf *root;
builtin/am.c +0 -1
@@ -44,7 +44,6 @@#include "path.h" #include "repository.h" #include "pretty.h" -#include "wrapper.h" /** * Returns the length of the first line of msg.
builtin/bisect.c +0 -1
@@ -15,7 +15,6 @@#include "prompt.h" #include "quote.h" #include "revision.h" -#include "wrapper.h" static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS") static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
builtin/branch.c +0 -1
@@ -28,7 +28,6 @@#include "worktree.h" #include "help.h" #include "commit-reach.h" -#include "wrapper.h" static const char *const builtin_branch_usage[] = {N_ ("git branch [<options>] [-r | -a] [--merged] [--no-merged]" ),
builtin/bugreport.c +0 -1
@@ -11,7 +11,6 @@#include "diagnose.h" #include "object-file.h" #include "setup.h" -#include "wrapper.h" static void get_system_info (struct strbuf *sys_info) {
builtin/clone.c +0 -1
@@ -45,7 +45,6 @@#include "hook.h" #include "bundle.h" #include "bundle-uri.h" -#include "wrapper.h" /* * Overall FIXMEs:
builtin/config.c +0 -1
@@ -14,7 +14,6 @@#include "setup.h" #include "strbuf.h" #include "worktree.h" -#include "wrapper.h" static const char *const builtin_config_usage[] = {N_ ("git config [<options>]" ),
builtin/credential-cache.c +0 -1
@@ -3,7 +3,6 @@#include "parse-options.h" #include "path.h" #include "strbuf.h" -#include "wrapper.h" #include "write-or-die.h" #ifndef NO_UNIX_SOCKETS
builtin/difftool.c +0 -1
@@ -32,7 +32,6 @@#include "dir.h" #include "entry.h" #include "setup.h" -#include "wrapper.h" static int trust_exit_code;
builtin/fast-import.c +0 -1
@@ -26,7 +26,6 @@#include "commit-reach.h" #include "khash.h" #include "date.h" -#include "wrapper.h" #define PACK_ID_BITS 16#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
builtin/fmt-merge-msg.c +0 -1
@@ -3,7 +3,6 @@#include "fmt-merge-msg.h" #include "gettext.h" #include "parse-options.h" -#include "wrapper.h" static const char *const fmt_merge_msg_usage[] = {N_ ("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]" ),
builtin/gc.c +0 -1
@@ -41,7 +41,6 @@#include "hook.h" #include "setup.h" #include "trace2.h" -#include "wrapper.h" #define FAILED_RUN "failed to run %s"
builtin/get-tar-commit-id.c +0 -1
@@ -5,7 +5,6 @@#include "commit.h" #include "tar.h" #include "quote.h" -#include "wrapper.h" static const char builtin_get_tar_commit_id_usage[] ="git get-tar-commit-id" ;
builtin/index-pack.c +0 -1
@@ -25,7 +25,6 @@#include "replace-object.h" #include "promisor-remote.h" #include "setup.h" -#include "wrapper.h" static const char index_pack_usage[] ="git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])" ;
builtin/init-db.c +0 -1
@@ -13,7 +13,6 @@#include "path.h" #include "setup.h" #include "strbuf.h" -#include "wrapper.h" static int guess_repository_type (const char *git_dir) {
builtin/merge.c +0 -1
@@ -53,7 +53,6 @@#include "commit-reach.h" #include "wt-status.h" #include "commit-graph.h" -#include "wrapper.h" #define DEFAULT_TWOHEAD (1<<0)#define DEFAULT_OCTOPUS (1<<1)
builtin/pack-objects.c +0 -1
@@ -43,7 +43,6 @@#include "promisor-remote.h" #include "pack-mtimes.h" #include "parse-options.h" -#include "wrapper.h" /* * Objects we are going to pack are collected in the `to_pack` structure.
builtin/rebase.c +0 -1
@@ -37,7 +37,6 @@#include "reset.h" #include "trace2.h" #include "hook.h" -#include "wrapper.h" static char const *const builtin_rebase_usage[] = { N_("git rebase [-i] [options] [--exec <cmd>] "
builtin/receive-pack.c +0 -1
@@ -40,7 +40,6 @@#include "worktree.h" #include "shallow.h" #include "parse-options.h" -#include "wrapper.h" static const char *const receive_pack_usage[] = {N_ ("git receive-pack <git-dir>" ),
builtin/rerere.c +0 -1
@@ -6,7 +6,6 @@#include "repository.h" #include "string-list.h" #include "rerere.h" -#include "wrapper.h" #include "xdiff/xdiff.h" #include "xdiff-interface.h" #include "pathspec.h"
builtin/unpack-file.c +0 -1
@@ -3,7 +3,6 @@#include "hex.h" #include "object-name.h" #include "object-store-ll.h" -#include "wrapper.h" static char *create_temp_file (struct object_id *oid) {
builtin/worktree.c +0 -1
@@ -22,7 +22,6 @@#include "submodule.h" #include "utf8.h" #include "worktree.h" -#include "wrapper.h" #include "quote.h" #define BUILTIN_WORKTREE_ADD_USAGE \
bulk-checkin.c +0 -1
@@ -17,7 +17,6 @@#include "packfile.h" #include "object-file.h" #include "object-store-ll.h" -#include "wrapper.h" static int odb_transaction_nesting;
combine-diff.c +0 -1
@@ -17,7 +17,6 @@#include "userdiff.h" #include "oid-array.h" #include "revision.h" -#include "wrapper.h" static int compare_paths (const struct combine_diff_path *one,const struct diff_filespec *two)
commit-graph.c +0 -1
@@ -26,7 +26,6 @@#include "trace2.h" #include "tree.h" #include "chunk-format.h" -#include "wrapper.h" void git_test_write_commit_graph_or_die (void ) {
compat/terminal.c +0 -1
@@ -6,7 +6,6 @@#include "run-command.h" #include "string-list.h" #include "hashmap.h" -#include "wrapper.h" #if defined(HAVE_DEV_TTY ) || defined(GIT_WINDOWS_NATIVE )
config.c +0 -1
@@ -39,7 +39,6 @@#include "wildmatch.h" #include "worktree.h" #include "ws.h" -#include "wrapper.h" #include "write-or-die.h" struct config_source {
convert.c +0 -1
@@ -16,7 +16,6 @@#include "trace.h" #include "utf8.h" #include "merge-ll.h" -#include "wrapper.h" /* * convert.c - convert a file when checking it out and checking it in.
copy.c +0 -1
@@ -1,7 +1,6 @@#include "git-compat-util.h" #include "copy.h" #include "path.h" -#include "wrapper.h" int copy_fd (int ifd,int ofd) {
csum-file.c +0 -1
@@ -11,7 +11,6 @@#include "progress.h" #include "csum-file.h" #include "hash.h" -#include "wrapper.h" static void verify_buffer_or_die(struct hashfile *f, const void *buf,
daemon.c +0 -1
@@ -10,7 +10,6 @@#include "setup.h" #include "strbuf.h" #include "string-list.h" -#include "wrapper.h" #ifdef NO_INITGROUPS #define initgroups (x, y) (0)/* nothing */
diff.c +0 -1
@@ -43,7 +43,6 @@#include "setup.h" #include "strmap.h" #include "ws.h" -#include "wrapper.h" #ifdef NO_FAST_WORKING_DIRECTORY #define FAST_WORKING_DIRECTORY 0
dir.c +0 -1
@@ -32,7 +32,6 @@#include "symlinks.h" #include "trace2.h" #include "tree.h" -#include "wrapper.h" /* * Tells read_directory_recursive how a file or directory should be treated.
editor.c +0 -1
@@ -11,7 +11,6 @@#include "strvec.h" #include "run-command.h" #include "sigchain.h" -#include "wrapper.h" #ifndef DEFAULT_EDITOR #define DEFAULT_EDITOR "vi"
entry.c +0 -1
@@ -14,7 +14,6 @@#include "fsmonitor.h" #include "entry.h" #include "parallel-checkout.h" -#include "wrapper.h" static void create_directories (const char *path,int path_len,const struct checkout *state)
environment.c +0 -1
@@ -28,7 +28,6 @@#include "setup.h" #include "shallow.h" #include "trace.h" -#include "wrapper.h" #include "write-or-die.h" int trust_executable_bit =1 ;
fetch-pack.c +0 -1
@@ -34,7 +34,6 @@#include "commit-graph.h" #include "sigchain.h" #include "mergesort.h" -#include "wrapper.h" static int transfer_unpack_limit =-1 ;static int fetch_unpack_limit =-1 ;
gpg-interface.c +0 -1
@@ -12,7 +12,6 @@#include "sigchain.h" #include "tempfile.h" #include "alias.h" -#include "wrapper.h" #include "environment.h" static int git_gpg_config (const char *,const char *,void *);
grep.c +0 -1
@@ -12,7 +12,6 @@#include "commit.h" #include "quote.h" #include "help.h" -#include "wrapper.h" static int grep_source_load (struct grep_source *gs); static int grep_source_is_binary(struct grep_source *gs,
http-backend.c +0 -1
@@ -19,7 +19,6 @@#include "object-store-ll.h" #include "protocol.h" #include "date.h" -#include "wrapper.h" #include "write-or-die.h" static const char content_type[] ="Content-Type" ;
imap-send.c +0 -1
@@ -30,7 +30,6 @@#include "parse-options.h" #include "setup.h" #include "strbuf.h" -#include "wrapper.h" #if defined(NO_OPENSSL ) && !defined(HAVE_OPENSSL_CSPRNG )typedef void *SSL ;#endif
merge-ll.c +0 -1
@@ -13,7 +13,6 @@#include "merge-ll.h" #include "quote.h" #include "strbuf.h" -#include "wrapper.h" struct ll_merge_driver ;
merge-recursive.c +0 -1
@@ -38,7 +38,6 @@#include "tag.h" #include "tree-walk.h" #include "unpack-trees.h" -#include "wrapper.h" #include "xdiff-interface.h" struct merge_options_internal {
notes-merge.c +0 -1
@@ -20,7 +20,6 @@#include "trace.h" #include "notes-utils.h" #include "commit-reach.h" -#include "wrapper.h" struct notes_merge_pair {struct object_id obj, base, local, remote;
object-file.c +0 -1
@@ -44,7 +44,6 @@#include "setup.h" #include "submodule.h" #include "fsck.h" -#include "wrapper.h" /* The maximum size for an object header. */ #define MAX_HEADER_LEN 32
pack-write.c +0 -1
@@ -12,7 +12,6 @@#include "pack-revindex.h" #include "path.h" #include "strbuf.h" -#include "wrapper.h" void reset_pack_idx_option (struct pack_idx_option *opts) {
packfile.c +0 -1
@@ -24,7 +24,6 @@#include "commit-graph.h" #include "pack-revindex.h" #include "promisor-remote.h" -#include "wrapper.h" char *odb_pack_name(struct strbuf *buf, const unsigned char *hash,
parallel-checkout.c +0 -1
@@ -15,7 +15,6 @@#include "symlinks.h" #include "thread-utils.h" #include "trace2.h" -#include "wrapper.h" struct pc_worker {struct child_process cp;
path.c +0 -1
@@ -18,7 +18,6 @@#include "object-store-ll.h" #include "lockfile.h" #include "exec-cmd.h" -#include "wrapper.h" static int get_st_mode_bits (const char *path,int *mode) {
pkt-line.c +0 -1
@@ -5,7 +5,6 @@#include "hex.h" #include "run-command.h" #include "trace.h" -#include "wrapper.h" #include "write-or-die.h" char packet_buffer[LARGE_PACKET_MAX ];
read-cache.c +0 -1
@@ -46,7 +46,6 @@#include "csum-file.h" #include "promisor-remote.h" #include "hook.h" -#include "wrapper.h" /* Mask for the name length in ce_flags in the on-disk index */
rebase-interactive.c +0 -1
@@ -11,7 +11,6 @@#include "config.h" #include "dir.h" #include "object-name.h" -#include "wrapper.h" static const char edit_todo_list_advice[] = N_("You can fix this with 'git rebase --edit-todo' "
refs.c +0 -1
@@ -30,7 +30,6 @@#include "date.h" #include "commit.h" #include "wildmatch.h" -#include "wrapper.h" /* * List of all available backends
rerere.c +0 -1
@@ -20,7 +20,6 @@#include "object-store-ll.h" #include "hash-lookup.h" #include "strmap.h" -#include "wrapper.h" #define RESOLVED 0#define PUNTED 1
send-pack.c +0 -1
@@ -15,7 +15,6 @@#include "quote.h" #include "transport.h" #include "version.h" -#include "wrapper.h" #include "oid-array.h" #include "gpg-interface.h" #include "shallow.h"
sequencer.c +0 -1
@@ -49,7 +49,6 @@#include "rebase-interactive.h" #include "reset.h" #include "branch.h" -#include "wrapper.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
server-info.c +0 -1
@@ -14,7 +14,6 @@#include "object-store-ll.h" #include "server-info.h" #include "strbuf.h" -#include "wrapper.h" struct update_info_ctx {FILE *cur_fp;
setup.c +0 -1
@@ -17,7 +17,6 @@#include "quote.h" #include "trace2.h" #include "worktree.h" -#include "wrapper.h" static int inside_git_dir =-1 ;static int inside_work_tree =-1 ;
shallow.c +0 -1
@@ -20,7 +20,6 @@#include "shallow.h" #include "statinfo.h" #include "trace.h" -#include "wrapper.h" void set_alternate_shallow_file (struct repository *r,const char *path,int override) {
strbuf.c +0 -1
@@ -8,7 +8,6 @@#include "string-list.h" #include "utf8.h" #include "date.h" -#include "wrapper.h" int starts_with (const char *str,const char *prefix) {
streaming.c +0 -1
@@ -10,7 +10,6 @@#include "object-store-ll.h" #include "replace-object.h" #include "packfile.h" -#include "wrapper.h" typedef int (*open_istream_fn)(struct git_istream *, struct repository *,
t/helper/test-delta.c +0 -1
@@ -11,7 +11,6 @@#include "test-tool.h" #include "git-compat-util.h" #include "delta.h" -#include "wrapper.h" static const char usage_str[] ="test-tool delta (-d|-p) <from_file> <data_file> <out_file>" ;
t/helper/test-fsmonitor-client.c +0 -1
@@ -11,7 +11,6 @@#include "setup.h" #include "thread-utils.h" #include "trace2.h" -#include "wrapper.h" #ifndef HAVE_FSMONITOR_DAEMON_BACKEND int cmd__fsmonitor_client(int argc UNUSED, const char **argv UNUSED)
t/helper/test-read-cache.c +0 -1
@@ -4,7 +4,6 @@#include "read-cache-ll.h" #include "repository.h" #include "setup.h" -#include "wrapper.h" int cmd__read_cache (int argc,const char **argv) {
tag.c +0 -1
@@ -10,7 +10,6 @@#include "gpg-interface.h" #include "hex.h" #include "packfile.h" -#include "wrapper.h" const char *tag_type ="tag" ;
tempfile.c +0 -1
@@ -47,7 +47,6 @@#include "path.h" #include "tempfile.h" #include "sigchain.h" -#include "wrapper.h" static VOLATILE_LIST_HEAD (tempfile_list);
trace.c +0 -1
@@ -27,7 +27,6 @@#include "quote.h" #include "setup.h" #include "trace.h" -#include "wrapper.h" struct trace_key trace_default_key = {"GIT_TRACE" ,0 ,0 ,0 };struct trace_key trace_perf_key =TRACE_KEY_INIT (PERFORMANCE );
transport-helper.c +0 -1
@@ -19,7 +19,6 @@#include "refspec.h" #include "transport-internal.h" #include "protocol.h" -#include "wrapper.h" static int debug;
transport.c +0 -1
@@ -30,7 +30,6 @@#include "object-store-ll.h" #include "color.h" #include "bundle-uri.h" -#include "wrapper.h" static int transport_use_color =-1 ;static char transport_colors[][COLOR_MAXLEN ] = {
upload-pack.c +0 -1
@@ -32,7 +32,6 @@#include "commit-graph.h" #include "commit-reach.h" #include "shallow.h" -#include "wrapper.h" #include "write-or-die.h" /* Remember to update object flag allocation in object.h */
usage.c +0 -1
@@ -6,7 +6,6 @@#include "git-compat-util.h" #include "gettext.h" #include "trace2.h" -#include "wrapper.h" static void vreportf (const char *prefix,const char *err,va_list params) {
worktree.c +0 -1
@@ -12,7 +12,6 @@#include "dir.h" #include "wt-status.h" #include "config.h" -#include "wrapper.h" void free_worktrees (struct worktree **worktrees) {
wrapper.c +0 -1
@@ -9,7 +9,6 @@#include "repository.h" #include "strbuf.h" #include "trace2.h" -#include "wrapper.h" static intmax_t count_fsync_writeout_only;static intmax_t count_fsync_hardware_flush;
write-or-die.c +0 -1
@@ -1,7 +1,6 @@#include "git-compat-util.h" #include "config.h" #include "run-command.h" -#include "wrapper.h" #include "write-or-die.h" /*
Signature · 1 line
2.41.0.rc2.161.g9c6817b8e7-goog
PATCH v3 8/8 common: move alloc macros to common.h
In reply to Calvin Wanalloc_nr, ALLOC_GROW, and ALLOC_GROW_BY are commonly used macros for dynamic array allocation. Moving these macros to common.h focuses alloc.[ch] to allocation for Git objects and additionally allows us to remove inclusions to alloc.h from files that solely used the above macros.
--- add-patch.c | 1 - alias.c | 1 - alloc.h | 75 ------------------------------ apply.c | 1 - archive-tar.c | 1 - archive.c | 1 - attr.c | 1 - builtin/blame.c | 1 - builtin/cat-file.c | 1 - builtin/checkout--worker.c | 1 - builtin/config.c | 1 - builtin/credential-cache--daemon.c | 1 - builtin/fetch-pack.c | 1 - builtin/fsmonitor--daemon.c | 1 - builtin/grep.c | 1 - builtin/index-pack.c | 1 - builtin/log.c | 1 - builtin/merge.c | 1 - builtin/mktree.c | 1 - builtin/mv.c | 1 - builtin/name-rev.c | 1 - builtin/pack-objects.c | 1 - builtin/repack.c | 1 - builtin/rev-parse.c | 1 - builtin/revert.c | 1 - builtin/rm.c | 1 - builtin/submodule--helper.c | 1 - bulk-checkin.c | 1 - cache-tree.c | 1 - chunk-format.c | 1 - commit-reach.c | 1 - common.h | 75 ++++++++++++++++++++++++++++++ config.c | 1 - daemon.c | 1 - delta-islands.c | 1 - diff.c | 1 - diffcore-rename.c | 1 - dir-iterator.c | 1 - dir.c | 1 - ewah/bitmap.c | 1 - ewah/ewah_bitmap.c | 1 - fetch-pack.c | 1 - fmt-merge-msg.c | 1 - fsck.c | 1 - help.c | 1 - http-backend.c | 1 - line-log.c | 1 - list-objects-filter-options.c | 1 - list-objects-filter.c | 1 - midx.c | 1 - object-file.c | 1 - oid-array.c | 1 - oidtree.c | 1 - pack-bitmap-write.c | 1 - pack-bitmap.c | 1 - pack-objects.c | 1 - packfile.c | 1 - parallel-checkout.c | 1 - pretty.c | 1 - prio-queue.c | 1 - quote.c | 1 - read-cache.c | 1 - ref-filter.c | 1 - reflog-walk.c | 1 - refs.c | 1 - refspec.c | 1 - remote-curl.c | 1 - remote.c | 1 - rerere.c | 1 - revision.c | 1 - sequencer.c | 1 - server-info.c | 1 - shallow.c | 1 - sigchain.c | 1 - sparse-index.c | 1 - split-index.c | 1 - strbuf.c | 1 - string-list.c | 1 - strvec.c | 1 - submodule-config.c | 1 - submodule.c | 1 - t/helper/test-reach.c | 1 - trace2/tr2_tls.c | 1 - trailer.c | 1 - transport.c | 1 - tree-walk.c | 1 - userdiff.c | 1 - worktree.c | 1 - 88 files changed, 75 insertions(+), 161 deletions(-)
add-patch.c +0 -1
@@ -1,7 +1,6 @@#include "git-compat-util.h" #include "add-interactive.h" #include "advice.h" -#include "alloc.h" #include "editor.h" #include "environment.h" #include "gettext.h"
alias.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "alias.h" -#include "alloc.h" #include "config.h" #include "gettext.h" #include "strbuf.h"
alloc.h +0 -75
79 lines not on this page · raw message
apply.c +0 -1
@@ -9,7 +9,6 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "base85.h" #include "config.h" #include "object-store-ll.h"
archive-tar.c +0 -1
@@ -2,7 +2,6 @@* Copyright (c) 2005, 2006 Rene Scharfe */ #include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "gettext.h" #include "git-zlib.h"
archive.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "environment.h"
attr.c +0 -1
@@ -7,7 +7,6 @@*/ #include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "exec-cmd.h"
builtin/blame.c +0 -1
@@ -6,7 +6,6 @@*/ #include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "color.h" #include "builtin.h"
builtin/cat-file.c +0 -1
@@ -5,7 +5,6 @@*/ #define USE_THE_INDEX_VARIABLE #include "builtin.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "diff.h"
builtin/checkout--worker.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "config.h" #include "entry.h" #include "gettext.h"
builtin/config.c +0 -1
@@ -1,6 +1,5 @@#include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "color.h" #include "editor.h"
builtin/credential-cache--daemon.c +0 -1
@@ -1,6 +1,5 @@#include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "gettext.h" #include "object-file.h" #include "parse-options.h"
builtin/fetch-pack.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "gettext.h" #include "hex.h" #include "object-file.h"
builtin/fsmonitor--daemon.c +0 -1
@@ -1,6 +1,5 @@#include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
builtin/grep.c +0 -1
@@ -4,7 +4,6 @@* Copyright (c) 2006 Junio C Hamano */ #include "builtin.h" -#include "alloc.h" #include "gettext.h" #include "hex.h" #include "repository.h"
builtin/index-pack.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "config.h" #include "delta.h" #include "environment.h"
builtin/log.c +0 -1
@@ -6,7 +6,6 @@*/ #include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
builtin/merge.c +0 -1
@@ -10,7 +10,6 @@#include "builtin.h" #include "abspath.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "editor.h" #include "environment.h"
builtin/mktree.c +0 -1
@@ -4,7 +4,6 @@* Copyright (c) Junio C Hamano, 2006, 2009 */ #include "builtin.h" -#include "alloc.h" #include "gettext.h" #include "hex.h" #include "quote.h"
builtin/mv.c +0 -1
@@ -7,7 +7,6 @@#include "builtin.h" #include "abspath.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
builtin/name-rev.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
builtin/pack-objects.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
builtin/repack.c +0 -1
@@ -1,5 +1,4 @@#include "builtin.h" -#include "alloc.h" #include "config.h" #include "dir.h" #include "environment.h"
builtin/rev-parse.c +0 -1
@@ -6,7 +6,6 @@#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "commit.h" #include "environment.h"
builtin/revert.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "builtin.h" #include "parse-options.h"
builtin/rm.c +0 -1
@@ -5,7 +5,6 @@*/ #define USE_THE_INDEX_VARIABLE #include "builtin.h" -#include "alloc.h" #include "advice.h" #include "config.h" #include "lockfile.h"
builtin/submodule--helper.c +0 -1
@@ -1,7 +1,6 @@#define USE_THE_INDEX_VARIABLE #include "builtin.h" #include "abspath.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
bulk-checkin.c +0 -1
@@ -2,7 +2,6 @@* Copyright (c) 2011, Google Inc. */ #include "git-compat-util.h" -#include "alloc.h" #include "bulk-checkin.h" #include "environment.h" #include "gettext.h"
cache-tree.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "environment.h" #include "hex.h" #include "lockfile.h"
chunk-format.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "chunk-format.h" #include "csum-file.h" #include "gettext.h"
commit-reach.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "commit.h" #include "commit-graph.h" #include "decorate.h"
common.h +75 -0
81 lines not on this page · raw message
config.c +0 -1
@@ -8,7 +8,6 @@#include "git-compat-util.h" #include "abspath.h" #include "advice.h" -#include "alloc.h" #include "date.h" #include "branch.h" #include "config.h"
daemon.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "path.h"
delta-islands.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "attr.h" #include "object.h" #include "blob.h"
diff.c +0 -1
@@ -3,7 +3,6 @@*/ #include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "base85.h" #include "config.h" #include "convert.h"
diffcore-rename.c +0 -1
@@ -3,7 +3,6 @@* Copyright (C) 2005 Junio C Hamano */ #include "git-compat-util.h" -#include "alloc.h" #include "diff.h" #include "diffcore.h" #include "object-store-ll.h"
dir-iterator.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "dir.h" #include "iterator.h" #include "dir-iterator.h"
dir.c +0 -1
@@ -7,7 +7,6 @@*/ #include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "dir.h"
ewah/bitmap.c +0 -1
@@ -17,7 +17,6 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ #include "git-compat-util.h" -#include "alloc.h" #include "ewok.h" #define EWAH_MASK (x) ((eword_t)1 << (x % BITS_IN_EWORD))
ewah/ewah_bitmap.c +0 -1
@@ -17,7 +17,6 @@* along with this program; if not, see <http://www.gnu.org/licenses/>. */ #include "git-compat-util.h" -#include "alloc.h" #include "ewok.h" #include "ewok_rlw.h"
fetch-pack.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "repository.h" #include "config.h" #include "date.h"
fmt-merge-msg.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "refs.h"
fsck.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "date.h" #include "dir.h" #include "hex.h"
help.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "builtin.h" #include "exec-cmd.h"
http-backend.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "git-zlib.h"
line-log.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "line-range.h" #include "hex.h" #include "tag.h"
list-objects-filter-options.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "commit.h" #include "config.h" #include "gettext.h"
list-objects-filter.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "dir.h" #include "gettext.h" #include "hex.h"
midx.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "csum-file.h" #include "dir.h"
object-file.c +0 -1
@@ -8,7 +8,6 @@*/ #include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "convert.h" #include "environment.h"
oid-array.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "oid-array.h" #include "hash-lookup.h"
oidtree.c +0 -1
@@ -4,7 +4,6 @@*/ #include "git-compat-util.h" #include "oidtree.h" -#include "alloc.h" #include "hash.h" struct oidtree_iter_data {
pack-bitmap-write.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
pack-bitmap.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "commit.h" #include "gettext.h" #include "hex.h"
pack-objects.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "object.h" #include "pack.h" #include "pack-objects.h"
packfile.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "hex.h"
parallel-checkout.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "entry.h" #include "gettext.h"
pretty.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "commit.h" #include "environment.h"
prio-queue.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "prio-queue.h" static inline int compare (struct prio_queue *queue,int i,int j)
quote.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "path.h" #include "quote.h" #include "strbuf.h"
read-cache.c +0 -1
@@ -4,7 +4,6 @@* Copyright (C) Linus Torvalds, 2005 */ #include "git-compat-util.h" -#include "alloc.h" #include "bulk-checkin.h" #include "config.h" #include "date.h"
ref-filter.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "gpg-interface.h"
reflog-walk.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "commit.h" #include "refs.h" #include "diff.h"
refs.c +0 -1
@@ -4,7 +4,6 @@#include "git-compat-util.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "hashmap.h"
refspec.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "gettext.h" #include "hash.h" #include "hex.h"
remote-curl.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
remote.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
rerere.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "config.h" #include "copy.h" #include "gettext.h"
revision.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
sequencer.c +0 -1
@@ -1,7 +1,6 @@#include "git-compat-util.h" #include "abspath.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "copy.h" #include "environment.h"
server-info.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "dir.h" #include "environment.h" #include "hex.h"
shallow.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "hex.h" #include "repository.h" #include "tempfile.h"
sigchain.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "sigchain.h" #define SIGCHAIN_MAX_SIGNALS 32
sparse-index.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "name-hash.h"
split-index.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "gettext.h" #include "hash.h" #include "mem-pool.h"
strbuf.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "gettext.h" #include "hex.h" #include "strbuf.h"
string-list.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "string-list.h" -#include "alloc.h" void string_list_init_nodup (struct string_list *list) {
strvec.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "strvec.h" -#include "alloc.h" #include "hex.h" #include "strbuf.h"
submodule-config.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "dir.h" #include "environment.h" #include "gettext.h"
submodule.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "repository.h" #include "config.h" #include "submodule-config.h"
t/helper/test-reach.c +0 -1
@@ -1,5 +1,4 @@#include "test-tool.h" -#include "alloc.h" #include "commit.h" #include "commit-reach.h" #include "config.h"
trace2/tr2_tls.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "thread-utils.h" #include "trace.h" #include "trace2/tr2_tls.h"
trailer.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "gettext.h"
transport.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "advice.h" -#include "alloc.h" #include "config.h" #include "environment.h" #include "hex.h"
tree-walk.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "tree-walk.h" -#include "alloc.h" #include "dir.h" #include "gettext.h" #include "hex.h"
userdiff.c +0 -1
@@ -1,5 +1,4 @@#include "git-compat-util.h" -#include "alloc.h" #include "config.h" #include "userdiff.h" #include "attr.h"
worktree.c +0 -1
@@ -1,6 +1,5 @@#include "git-compat-util.h" #include "abspath.h" -#include "alloc.h" #include "environment.h" #include "gettext.h" #include "path.h"
Signature · 1 line
2.41.0.rc2.161.g9c6817b8e7-goog
v4 cover git-compat-util cleanups
In reply to Calvin WanChanges since v3:
- Dropped patches 5 and 6 since removing the circular dependency in common.h turns out to be quite difficult
- Patch 8 moves the alloc macros to git-compat-util.h rather than common.h since that does not exist anymore
Note for the maintainer:
I rebased this series onto both seen and next and they rebased cleanly. As currently submitted, it is rebased onto next at (38632f3da). Hopefully this series now doesn't cause any issues with other inflight series.
Calvin Wan (6):
git-compat-util: move strbuf.c funcs to its header
git-compat-util: move wrapper.c funcs to its header sane-ctype.h: create header for sane-ctype macros
kwset: move translation table from ctype
treewide: remove unnecessary includes for wrapper.h
common: move alloc macros to common.h
add-patch.c | 1 - alias.c | 1 - alloc.h | 75 -------- apply.c | 2 - archive-tar.c | 1 - archive.c | 1 - attr.c | 1 - builtin/am.c | 1 - builtin/bisect.c | 1 - builtin/blame.c | 1 - builtin/branch.c | 1 - builtin/bugreport.c | 1 - builtin/cat-file.c | 1 - builtin/checkout--worker.c | 1 - builtin/clone.c | 1 - builtin/config.c | 2 - builtin/credential-cache--daemon.c | 1 - builtin/credential-cache.c | 1 - builtin/difftool.c | 1 - builtin/fast-import.c | 1 - builtin/fetch-pack.c | 1 - builtin/fmt-merge-msg.c | 1 - builtin/fsmonitor--daemon.c | 1 - builtin/gc.c | 1 - builtin/get-tar-commit-id.c | 1 - builtin/grep.c | 1 - builtin/index-pack.c | 2 - builtin/init-db.c | 1 - builtin/log.c | 1 - builtin/merge.c | 2 - builtin/mktree.c | 1 - builtin/mv.c | 1 - builtin/name-rev.c | 1 - builtin/pack-objects.c | 2 - builtin/rebase.c | 1 - builtin/receive-pack.c | 1 - builtin/repack.c | 1 - builtin/rerere.c | 1 - builtin/rev-parse.c | 1 - builtin/revert.c | 1 - builtin/rm.c | 1 - builtin/submodule--helper.c | 1 - builtin/symbolic-ref.c | 1 + builtin/unpack-file.c | 1 - builtin/unpack-objects.c | 1 + builtin/worktree.c | 1 - bulk-checkin.c | 2 - cache-tree.c | 1 - chunk-format.c | 1 - combine-diff.c | 1 - commit-graph.c | 1 - commit-reach.c | 1 - compat/terminal.c | 1 - config.c | 2 - convert.c | 1 - copy.c | 1 - csum-file.c | 1 - ctype.c | 36 ---- daemon.c | 2 - delta-islands.c | 1 - diff.c | 2 - diffcore-rename.c | 1 - dir-iterator.c | 1 - dir.c | 2 - editor.c | 1 - entry.c | 1 - environment.c | 1 - ewah/bitmap.c | 1 - ewah/ewah_bitmap.c | 1 - fetch-pack.c | 2 - fmt-merge-msg.c | 1 - fsck.c | 1 - git-compat-util.h | 284 ++++++++--------------------- gpg-interface.c | 1 - grep.c | 1 - help.c | 1 - http-backend.c | 2 - imap-send.c | 1 - kwset.c | 36 ++++ kwset.h | 2 + line-log.c | 1 - list-objects-filter-options.c | 1 - list-objects-filter.c | 1 - merge-ll.c | 1 - merge-recursive.c | 1 - midx.c | 1 - notes-merge.c | 1 - object-file.c | 2 - oid-array.c | 1 - oidtree.c | 1 - pack-bitmap-write.c | 1 - pack-bitmap.c | 1 - pack-objects.c | 1 - pack-write.c | 1 - packfile.c | 2 - parallel-checkout.c | 2 - path.c | 1 - pkt-line.c | 1 - pretty.c | 1 - prio-queue.c | 1 - quote.c | 1 - read-cache.c | 2 - rebase-interactive.c | 1 - ref-filter.c | 1 - reflog-walk.c | 1 - refs.c | 2 - refspec.c | 1 - remote-curl.c | 1 - remote.c | 1 - rerere.c | 2 - revision.c | 1 - sane-ctype.h | 66 +++++++ send-pack.c | 1 - sequencer.c | 2 - server-info.c | 2 - setup.c | 1 - shallow.c | 2 - sigchain.c | 1 - sparse-index.c | 1 - split-index.c | 1 - strbuf.c | 2 - strbuf.h | 32 ++++ streaming.c | 1 - string-list.c | 1 - strvec.c | 1 - submodule-config.c | 1 - submodule.c | 1 - t/helper/test-delta.c | 1 - t/helper/test-fsmonitor-client.c | 1 - t/helper/test-reach.c | 1 - t/helper/test-read-cache.c | 1 - tag.c | 1 - tempfile.c | 1 - trace.c | 1 - trace2/tr2_tls.c | 1 - trailer.c | 1 - transport-helper.c | 1 - transport.c | 2 - tree-walk.c | 1 - upload-pack.c | 1 - usage.c | 1 - userdiff.c | 1 - versioncmp.c | 1 + worktree.c | 2 - wrapper.c | 1 - wrapper.h | 111 +++++++++++ write-or-die.c | 1 - 147 files changed, 327 insertions(+), 478 deletions(-) create mode 100644 sane-ctype.h
Range-diff against v3:
1: 03efb2c4b3 < -: ---------- init-db: document existing bug with core.bare in template config
2: 020191c84e < -: ---------- init-db: remove unnecessary global variable
3: 4f2631b200 < -: ---------- init-db, clone: change unnecessary global into passed parameter
4: 40e8349c97 < -: ---------- setup: adopt shared init-db & clone code
5: 8ce842e5e4 < -: ---------- read-cache: move shared commit and ls-files code
6: 9a435193b6 < -: ---------- add: modify add_files_to_cache() to avoid globals
7: f9fb1ec0c5 < -: ---------- read-cache: move shared add/checkout/commit code
8: 193ccad5dd < -: ---------- statinfo: move stat_{data,validity} functions from cache/read-cache
9: 8fb86883ed < -: ---------- run-command.h: move declarations for run-command.c from cache.h
10: 5e579aeeb5 < -: ---------- name-hash.h: move declarations for name-hash.c from cache.h
11: 5c0c5257a6 < -: ---------- sparse-index.h: move declarations for sparse-index.c from cache.h
12: 230b0e9968 < -: ---------- preload-index.h: move declarations for preload-index.c from elsewhere
13: 66327b7465 < -: ---------- diff.h: move declaration for global in diff.c from cache.h
14: 61830c7bfa < -: ---------- merge.h: move declarations for merge.c from cache.h
15: 0979c990b1 < -: ---------- repository.h: move declaration of the_index from cache.h
16: eb2fac9a86 < -: ---------- read-cache*.h: move declarations for read-cache.c functions from cache.h
17: 0cda8f7c94 < -: ---------- cache.h: remove this no-longer-used header
18: 82ce975a19 < -: ---------- log-tree: replace include of revision.h with simple forward declaration
19: 75334a2bc0 < -: ---------- repository: remove unnecessary include of path.h
20: 940ebf92de < -: ---------- diff.h: remove unnecessary include of oidset.h
21: fc12c810dc < -: ---------- list-objects-filter-options.h: remove unneccessary include
22: 8985e07940 < -: ---------- builtin.h: remove unneccessary includes
23: af118e7cf0 < -: ---------- git-compat-util.h: remove unneccessary include of wildmatch.h
24: 7e33c8f9b1 < -: ---------- merge-ll: rename from ll-merge
25: 5e96b1b130 < -: ---------- khash: name the structs that khash declares
26: 2d6aa61e78 < -: ---------- object-store-ll.h: split this header out of object-store.h
27: f6927dd57c < -: ---------- hash-ll, hashmap: move oidhash() to hash-ll
28: 482d3c671e < -: ---------- fsmonitor-ll.h: split this header out of fsmonitor.h
29: aa680f395a < -: ---------- strbuf: clarify API boundary
30: 44b977d1b0 < -: ---------- abspath: move related functions to abspath
31: 99852416e8 < -: ---------- credential-store: move related functions to credential-store file
32: 09aef95f30 < -: ---------- object-name: move related functions to object-name
33: 36048bca4c < -: ---------- path: move related function to path
34: 02a02faf12 < -: ---------- strbuf: clarify dependency
35: 63a933ff2f < -: ---------- strbuf: remove global variable
36: d352eae308 = 1: 144284a8f1 git-compat-util: move strbuf.c funcs to its header
37: fe4fd6f92a = 2: 39913c44e8 git-compat-util: move wrapper.c funcs to its header
38: ec7ea12f7c = 3: c495762940 sane-ctype.h: create header for sane-ctype macros
39: 4f95b4121e = 4: 2750d35e6d kwset: move translation table from ctype
40: 36525e39d5 < -: ---------- common.h: move non-compat specific macros and functions
41: 21f0f31ff3 < -: ---------- git-compat-util: move usage.c funcs to its header
42: 531db31c5c ! 5: b5fb55d235 treewide: remove unnecessary includes for wrapper.h
@@ gpg-interface.c
-#include "wrapper.h"
#include "environment.h"
- static int git_gpg_config(const char *, const char *, void *);
+ static int git_gpg_config(const char *, const char *,
## grep.c ##
@@
43: 98694f7add ! 6: 140d98111f common: move alloc macros to common.h
@@ Commit message
common: move alloc macros to common.h
alloc_nr, ALLOC_GROW, and ALLOC_GROW_BY are commonly used macros for
- dynamic array allocation. Moving these macros to common.h focuses
- alloc.[ch] to allocation for Git objects and additionally allows us to
- remove inclusions to alloc.h from files that solely used the above
- macros.
+ dynamic array allocation. Moving these macros to git-compat-util.h with
+ the other alloc macros focuses alloc.[ch] to allocation for Git objects
+ and additionally allows us to remove inclusions to alloc.h from files
+ that solely used the above macros.
## add-patch.c ##
@@
@@ commit-reach.c
#include "commit-graph.h"
#include "decorate.h"
- ## common.h ##
-@@ common.h: static inline int cast_size_t_to_int(size_t a)
- */
- #define FREE_AND_NULL(p) do { free(p); (p) = NULL; } while (0)
-
-+#define alloc_nr(x) (((x)+16)*3/2)
-+
-+/**
-+ * Dynamically growing an array using realloc() is error prone and boring.
-+ *
-+ * Define your array with:
-+ *
-+ * - a pointer (`item`) that points at the array, initialized to `NULL`
-+ * (although please name the variable based on its contents, not on its
-+ * type);
-+ *
-+ * - an integer variable (`alloc`) that keeps track of how big the current
-+ * allocation is, initialized to `0`;
-+ *
-+ * - another integer variable (`nr`) to keep track of how many elements the
-+ * array currently has, initialized to `0`.
-+ *
-+ * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,
-+ * alloc)`. This ensures that the array can hold at least `n` elements by
-+ * calling `realloc(3)` and adjusting `alloc` variable.
-+ *
-+ * ------------
-+ * sometype *item;
-+ * size_t nr;
-+ * size_t alloc
-+ *
-+ * for (i = 0; i < nr; i++)
-+ * if (we like item[i] already)
-+ * return;
-+ *
-+ * // we did not like any existing one, so add one
-+ * ALLOC_GROW(item, nr + 1, alloc);
-+ * item[nr++] = value you like;
-+ * ------------
-+ *
-+ * You are responsible for updating the `nr` variable.
-+ *
-+ * If you need to specify the number of elements to allocate explicitly
-+ * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.
-+ *
-+ * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some
-+ * added niceties.
-+ *
-+ * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
-+ */
-+#define ALLOC_GROW(x, nr, alloc) \
-+ do { \
-+ if ((nr) > alloc) { \
-+ if (alloc_nr(alloc) < (nr)) \
-+ alloc = (nr); \
-+ else \
-+ alloc = alloc_nr(alloc); \
-+ REALLOC_ARRAY(x, alloc); \
-+ } \
-+ } while (0)
-+
-+/*
-+ * Similar to ALLOC_GROW but handles updating of the nr value and
-+ * zeroing the bytes of the newly-grown array elements.
-+ *
-+ * DO NOT USE any expression with side-effect for any of the
-+ * arguments.
-+ */
-+#define ALLOC_GROW_BY(x, nr, increase, alloc) \
-+ do { \
-+ if (increase) { \
-+ size_t new_nr = nr + (increase); \
-+ if (new_nr < nr) \
-+ BUG("negative growth in ALLOC_GROW_BY"); \
-+ ALLOC_GROW(x, new_nr, alloc); \
-+ memset((x) + nr, 0, sizeof(*(x)) * (increase)); \
-+ nr = new_nr; \
-+ } \
-+ } while (0)
-+
- #define ALLOC_ARRAY(x, alloc) (x) = xmalloc(st_mult(sizeof(*(x)), (alloc)))
- #define CALLOC_ARRAY(x, alloc) (x) = xcalloc((alloc), sizeof(*(x)))
- #define REALLOC_ARRAY(x, alloc) (x) = xrealloc((x), st_mult(sizeof(*(x)), (alloc)))
-
## config.c ##
@@
#include "git-compat-util.h"
@@ fsck.c
#include "dir.h"
#include "hex.h"
+ ## git-compat-util.h ##
+@@ git-compat-util.h: static inline void move_array(void *dst, const void *src, size_t n, size_t size)
+ #define FLEXPTR_ALLOC_STR(x, ptrname, str) \
+ FLEXPTR_ALLOC_MEM((x), ptrname, (str), strlen(str))
+
++#define alloc_nr(x) (((x)+16)*3/2)
++
++/**
++ * Dynamically growing an array using realloc() is error prone and boring.
++ *
++ * Define your array with:
++ *
++ * - a pointer (`item`) that points at the array, initialized to `NULL`
++ * (although please name the variable based on its contents, not on its
++ * type);
++ *
++ * - an integer variable (`alloc`) that keeps track of how big the current
++ * allocation is, initialized to `0`;
++ *
++ * - another integer variable (`nr`) to keep track of how many elements the
++ * array currently has, initialized to `0`.
++ *
++ * Then before adding `n`th element to the item, call `ALLOC_GROW(item, n,
++ * alloc)`. This ensures that the array can hold at least `n` elements by
++ * calling `realloc(3)` and adjusting `alloc` variable.
++ *
++ * ------------
++ * sometype *item;
++ * size_t nr;
++ * size_t alloc
++ *
++ * for (i = 0; i < nr; i++)
++ * if (we like item[i] already)
++ * return;
++ *
++ * // we did not like any existing one, so add one
++ * ALLOC_GROW(item, nr + 1, alloc);
++ * item[nr++] = value you like;
++ * ------------
++ *
++ * You are responsible for updating the `nr` variable.
++ *
++ * If you need to specify the number of elements to allocate explicitly
++ * then use the macro `REALLOC_ARRAY(item, alloc)` instead of `ALLOC_GROW`.
++ *
++ * Consider using ALLOC_GROW_BY instead of ALLOC_GROW as it has some
++ * added niceties.
++ *
++ * DO NOT USE any expression with side-effect for 'x', 'nr', or 'alloc'.
++ */
++#define ALLOC_GROW(x, nr, alloc) \
++ do { \
++ if ((nr) > alloc) { \
++ if (alloc_nr(alloc) < (nr)) \
++ alloc = (nr); \
++ else \
++ alloc = alloc_nr(alloc); \
++ REALLOC_ARRAY(x, alloc); \
++ } \
++ } while (0)
++
++/*
++ * Similar to ALLOC_GROW but handles updating of the nr value and
++ * zeroing the bytes of the newly-grown array elements.
++ *
++ * DO NOT USE any expression with side-effect for any of the
++ * arguments.
++ */
++#define ALLOC_GROW_BY(x, nr, increase, alloc) \
++ do { \
++ if (increase) { \
++ size_t new_nr = nr + (increase); \
++ if (new_nr < nr) \
++ BUG("negative growth in ALLOC_GROW_BY"); \
++ ALLOC_GROW(x, new_nr, alloc); \
++ memset((x) + nr, 0, sizeof(*(x)) * (increase)); \
++ nr = new_nr; \
++ } \
++ } while (0)
++
+ static inline char *xstrdup_or_null(const char *str)
+ {
+ return str ? xstrdup(str) : NULL;
+
## help.c ##
@@
#include "git-compat-util.h"Signature · 1 line
2.41.0.255.g8b1d071c50-goog
PATCH v4 1/6 git-compat-util: move strbuf.c funcs to its header
While functions like starts_with() probably should not belong in the boundaries of the strbuf library, this commit focuses on first splitting out headers from git-compat-util.h.
--- builtin/symbolic-ref.c | 1 + builtin/unpack-objects.c | 1 + git-compat-util.h | 32 -------------------------------- strbuf.h | 32 ++++++++++++++++++++++++++++++++ versioncmp.c | 1 + 5 files changed, 35 insertions(+), 32 deletions(-)
builtin/symbolic-ref.c +1 -0
@@ -3,6 +3,7 @@#include "gettext.h" #include "refs.h" #include "parse-options.h" +#include "strbuf.h" static const char *const git_symbolic_ref_usage[] = {N_ ("git symbolic-ref [-m <reason>] <name> <ref>" ),
builtin/unpack-objects.c +1 -0
@@ -12,6 +12,7 @@#include "blob.h" #include "commit.h" #include "replace-object.h" +#include "strbuf.h" #include "tag.h" #include "tree.h" #include "tree-walk.h"
git-compat-util.h +0 -32
@@ -679,9 +679,6 @@ void set_warn_routine(report_fn routine);report_fn get_warn_routine (void );void set_die_is_recursing_routine (int (*routine)(void )); -int starts_with (const char *str,const char *prefix); -int istarts_with (const char *str,const char *prefix); -/* * If the string "str" begins with the string found in "prefix", return 1. * The "out" parameter is set to "str + strlen(prefix)" (i.e., to the point in
@@ -710,29 +707,6 @@ static inline int skip_prefix(const char *str, const char *prefix,return 0 ; } -/* -* If the string "str" is the same as the string in "prefix", then the "arg" -* parameter is set to the "def" parameter and 1 is returned. -* If the string "str" begins with the string found in "prefix" and then a -* "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1" -* (i.e., to the point in the string right after the prefix and the "=" sign), -* and 1 is returned. -* -* Otherwise, return 0 and leave "arg" untouched. -* -* When we accept both a "--key" and a "--key=<val>" option, this function -* can be used instead of !strcmp(arg, "--key") and then -* skip_prefix(arg, "--key=", &arg) to parse such an option. -*/ -int skip_to_optional_arg_default (const char *str,const char *prefix, -const char **arg,const char *def); - -static inline int skip_to_optional_arg (const char *str,const char *prefix, -const char **arg) -{ -return skip_to_optional_arg_default (str, prefix, arg,"" ); -} -/* * Like skip_prefix, but promises never to read past "len" bytes of the input * buffer, and returns the remaining number of bytes in "out" via "outlen".
@@ -777,12 +751,6 @@ static inline int strip_suffix(const char *str, const char *suffix, size_t *len)return strip_suffix_mem (str, len, suffix); } -static inline int ends_with (const char *str,const char *suffix) -{ -size_t len; -return strip_suffix (str, suffix, &len); -} -#define SWAP (a, b) do { \ void *_swap_a_ptr = &(a); \ void *_swap_b_ptr = &(b); \
strbuf.h +32 -0
@@ -671,4 +671,36 @@ char *xstrvfmt(const char *fmt, va_list ap); __attribute__((format (printf,1 ,2 )))char *xstrfmt (const char *fmt, ...); +int starts_with (const char *str,const char *prefix); +int istarts_with (const char *str,const char *prefix); + +/* +* If the string "str" is the same as the string in "prefix", then the "arg" +* parameter is set to the "def" parameter and 1 is returned. +* If the string "str" begins with the string found in "prefix" and then a +* "=" sign, then the "arg" parameter is set to "str + strlen(prefix) + 1" +* (i.e., to the point in the string right after the prefix and the "=" sign), +* and 1 is returned. +* +* Otherwise, return 0 and leave "arg" untouched. +* +* When we accept both a "--key" and a "--key=<val>" option, this function +* can be used instead of !strcmp(arg, "--key") and then +* skip_prefix(arg, "--key=", &arg) to parse such an option. +*/ +int skip_to_optional_arg_default (const char *str,const char *prefix, +const char **arg,const char *def); + +static inline int skip_to_optional_arg (const char *str,const char *prefix, +const char **arg) +{ +return skip_to_optional_arg_default (str, prefix, arg,"" ); +} + +static inline int ends_with (const char *str,const char *suffix) +{ +size_t len; +return strip_suffix (str, suffix, &len); +} +#endif /* STRBUF_H */
versioncmp.c +1 -0
@@ -1,5 +1,6 @@#include "git-compat-util.h" #include "config.h" +#include "strbuf.h" #include "string-list.h" #include "versioncmp.h"
Signature · 1 line
2.41.0.255.g8b1d071c50-goog
PATCH v4 2/6 git-compat-util: move wrapper.c funcs to its header
In reply to Calvin WanSince the functions in wrapper.c are widely used across the codebase, include it by default in git-compat-util.h. A future patch will remove now unnecessary inclusions of wrapper.h from other files.
--- git-compat-util.h | 112 +--------------------------------------------- wrapper.h | 111 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 112 insertions(+), 111 deletions(-)
git-compat-util.h +1 -111
@@ -627,7 +627,7 @@ static inline int git_has_dir_sep(const char *path)#include "compat/bswap.h" -struct strbuf ; +#include "wrapper.h" /* General helper functions */ NORETURN void usage(const char *err);
@@ -1047,36 +1047,6 @@ static inline int cast_size_t_to_int(size_t a)# define xalloca (size) (xmalloc(size))# define xalloca_free (p) (free(p))#endif -char *xstrdup (const char *str); -void *xmalloc (size_t size); -void *xmallocz (size_t size); -void *xmallocz_gently (size_t size); -void *xmemdupz (const void *data,size_t len); -char *xstrndup (const char *str,size_t len); -void *xrealloc (void *ptr,size_t size); -void *xcalloc (size_t nmemb,size_t size); -void xsetenv (const char *name,const char *value,int overwrite); -void *xmmap (void *start,size_t length,int prot,int flags,int fd,off_t offset); -const char *mmap_os_err (void ); -void *xmmap_gently (void *start,size_t length,int prot,int flags,int fd,off_t offset); -int xopen (const char *path,int flags, ...); -ssize_t xread (int fd,void *buf,size_t len); -ssize_t xwrite (int fd,const void *buf,size_t len); -ssize_t xpread (int fd,void *buf,size_t len,off_t offset); -int xdup (int fd); -FILE *xfopen (const char *path,const char *mode); -FILE *xfdopen (int fd,const char *mode); -int xmkstemp (char *temp_filename); -int xmkstemp_mode (char *temp_filename,int mode); -char *xgetcwd (void ); -FILE *fopen_for_writing (const char *path); -FILE *fopen_or_warn (const char *path,const char *mode); - -/* -* Like strncmp, but only return zero if s is NUL-terminated and exactly len -* characters long. If it is not, consider it greater than t. -*/ -int xstrncmpz (const char *s,const char *t,size_t len);/* * FREE_AND_NULL(ptr) is like free(ptr) followed by ptr = NULL. Note
@@ -1178,15 +1148,10 @@ static inline size_t xsize_t(off_t len)return (size_t ) len; } -__attribute__((format (printf,3 ,4 ))) -int xsnprintf (char *dst,size_t max,const char *fmt, ...); -#ifndef HOST_NAME_MAX #define HOST_NAME_MAX 256#endif -int xgethostname (char *buf,size_t len); -/* in ctype.c, for kwset users */ extern const unsigned char tolower_trans_tbl[256 ];
@@ -1427,72 +1392,6 @@ void bug_fl(const char *file, int line, const char *fmt, ...);#endif #endif -enum fsync_action { -FSYNC_WRITEOUT_ONLY , -FSYNC_HARDWARE_FLUSH -}; - -/* -* Issues an fsync against the specified file according to the specified mode. -* -* FSYNC_WRITEOUT_ONLY attempts to use interfaces available on some operating -* systems to flush the OS cache without issuing a flush command to the storage -* controller. If those interfaces are unavailable, the function fails with -* ENOSYS. -* -* FSYNC_HARDWARE_FLUSH does an OS writeout and hardware flush to ensure that -* changes are durable. It is not expected to fail. -*/ -int git_fsync (int fd,enum fsync_action action); - -/* -* Writes out trace statistics for fsync using the trace2 API. -*/ -void trace_git_fsync_stats (void ); - -/* -* Preserves errno, prints a message, but gives no warning for ENOENT. -* Returns 0 on success, which includes trying to unlink an object that does -* not exist. -*/ -int unlink_or_warn (const char *path); -/* -* Tries to unlink file. Returns 0 if unlink succeeded -* or the file already didn't exist. Returns -1 and -* appends a message to err suitable for -* 'error("%s", err->buf)' on error. -*/ -int unlink_or_msg (const char *file,struct strbuf *err); -/* -* Preserves errno, prints a message, but gives no warning for ENOENT. -* Returns 0 on success, which includes trying to remove a directory that does -* not exist. -*/ -int rmdir_or_warn (const char *path); -/* -* Calls the correct function out of {unlink,rmdir}_or_warn based on -* the supplied file mode. -*/ -int remove_or_warn (unsigned int mode,const char *path); - -/* -* Call access(2), but warn for any error except "missing file" -* (ENOENT or ENOTDIR). -*/ -#define ACCESS_EACCES_OK (1U << 0) -int access_or_warn (const char *path,int mode,unsigned flag); -int access_or_die (const char *path,int mode,unsigned flag); - -/* Warn on an inaccessible file if errno indicates this is an error */ -int warn_on_fopen_errors (const char *path); - -/* -* Open with O_NOFOLLOW, or equivalent. Note that the fallback equivalent -* may be racy. Do not use this as protection against an attacker who can -* simultaneously create paths. -*/ -int open_nofollow (const char *path,int flags); -#ifndef SHELL_PATH # define SHELL_PATH "/bin/sh"#endif
@@ -1632,13 +1531,4 @@ static inline void *container_of_or_null_offset(void *ptr, size_t offset) ((uintptr_t)&(ptr)->member - (uintptr_t)(ptr))#endif /* !__GNUC__ */ -void sleep_millisec (int millisec); - -/* -* Generate len bytes from the system cryptographically secure PRNG. -* Returns 0 on success and -1 on error, setting errno. The inability to -* satisfy the full request is an error. -*/ -int csprng_bytes (void *buf,size_t len); -#endif
wrapper.h +111 -0
121 lines not on this page · raw message
Signature · 1 line
2.41.0.255.g8b1d071c50-goog
PATCH v4 3/6 sane-ctype.h: create header for sane-ctype macros
In reply to Calvin WanSplitting these macros from git-compat-util.h cleans up the file and allows future third-party sources to not use these overrides if they do not wish to.
--- git-compat-util.h | 62 +------------------------------------------- sane-ctype.h | 66 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 61 deletions(-) create mode 100644 sane-ctype.h
git-compat-util.h +1 -61
@@ -1155,67 +1155,7 @@ static inline size_t xsize_t(off_t len)/* in ctype.c, for kwset users */ extern const unsigned char tolower_trans_tbl[256 ]; -/* Sane ctype - no locale, and works with signed chars */ -#undef isascii -#undef isspace -#undef isdigit -#undef isalpha -#undef isalnum -#undef isprint -#undef islower -#undef isupper -#undef tolower -#undef toupper -#undef iscntrl -#undef ispunct -#undef isxdigit - -extern const unsigned char sane_ctype[256 ]; -extern const signed char hexval_table[256 ]; -#define GIT_SPACE 0x01 -#define GIT_DIGIT 0x02 -#define GIT_ALPHA 0x04 -#define GIT_GLOB_SPECIAL 0x08 -#define GIT_REGEX_SPECIAL 0x10 -#define GIT_PATHSPEC_MAGIC 0x20 -#define GIT_CNTRL 0x40 -#define GIT_PUNCT 0x80 -#define sane_istest (x,mask) ((sane_ctype[(unsigned char)(x)] & (mask)) != 0) -#define isascii (x) (((x) & ~0x7f) == 0) -#define isspace (x) sane_istest(x,GIT_SPACE) -#define isdigit (x) sane_istest(x,GIT_DIGIT) -#define isalpha (x) sane_istest(x,GIT_ALPHA) -#define isalnum (x) sane_istest(x,GIT_ALPHA | GIT_DIGIT) -#define isprint (x) ((x) >= 0x20 && (x) <= 0x7e) -#define islower (x) sane_iscase(x, 1) -#define isupper (x) sane_iscase(x, 0) -#define is_glob_special (x) sane_istest(x,GIT_GLOB_SPECIAL) -#define is_regex_special (x) sane_istest(x,GIT_GLOB_SPECIAL | GIT_REGEX_SPECIAL) -#define iscntrl (x) (sane_istest(x,GIT_CNTRL)) -#define ispunct (x) sane_istest(x, GIT_PUNCT | GIT_REGEX_SPECIAL | \ - GIT_GLOB_SPECIAL | GIT_PATHSPEC_MAGIC) -#define isxdigit (x) (hexval_table[(unsigned char)(x)] != -1) -#define tolower (x) sane_case((unsigned char)(x), 0x20) -#define toupper (x) sane_case((unsigned char)(x), 0) -#define is_pathspec_magic (x) sane_istest(x,GIT_PATHSPEC_MAGIC) - -static inline int sane_case (int x,int high) -{ -if (sane_istest (x,GIT_ALPHA )) - x = (x & ~0x20 ) | high; -return x; -} - -static inline int sane_iscase (int x,int is_lower) -{ -if (!sane_istest (x,GIT_ALPHA )) -return 0 ; - -if (is_lower) -return (x &0x20 ) !=0 ; -else -return (x &0x20 ) ==0 ; -} +#include "sane-ctype.h" /* * Like skip_prefix, but compare case-insensitively. Note that the comparison
sane-ctype.h new file +66 -0
66 lines not on this page · raw message
Signature · 1 line
2.41.0.255.g8b1d071c50-goog
PATCH v4 4/6 kwset: move translation table from ctype
In reply to Calvin WanThis table was originally introduced to solely be used with kwset machinery (0f871cf56e), so it would make sense for it to belong in kwset.[ch] rather than ctype.c and git-compat-util.h. It is only used in diffcore-pickaxe.c, which already includes kwset.h so no other headers have to be modified.
--- ctype.c | 36 ------------------------------------ git-compat-util.h | 3 --- kwset.c | 36 ++++++++++++++++++++++++++++++++++++ kwset.h | 2 ++ 4 files changed, 38 insertions(+), 39 deletions(-)
ctype.c +0 -36
@@ -28,39 +28,3 @@ const unsigned char sane_ctype[256] = { A, A, A, A, A, A, A, A, A, A, A, R, R, U, P, X, /* 112..127 */ /* Nothing in the 128.. range */ }; - -/* For case-insensitive kwset */ -const unsigned char tolower_trans_tbl[256 ] = { -0x00 ,0x01 ,0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x07 , -0x08 ,0x09 ,0x0a ,0x0b ,0x0c ,0x0d ,0x0e ,0x0f , -0x10 ,0x11 ,0x12 ,0x13 ,0x14 ,0x15 ,0x16 ,0x17 , -0x18 ,0x19 ,0x1a ,0x1b ,0x1c ,0x1d ,0x1e ,0x1f , -' ' ,'!' ,'"' ,'#' ,'$' ,'%' ,'&' ,0x27 , -'(' ,')' ,'*' ,'+' ,',' ,'-' ,'.' ,'/' , -'0' ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' , -'8' ,'9' ,':' ,';' ,'<' ,'=' ,'>' ,'?' , -'@' ,'a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' , -'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o' , -'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' , -'x' ,'y' ,'z' ,'[' ,0x5c ,']' ,'^' ,'_' , -'`' ,'a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' , -'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o' , -'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' , -'x' ,'y' ,'z' ,'{' ,'|' ,'}' ,'~' ,0x7f , -0x80 ,0x81 ,0x82 ,0x83 ,0x84 ,0x85 ,0x86 ,0x87 , -0x88 ,0x89 ,0x8a ,0x8b ,0x8c ,0x8d ,0x8e ,0x8f , -0x90 ,0x91 ,0x92 ,0x93 ,0x94 ,0x95 ,0x96 ,0x97 , -0x98 ,0x99 ,0x9a ,0x9b ,0x9c ,0x9d ,0x9e ,0x9f , -0xa0 ,0xa1 ,0xa2 ,0xa3 ,0xa4 ,0xa5 ,0xa6 ,0xa7 , -0xa8 ,0xa9 ,0xaa ,0xab ,0xac ,0xad ,0xae ,0xaf , -0xb0 ,0xb1 ,0xb2 ,0xb3 ,0xb4 ,0xb5 ,0xb6 ,0xb7 , -0xb8 ,0xb9 ,0xba ,0xbb ,0xbc ,0xbd ,0xbe ,0xbf , -0xc0 ,0xc1 ,0xc2 ,0xc3 ,0xc4 ,0xc5 ,0xc6 ,0xc7 , -0xc8 ,0xc9 ,0xca ,0xcb ,0xcc ,0xcd ,0xce ,0xcf , -0xd0 ,0xd1 ,0xd2 ,0xd3 ,0xd4 ,0xd5 ,0xd6 ,0xd7 , -0xd8 ,0xd9 ,0xda ,0xdb ,0xdc ,0xdd ,0xde ,0xdf , -0xe0 ,0xe1 ,0xe2 ,0xe3 ,0xe4 ,0xe5 ,0xe6 ,0xe7 , -0xe8 ,0xe9 ,0xea ,0xeb ,0xec ,0xed ,0xee ,0xef , -0xf0 ,0xf1 ,0xf2 ,0xf3 ,0xf4 ,0xf5 ,0xf6 ,0xf7 , -0xf8 ,0xf9 ,0xfa ,0xfb ,0xfc ,0xfd ,0xfe ,0xff , -};
git-compat-util.h +0 -3
@@ -1152,9 +1152,6 @@ static inline size_t xsize_t(off_t len)#define HOST_NAME_MAX 256#endif -/* in ctype.c, for kwset users */ -extern const unsigned char tolower_trans_tbl[256 ]; -#include "sane-ctype.h" /*
kwset.c +36 -0
@@ -49,6 +49,42 @@ static void *obstack_chunk_alloc(long size)#define U (c) ((unsigned char) (c)) +/* For case-insensitive kwset */ +const unsigned char tolower_trans_tbl[256 ] = { +0x00 ,0x01 ,0x02 ,0x03 ,0x04 ,0x05 ,0x06 ,0x07 , +0x08 ,0x09 ,0x0a ,0x0b ,0x0c ,0x0d ,0x0e ,0x0f , +0x10 ,0x11 ,0x12 ,0x13 ,0x14 ,0x15 ,0x16 ,0x17 , +0x18 ,0x19 ,0x1a ,0x1b ,0x1c ,0x1d ,0x1e ,0x1f , +' ' ,'!' ,'"' ,'#' ,'$' ,'%' ,'&' ,0x27 , +'(' ,')' ,'*' ,'+' ,',' ,'-' ,'.' ,'/' , +'0' ,'1' ,'2' ,'3' ,'4' ,'5' ,'6' ,'7' , +'8' ,'9' ,':' ,';' ,'<' ,'=' ,'>' ,'?' , +'@' ,'a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' , +'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o' , +'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' , +'x' ,'y' ,'z' ,'[' ,0x5c ,']' ,'^' ,'_' , +'`' ,'a' ,'b' ,'c' ,'d' ,'e' ,'f' ,'g' , +'h' ,'i' ,'j' ,'k' ,'l' ,'m' ,'n' ,'o' , +'p' ,'q' ,'r' ,'s' ,'t' ,'u' ,'v' ,'w' , +'x' ,'y' ,'z' ,'{' ,'|' ,'}' ,'~' ,0x7f , +0x80 ,0x81 ,0x82 ,0x83 ,0x84 ,0x85 ,0x86 ,0x87 , +0x88 ,0x89 ,0x8a ,0x8b ,0x8c ,0x8d ,0x8e ,0x8f , +0x90 ,0x91 ,0x92 ,0x93 ,0x94 ,0x95 ,0x96 ,0x97 , +0x98 ,0x99 ,0x9a ,0x9b ,0x9c ,0x9d ,0x9e ,0x9f , +0xa0 ,0xa1 ,0xa2 ,0xa3 ,0xa4 ,0xa5 ,0xa6 ,0xa7 , +0xa8 ,0xa9 ,0xaa ,0xab ,0xac ,0xad ,0xae ,0xaf , +0xb0 ,0xb1 ,0xb2 ,0xb3 ,0xb4 ,0xb5 ,0xb6 ,0xb7 , +0xb8 ,0xb9 ,0xba ,0xbb ,0xbc ,0xbd ,0xbe ,0xbf , +0xc0 ,0xc1 ,0xc2 ,0xc3 ,0xc4 ,0xc5 ,0xc6 ,0xc7 , +0xc8 ,0xc9 ,0xca ,0xcb ,0xcc ,0xcd ,0xce ,0xcf , +0xd0 ,0xd1 ,0xd2 ,0xd3 ,0xd4 ,0xd5 ,0xd6 ,0xd7 , +0xd8 ,0xd9 ,0xda ,0xdb ,0xdc ,0xdd ,0xde ,0xdf , +0xe0 ,0xe1 ,0xe2 ,0xe3 ,0xe4 ,0xe5 ,0xe6 ,0xe7 , +0xe8 ,0xe9 ,0xea ,0xeb ,0xec ,0xed ,0xee ,0xef , +0xf0 ,0xf1 ,0xf2 ,0xf3 ,0xf4 ,0xf5 ,0xf6 ,0xf7 , +0xf8 ,0xf9 ,0xfa ,0xfb ,0xfc ,0xfd ,0xfe ,0xff , +}; +/* Balanced tree of edges and labels leaving a given trie node. */ struct tree {
kwset.h +2 -0
@@ -26,6 +26,8 @@The author may be reached (Email) at the address [email protected], or (US mail) as Mike Haertel c/o Free Software Foundation. */ +extern const unsigned char tolower_trans_tbl[256 ]; +struct kwsmatch {int index;/* Index number of matching keyword. */
Signature · 1 line
2.41.0.255.g8b1d071c50-goog
PATCH v4 5/6 treewide: remove unnecessary includes for wrapper.h
In reply to Calvin Wan--- apply.c | 1 - builtin/am.c | 1 - builtin/bisect.c | 1 - builtin/branch.c | 1 - builtin/bugreport.c | 1 - builtin/clone.c | 1 - builtin/config.c | 1 - builtin/credential-cache.c | 1 - builtin/difftool.c | 1 - builtin/fast-import.c | 1 - builtin/fmt-merge-msg.c | 1 - builtin/gc.c | 1 - builtin/get-tar-commit-id.c | 1 - builtin/index-pack.c | 1 - builtin/init-db.c | 1 - builtin/merge.c | 1 - builtin/pack-objects.c | 1 - builtin/rebase.c | 1 - builtin/receive-pack.c | 1 - builtin/rerere.c | 1 - builtin/unpack-file.c | 1 - builtin/worktree.c | 1 - bulk-checkin.c | 1 - combine-diff.c | 1 - commit-graph.c | 1 - compat/terminal.c | 1 - config.c | 1 - convert.c | 1 - copy.c | 1 - csum-file.c | 1 - daemon.c | 1 - diff.c | 1 - dir.c | 1 - editor.c | 1 - entry.c | 1 - environment.c | 1 - fetch-pack.c | 1 - gpg-interface.c | 1 - grep.c | 1 - http-backend.c | 1 - imap-send.c | 1 - merge-ll.c | 1 - merge-recursive.c | 1 - notes-merge.c | 1 - object-file.c | 1 - pack-write.c | 1 - packfile.c | 1 - parallel-checkout.c | 1 - path.c | 1 - pkt-line.c | 1 - read-cache.c | 1 - rebase-interactive.c | 1 - refs.c | 1 - rerere.c | 1 - send-pack.c | 1 - sequencer.c | 1 - server-info.c | 1 - setup.c | 1 - shallow.c | 1 - strbuf.c | 1 - streaming.c | 1 - t/helper/test-delta.c | 1 - t/helper/test-fsmonitor-client.c | 1 - t/helper/test-read-cache.c | 1 - tag.c | 1 - tempfile.c | 1 - trace.c | 1 - transport-helper.c | 1 - transport.c | 1 - upload-pack.c | 1 - usage.c | 1 - worktree.c | 1 - wrapper.c | 1 - write-or-die.c | 1 - 74 files changed, 74 deletions(-)
apply.c +0 -1
@@ -37,7 +37,6 @@#include "symlinks.h" #include "wildmatch.h" #include "ws.h" -#include "wrapper.h" struct gitdiff_data {struct strbuf *root;
builtin/am.c +0 -1
@@ -44,7 +44,6 @@#include "path.h" #include "repository.h" #include "pretty.h" -#include "wrapper.h" /** * Returns the length of the first line of msg.
builtin/bisect.c +0 -1
@@ -15,7 +15,6 @@#include "prompt.h" #include "quote.h" #include "revision.h" -#include "wrapper.h" static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS") static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
builtin/branch.c +0 -1
@@ -28,7 +28,6 @@#include "worktree.h" #include "help.h" #include "commit-reach.h" -#include "wrapper.h" static const char *const builtin_branch_usage[] = {N_ ("git branch [<options>] [-r | -a] [--merged] [--no-merged]" ),
builtin/bugreport.c +0 -1
@@ -11,7 +11,6 @@#include "diagnose.h" #include "object-file.h" #include "setup.h" -#include "wrapper.h" static void get_system_info (struct strbuf *sys_info) {
builtin/clone.c +0 -1
@@ -45,7 +45,6 @@#include "hook.h" #include "bundle.h" #include "bundle-uri.h" -#include "wrapper.h" /* * Overall FIXMEs:
builtin/config.c +0 -1
@@ -15,7 +15,6 @@#include "setup.h" #include "strbuf.h" #include "worktree.h" -#include "wrapper.h" static const char *const builtin_config_usage[] = {N_ ("git config [<options>]" ),
builtin/credential-cache.c +0 -1
@@ -3,7 +3,6 @@#include "parse-options.h" #include "path.h" #include "strbuf.h" -#include "wrapper.h" #include "write-or-die.h" #ifndef NO_UNIX_SOCKETS
builtin/difftool.c +0 -1
@@ -32,7 +32,6 @@#include "dir.h" #include "entry.h" #include "setup.h" -#include "wrapper.h" static int trust_exit_code;
builtin/fast-import.c +0 -1
@@ -26,7 +26,6 @@#include "commit-reach.h" #include "khash.h" #include "date.h" -#include "wrapper.h" #define PACK_ID_BITS 16#define MAX_PACK_ID ((1<<PACK_ID_BITS)-1)
builtin/fmt-merge-msg.c +0 -1
@@ -3,7 +3,6 @@#include "fmt-merge-msg.h" #include "gettext.h" #include "parse-options.h" -#include "wrapper.h" static const char *const fmt_merge_msg_usage[] = {N_ ("git fmt-merge-msg [-m <message>] [--log[=<n>] | --no-log] [--file <file>]" ),
builtin/gc.c +0 -1
@@ -41,7 +41,6 @@#include "hook.h" #include "setup.h" #include "trace2.h" -#include "wrapper.h" #define FAILED_RUN "failed to run %s"
builtin/get-tar-commit-id.c +0 -1
@@ -5,7 +5,6 @@#include "commit.h" #include "tar.h" #include "quote.h" -#include "wrapper.h" static const char builtin_get_tar_commit_id_usage[] ="git get-tar-commit-id" ;
builtin/index-pack.c +0 -1
@@ -25,7 +25,6 @@#include "replace-object.h" #include "promisor-remote.h" #include "setup.h" -#include "wrapper.h" static const char index_pack_usage[] ="git index-pack [-v] [-o <index-file>] [--keep | --keep=<msg>] [--[no-]rev-index] [--verify] [--strict] (<pack-file> | --stdin [--fix-thin] [<pack-file>])" ;
builtin/init-db.c +0 -1
@@ -13,7 +13,6 @@#include "path.h" #include "setup.h" #include "strbuf.h" -#include "wrapper.h" static int guess_repository_type (const char *git_dir) {
builtin/merge.c +0 -1
@@ -53,7 +53,6 @@#include "commit-reach.h" #include "wt-status.h" #include "commit-graph.h" -#include "wrapper.h" #define DEFAULT_TWOHEAD (1<<0)#define DEFAULT_OCTOPUS (1<<1)
builtin/pack-objects.c +0 -1
@@ -43,7 +43,6 @@#include "promisor-remote.h" #include "pack-mtimes.h" #include "parse-options.h" -#include "wrapper.h" /* * Objects we are going to pack are collected in the `to_pack` structure.
builtin/rebase.c +0 -1
@@ -37,7 +37,6 @@#include "reset.h" #include "trace2.h" #include "hook.h" -#include "wrapper.h" static char const *const builtin_rebase_usage[] = { N_("git rebase [-i] [options] [--exec <cmd>] "
builtin/receive-pack.c +0 -1
@@ -40,7 +40,6 @@#include "worktree.h" #include "shallow.h" #include "parse-options.h" -#include "wrapper.h" static const char *const receive_pack_usage[] = {N_ ("git receive-pack <git-dir>" ),
builtin/rerere.c +0 -1
@@ -6,7 +6,6 @@#include "repository.h" #include "string-list.h" #include "rerere.h" -#include "wrapper.h" #include "xdiff/xdiff.h" #include "xdiff-interface.h" #include "pathspec.h"
builtin/unpack-file.c +0 -1
@@ -3,7 +3,6 @@#include "hex.h" #include "object-name.h" #include "object-store-ll.h" -#include "wrapper.h" static char *create_temp_file (struct object_id *oid) {
builtin/worktree.c +0 -1
@@ -24,7 +24,6 @@#include "submodule.h" #include "utf8.h" #include "worktree.h" -#include "wrapper.h" #include "quote.h" #define BUILTIN_WORKTREE_ADD_USAGE \
bulk-checkin.c +0 -1
@@ -17,7 +17,6 @@#include "packfile.h" #include "object-file.h" #include "object-store-ll.h" -#include "wrapper.h" static int odb_transaction_nesting;
combine-diff.c +0 -1
@@ -17,7 +17,6 @@#include "userdiff.h" #include "oid-array.h" #include "revision.h" -#include "wrapper.h" static int compare_paths (const struct combine_diff_path *one,const struct diff_filespec *two)
commit-graph.c +0 -1
@@ -26,7 +26,6 @@#include "trace2.h" #include "tree.h" #include "chunk-format.h" -#include "wrapper.h" void git_test_write_commit_graph_or_die (void ) {
compat/terminal.c +0 -1
@@ -6,7 +6,6 @@#include "run-command.h" #include "string-list.h" #include "hashmap.h" -#include "wrapper.h" #if defined(HAVE_DEV_TTY ) || defined(GIT_WINDOWS_NATIVE )
config.c +0 -1
@@ -39,7 +39,6 @@#include "wildmatch.h" #include "worktree.h" #include "ws.h" -#include "wrapper.h" #include "write-or-die.h" struct config_source {
convert.c +0 -1
@@ -16,7 +16,6 @@#include "trace.h" #include "utf8.h" #include "merge-ll.h" -#include "wrapper.h" /* * convert.c - convert a file when checking it out and checking it in.
copy.c +0 -1
@@ -1,7 +1,6 @@#include "git-compat-util.h" #include "copy.h" #include "path.h" -#include "wrapper.h" int copy_fd (int ifd,int ofd) {
csum-file.c +0 -1
@@ -11,7 +11,6 @@#include "progress.h" #include "csum-file.h" #include "hash.h" -#include "wrapper.h" static void verify_buffer_or_die(struct hashfile *f, const void *buf,
daemon.c +0 -1
@@ -10,7 +10,6 @@#include "setup.h" #include "strbuf.h" #include "string-list.h" -#include "wrapper.h" #ifdef NO_INITGROUPS #define initgroups (x, y) (0)/* nothing */
diff.c +0 -1
@@ -43,7 +43,6 @@#include "setup.h" #include "strmap.h" #include "ws.h" -#include "wrapper.h" #ifdef NO_FAST_WORKING_DIRECTORY #define FAST_WORKING_DIRECTORY 0
dir.c +0 -1
@@ -32,7 +32,6 @@#include "symlinks.h" #include "trace2.h" #include "tree.h" -#include "wrapper.h" /* * Tells read_directory_recursive how a file or directory should be treated.
editor.c +0 -1
@@ -11,7 +11,6 @@#include "strvec.h" #include "run-command.h" #include "sigchain.h" -#include "wrapper.h" #ifndef DEFAULT_EDITOR #define DEFAULT_EDITOR "vi"
entry.c +0 -1
@@ -14,7 +14,6 @@#include "fsmonitor.h" #include "entry.h" #include "parallel-checkout.h" -#include "wrapper.h" static void create_directories (const char *path,int path_len,const struct checkout *state)
environment.c +0 -1
@@ -28,7 +28,6 @@#include "setup.h" #include "shallow.h" #include "trace.h" -#include "wrapper.h" #include "write-or-die.h" int trust_executable_bit =1 ;
fetch-pack.c +0 -1
@@ -34,7 +34,6 @@#include "commit-graph.h" #include "sigchain.h" #include "mergesort.h" -#include "wrapper.h" static int transfer_unpack_limit =-1 ;static int fetch_unpack_limit =-1 ;
gpg-interface.c +0 -1
@@ -12,7 +12,6 @@#include "sigchain.h" #include "tempfile.h" #include "alias.h" -#include "wrapper.h" #include "environment.h" static int git_gpg_config(const char *, const char *,
grep.c +0 -1
@@ -12,7 +12,6 @@#include "commit.h" #include "quote.h" #include "help.h" -#include "wrapper.h" static int grep_source_load (struct grep_source *gs); static int grep_source_is_binary(struct grep_source *gs,
http-backend.c +0 -1
@@ -19,7 +19,6 @@#include "object-store-ll.h" #include "protocol.h" #include "date.h" -#include "wrapper.h" #include "write-or-die.h" static const char content_type[] ="Content-Type" ;
imap-send.c +0 -1
@@ -30,7 +30,6 @@#include "parse-options.h" #include "setup.h" #include "strbuf.h" -#include "wrapper.h" #if defined(NO_OPENSSL ) && !defined(HAVE_OPENSSL_CSPRNG )typedef void *SSL ;#endif
merge-ll.c +0 -1
@@ -13,7 +13,6 @@#include "merge-ll.h" #include "quote.h" #include "strbuf.h" -#include "wrapper.h" struct ll_merge_driver ;
merge-recursive.c +0 -1
@@ -38,7 +38,6 @@#include "tag.h" #include "tree-walk.h" #include "unpack-trees.h" -#include "wrapper.h" #include "xdiff-interface.h" struct merge_options_internal {
notes-merge.c +0 -1
@@ -20,7 +20,6 @@#include "trace.h" #include "notes-utils.h" #include "commit-reach.h" -#include "wrapper.h" struct notes_merge_pair {struct object_id obj, base, local, remote;
object-file.c +0 -1
@@ -44,7 +44,6 @@#include "setup.h" #include "submodule.h" #include "fsck.h" -#include "wrapper.h" /* The maximum size for an object header. */ #define MAX_HEADER_LEN 32
pack-write.c +0 -1
@@ -12,7 +12,6 @@#include "pack-revindex.h" #include "path.h" #include "strbuf.h" -#include "wrapper.h" void reset_pack_idx_option (struct pack_idx_option *opts) {
packfile.c +0 -1
@@ -24,7 +24,6 @@#include "commit-graph.h" #include "pack-revindex.h" #include "promisor-remote.h" -#include "wrapper.h" char *odb_pack_name(struct strbuf *buf, const unsigned char *hash,
parallel-checkout.c +0 -1
@@ -15,7 +15,6 @@#include "symlinks.h" #include "thread-utils.h" #include "trace2.h" -#include "wrapper.h" struct pc_worker {struct child_process cp;
path.c +0 -1
@@ -18,7 +18,6 @@#include "object-store-ll.h" #include "lockfile.h" #include "exec-cmd.h" -#include "wrapper.h" static int get_st_mode_bits (const char *path,int *mode) {
pkt-line.c +0 -1
@@ -5,7 +5,6 @@#include "hex.h" #include "run-command.h" #include "trace.h" -#include "wrapper.h" #include "write-or-die.h" char packet_buffer[LARGE_PACKET_MAX ];
read-cache.c +0 -1
@@ -46,7 +46,6 @@#include "csum-file.h" #include "promisor-remote.h" #include "hook.h" -#include "wrapper.h" /* Mask for the name length in ce_flags in the on-disk index */
rebase-interactive.c +0 -1
@@ -11,7 +11,6 @@#include "config.h" #include "dir.h" #include "object-name.h" -#include "wrapper.h" static const char edit_todo_list_advice[] = N_("You can fix this with 'git rebase --edit-todo' "
refs.c +0 -1
@@ -30,7 +30,6 @@#include "date.h" #include "commit.h" #include "wildmatch.h" -#include "wrapper.h" /* * List of all available backends
rerere.c +0 -1
@@ -20,7 +20,6 @@#include "object-store-ll.h" #include "hash-lookup.h" #include "strmap.h" -#include "wrapper.h" #define RESOLVED 0#define PUNTED 1
send-pack.c +0 -1
@@ -15,7 +15,6 @@#include "quote.h" #include "transport.h" #include "version.h" -#include "wrapper.h" #include "oid-array.h" #include "gpg-interface.h" #include "shallow.h"
sequencer.c +0 -1
@@ -49,7 +49,6 @@#include "rebase-interactive.h" #include "reset.h" #include "branch.h" -#include "wrapper.h" #define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
server-info.c +0 -1
@@ -14,7 +14,6 @@#include "object-store-ll.h" #include "server-info.h" #include "strbuf.h" -#include "wrapper.h" struct update_info_ctx {FILE *cur_fp;
setup.c +0 -1
@@ -17,7 +17,6 @@#include "quote.h" #include "trace2.h" #include "worktree.h" -#include "wrapper.h" static int inside_git_dir =-1 ;static int inside_work_tree =-1 ;
shallow.c +0 -1
@@ -20,7 +20,6 @@#include "shallow.h" #include "statinfo.h" #include "trace.h" -#include "wrapper.h" void set_alternate_shallow_file (struct repository *r,const char *path,int override) {
strbuf.c +0 -1
@@ -6,7 +6,6 @@#include "string-list.h" #include "utf8.h" #include "date.h" -#include "wrapper.h" int starts_with (const char *str,const char *prefix) {
streaming.c +0 -1
@@ -10,7 +10,6 @@#include "object-store-ll.h" #include "replace-object.h" #include "packfile.h" -#include "wrapper.h" typedef int (*open_istream_fn)(struct git_istream *, struct repository *,
t/helper/test-delta.c +0 -1
@@ -11,7 +11,6 @@#include "test-tool.h" #include "git-compat-util.h" #include "delta.h" -#include "wrapper.h" static const char usage_str[] ="test-tool delta (-d|-p) <from_file> <data_file> <out_file>" ;
t/helper/test-fsmonitor-client.c +0 -1
@@ -11,7 +11,6 @@#include "setup.h" #include "thread-utils.h" #include "trace2.h" -#include "wrapper.h" #ifndef HAVE_FSMONITOR_DAEMON_BACKEND int cmd__fsmonitor_client(int argc UNUSED, const char **argv UNUSED)
t/helper/test-read-cache.c +0 -1
@@ -4,7 +4,6 @@#include "read-cache-ll.h" #include "repository.h" #include "setup.h" -#include "wrapper.h" int cmd__read_cache (int argc,const char **argv) {
tag.c +0 -1
@@ -10,7 +10,6 @@#include "gpg-interface.h" #include "hex.h" #include "packfile.h" -#include "wrapper.h" const char *tag_type ="tag" ;
tempfile.c +0 -1
@@ -47,7 +47,6 @@#include "path.h" #include "tempfile.h" #include "sigchain.h" -#include "wrapper.h" static VOLATILE_LIST_HEAD (tempfile_list);
trace.c +0 -1
@@ -27,7 +27,6 @@#include "quote.h" #include "setup.h" #include "trace.h" -#include "wrapper.h" struct trace_key trace_default_key = {"GIT_TRACE" ,0 ,0 ,0 };struct trace_key trace_perf_key =TRACE_KEY_INIT (PERFORMANCE );
transport-helper.c +0 -1
@@ -19,7 +19,6 @@#include "refspec.h" #include "transport-internal.h" #include "protocol.h" -#include "wrapper.h" static int debug;
transport.c +0 -1
@@ -30,7 +30,6 @@#include "object-store-ll.h" #include "color.h" #include "bundle-uri.h" -#include "wrapper.h" static int transport_use_color =-1 ;static char transport_colors[][COLOR_MAXLEN ] = {
upload-pack.c +0 -1
@@ -32,7 +32,6 @@#include "commit-graph.h" #include "commit-reach.h" #include "shallow.h" -#include "wrapper.h" #include "write-or-die.h" /* Remember to update object flag allocation in object.h */
usage.c +0 -1
@@ -6,7 +6,6 @@#include "git-compat-util.h" #include "gettext.h" #include "trace2.h" -#include "wrapper.h" static void vreportf (const char *prefix,const char *err,va_list params) {
worktree.c +0 -1
@@ -12,7 +12,6 @@#include "dir.h" #include "wt-status.h" #include "config.h" -#include "wrapper.h" void free_worktrees (struct worktree **worktrees) {
wrapper.c +0 -1
@@ -9,7 +9,6 @@#include "repository.h" #include "strbuf.h" #include "trace2.h" -#include "wrapper.h" static intmax_t count_fsync_writeout_only;static intmax_t count_fsync_hardware_flush;
write-or-die.c +0 -1
@@ -1,7 +1,6 @@#include "git-compat-util.h" #include "config.h" #include "run-command.h" -#include "wrapper.h" #include "write-or-die.h" /*
Signature · 1 line
2.41.0.255.g8b1d071c50-goog