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