Merge branch 'rs/imap-send-simplify-cmd-issuing-codepath'
[git/gitster.git] / path.h
blobea96487b292bdb149061dc2b35c07e7529ed01ef
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 * 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.
32 * Constructs a path into the common git directory of repository `repo` and
33 * append it in the provided buffer `sb`.
35 void strbuf_git_common_path(struct strbuf *sb,
36 const struct repository *repo,
37 const char *fmt, ...)
38 __attribute__((format (printf, 3, 4)));
41 * Return a statically allocated path into the main repository's
42 * (the_repository) common git directory.
44 const char *git_common_path(const char *fmt, ...)
45 __attribute__((format (printf, 1, 2)));
49 * The `git_path` family of functions will construct a path into a repository's
50 * git directory.
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).
57 * For an exhaustive list of the adjustments made look at `common_list` and
58 * `adjust_git_path` in path.c.
62 * Return a path into the git directory of repository `repo`.
64 char *repo_git_path(const struct repository *repo,
65 const char *fmt, ...)
66 __attribute__((format (printf, 2, 3)));
69 * Construct a path into the git directory of repository `repo` and append it
70 * to the provided buffer `sb`.
72 void strbuf_repo_git_path(struct strbuf *sb,
73 const struct repository *repo,
74 const char *fmt, ...)
75 __attribute__((format (printf, 3, 4)));
78 * Return a statically allocated path into the main repository's
79 * (the_repository) git directory.
81 const char *git_path(const char *fmt, ...)
82 __attribute__((format (printf, 1, 2)));
85 * Return a path into the main repository's (the_repository) git directory.
87 char *git_pathdup(const char *fmt, ...)
88 __attribute__((format (printf, 1, 2)));
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.
95 char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
96 __attribute__((format (printf, 2, 3)));
99 * Construct a path into the main repository's (the_repository) git directory
100 * and append it to the provided buffer `sb`.
102 void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
103 __attribute__((format (printf, 2, 3)));
106 * Return a path into the worktree of repository `repo`.
108 * If the repository doesn't have a worktree NULL is returned.
110 char *repo_worktree_path(const struct repository *repo,
111 const char *fmt, ...)
112 __attribute__((format (printf, 2, 3)));
115 * Construct a path into the worktree of repository `repo` and append it
116 * to the provided buffer `sb`.
118 * If the repository doesn't have a worktree nothing will be appended to `sb`.
120 void strbuf_repo_worktree_path(struct strbuf *sb,
121 const struct repository *repo,
122 const char *fmt, ...)
123 __attribute__((format (printf, 3, 4)));
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).
129 char *git_pathdup_submodule(const char *path, const char *fmt, ...)
130 __attribute__((format (printf, 2, 3)));
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).
137 int strbuf_git_path_submodule(struct strbuf *sb, const char *path,
138 const char *fmt, ...)
139 __attribute__((format (printf, 3, 4)));
141 void report_linked_checkout_garbage(void);
144 * You can define a static memoized git path like:
146 * static GIT_PATH_FUNC(git_path_foo, "FOO")
148 * or use one of the global ones below.
150 #define GIT_PATH_FUNC(func, filename) \
151 const char *func(void) \
153 static char *ret; \
154 if (!ret) \
155 ret = git_pathdup(filename); \
156 return ret; \
159 #define REPO_GIT_PATH_FUNC(var, filename) \
160 const char *git_path_##var(struct repository *r) \
162 if (!r->cached_paths.var) \
163 r->cached_paths.var = repo_git_path(r, filename); \
164 return r->cached_paths.var; \
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);
175 int ends_with_path_components(const char *path, const char *components);
176 int validate_headref(const char *ref);
178 int calc_shared_perm(int mode);
179 int adjust_shared_perm(const char *path);
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);
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.
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);
197 * These functions match their is_hfs_dotgit() counterparts; see utf8.h for
198 * details.
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);
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.
212 int looks_like_command_line_option(const char *str);
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.
219 char *xdg_config_home_for(const char *subdir, const char *filename);
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.
226 char *xdg_config_home(const char *filename);
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.
233 char *xdg_cache_home(const char *filename);
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.
241 void safe_create_dir(const char *dir, int share);
243 #endif /* PATH_H */