2017-06-22 18:43:35 +00:00
|
|
|
#ifndef PATH_H
|
|
|
|
#define PATH_H
|
|
|
|
|
2017-06-22 18:43:37 +00:00
|
|
|
struct repository;
|
2018-08-15 17:54:05 +00:00
|
|
|
struct strbuf;
|
2023-03-21 06:26:00 +00:00
|
|
|
struct string_list;
|
2017-06-22 18:43:37 +00:00
|
|
|
|
2017-06-22 18:43:35 +00:00
|
|
|
/*
|
2017-12-13 18:28:02 +00:00
|
|
|
* The result to all functions which return statically allocated memory may be
|
|
|
|
* overwritten by another call to _any_ one of these functions. Consider using
|
|
|
|
* the safer variants which operate on strbufs or return allocated memory.
|
2017-06-22 18:43:35 +00:00
|
|
|
*/
|
|
|
|
|
2017-12-13 18:28:02 +00:00
|
|
|
/*
|
|
|
|
* Return a statically allocated path.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
const char *mkpath(const char *fmt, ...)
|
2017-12-13 18:28:02 +00:00
|
|
|
__attribute__((format (printf, 1, 2)));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a path.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
char *mkpathdup(const char *fmt, ...)
|
2017-12-13 18:28:02 +00:00
|
|
|
__attribute__((format (printf, 1, 2)));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct a path and place the result in the provided buffer `buf`.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
char *mksnpath(char *buf, size_t n, const char *fmt, ...)
|
2017-06-22 18:43:35 +00:00
|
|
|
__attribute__((format (printf, 3, 4)));
|
2017-12-13 18:28:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The `git_common_path` family of functions will construct a path into a
|
|
|
|
* repository's common git directory, which is shared by all worktrees.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Constructs a path into the common git directory of repository `repo` and
|
|
|
|
* append it in the provided buffer `sb`.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
void strbuf_git_common_path(struct strbuf *sb,
|
2019-04-29 08:28:23 +00:00
|
|
|
const struct repository *repo,
|
|
|
|
const char *fmt, ...)
|
2017-06-22 18:43:37 +00:00
|
|
|
__attribute__((format (printf, 3, 4)));
|
2017-12-13 18:28:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a statically allocated path into the main repository's
|
|
|
|
* (the_repository) common git directory.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
const char *git_common_path(const char *fmt, ...)
|
2017-06-22 18:43:35 +00:00
|
|
|
__attribute__((format (printf, 1, 2)));
|
|
|
|
|
2017-12-13 18:28:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The `git_path` family of functions will construct a path into a repository's
|
|
|
|
* git directory.
|
|
|
|
*
|
|
|
|
* These functions will perform adjustments to the resultant path to account
|
|
|
|
* for special paths which are either considered common among worktrees (e.g.
|
|
|
|
* paths into the object directory) or have been explicitly set via an
|
|
|
|
* environment variable or config (e.g. path to the index file).
|
|
|
|
*
|
|
|
|
* For an exhaustive list of the adjustments made look at `common_list` and
|
|
|
|
* `adjust_git_path` in path.c.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a path into the git directory of repository `repo`.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
char *repo_git_path(const struct repository *repo,
|
2019-04-29 08:28:23 +00:00
|
|
|
const char *fmt, ...)
|
2017-06-22 18:43:40 +00:00
|
|
|
__attribute__((format (printf, 2, 3)));
|
2017-12-13 18:28:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct a path into the git directory of repository `repo` and append it
|
|
|
|
* to the provided buffer `sb`.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
void strbuf_repo_git_path(struct strbuf *sb,
|
2019-04-29 08:28:23 +00:00
|
|
|
const struct repository *repo,
|
|
|
|
const char *fmt, ...)
|
2017-06-22 18:43:40 +00:00
|
|
|
__attribute__((format (printf, 3, 4)));
|
|
|
|
|
2017-12-13 18:28:02 +00:00
|
|
|
/*
|
|
|
|
* Return a statically allocated path into the main repository's
|
|
|
|
* (the_repository) git directory.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
const char *git_path(const char *fmt, ...)
|
2017-12-13 18:28:02 +00:00
|
|
|
__attribute__((format (printf, 1, 2)));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a path into the main repository's (the_repository) git directory.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
char *git_pathdup(const char *fmt, ...)
|
2017-12-13 18:28:02 +00:00
|
|
|
__attribute__((format (printf, 1, 2)));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct a path into the main repository's (the_repository) git directory
|
|
|
|
* and place it in the provided buffer `buf`, the contents of the buffer will
|
|
|
|
* be overridden.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
|
2017-12-13 18:28:02 +00:00
|
|
|
__attribute__((format (printf, 2, 3)));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct a path into the main repository's (the_repository) git directory
|
|
|
|
* and append it to the provided buffer `sb`.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
|
2017-12-13 18:28:02 +00:00
|
|
|
__attribute__((format (printf, 2, 3)));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a path into the worktree of repository `repo`.
|
|
|
|
*
|
|
|
|
* If the repository doesn't have a worktree NULL is returned.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
char *repo_worktree_path(const struct repository *repo,
|
2017-06-22 18:43:41 +00:00
|
|
|
const char *fmt, ...)
|
|
|
|
__attribute__((format (printf, 2, 3)));
|
2017-12-13 18:28:02 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct a path into the worktree of repository `repo` and append it
|
|
|
|
* to the provided buffer `sb`.
|
|
|
|
*
|
|
|
|
* If the repository doesn't have a worktree nothing will be appended to `sb`.
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
void strbuf_repo_worktree_path(struct strbuf *sb,
|
2017-06-22 18:43:41 +00:00
|
|
|
const struct repository *repo,
|
|
|
|
const char *fmt, ...)
|
|
|
|
__attribute__((format (printf, 3, 4)));
|
|
|
|
|
2017-12-13 18:28:02 +00:00
|
|
|
/*
|
|
|
|
* Return a path into a submodule's git directory located at `path`. `path`
|
|
|
|
* must only reference a submodule of the main repository (the_repository).
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
char *git_pathdup_submodule(const char *path, const char *fmt, ...)
|
2017-12-13 18:28:02 +00:00
|
|
|
__attribute__((format (printf, 2, 3)));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct a path into a submodule's git directory located at `path` and
|
|
|
|
* append it to the provided buffer `sb`. `path` must only reference a
|
|
|
|
* submodule of the main repository (the_repository).
|
|
|
|
*/
|
2019-04-29 08:28:20 +00:00
|
|
|
int strbuf_git_path_submodule(struct strbuf *sb, const char *path,
|
2017-12-13 18:28:02 +00:00
|
|
|
const char *fmt, ...)
|
|
|
|
__attribute__((format (printf, 3, 4)));
|
|
|
|
|
2019-04-29 08:28:14 +00:00
|
|
|
void report_linked_checkout_garbage(void);
|
2017-06-22 18:43:35 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* You can define a static memoized git path like:
|
|
|
|
*
|
2018-07-09 19:25:35 +00:00
|
|
|
* static GIT_PATH_FUNC(git_path_foo, "FOO")
|
2017-06-22 18:43:35 +00:00
|
|
|
*
|
|
|
|
* or use one of the global ones below.
|
|
|
|
*/
|
|
|
|
#define GIT_PATH_FUNC(func, filename) \
|
|
|
|
const char *func(void) \
|
|
|
|
{ \
|
|
|
|
static char *ret; \
|
|
|
|
if (!ret) \
|
|
|
|
ret = git_pathdup(filename); \
|
|
|
|
return ret; \
|
|
|
|
}
|
|
|
|
|
2018-05-17 22:51:51 +00:00
|
|
|
#define REPO_GIT_PATH_FUNC(var, filename) \
|
|
|
|
const char *git_path_##var(struct repository *r) \
|
|
|
|
{ \
|
|
|
|
if (!r->cached_paths.var) \
|
2018-12-15 00:09:41 +00:00
|
|
|
r->cached_paths.var = repo_git_path(r, filename); \
|
2018-05-17 22:51:51 +00:00
|
|
|
return r->cached_paths.var; \
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *git_path_squash_msg(struct repository *r);
|
|
|
|
const char *git_path_merge_msg(struct repository *r);
|
|
|
|
const char *git_path_merge_rr(struct repository *r);
|
|
|
|
const char *git_path_merge_mode(struct repository *r);
|
|
|
|
const char *git_path_merge_head(struct repository *r);
|
|
|
|
const char *git_path_fetch_head(struct repository *r);
|
|
|
|
const char *git_path_shallow(struct repository *r);
|
2017-06-22 18:43:35 +00:00
|
|
|
|
2019-08-25 23:33:39 +00:00
|
|
|
int ends_with_path_components(const char *path, const char *components);
|
2023-03-21 06:26:00 +00:00
|
|
|
int validate_headref(const char *ref);
|
|
|
|
|
|
|
|
int adjust_shared_perm(const char *path);
|
|
|
|
|
|
|
|
char *interpolate_path(const char *path, int real_home);
|
|
|
|
const char *enter_repo(const char *path, int strict);
|
|
|
|
const char *remove_leading_path(const char *in, const char *prefix);
|
|
|
|
const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
|
|
|
|
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
|
|
|
|
int normalize_path_copy(char *dst, const char *src);
|
2023-06-06 19:48:42 +00:00
|
|
|
/**
|
|
|
|
* Normalize in-place the path contained in the strbuf. If an error occurs,
|
|
|
|
* the contents of "sb" are left untouched, and -1 is returned.
|
|
|
|
*/
|
|
|
|
int strbuf_normalize_path(struct strbuf *src);
|
2023-03-21 06:26:00 +00:00
|
|
|
int longest_ancestor_length(const char *path, struct string_list *prefixes);
|
|
|
|
char *strip_path_suffix(const char *path, const char *suffix);
|
|
|
|
int daemon_avoid_alias(const char *path);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These functions match their is_hfs_dotgit() counterparts; see utf8.h for
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
int is_ntfs_dotgit(const char *name);
|
|
|
|
int is_ntfs_dotgitmodules(const char *name);
|
|
|
|
int is_ntfs_dotgitignore(const char *name);
|
|
|
|
int is_ntfs_dotgitattributes(const char *name);
|
|
|
|
int is_ntfs_dotmailmap(const char *name);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Returns true iff "str" could be confused as a command-line option when
|
|
|
|
* passed to a sub-program like "ssh". Note that this has nothing to do with
|
|
|
|
* shell-quoting, which should be handled separately; we're assuming here that
|
|
|
|
* the string makes it verbatim to the sub-program.
|
|
|
|
*/
|
|
|
|
int looks_like_command_line_option(const char *str);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a newly allocated string with the evaluation of
|
|
|
|
* "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
|
|
|
|
* "$HOME/.config/$subdir/$filename". Return NULL upon error.
|
|
|
|
*/
|
|
|
|
char *xdg_config_home_for(const char *subdir, const char *filename);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a newly allocated string with the evaluation of
|
|
|
|
* "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
|
|
|
|
* "$HOME/.config/git/$filename". Return NULL upon error.
|
|
|
|
*/
|
|
|
|
char *xdg_config_home(const char *filename);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a newly allocated string with the evaluation of
|
|
|
|
* "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise
|
|
|
|
* "$HOME/.cache/git/$filename". Return NULL upon error.
|
|
|
|
*/
|
|
|
|
char *xdg_cache_home(const char *filename);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create a directory and (if share is nonzero) adjust its permissions
|
|
|
|
* according to the shared_repository setting. Only use this for
|
|
|
|
* directories under $GIT_DIR. Don't use it for working tree
|
|
|
|
* directories.
|
|
|
|
*/
|
|
|
|
void safe_create_dir(const char *dir, int share);
|
2019-08-25 23:33:39 +00:00
|
|
|
|
2017-06-22 18:43:35 +00:00
|
|
|
#endif /* PATH_H */
|