]> git.ipfire.org Git - thirdparty/git.git/blame - path.h
A bit more topics before -rc1
[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
c07b3adf
BW
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 */
b199d714 35void strbuf_git_common_path(struct strbuf *sb,
ad6dad09
DL
36 const struct repository *repo,
37 const char *fmt, ...)
b337172c 38 __attribute__((format (printf, 3, 4)));
c07b3adf
BW
39
40/*
41 * Return a statically allocated path into the main repository's
42 * (the_repository) common git directory.
43 */
b199d714 44const char *git_common_path(const char *fmt, ...)
e7d72d07 45 __attribute__((format (printf, 1, 2)));
e7d72d07 46
c07b3adf
BW
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 */
b199d714 64char *repo_git_path(const struct repository *repo,
ad6dad09 65 const char *fmt, ...)
3181d863 66 __attribute__((format (printf, 2, 3)));
c07b3adf
BW
67
68/*
69 * Construct a path into the git directory of repository `repo` and append it
70 * to the provided buffer `sb`.
71 */
b199d714 72void strbuf_repo_git_path(struct strbuf *sb,
ad6dad09
DL
73 const struct repository *repo,
74 const char *fmt, ...)
3181d863
BW
75 __attribute__((format (printf, 3, 4)));
76
c07b3adf
BW
77/*
78 * Return a statically allocated path into the main repository's
79 * (the_repository) git directory.
80 */
b199d714 81const char *git_path(const char *fmt, ...)
c07b3adf
BW
82 __attribute__((format (printf, 1, 2)));
83
84/*
85 * Return a path into the main repository's (the_repository) git directory.
86 */
b199d714 87char *git_pathdup(const char *fmt, ...)
c07b3adf
BW
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 */
b199d714 95char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
c07b3adf
BW
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 */
b199d714 102void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
c07b3adf
BW
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 */
b199d714 110char *repo_worktree_path(const struct repository *repo,
b42b0c09
BW
111 const char *fmt, ...)
112 __attribute__((format (printf, 2, 3)));
c07b3adf
BW
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 */
b199d714 120void strbuf_repo_worktree_path(struct strbuf *sb,
b42b0c09
BW
121 const struct repository *repo,
122 const char *fmt, ...)
123 __attribute__((format (printf, 3, 4)));
124
c07b3adf
BW
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 */
b199d714 129char *git_pathdup_submodule(const char *path, const char *fmt, ...)
c07b3adf
BW
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 */
b199d714 137int strbuf_git_path_submodule(struct strbuf *sb, const char *path,
c07b3adf
BW
138 const char *fmt, ...)
139 __attribute__((format (printf, 3, 4)));
140
55454427 141void report_linked_checkout_garbage(void);
e7d72d07
BW
142
143/*
144 * You can define a static memoized git path like:
145 *
9ad36356 146 * static GIT_PATH_FUNC(git_path_foo, "FOO")
e7d72d07
BW
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
102de880
SB
159#define REPO_GIT_PATH_FUNC(var, filename) \
160 const char *git_path_##var(struct repository *r) \
161 { \
162 if (!r->cached_paths.var) \
b6b24fc5 163 r->cached_paths.var = repo_git_path(r, filename); \
102de880
SB
164 return r->cached_paths.var; \
165 }
166
102de880
SB
167const char *git_path_squash_msg(struct repository *r);
168const char *git_path_merge_msg(struct repository *r);
169const char *git_path_merge_rr(struct repository *r);
170const char *git_path_merge_mode(struct repository *r);
171const char *git_path_merge_head(struct repository *r);
172const char *git_path_fetch_head(struct repository *r);
173const char *git_path_shallow(struct repository *r);
e7d72d07 174
ce17feb1 175int ends_with_path_components(const char *path, const char *components);
905f9693
EN
176int validate_headref(const char *ref);
177
57db2a09 178int calc_shared_perm(int mode);
905f9693
EN
179int adjust_shared_perm(const char *path);
180
181char *interpolate_path(const char *path, int real_home);
182const char *enter_repo(const char *path, int strict);
183const char *remove_leading_path(const char *in, const char *prefix);
184const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
185int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
186int normalize_path_copy(char *dst, const char *src);
aba07068
CW
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 */
191int strbuf_normalize_path(struct strbuf *src);
905f9693
EN
192int longest_ancestor_length(const char *path, struct string_list *prefixes);
193char *strip_path_suffix(const char *path, const char *suffix);
194int daemon_avoid_alias(const char *path);
195
196/*
197 * These functions match their is_hfs_dotgit() counterparts; see utf8.h for
198 * details.
199 */
200int is_ntfs_dotgit(const char *name);
201int is_ntfs_dotgitmodules(const char *name);
202int is_ntfs_dotgitignore(const char *name);
203int is_ntfs_dotgitattributes(const char *name);
204int 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 */
212int 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 */
219char *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 */
226char *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 */
233char *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 */
241void safe_create_dir(const char *dir, int share);
ce17feb1 242
e7d72d07 243#endif /* PATH_H */