Blame


1 1ea7ccc6 2021-11-15 thomas /*
2 1ea7ccc6 2021-11-15 thomas * Copyright (c) 2018, 2019, 2020 Stefan Sperling <stsp@openbsd.org>
3 1ea7ccc6 2021-11-15 thomas *
4 1ea7ccc6 2021-11-15 thomas * Permission to use, copy, modify, and distribute this software for any
5 1ea7ccc6 2021-11-15 thomas * purpose with or without fee is hereby granted, provided that the above
6 1ea7ccc6 2021-11-15 thomas * copyright notice and this permission notice appear in all copies.
7 1ea7ccc6 2021-11-15 thomas *
8 1ea7ccc6 2021-11-15 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 1ea7ccc6 2021-11-15 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 1ea7ccc6 2021-11-15 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 1ea7ccc6 2021-11-15 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 1ea7ccc6 2021-11-15 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 1ea7ccc6 2021-11-15 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 1ea7ccc6 2021-11-15 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 1ea7ccc6 2021-11-15 thomas */
16 1ea7ccc6 2021-11-15 thomas
17 1ea7ccc6 2021-11-15 thomas #include <sys/stat.h>
18 8b925c6c 2022-07-16 thomas #include <sys/queue.h>
19 1ea7ccc6 2021-11-15 thomas
20 1ea7ccc6 2021-11-15 thomas #include <errno.h>
21 1ea7ccc6 2021-11-15 thomas #include <fcntl.h>
22 1ea7ccc6 2021-11-15 thomas #include <limits.h>
23 1ea7ccc6 2021-11-15 thomas #include <stddef.h>
24 1ea7ccc6 2021-11-15 thomas #include <stdio.h>
25 1ea7ccc6 2021-11-15 thomas #include <stdlib.h>
26 1ea7ccc6 2021-11-15 thomas #include <string.h>
27 1ea7ccc6 2021-11-15 thomas #include <unistd.h>
28 1ea7ccc6 2021-11-15 thomas
29 1ea7ccc6 2021-11-15 thomas #include "got_cancel.h"
30 1ea7ccc6 2021-11-15 thomas #include "got_error.h"
31 1ea7ccc6 2021-11-15 thomas #include "got_reference.h"
32 1ea7ccc6 2021-11-15 thomas #include "got_path.h"
33 1ea7ccc6 2021-11-15 thomas #include "got_worktree.h"
34 1ea7ccc6 2021-11-15 thomas #include "got_repository.h"
35 1ea7ccc6 2021-11-15 thomas #include "got_gotconfig.h"
36 1ea7ccc6 2021-11-15 thomas #include "got_object.h"
37 1ea7ccc6 2021-11-15 thomas
38 1ea7ccc6 2021-11-15 thomas #include "got_lib_worktree.h"
39 1ea7ccc6 2021-11-15 thomas #include "got_lib_gotconfig.h"
40 1ea7ccc6 2021-11-15 thomas
41 1ea7ccc6 2021-11-15 thomas static const struct got_error *
42 1ea7ccc6 2021-11-15 thomas read_meta_file(char **content, const char *path_got, const char *name)
43 1ea7ccc6 2021-11-15 thomas {
44 1ea7ccc6 2021-11-15 thomas const struct got_error *err = NULL;
45 1ea7ccc6 2021-11-15 thomas char *path;
46 1ea7ccc6 2021-11-15 thomas int fd = -1;
47 1ea7ccc6 2021-11-15 thomas ssize_t n;
48 1ea7ccc6 2021-11-15 thomas struct stat sb;
49 1ea7ccc6 2021-11-15 thomas
50 1ea7ccc6 2021-11-15 thomas *content = NULL;
51 1ea7ccc6 2021-11-15 thomas
52 1ea7ccc6 2021-11-15 thomas if (asprintf(&path, "%s/%s", path_got, name) == -1) {
53 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno("asprintf");
54 1ea7ccc6 2021-11-15 thomas path = NULL;
55 1ea7ccc6 2021-11-15 thomas goto done;
56 1ea7ccc6 2021-11-15 thomas }
57 1ea7ccc6 2021-11-15 thomas
58 06340621 2021-12-31 thomas fd = open(path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
59 1ea7ccc6 2021-11-15 thomas if (fd == -1) {
60 1ea7ccc6 2021-11-15 thomas if (errno == ENOENT)
61 1ea7ccc6 2021-11-15 thomas err = got_error_path(path, GOT_ERR_WORKTREE_META);
62 1ea7ccc6 2021-11-15 thomas else
63 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno2("open", path);
64 1ea7ccc6 2021-11-15 thomas goto done;
65 1ea7ccc6 2021-11-15 thomas }
66 1ea7ccc6 2021-11-15 thomas if (flock(fd, LOCK_SH | LOCK_NB) == -1) {
67 1ea7ccc6 2021-11-15 thomas err = (errno == EWOULDBLOCK ? got_error(GOT_ERR_WORKTREE_BUSY)
68 1ea7ccc6 2021-11-15 thomas : got_error_from_errno2("flock", path));
69 1ea7ccc6 2021-11-15 thomas goto done;
70 1ea7ccc6 2021-11-15 thomas }
71 1ea7ccc6 2021-11-15 thomas
72 1ea7ccc6 2021-11-15 thomas if (fstat(fd, &sb) != 0) {
73 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno2("fstat", path);
74 1ea7ccc6 2021-11-15 thomas goto done;
75 1ea7ccc6 2021-11-15 thomas }
76 1ea7ccc6 2021-11-15 thomas *content = calloc(1, sb.st_size);
77 1ea7ccc6 2021-11-15 thomas if (*content == NULL) {
78 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno("calloc");
79 1ea7ccc6 2021-11-15 thomas goto done;
80 1ea7ccc6 2021-11-15 thomas }
81 1ea7ccc6 2021-11-15 thomas
82 1ea7ccc6 2021-11-15 thomas n = read(fd, *content, sb.st_size);
83 1ea7ccc6 2021-11-15 thomas if (n != sb.st_size) {
84 1ea7ccc6 2021-11-15 thomas err = (n == -1 ? got_error_from_errno2("read", path) :
85 1ea7ccc6 2021-11-15 thomas got_error_path(path, GOT_ERR_WORKTREE_META));
86 1ea7ccc6 2021-11-15 thomas goto done;
87 1ea7ccc6 2021-11-15 thomas }
88 1ea7ccc6 2021-11-15 thomas if ((*content)[sb.st_size - 1] != '\n') {
89 1ea7ccc6 2021-11-15 thomas err = got_error_path(path, GOT_ERR_WORKTREE_META);
90 1ea7ccc6 2021-11-15 thomas goto done;
91 1ea7ccc6 2021-11-15 thomas }
92 1ea7ccc6 2021-11-15 thomas (*content)[sb.st_size - 1] = '\0';
93 1ea7ccc6 2021-11-15 thomas
94 1ea7ccc6 2021-11-15 thomas done:
95 1ea7ccc6 2021-11-15 thomas if (fd != -1 && close(fd) == -1 && err == NULL)
96 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno2("close", path_got);
97 1ea7ccc6 2021-11-15 thomas free(path);
98 1ea7ccc6 2021-11-15 thomas if (err) {
99 1ea7ccc6 2021-11-15 thomas free(*content);
100 1ea7ccc6 2021-11-15 thomas *content = NULL;
101 1ea7ccc6 2021-11-15 thomas }
102 1ea7ccc6 2021-11-15 thomas return err;
103 1ea7ccc6 2021-11-15 thomas }
104 1ea7ccc6 2021-11-15 thomas
105 1ea7ccc6 2021-11-15 thomas static const struct got_error *
106 1ea7ccc6 2021-11-15 thomas open_worktree(struct got_worktree **worktree, const char *path)
107 1ea7ccc6 2021-11-15 thomas {
108 1ea7ccc6 2021-11-15 thomas const struct got_error *err = NULL;
109 1ea7ccc6 2021-11-15 thomas char *path_got;
110 1ea7ccc6 2021-11-15 thomas char *formatstr = NULL;
111 1ea7ccc6 2021-11-15 thomas char *uuidstr = NULL;
112 1ea7ccc6 2021-11-15 thomas char *path_lock = NULL;
113 1ea7ccc6 2021-11-15 thomas char *base_commit_id_str = NULL;
114 1ea7ccc6 2021-11-15 thomas int version, fd = -1;
115 1ea7ccc6 2021-11-15 thomas const char *errstr;
116 1ea7ccc6 2021-11-15 thomas struct got_repository *repo = NULL;
117 b6652669 2022-06-23 thomas int *pack_fds = NULL;
118 1ea7ccc6 2021-11-15 thomas uint32_t uuid_status;
119 1ea7ccc6 2021-11-15 thomas
120 1ea7ccc6 2021-11-15 thomas *worktree = NULL;
121 1ea7ccc6 2021-11-15 thomas
122 1ea7ccc6 2021-11-15 thomas if (asprintf(&path_got, "%s/%s", path, GOT_WORKTREE_GOT_DIR) == -1) {
123 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno("asprintf");
124 1ea7ccc6 2021-11-15 thomas path_got = NULL;
125 1ea7ccc6 2021-11-15 thomas goto done;
126 1ea7ccc6 2021-11-15 thomas }
127 1ea7ccc6 2021-11-15 thomas
128 1ea7ccc6 2021-11-15 thomas if (asprintf(&path_lock, "%s/%s", path_got, GOT_WORKTREE_LOCK) == -1) {
129 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno("asprintf");
130 1ea7ccc6 2021-11-15 thomas path_lock = NULL;
131 1ea7ccc6 2021-11-15 thomas goto done;
132 1ea7ccc6 2021-11-15 thomas }
133 1ea7ccc6 2021-11-15 thomas
134 06340621 2021-12-31 thomas fd = open(path_lock, O_RDWR | O_EXLOCK | O_NONBLOCK | O_CLOEXEC);
135 1ea7ccc6 2021-11-15 thomas if (fd == -1) {
136 1ea7ccc6 2021-11-15 thomas err = (errno == EWOULDBLOCK ? got_error(GOT_ERR_WORKTREE_BUSY)
137 1ea7ccc6 2021-11-15 thomas : got_error_from_errno2("open", path_lock));
138 1ea7ccc6 2021-11-15 thomas goto done;
139 1ea7ccc6 2021-11-15 thomas }
140 1ea7ccc6 2021-11-15 thomas
141 1ea7ccc6 2021-11-15 thomas err = read_meta_file(&formatstr, path_got, GOT_WORKTREE_FORMAT);
142 1ea7ccc6 2021-11-15 thomas if (err)
143 1ea7ccc6 2021-11-15 thomas goto done;
144 1ea7ccc6 2021-11-15 thomas
145 1ea7ccc6 2021-11-15 thomas version = strtonum(formatstr, 1, INT_MAX, &errstr);
146 1ea7ccc6 2021-11-15 thomas if (errstr) {
147 1ea7ccc6 2021-11-15 thomas err = got_error_msg(GOT_ERR_WORKTREE_META,
148 1ea7ccc6 2021-11-15 thomas "could not parse work tree format version number");
149 1ea7ccc6 2021-11-15 thomas goto done;
150 1ea7ccc6 2021-11-15 thomas }
151 1ea7ccc6 2021-11-15 thomas if (version != GOT_WORKTREE_FORMAT_VERSION) {
152 1ea7ccc6 2021-11-15 thomas err = got_error(GOT_ERR_WORKTREE_VERS);
153 1ea7ccc6 2021-11-15 thomas goto done;
154 1ea7ccc6 2021-11-15 thomas }
155 1ea7ccc6 2021-11-15 thomas
156 1ea7ccc6 2021-11-15 thomas *worktree = calloc(1, sizeof(**worktree));
157 1ea7ccc6 2021-11-15 thomas if (*worktree == NULL) {
158 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno("calloc");
159 1ea7ccc6 2021-11-15 thomas goto done;
160 1ea7ccc6 2021-11-15 thomas }
161 1ea7ccc6 2021-11-15 thomas (*worktree)->lockfd = -1;
162 1ea7ccc6 2021-11-15 thomas
163 1ea7ccc6 2021-11-15 thomas (*worktree)->root_path = realpath(path, NULL);
164 1ea7ccc6 2021-11-15 thomas if ((*worktree)->root_path == NULL) {
165 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno2("realpath", path);
166 1ea7ccc6 2021-11-15 thomas goto done;
167 1ea7ccc6 2021-11-15 thomas }
168 1ea7ccc6 2021-11-15 thomas err = read_meta_file(&(*worktree)->repo_path, path_got,
169 1ea7ccc6 2021-11-15 thomas GOT_WORKTREE_REPOSITORY);
170 1ea7ccc6 2021-11-15 thomas if (err)
171 1ea7ccc6 2021-11-15 thomas goto done;
172 1ea7ccc6 2021-11-15 thomas
173 1ea7ccc6 2021-11-15 thomas err = read_meta_file(&(*worktree)->path_prefix, path_got,
174 1ea7ccc6 2021-11-15 thomas GOT_WORKTREE_PATH_PREFIX);
175 1ea7ccc6 2021-11-15 thomas if (err)
176 1ea7ccc6 2021-11-15 thomas goto done;
177 1ea7ccc6 2021-11-15 thomas
178 1ea7ccc6 2021-11-15 thomas err = read_meta_file(&base_commit_id_str, path_got,
179 1ea7ccc6 2021-11-15 thomas GOT_WORKTREE_BASE_COMMIT);
180 1ea7ccc6 2021-11-15 thomas if (err)
181 1ea7ccc6 2021-11-15 thomas goto done;
182 1ea7ccc6 2021-11-15 thomas
183 1ea7ccc6 2021-11-15 thomas err = read_meta_file(&uuidstr, path_got, GOT_WORKTREE_UUID);
184 1ea7ccc6 2021-11-15 thomas if (err)
185 1ea7ccc6 2021-11-15 thomas goto done;
186 1ea7ccc6 2021-11-15 thomas uuid_from_string(uuidstr, &(*worktree)->uuid, &uuid_status);
187 1ea7ccc6 2021-11-15 thomas if (uuid_status != uuid_s_ok) {
188 1ea7ccc6 2021-11-15 thomas err = got_error_uuid(uuid_status, "uuid_from_string");
189 1ea7ccc6 2021-11-15 thomas goto done;
190 1ea7ccc6 2021-11-15 thomas }
191 1ea7ccc6 2021-11-15 thomas
192 b6652669 2022-06-23 thomas err = got_repo_pack_fds_open(&pack_fds);
193 1ea7ccc6 2021-11-15 thomas if (err)
194 1ea7ccc6 2021-11-15 thomas goto done;
195 1ea7ccc6 2021-11-15 thomas
196 b6652669 2022-06-23 thomas err = got_repo_open(&repo, (*worktree)->repo_path, NULL, pack_fds);
197 7cd52833 2022-06-23 thomas if (err)
198 7cd52833 2022-06-23 thomas goto done;
199 7cd52833 2022-06-23 thomas
200 1ea7ccc6 2021-11-15 thomas err = got_object_resolve_id_str(&(*worktree)->base_commit_id, repo,
201 1ea7ccc6 2021-11-15 thomas base_commit_id_str);
202 1ea7ccc6 2021-11-15 thomas if (err)
203 1ea7ccc6 2021-11-15 thomas goto done;
204 1ea7ccc6 2021-11-15 thomas
205 1ea7ccc6 2021-11-15 thomas err = read_meta_file(&(*worktree)->head_ref_name, path_got,
206 1ea7ccc6 2021-11-15 thomas GOT_WORKTREE_HEAD_REF);
207 1ea7ccc6 2021-11-15 thomas if (err)
208 1ea7ccc6 2021-11-15 thomas goto done;
209 1ea7ccc6 2021-11-15 thomas
210 1ea7ccc6 2021-11-15 thomas if (asprintf(&(*worktree)->gotconfig_path, "%s/%s/%s",
211 1ea7ccc6 2021-11-15 thomas (*worktree)->root_path,
212 1ea7ccc6 2021-11-15 thomas GOT_WORKTREE_GOT_DIR, GOT_GOTCONFIG_FILENAME) == -1) {
213 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno("asprintf");
214 1ea7ccc6 2021-11-15 thomas goto done;
215 1ea7ccc6 2021-11-15 thomas }
216 1ea7ccc6 2021-11-15 thomas
217 1ea7ccc6 2021-11-15 thomas err = got_gotconfig_read(&(*worktree)->gotconfig,
218 1ea7ccc6 2021-11-15 thomas (*worktree)->gotconfig_path);
219 1ea7ccc6 2021-11-15 thomas
220 06340621 2021-12-31 thomas (*worktree)->root_fd = open((*worktree)->root_path,
221 06340621 2021-12-31 thomas O_DIRECTORY | O_CLOEXEC);
222 1ea7ccc6 2021-11-15 thomas if ((*worktree)->root_fd == -1) {
223 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno2("open", (*worktree)->root_path);
224 1ea7ccc6 2021-11-15 thomas goto done;
225 1ea7ccc6 2021-11-15 thomas }
226 1ea7ccc6 2021-11-15 thomas done:
227 1ea7ccc6 2021-11-15 thomas if (repo) {
228 1ea7ccc6 2021-11-15 thomas const struct got_error *close_err = got_repo_close(repo);
229 1ea7ccc6 2021-11-15 thomas if (err == NULL)
230 1ea7ccc6 2021-11-15 thomas err = close_err;
231 b6652669 2022-06-23 thomas }
232 b6652669 2022-06-23 thomas if (pack_fds) {
233 b6652669 2022-06-23 thomas const struct got_error *pack_err =
234 b6652669 2022-06-23 thomas got_repo_pack_fds_close(pack_fds);
235 b6652669 2022-06-23 thomas if (err == NULL)
236 b6652669 2022-06-23 thomas err = pack_err;
237 1ea7ccc6 2021-11-15 thomas }
238 1ea7ccc6 2021-11-15 thomas free(path_got);
239 1ea7ccc6 2021-11-15 thomas free(path_lock);
240 1ea7ccc6 2021-11-15 thomas free(base_commit_id_str);
241 1ea7ccc6 2021-11-15 thomas free(uuidstr);
242 1ea7ccc6 2021-11-15 thomas free(formatstr);
243 1ea7ccc6 2021-11-15 thomas if (err) {
244 1ea7ccc6 2021-11-15 thomas if (fd != -1)
245 1ea7ccc6 2021-11-15 thomas close(fd);
246 1ea7ccc6 2021-11-15 thomas if (*worktree != NULL)
247 1ea7ccc6 2021-11-15 thomas got_worktree_close(*worktree);
248 1ea7ccc6 2021-11-15 thomas *worktree = NULL;
249 1ea7ccc6 2021-11-15 thomas } else
250 1ea7ccc6 2021-11-15 thomas (*worktree)->lockfd = fd;
251 1ea7ccc6 2021-11-15 thomas
252 1ea7ccc6 2021-11-15 thomas return err;
253 1ea7ccc6 2021-11-15 thomas }
254 1ea7ccc6 2021-11-15 thomas
255 1ea7ccc6 2021-11-15 thomas const struct got_error *
256 1ea7ccc6 2021-11-15 thomas got_worktree_open(struct got_worktree **worktree, const char *path)
257 1ea7ccc6 2021-11-15 thomas {
258 1ea7ccc6 2021-11-15 thomas const struct got_error *err = NULL;
259 1ea7ccc6 2021-11-15 thomas char *worktree_path;
260 1ea7ccc6 2021-11-15 thomas
261 1ea7ccc6 2021-11-15 thomas worktree_path = strdup(path);
262 1ea7ccc6 2021-11-15 thomas if (worktree_path == NULL)
263 1ea7ccc6 2021-11-15 thomas return got_error_from_errno("strdup");
264 1ea7ccc6 2021-11-15 thomas
265 1ea7ccc6 2021-11-15 thomas for (;;) {
266 1ea7ccc6 2021-11-15 thomas char *parent_path;
267 1ea7ccc6 2021-11-15 thomas
268 1ea7ccc6 2021-11-15 thomas err = open_worktree(worktree, worktree_path);
269 1ea7ccc6 2021-11-15 thomas if (err && !(err->code == GOT_ERR_ERRNO && errno == ENOENT)) {
270 1ea7ccc6 2021-11-15 thomas free(worktree_path);
271 1ea7ccc6 2021-11-15 thomas return err;
272 1ea7ccc6 2021-11-15 thomas }
273 1ea7ccc6 2021-11-15 thomas if (*worktree) {
274 1ea7ccc6 2021-11-15 thomas free(worktree_path);
275 1ea7ccc6 2021-11-15 thomas return NULL;
276 1ea7ccc6 2021-11-15 thomas }
277 1ea7ccc6 2021-11-15 thomas if (worktree_path[0] == '/' && worktree_path[1] == '\0')
278 1ea7ccc6 2021-11-15 thomas break;
279 1ea7ccc6 2021-11-15 thomas err = got_path_dirname(&parent_path, worktree_path);
280 1ea7ccc6 2021-11-15 thomas if (err) {
281 1ea7ccc6 2021-11-15 thomas if (err->code != GOT_ERR_BAD_PATH) {
282 1ea7ccc6 2021-11-15 thomas free(worktree_path);
283 1ea7ccc6 2021-11-15 thomas return err;
284 1ea7ccc6 2021-11-15 thomas }
285 1ea7ccc6 2021-11-15 thomas break;
286 1ea7ccc6 2021-11-15 thomas }
287 1ea7ccc6 2021-11-15 thomas free(worktree_path);
288 1ea7ccc6 2021-11-15 thomas worktree_path = parent_path;
289 1ea7ccc6 2021-11-15 thomas }
290 1ea7ccc6 2021-11-15 thomas
291 1ea7ccc6 2021-11-15 thomas free(worktree_path);
292 1ea7ccc6 2021-11-15 thomas return got_error(GOT_ERR_NOT_WORKTREE);
293 1ea7ccc6 2021-11-15 thomas }
294 1ea7ccc6 2021-11-15 thomas
295 1ea7ccc6 2021-11-15 thomas const struct got_error *
296 1ea7ccc6 2021-11-15 thomas got_worktree_close(struct got_worktree *worktree)
297 1ea7ccc6 2021-11-15 thomas {
298 1ea7ccc6 2021-11-15 thomas const struct got_error *err = NULL;
299 1ea7ccc6 2021-11-15 thomas
300 1ea7ccc6 2021-11-15 thomas if (worktree->lockfd != -1) {
301 1ea7ccc6 2021-11-15 thomas if (close(worktree->lockfd) == -1)
302 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno2("close",
303 1ea7ccc6 2021-11-15 thomas got_worktree_get_root_path(worktree));
304 1ea7ccc6 2021-11-15 thomas }
305 1ea7ccc6 2021-11-15 thomas if (close(worktree->root_fd) == -1 && err == NULL)
306 1ea7ccc6 2021-11-15 thomas err = got_error_from_errno2("close",
307 1ea7ccc6 2021-11-15 thomas got_worktree_get_root_path(worktree));
308 1ea7ccc6 2021-11-15 thomas free(worktree->repo_path);
309 1ea7ccc6 2021-11-15 thomas free(worktree->path_prefix);
310 1ea7ccc6 2021-11-15 thomas free(worktree->base_commit_id);
311 1ea7ccc6 2021-11-15 thomas free(worktree->head_ref_name);
312 1ea7ccc6 2021-11-15 thomas free(worktree->root_path);
313 1ea7ccc6 2021-11-15 thomas free(worktree->gotconfig_path);
314 1ea7ccc6 2021-11-15 thomas got_gotconfig_free(worktree->gotconfig);
315 1ea7ccc6 2021-11-15 thomas free(worktree);
316 1ea7ccc6 2021-11-15 thomas return err;
317 1ea7ccc6 2021-11-15 thomas }
318 1ea7ccc6 2021-11-15 thomas
319 1ea7ccc6 2021-11-15 thomas const char *
320 1ea7ccc6 2021-11-15 thomas got_worktree_get_root_path(struct got_worktree *worktree)
321 1ea7ccc6 2021-11-15 thomas {
322 1ea7ccc6 2021-11-15 thomas return worktree->root_path;
323 1ea7ccc6 2021-11-15 thomas }
324 1ea7ccc6 2021-11-15 thomas
325 1ea7ccc6 2021-11-15 thomas const char *
326 1ea7ccc6 2021-11-15 thomas got_worktree_get_repo_path(struct got_worktree *worktree)
327 1ea7ccc6 2021-11-15 thomas {
328 1ea7ccc6 2021-11-15 thomas return worktree->repo_path;
329 1ea7ccc6 2021-11-15 thomas }
330 1ea7ccc6 2021-11-15 thomas
331 1ea7ccc6 2021-11-15 thomas const char *
332 1ea7ccc6 2021-11-15 thomas got_worktree_get_path_prefix(struct got_worktree *worktree)
333 1ea7ccc6 2021-11-15 thomas {
334 1ea7ccc6 2021-11-15 thomas return worktree->path_prefix;
335 1ea7ccc6 2021-11-15 thomas }