path: drop git_path()
in favor of repo_git_path()
Remove `git_path()` in favor of the `repo_git_path()` family of functions, which makes the implicit dependency on `the_repository` go away. Note that `git_path()` returned a string allocated via `get_pathname()`, which uses a rotating set of statically allocated buffers. Consequently, callers didn't have to free the returned string. The same isn't true for `repo_common_path()`, so we also have to add logic to free the returned strings. This refactoring also allows us to remove `repo_common_pathv()` as well as `get_pathname()` from the public interface. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
8ee018d863
commit
88dd321cfe
27
path.h
27
path.h
@ -221,37 +221,10 @@ char *xdg_cache_home(const char *filename);
|
||||
*/
|
||||
void safe_create_dir(const char *dir, int share);
|
||||
|
||||
/*
|
||||
* Do not use this function. It is only exported to other subsystems until we
|
||||
* can get rid of the below block of functions that implicitly rely on
|
||||
* `the_repository`.
|
||||
*/
|
||||
struct strbuf *get_pathname(void);
|
||||
|
||||
# ifdef USE_THE_REPOSITORY_VARIABLE
|
||||
# include "strbuf.h"
|
||||
# include "repository.h"
|
||||
|
||||
/* Internal implementation details that should not be used. */
|
||||
void repo_git_pathv(const struct repository *repo,
|
||||
const struct worktree *wt, struct strbuf *buf,
|
||||
const char *fmt, va_list args);
|
||||
|
||||
/*
|
||||
* Return a statically allocated path into the main repository's
|
||||
* (the_repository) git directory.
|
||||
*/
|
||||
__attribute__((format (printf, 1, 2)))
|
||||
static inline 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;
|
||||
}
|
||||
|
||||
#define GIT_PATH_FUNC(func, filename) \
|
||||
const char *func(void) \
|
||||
{ \
|
||||
|
Reference in New Issue
Block a user