t1503: move reffiles specific tests to t0600
[alt-git.git] / path.h
blob639372edd9ee36127e3b89084f89ee59d12ff60f
1 #ifndef PATH_H
2 #define PATH_H
4 struct repository;
5 struct strbuf;
6 struct string_list;
8 /*
9 * The result to all functions which return statically allocated memory may be
10 * overwritten by another call to _any_ one of these functions. Consider using
11 * the safer variants which operate on strbufs or return allocated memory.
15 * Return a statically allocated path.
17 const char *mkpath(const char *fmt, ...)
18 __attribute__((format (printf, 1, 2)));
21 * Return a path.
23 char *mkpathdup(const char *fmt, ...)
24 __attribute__((format (printf, 1, 2)));
27 * Construct a path and place the result in the provided buffer `buf`.
29 char *mksnpath(char *buf, size_t n, const char *fmt, ...)
30 __attribute__((format (printf, 3, 4)));
33 * The `git_common_path` family of functions will construct a path into a
34 * repository's common git directory, which is shared by all worktrees.
38 * Constructs a path into the common git directory of repository `repo` and
39 * append it in the provided buffer `sb`.
41 void strbuf_git_common_path(struct strbuf *sb,
42 const struct repository *repo,
43 const char *fmt, ...)
44 __attribute__((format (printf, 3, 4)));
47 * Return a statically allocated path into the main repository's
48 * (the_repository) common git directory.
50 const char *git_common_path(const char *fmt, ...)
51 __attribute__((format (printf, 1, 2)));
55 * The `git_path` family of functions will construct a path into a repository's
56 * git directory.
58 * These functions will perform adjustments to the resultant path to account
59 * for special paths which are either considered common among worktrees (e.g.
60 * paths into the object directory) or have been explicitly set via an
61 * environment variable or config (e.g. path to the index file).
63 * For an exhaustive list of the adjustments made look at `common_list` and
64 * `adjust_git_path` in path.c.
68 * Return a path into the git directory of repository `repo`.
70 char *repo_git_path(const struct repository *repo,
71 const char *fmt, ...)
72 __attribute__((format (printf, 2, 3)));
75 * Construct a path into the git directory of repository `repo` and append it
76 * to the provided buffer `sb`.
78 void strbuf_repo_git_path(struct strbuf *sb,
79 const struct repository *repo,
80 const char *fmt, ...)
81 __attribute__((format (printf, 3, 4)));
84 * Return a statically allocated path into the main repository's
85 * (the_repository) git directory.
87 const char *git_path(const char *fmt, ...)
88 __attribute__((format (printf, 1, 2)));
91 * Return a path into the main repository's (the_repository) git directory.
93 char *git_pathdup(const char *fmt, ...)
94 __attribute__((format (printf, 1, 2)));
97 * Construct a path into the main repository's (the_repository) git directory
98 * and place it in the provided buffer `buf`, the contents of the buffer will
99 * be overridden.
101 char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
102 __attribute__((format (printf, 2, 3)));
105 * Construct a path into the main repository's (the_repository) git directory
106 * and append it to the provided buffer `sb`.
108 void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
109 __attribute__((format (printf, 2, 3)));
112 * Return a path into the worktree of repository `repo`.
114 * If the repository doesn't have a worktree NULL is returned.
116 char *repo_worktree_path(const struct repository *repo,
117 const char *fmt, ...)
118 __attribute__((format (printf, 2, 3)));
121 * Construct a path into the worktree of repository `repo` and append it
122 * to the provided buffer `sb`.
124 * If the repository doesn't have a worktree nothing will be appended to `sb`.
126 void strbuf_repo_worktree_path(struct strbuf *sb,
127 const struct repository *repo,
128 const char *fmt, ...)
129 __attribute__((format (printf, 3, 4)));
132 * Return a path into a submodule's git directory located at `path`. `path`
133 * must only reference a submodule of the main repository (the_repository).
135 char *git_pathdup_submodule(const char *path, const char *fmt, ...)
136 __attribute__((format (printf, 2, 3)));
139 * Construct a path into a submodule's git directory located at `path` and
140 * append it to the provided buffer `sb`. `path` must only reference a
141 * submodule of the main repository (the_repository).
143 int strbuf_git_path_submodule(struct strbuf *sb, const char *path,
144 const char *fmt, ...)
145 __attribute__((format (printf, 3, 4)));
147 void report_linked_checkout_garbage(void);
150 * You can define a static memoized git path like:
152 * static GIT_PATH_FUNC(git_path_foo, "FOO")
154 * or use one of the global ones below.
156 #define GIT_PATH_FUNC(func, filename) \
157 const char *func(void) \
159 static char *ret; \
160 if (!ret) \
161 ret = git_pathdup(filename); \
162 return ret; \
165 #define REPO_GIT_PATH_FUNC(var, filename) \
166 const char *git_path_##var(struct repository *r) \
168 if (!r->cached_paths.var) \
169 r->cached_paths.var = repo_git_path(r, filename); \
170 return r->cached_paths.var; \
173 const char *git_path_squash_msg(struct repository *r);
174 const char *git_path_merge_msg(struct repository *r);
175 const char *git_path_merge_rr(struct repository *r);
176 const char *git_path_merge_mode(struct repository *r);
177 const char *git_path_merge_head(struct repository *r);
178 const char *git_path_merge_autostash(struct repository *r);
179 const char *git_path_auto_merge(struct repository *r);
180 const char *git_path_fetch_head(struct repository *r);
181 const char *git_path_shallow(struct repository *r);
183 int ends_with_path_components(const char *path, const char *components);
184 int validate_headref(const char *ref);
186 int adjust_shared_perm(const char *path);
188 char *interpolate_path(const char *path, int real_home);
189 const char *enter_repo(const char *path, int strict);
190 const char *remove_leading_path(const char *in, const char *prefix);
191 const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
192 int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
193 int normalize_path_copy(char *dst, const char *src);
195 * Normalize in-place the path contained in the strbuf. If an error occurs,
196 * the contents of "sb" are left untouched, and -1 is returned.
198 int strbuf_normalize_path(struct strbuf *src);
199 int longest_ancestor_length(const char *path, struct string_list *prefixes);
200 char *strip_path_suffix(const char *path, const char *suffix);
201 int daemon_avoid_alias(const char *path);
204 * These functions match their is_hfs_dotgit() counterparts; see utf8.h for
205 * details.
207 int is_ntfs_dotgit(const char *name);
208 int is_ntfs_dotgitmodules(const char *name);
209 int is_ntfs_dotgitignore(const char *name);
210 int is_ntfs_dotgitattributes(const char *name);
211 int is_ntfs_dotmailmap(const char *name);
214 * Returns true iff "str" could be confused as a command-line option when
215 * passed to a sub-program like "ssh". Note that this has nothing to do with
216 * shell-quoting, which should be handled separately; we're assuming here that
217 * the string makes it verbatim to the sub-program.
219 int looks_like_command_line_option(const char *str);
222 * Return a newly allocated string with the evaluation of
223 * "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
224 * "$HOME/.config/$subdir/$filename". Return NULL upon error.
226 char *xdg_config_home_for(const char *subdir, const char *filename);
229 * Return a newly allocated string with the evaluation of
230 * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
231 * "$HOME/.config/git/$filename". Return NULL upon error.
233 char *xdg_config_home(const char *filename);
236 * Return a newly allocated string with the evaluation of
237 * "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise
238 * "$HOME/.cache/git/$filename". Return NULL upon error.
240 char *xdg_cache_home(const char *filename);
243 * Create a directory and (if share is nonzero) adjust its permissions
244 * according to the shared_repository setting. Only use this for
245 * directories under $GIT_DIR. Don't use it for working tree
246 * directories.
248 void safe_create_dir(const char *dir, int share);
250 #endif /* PATH_H */