diff options
author | Patrick Steinhardt <ps@pks.im> | 2024-08-13 11:13:40 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-08-13 19:01:01 +0200 |
commit | 7ac16649eca0ee206fdb203a76fa4330484b3b6a (patch) | |
tree | df7b9143ab79c5832a49ad51ea7ab3133192492d /path.c | |
parent | path: stop relying on `the_repository` in `worktree_git_path()` (diff) | |
download | git-7ac16649eca0ee206fdb203a76fa4330484b3b6a.tar.xz git-7ac16649eca0ee206fdb203a76fa4330484b3b6a.zip |
path: hide functions using `the_repository` by default
The path subsystem provides a bunch of legacy functions that compute
paths relative to the "gitdir" and "commondir" directories of the global
`the_repository` variable. Use of those functions is discouraged, and it
is easy to miss the implicit dependency on `the_repository` that calls
to those functions may cause.
With `USE_THE_REPOSITORY_VARIABLE`, we have recently introduced a tool
that allows us to get rid of such functions over time. With this macro,
we can hide away functions that have such implicit dependency such that
other subsystems that want to be free of `the_repository` will not use
them by accident.
Move all path-related functions that use `the_repository` into a block
that gets only conditionally compiled depending on whether or not the
macro has been defined. This also removes all dependencies on that
variable in "path.c", allowing us to remove the definition of said
preprocessor macro.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'path.c')
-rw-r--r-- | path.c | 52 |
1 files changed, 1 insertions, 51 deletions
@@ -2,8 +2,6 @@ * Utilities for paths and pathnames */ -#define USE_THE_REPOSITORY_VARIABLE - #include "git-compat-util.h" #include "abspath.h" #include "environment.h" @@ -30,7 +28,7 @@ static int get_st_mode_bits(const char *path, int *mode) return 0; } -static struct strbuf *get_pathname(void) +struct strbuf *get_pathname(void) { static struct strbuf pathname_array[4] = { STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT @@ -453,44 +451,6 @@ void strbuf_repo_git_path(struct strbuf *sb, va_end(args); } -char *git_path_buf(struct strbuf *buf, const char *fmt, ...) -{ - va_list args; - strbuf_reset(buf); - va_start(args, fmt); - repo_git_pathv(the_repository, NULL, buf, fmt, args); - va_end(args); - return buf->buf; -} - -void strbuf_git_path(struct strbuf *sb, const char *fmt, ...) -{ - va_list args; - va_start(args, fmt); - repo_git_pathv(the_repository, NULL, sb, fmt, args); - va_end(args); -} - -const char *git_path(const char *fmt, ...) -{ - struct strbuf *pathname = get_pathname(); - va_list args; - va_start(args, fmt); - repo_git_pathv(the_repository, NULL, pathname, fmt, args); - va_end(args); - return pathname->buf; -} - -char *git_pathdup(const char *fmt, ...) -{ - struct strbuf path = STRBUF_INIT; - va_list args; - va_start(args, fmt); - repo_git_pathv(the_repository, NULL, &path, fmt, args); - va_end(args); - return strbuf_detach(&path, NULL); -} - char *mkpathdup(const char *fmt, ...) { struct strbuf sb = STRBUF_INIT; @@ -634,16 +594,6 @@ void repo_common_pathv(const struct repository *repo, strbuf_cleanup_path(sb); } -const char *git_common_path(const char *fmt, ...) -{ - struct strbuf *pathname = get_pathname(); - va_list args; - va_start(args, fmt); - repo_common_pathv(the_repository, pathname, fmt, args); - va_end(args); - return pathname->buf; -} - void strbuf_git_common_path(struct strbuf *sb, const struct repository *repo, const char *fmt, ...) |