Blame


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