]>
Commit | Line | Data |
---|---|---|
e7d72d07 BW |
1 | #ifndef PATH_H |
2 | #define PATH_H | |
3 | ||
b337172c | 4 | struct repository; |
ef3ca954 | 5 | struct strbuf; |
b337172c | 6 | |
e7d72d07 | 7 | /* |
c07b3adf BW |
8 | * The result to all functions which return statically allocated memory may be |
9 | * overwritten by another call to _any_ one of these functions. Consider using | |
10 | * the safer variants which operate on strbufs or return allocated memory. | |
e7d72d07 | 11 | */ |
e7d72d07 | 12 | |
c07b3adf BW |
13 | /* |
14 | * Return a statically allocated path. | |
15 | */ | |
b199d714 | 16 | const char *mkpath(const char *fmt, ...) |
c07b3adf BW |
17 | __attribute__((format (printf, 1, 2))); |
18 | ||
19 | /* | |
20 | * Return a path. | |
21 | */ | |
b199d714 | 22 | char *mkpathdup(const char *fmt, ...) |
c07b3adf BW |
23 | __attribute__((format (printf, 1, 2))); |
24 | ||
25 | /* | |
26 | * Construct a path and place the result in the provided buffer `buf`. | |
27 | */ | |
b199d714 | 28 | char *mksnpath(char *buf, size_t n, const char *fmt, ...) |
e7d72d07 | 29 | __attribute__((format (printf, 3, 4))); |
c07b3adf BW |
30 | |
31 | /* | |
32 | * The `git_common_path` family of functions will construct a path into a | |
33 | * repository's common git directory, which is shared by all worktrees. | |
34 | */ | |
35 | ||
36 | /* | |
37 | * Constructs a path into the common git directory of repository `repo` and | |
38 | * append it in the provided buffer `sb`. | |
39 | */ | |
b199d714 | 40 | void strbuf_git_common_path(struct strbuf *sb, |
ad6dad09 DL |
41 | const struct repository *repo, |
42 | const char *fmt, ...) | |
b337172c | 43 | __attribute__((format (printf, 3, 4))); |
c07b3adf BW |
44 | |
45 | /* | |
46 | * Return a statically allocated path into the main repository's | |
47 | * (the_repository) common git directory. | |
48 | */ | |
b199d714 | 49 | const char *git_common_path(const char *fmt, ...) |
e7d72d07 | 50 | __attribute__((format (printf, 1, 2))); |
e7d72d07 | 51 | |
c07b3adf BW |
52 | |
53 | /* | |
54 | * The `git_path` family of functions will construct a path into a repository's | |
55 | * git directory. | |
56 | * | |
57 | * These functions will perform adjustments to the resultant path to account | |
58 | * for special paths which are either considered common among worktrees (e.g. | |
59 | * paths into the object directory) or have been explicitly set via an | |
60 | * environment variable or config (e.g. path to the index file). | |
61 | * | |
62 | * For an exhaustive list of the adjustments made look at `common_list` and | |
63 | * `adjust_git_path` in path.c. | |
64 | */ | |
65 | ||
66 | /* | |
67 | * Return a path into the git directory of repository `repo`. | |
68 | */ | |
b199d714 | 69 | char *repo_git_path(const struct repository *repo, |
ad6dad09 | 70 | const char *fmt, ...) |
3181d863 | 71 | __attribute__((format (printf, 2, 3))); |
c07b3adf BW |
72 | |
73 | /* | |
74 | * Construct a path into the git directory of repository `repo` and append it | |
75 | * to the provided buffer `sb`. | |
76 | */ | |
b199d714 | 77 | void strbuf_repo_git_path(struct strbuf *sb, |
ad6dad09 DL |
78 | const struct repository *repo, |
79 | const char *fmt, ...) | |
3181d863 BW |
80 | __attribute__((format (printf, 3, 4))); |
81 | ||
c07b3adf BW |
82 | /* |
83 | * Return a statically allocated path into the main repository's | |
84 | * (the_repository) git directory. | |
85 | */ | |
b199d714 | 86 | const char *git_path(const char *fmt, ...) |
c07b3adf BW |
87 | __attribute__((format (printf, 1, 2))); |
88 | ||
89 | /* | |
90 | * Return a path into the main repository's (the_repository) git directory. | |
91 | */ | |
b199d714 | 92 | char *git_pathdup(const char *fmt, ...) |
c07b3adf BW |
93 | __attribute__((format (printf, 1, 2))); |
94 | ||
95 | /* | |
96 | * Construct a path into the main repository's (the_repository) git directory | |
97 | * and place it in the provided buffer `buf`, the contents of the buffer will | |
98 | * be overridden. | |
99 | */ | |
b199d714 | 100 | char *git_path_buf(struct strbuf *buf, const char *fmt, ...) |
c07b3adf BW |
101 | __attribute__((format (printf, 2, 3))); |
102 | ||
103 | /* | |
104 | * Construct a path into the main repository's (the_repository) git directory | |
105 | * and append it to the provided buffer `sb`. | |
106 | */ | |
b199d714 | 107 | void strbuf_git_path(struct strbuf *sb, const char *fmt, ...) |
c07b3adf BW |
108 | __attribute__((format (printf, 2, 3))); |
109 | ||
110 | /* | |
111 | * Return a path into the worktree of repository `repo`. | |
112 | * | |
113 | * If the repository doesn't have a worktree NULL is returned. | |
114 | */ | |
b199d714 | 115 | char *repo_worktree_path(const struct repository *repo, |
b42b0c09 BW |
116 | const char *fmt, ...) |
117 | __attribute__((format (printf, 2, 3))); | |
c07b3adf BW |
118 | |
119 | /* | |
120 | * Construct a path into the worktree of repository `repo` and append it | |
121 | * to the provided buffer `sb`. | |
122 | * | |
123 | * If the repository doesn't have a worktree nothing will be appended to `sb`. | |
124 | */ | |
b199d714 | 125 | void strbuf_repo_worktree_path(struct strbuf *sb, |
b42b0c09 BW |
126 | const struct repository *repo, |
127 | const char *fmt, ...) | |
128 | __attribute__((format (printf, 3, 4))); | |
129 | ||
c07b3adf BW |
130 | /* |
131 | * Return a path into a submodule's git directory located at `path`. `path` | |
132 | * must only reference a submodule of the main repository (the_repository). | |
133 | */ | |
b199d714 | 134 | char *git_pathdup_submodule(const char *path, const char *fmt, ...) |
c07b3adf BW |
135 | __attribute__((format (printf, 2, 3))); |
136 | ||
137 | /* | |
138 | * Construct a path into a submodule's git directory located at `path` and | |
139 | * append it to the provided buffer `sb`. `path` must only reference a | |
140 | * submodule of the main repository (the_repository). | |
141 | */ | |
b199d714 | 142 | int strbuf_git_path_submodule(struct strbuf *sb, const char *path, |
c07b3adf BW |
143 | const char *fmt, ...) |
144 | __attribute__((format (printf, 3, 4))); | |
145 | ||
55454427 | 146 | void report_linked_checkout_garbage(void); |
e7d72d07 BW |
147 | |
148 | /* | |
149 | * You can define a static memoized git path like: | |
150 | * | |
9ad36356 | 151 | * static GIT_PATH_FUNC(git_path_foo, "FOO") |
e7d72d07 BW |
152 | * |
153 | * or use one of the global ones below. | |
154 | */ | |
155 | #define GIT_PATH_FUNC(func, filename) \ | |
156 | const char *func(void) \ | |
157 | { \ | |
158 | static char *ret; \ | |
159 | if (!ret) \ | |
160 | ret = git_pathdup(filename); \ | |
161 | return ret; \ | |
162 | } | |
163 | ||
102de880 SB |
164 | #define REPO_GIT_PATH_FUNC(var, filename) \ |
165 | const char *git_path_##var(struct repository *r) \ | |
166 | { \ | |
167 | if (!r->cached_paths.var) \ | |
b6b24fc5 | 168 | r->cached_paths.var = repo_git_path(r, filename); \ |
102de880 SB |
169 | return r->cached_paths.var; \ |
170 | } | |
171 | ||
172 | struct path_cache { | |
102de880 SB |
173 | const char *squash_msg; |
174 | const char *merge_msg; | |
175 | const char *merge_rr; | |
176 | const char *merge_mode; | |
177 | const char *merge_head; | |
a03b5553 | 178 | const char *merge_autostash; |
5291828d | 179 | const char *auto_merge; |
102de880 SB |
180 | const char *fetch_head; |
181 | const char *shallow; | |
182 | }; | |
183 | ||
b8825ef2 HWN |
184 | #define PATH_CACHE_INIT \ |
185 | { \ | |
186 | NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL \ | |
c8e4159e | 187 | } |
102de880 | 188 | |
102de880 SB |
189 | const char *git_path_squash_msg(struct repository *r); |
190 | const char *git_path_merge_msg(struct repository *r); | |
191 | const char *git_path_merge_rr(struct repository *r); | |
192 | const char *git_path_merge_mode(struct repository *r); | |
193 | const char *git_path_merge_head(struct repository *r); | |
a03b5553 | 194 | const char *git_path_merge_autostash(struct repository *r); |
5291828d | 195 | const char *git_path_auto_merge(struct repository *r); |
102de880 SB |
196 | const char *git_path_fetch_head(struct repository *r); |
197 | const char *git_path_shallow(struct repository *r); | |
e7d72d07 | 198 | |
ce17feb1 | 199 | |
200 | int ends_with_path_components(const char *path, const char *components); | |
201 | ||
e7d72d07 | 202 | #endif /* PATH_H */ |