]> git.ipfire.org Git - thirdparty/git.git/blame - path.h
The fourteenth batch
[thirdparty/git.git] / path.h
CommitLineData
e7d72d07
BW
1#ifndef PATH_H
2#define PATH_H
3
b337172c 4struct repository;
ef3ca954 5struct strbuf;
905f9693 6struct string_list;
b337172c 7
e7d72d07 8/*
c07b3adf
BW
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.
e7d72d07 12 */
e7d72d07 13
c07b3adf
BW
14/*
15 * Return a statically allocated path.
16 */
b199d714 17const char *mkpath(const char *fmt, ...)
c07b3adf
BW
18 __attribute__((format (printf, 1, 2)));
19
20/*
21 * Return a path.
22 */
b199d714 23char *mkpathdup(const char *fmt, ...)
c07b3adf
BW
24 __attribute__((format (printf, 1, 2)));
25
26/*
27 * Construct a path and place the result in the provided buffer `buf`.
28 */
b199d714 29char *mksnpath(char *buf, size_t n, const char *fmt, ...)
e7d72d07 30 __attribute__((format (printf, 3, 4)));
c07b3adf
BW
31
32/*
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.
35 */
36
37/*
38 * Constructs a path into the common git directory of repository `repo` and
39 * append it in the provided buffer `sb`.
40 */
b199d714 41void strbuf_git_common_path(struct strbuf *sb,
ad6dad09
DL
42 const struct repository *repo,
43 const char *fmt, ...)
b337172c 44 __attribute__((format (printf, 3, 4)));
c07b3adf
BW
45
46/*
47 * Return a statically allocated path into the main repository's
48 * (the_repository) common git directory.
49 */
b199d714 50const char *git_common_path(const char *fmt, ...)
e7d72d07 51 __attribute__((format (printf, 1, 2)));
e7d72d07 52
c07b3adf
BW
53
54/*
55 * The `git_path` family of functions will construct a path into a repository's
56 * git directory.
57 *
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).
62 *
63 * For an exhaustive list of the adjustments made look at `common_list` and
64 * `adjust_git_path` in path.c.
65 */
66
67/*
68 * Return a path into the git directory of repository `repo`.
69 */
b199d714 70char *repo_git_path(const struct repository *repo,
ad6dad09 71 const char *fmt, ...)
3181d863 72 __attribute__((format (printf, 2, 3)));
c07b3adf
BW
73
74/*
75 * Construct a path into the git directory of repository `repo` and append it
76 * to the provided buffer `sb`.
77 */
b199d714 78void strbuf_repo_git_path(struct strbuf *sb,
ad6dad09
DL
79 const struct repository *repo,
80 const char *fmt, ...)
3181d863
BW
81 __attribute__((format (printf, 3, 4)));
82
c07b3adf
BW
83/*
84 * Return a statically allocated path into the main repository's
85 * (the_repository) git directory.
86 */
b199d714 87const char *git_path(const char *fmt, ...)
c07b3adf
BW
88 __attribute__((format (printf, 1, 2)));
89
90/*
91 * Return a path into the main repository's (the_repository) git directory.
92 */
b199d714 93char *git_pathdup(const char *fmt, ...)
c07b3adf
BW
94 __attribute__((format (printf, 1, 2)));
95
96/*
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.
100 */
b199d714 101char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
c07b3adf
BW
102 __attribute__((format (printf, 2, 3)));
103
104/*
105 * Construct a path into the main repository's (the_repository) git directory
106 * and append it to the provided buffer `sb`.
107 */
b199d714 108void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
c07b3adf
BW
109 __attribute__((format (printf, 2, 3)));
110
111/*
112 * Return a path into the worktree of repository `repo`.
113 *
114 * If the repository doesn't have a worktree NULL is returned.
115 */
b199d714 116char *repo_worktree_path(const struct repository *repo,
b42b0c09
BW
117 const char *fmt, ...)
118 __attribute__((format (printf, 2, 3)));
c07b3adf
BW
119
120/*
121 * Construct a path into the worktree of repository `repo` and append it
122 * to the provided buffer `sb`.
123 *
124 * If the repository doesn't have a worktree nothing will be appended to `sb`.
125 */
b199d714 126void strbuf_repo_worktree_path(struct strbuf *sb,
b42b0c09
BW
127 const struct repository *repo,
128 const char *fmt, ...)
129 __attribute__((format (printf, 3, 4)));
130
c07b3adf
BW
131/*
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).
134 */
b199d714 135char *git_pathdup_submodule(const char *path, const char *fmt, ...)
c07b3adf
BW
136 __attribute__((format (printf, 2, 3)));
137
138/*
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).
142 */
b199d714 143int strbuf_git_path_submodule(struct strbuf *sb, const char *path,
c07b3adf
BW
144 const char *fmt, ...)
145 __attribute__((format (printf, 3, 4)));
146
55454427 147void report_linked_checkout_garbage(void);
e7d72d07
BW
148
149/*
150 * You can define a static memoized git path like:
151 *
9ad36356 152 * static GIT_PATH_FUNC(git_path_foo, "FOO")
e7d72d07
BW
153 *
154 * or use one of the global ones below.
155 */
156#define GIT_PATH_FUNC(func, filename) \
157 const char *func(void) \
158 { \
159 static char *ret; \
160 if (!ret) \
161 ret = git_pathdup(filename); \
162 return ret; \
163 }
164
102de880
SB
165#define REPO_GIT_PATH_FUNC(var, filename) \
166 const char *git_path_##var(struct repository *r) \
167 { \
168 if (!r->cached_paths.var) \
b6b24fc5 169 r->cached_paths.var = repo_git_path(r, filename); \
102de880
SB
170 return r->cached_paths.var; \
171 }
172
102de880
SB
173const char *git_path_squash_msg(struct repository *r);
174const char *git_path_merge_msg(struct repository *r);
175const char *git_path_merge_rr(struct repository *r);
176const char *git_path_merge_mode(struct repository *r);
177const char *git_path_merge_head(struct repository *r);
178const char *git_path_fetch_head(struct repository *r);
179const char *git_path_shallow(struct repository *r);
e7d72d07 180
ce17feb1 181int ends_with_path_components(const char *path, const char *components);
905f9693
EN
182int validate_headref(const char *ref);
183
184int adjust_shared_perm(const char *path);
185
186char *interpolate_path(const char *path, int real_home);
187const char *enter_repo(const char *path, int strict);
188const char *remove_leading_path(const char *in, const char *prefix);
189const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
190int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
191int normalize_path_copy(char *dst, const char *src);
aba07068
CW
192/**
193 * Normalize in-place the path contained in the strbuf. If an error occurs,
194 * the contents of "sb" are left untouched, and -1 is returned.
195 */
196int strbuf_normalize_path(struct strbuf *src);
905f9693
EN
197int longest_ancestor_length(const char *path, struct string_list *prefixes);
198char *strip_path_suffix(const char *path, const char *suffix);
199int daemon_avoid_alias(const char *path);
200
201/*
202 * These functions match their is_hfs_dotgit() counterparts; see utf8.h for
203 * details.
204 */
205int is_ntfs_dotgit(const char *name);
206int is_ntfs_dotgitmodules(const char *name);
207int is_ntfs_dotgitignore(const char *name);
208int is_ntfs_dotgitattributes(const char *name);
209int is_ntfs_dotmailmap(const char *name);
210
211/*
212 * Returns true iff "str" could be confused as a command-line option when
213 * passed to a sub-program like "ssh". Note that this has nothing to do with
214 * shell-quoting, which should be handled separately; we're assuming here that
215 * the string makes it verbatim to the sub-program.
216 */
217int looks_like_command_line_option(const char *str);
218
219/**
220 * Return a newly allocated string with the evaluation of
221 * "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
222 * "$HOME/.config/$subdir/$filename". Return NULL upon error.
223 */
224char *xdg_config_home_for(const char *subdir, const char *filename);
225
226/**
227 * Return a newly allocated string with the evaluation of
228 * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
229 * "$HOME/.config/git/$filename". Return NULL upon error.
230 */
231char *xdg_config_home(const char *filename);
232
233/**
234 * Return a newly allocated string with the evaluation of
235 * "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise
236 * "$HOME/.cache/git/$filename". Return NULL upon error.
237 */
238char *xdg_cache_home(const char *filename);
239
240/*
241 * Create a directory and (if share is nonzero) adjust its permissions
242 * according to the shared_repository setting. Only use this for
243 * directories under $GIT_DIR. Don't use it for working tree
244 * directories.
245 */
246void safe_create_dir(const char *dir, int share);
ce17feb1 247
e7d72d07 248#endif /* PATH_H */