merge-recursive: honor diff.algorithm
[git/gitster.git] / path.h
bloba6f0b70692a5c004584e147e7654b954897e1c6e
1 #ifndef PATH_H
2 #define PATH_H
4 struct repository;
5 struct strbuf;
6 struct string_list;
7 struct worktree;
9 /*
10 * The result to all functions which return statically allocated memory may be
11 * overwritten by another call to _any_ one of these functions. Consider using
12 * the safer variants which operate on strbufs or return allocated memory.
16 * Return a statically allocated path.
18 const char *mkpath(const char *fmt, ...)
19 __attribute__((format (printf, 1, 2)));
22 * Return a path.
24 char *mkpathdup(const char *fmt, ...)
25 __attribute__((format (printf, 1, 2)));
28 * The `git_common_path` family of functions will construct a path into a
29 * repository's common git directory, which is shared by all worktrees.
33 * Constructs a path into the common git directory of repository `repo` and
34 * append it in the provided buffer `sb`.
36 void strbuf_git_common_path(struct strbuf *sb,
37 const struct repository *repo,
38 const char *fmt, ...)
39 __attribute__((format (printf, 3, 4)));
42 * Return a statically allocated path into the main repository's
43 * (the_repository) common git directory.
45 const char *git_common_path(const char *fmt, ...)
46 __attribute__((format (printf, 1, 2)));
50 * The `git_path` family of functions will construct a path into a repository's
51 * git directory.
53 * These functions will perform adjustments to the resultant path to account
54 * for special paths which are either considered common among worktrees (e.g.
55 * paths into the object directory) or have been explicitly set via an
56 * environment variable or config (e.g. path to the index file).
58 * For an exhaustive list of the adjustments made look at `common_list` and
59 * `adjust_git_path` in path.c.
63 * Return a path into the git directory of repository `repo`.
65 char *repo_git_path(const struct repository *repo,
66 const char *fmt, ...)
67 __attribute__((format (printf, 2, 3)));
70 * Construct a path into the git directory of repository `repo` and append it
71 * to the provided buffer `sb`.
73 void strbuf_repo_git_path(struct strbuf *sb,
74 const struct repository *repo,
75 const char *fmt, ...)
76 __attribute__((format (printf, 3, 4)));
79 * Return a statically allocated path into the main repository's
80 * (the_repository) git directory.
82 const char *git_path(const char *fmt, ...)
83 __attribute__((format (printf, 1, 2)));
86 * Similar to git_path() but can produce paths for a specified
87 * worktree instead of current one
89 const char *worktree_git_path(const struct worktree *wt,
90 const char *fmt, ...)
91 __attribute__((format (printf, 2, 3)));
94 * Return a path into the main repository's (the_repository) git directory.
96 char *git_pathdup(const char *fmt, ...)
97 __attribute__((format (printf, 1, 2)));
100 * Construct a path into the main repository's (the_repository) git directory
101 * and place it in the provided buffer `buf`, the contents of the buffer will
102 * be overridden.
104 char *git_path_buf(struct strbuf *buf, const char *fmt, ...)
105 __attribute__((format (printf, 2, 3)));
108 * Construct a path into the main repository's (the_repository) git directory
109 * and append it to the provided buffer `sb`.
111 void strbuf_git_path(struct strbuf *sb, const char *fmt, ...)
112 __attribute__((format (printf, 2, 3)));
115 * Return a path into the worktree of repository `repo`.
117 * If the repository doesn't have a worktree NULL is returned.
119 char *repo_worktree_path(const struct repository *repo,
120 const char *fmt, ...)
121 __attribute__((format (printf, 2, 3)));
124 * Construct a path into the worktree of repository `repo` and append it
125 * to the provided buffer `sb`.
127 * If the repository doesn't have a worktree nothing will be appended to `sb`.
129 void strbuf_repo_worktree_path(struct strbuf *sb,
130 const struct repository *repo,
131 const char *fmt, ...)
132 __attribute__((format (printf, 3, 4)));
135 * Return a path into a submodule's git directory located at `path`. `path`
136 * must only reference a submodule of the main repository (the_repository).
138 char *git_pathdup_submodule(const char *path, const char *fmt, ...)
139 __attribute__((format (printf, 2, 3)));
142 * Construct a path into a submodule's git directory located at `path` and
143 * append it to the provided buffer `sb`. `path` must only reference a
144 * submodule of the main repository (the_repository).
146 int strbuf_git_path_submodule(struct strbuf *sb, const char *path,
147 const char *fmt, ...)
148 __attribute__((format (printf, 3, 4)));
150 void report_linked_checkout_garbage(void);
153 * You can define a static memoized git path like:
155 * static GIT_PATH_FUNC(git_path_foo, "FOO")
157 * or use one of the global ones below.
159 #define GIT_PATH_FUNC(func, filename) \
160 const char *func(void) \
162 static char *ret; \
163 if (!ret) \
164 ret = git_pathdup(filename); \
165 return ret; \
168 #define REPO_GIT_PATH_FUNC(var, filename) \
169 const char *git_path_##var(struct repository *r) \
171 if (!r->cached_paths.var) \
172 r->cached_paths.var = repo_git_path(r, filename); \
173 return r->cached_paths.var; \
176 const char *git_path_squash_msg(struct repository *r);
177 const char *git_path_merge_msg(struct repository *r);
178 const char *git_path_merge_rr(struct repository *r);
179 const char *git_path_merge_mode(struct repository *r);
180 const char *git_path_merge_head(struct repository *r);
181 const char *git_path_fetch_head(struct repository *r);
182 const char *git_path_shallow(struct repository *r);
184 int ends_with_path_components(const char *path, const char *components);
186 int calc_shared_perm(int mode);
187 int adjust_shared_perm(const char *path);
189 char *interpolate_path(const char *path, int real_home);
190 const char *enter_repo(const char *path, int strict);
191 const char *remove_leading_path(const char *in, const char *prefix);
192 const char *relative_path(const char *in, const char *prefix, struct strbuf *sb);
193 int normalize_path_copy_len(char *dst, const char *src, int *prefix_len);
194 int normalize_path_copy(char *dst, const char *src);
196 * Normalize in-place the path contained in the strbuf. If an error occurs,
197 * the contents of "sb" are left untouched, and -1 is returned.
199 int strbuf_normalize_path(struct strbuf *src);
200 int longest_ancestor_length(const char *path, struct string_list *prefixes);
201 char *strip_path_suffix(const char *path, const char *suffix);
202 int daemon_avoid_alias(const char *path);
205 * These functions match their is_hfs_dotgit() counterparts; see utf8.h for
206 * details.
208 int is_ntfs_dotgit(const char *name);
209 int is_ntfs_dotgitmodules(const char *name);
210 int is_ntfs_dotgitignore(const char *name);
211 int is_ntfs_dotgitattributes(const char *name);
212 int is_ntfs_dotmailmap(const char *name);
215 * Returns true iff "str" could be confused as a command-line option when
216 * passed to a sub-program like "ssh". Note that this has nothing to do with
217 * shell-quoting, which should be handled separately; we're assuming here that
218 * the string makes it verbatim to the sub-program.
220 int looks_like_command_line_option(const char *str);
223 * Return a newly allocated string with the evaluation of
224 * "$XDG_CONFIG_HOME/$subdir/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
225 * "$HOME/.config/$subdir/$filename". Return NULL upon error.
227 char *xdg_config_home_for(const char *subdir, const char *filename);
230 * Return a newly allocated string with the evaluation of
231 * "$XDG_CONFIG_HOME/git/$filename" if $XDG_CONFIG_HOME is non-empty, otherwise
232 * "$HOME/.config/git/$filename". Return NULL upon error.
234 char *xdg_config_home(const char *filename);
237 * Return a newly allocated string with the evaluation of
238 * "$XDG_CACHE_HOME/git/$filename" if $XDG_CACHE_HOME is non-empty, otherwise
239 * "$HOME/.cache/git/$filename". Return NULL upon error.
241 char *xdg_cache_home(const char *filename);
244 * Create a directory and (if share is nonzero) adjust its permissions
245 * according to the shared_repository setting. Only use this for
246 * directories under $GIT_DIR. Don't use it for working tree
247 * directories.
249 void safe_create_dir(const char *dir, int share);
251 #endif /* PATH_H */