2 5d56da81 2019-01-13 stsp * Copyright (c) 2018, 2019 Stefan Sperling <stsp@openbsd.org>
4 d71d75ad 2017-11-05 stsp * Permission to use, copy, modify, and distribute this software for any
5 d71d75ad 2017-11-05 stsp * purpose with or without fee is hereby granted, provided that the above
6 d71d75ad 2017-11-05 stsp * copyright notice and this permission notice appear in all copies.
8 d71d75ad 2017-11-05 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 d71d75ad 2017-11-05 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 d71d75ad 2017-11-05 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 d71d75ad 2017-11-05 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 d71d75ad 2017-11-05 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 d71d75ad 2017-11-05 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 d71d75ad 2017-11-05 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 2178c42e 2018-04-22 stsp #include <sys/types.h>
18 0ffeb3c2 2017-11-26 stsp #include <sys/stat.h>
19 d1cda826 2017-11-06 stsp #include <sys/queue.h>
20 f8b19efd 2021-10-13 stsp #include <sys/tree.h>
21 2178c42e 2018-04-22 stsp #include <sys/uio.h>
22 2178c42e 2018-04-22 stsp #include <sys/socket.h>
23 2178c42e 2018-04-22 stsp #include <sys/wait.h>
24 64a8571e 2022-01-07 stsp #include <sys/mman.h>
26 a1fd68d8 2018-01-12 stsp #include <errno.h>
27 2178c42e 2018-04-22 stsp #include <fcntl.h>
28 d71d75ad 2017-11-05 stsp #include <stdio.h>
29 ab9a70b2 2017-11-06 stsp #include <stdlib.h>
30 ab9a70b2 2017-11-06 stsp #include <string.h>
31 2178c42e 2018-04-22 stsp #include <stdint.h>
32 d71d75ad 2017-11-05 stsp #include <sha1.h>
33 81a12da5 2020-09-09 naddy #include <unistd.h>
34 ab9a70b2 2017-11-06 stsp #include <zlib.h>
35 ab9a70b2 2017-11-06 stsp #include <ctype.h>
36 e40622f4 2020-07-23 stsp #include <libgen.h>
37 ab9a70b2 2017-11-06 stsp #include <limits.h>
38 2178c42e 2018-04-22 stsp #include <imsg.h>
39 788c352e 2018-06-16 stsp #include <time.h>
41 ab9a70b2 2017-11-06 stsp #include "got_error.h"
42 d71d75ad 2017-11-05 stsp #include "got_object.h"
43 ab9a70b2 2017-11-06 stsp #include "got_repository.h"
44 511a516b 2018-05-19 stsp #include "got_opentemp.h"
45 324d37e7 2019-05-11 stsp #include "got_path.h"
47 718b3ab0 2018-03-17 stsp #include "got_lib_sha1.h"
48 718b3ab0 2018-03-17 stsp #include "got_lib_delta.h"
49 63581804 2018-07-09 stsp #include "got_lib_inflate.h"
50 718b3ab0 2018-03-17 stsp #include "got_lib_object.h"
51 2178c42e 2018-04-22 stsp #include "got_lib_privsep.h"
52 6bef87be 2018-09-11 stsp #include "got_lib_object_idcache.h"
53 6bef87be 2018-09-11 stsp #include "got_lib_object_cache.h"
54 ad242220 2018-09-08 stsp #include "got_lib_object_parse.h"
55 15a94983 2018-12-23 stsp #include "got_lib_pack.h"
56 7bb0daa1 2018-06-21 stsp #include "got_lib_repository.h"
59 ab9a70b2 2017-11-06 stsp #define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
62 0ab4c957 2022-06-13 stsp #ifndef nitems
63 0ab4c957 2022-06-13 stsp #define nitems(_a) (sizeof((_a)) / sizeof((_a)[0]))
66 3235492e 2018-04-01 stsp struct got_object_id *
67 3235492e 2018-04-01 stsp got_object_get_id(struct got_object *obj)
69 6402fb3c 2018-09-15 stsp return &obj->id;
72 bacc9935 2018-05-20 stsp const struct got_error *
73 bacc9935 2018-05-20 stsp got_object_get_id_str(char **outbuf, struct got_object *obj)
75 bacc9935 2018-05-20 stsp return got_object_id_str(outbuf, &obj->id);
78 15a94983 2018-12-23 stsp const struct got_error *
79 15a94983 2018-12-23 stsp got_object_get_type(int *type, struct got_repository *repo,
80 15a94983 2018-12-23 stsp struct got_object_id *id)
82 15a94983 2018-12-23 stsp const struct got_error *err = NULL;
83 15a94983 2018-12-23 stsp struct got_object *obj;
85 15a94983 2018-12-23 stsp err = got_object_open(&obj, repo, id);
89 b107e67f 2018-01-19 stsp switch (obj->type) {
90 a1fd68d8 2018-01-12 stsp case GOT_OBJ_TYPE_COMMIT:
91 a1fd68d8 2018-01-12 stsp case GOT_OBJ_TYPE_TREE:
92 a1fd68d8 2018-01-12 stsp case GOT_OBJ_TYPE_BLOB:
93 b107e67f 2018-01-19 stsp case GOT_OBJ_TYPE_TAG:
94 15a94983 2018-12-23 stsp *type = obj->type;
97 15a94983 2018-12-23 stsp err = got_error(GOT_ERR_OBJ_TYPE);
101 15a94983 2018-12-23 stsp got_object_close(obj);
102 15a94983 2018-12-23 stsp return err;
105 90bdb554 2019-04-11 stsp const struct got_error *
106 90bdb554 2019-04-11 stsp got_object_get_path(char **path, struct got_object_id *id,
107 90bdb554 2019-04-11 stsp struct got_repository *repo)
109 ab9a70b2 2017-11-06 stsp const struct got_error *err = NULL;
110 7a132809 2018-07-23 stsp char *hex = NULL;
111 41d2888b 2019-08-11 stsp char *path_objects;
113 e6b1056e 2018-04-22 stsp *path = NULL;
115 41d2888b 2019-08-11 stsp path_objects = got_repo_get_path_objects(repo);
116 ab9a70b2 2017-11-06 stsp if (path_objects == NULL)
117 638f9024 2019-05-13 stsp return got_error_from_errno("got_repo_get_path_objects");
119 ef0981d5 2018-02-12 stsp err = got_object_id_str(&hex, id);
123 d1cda826 2017-11-06 stsp if (asprintf(path, "%s/%.2x/%s", path_objects,
124 d1cda826 2017-11-06 stsp id->sha1[0], hex + 2) == -1)
125 638f9024 2019-05-13 stsp err = got_error_from_errno("asprintf");
129 d1cda826 2017-11-06 stsp free(path_objects);
130 d1cda826 2017-11-06 stsp return err;
133 762d73f4 2021-04-10 stsp const struct got_error *
134 762d73f4 2021-04-10 stsp got_object_open_loose_fd(int *fd, struct got_object_id *id,
135 4796fb13 2018-12-23 stsp struct got_repository *repo)
137 d1cda826 2017-11-06 stsp const struct got_error *err = NULL;
138 a1fd68d8 2018-01-12 stsp char *path;
140 90bdb554 2019-04-11 stsp err = got_object_get_path(&path, id, repo);
142 d1cda826 2017-11-06 stsp return err;
143 8bd0cdad 2021-12-31 stsp *fd = open(path, O_RDONLY | O_NOFOLLOW | O_CLOEXEC);
144 d5003b79 2018-04-22 stsp if (*fd == -1) {
145 e82b1d81 2019-07-27 stsp err = got_error_from_errno2("open", path);
149 4558fcd4 2018-01-14 stsp free(path);
150 2090a03d 2018-09-09 stsp return err;
153 2090a03d 2018-09-09 stsp static const struct got_error *
154 a158c901 2018-12-23 stsp request_packed_object(struct got_object **obj, struct got_pack *pack, int idx,
155 a158c901 2018-12-23 stsp struct got_object_id *id)
157 a158c901 2018-12-23 stsp const struct got_error *err = NULL;
158 a158c901 2018-12-23 stsp struct imsgbuf *ibuf = pack->privsep_child->ibuf;
160 a158c901 2018-12-23 stsp err = got_privsep_send_packed_obj_req(ibuf, idx, id);
162 a158c901 2018-12-23 stsp return err;
164 a158c901 2018-12-23 stsp err = got_privsep_recv_obj(obj, ibuf);
166 a158c901 2018-12-23 stsp return err;
168 a158c901 2018-12-23 stsp memcpy(&(*obj)->id, id, sizeof((*obj)->id));
170 a158c901 2018-12-23 stsp return NULL;
173 db696021 2022-01-04 stsp /* Create temporary files used during delta application. */
174 59d1e4a0 2021-03-10 stsp static const struct got_error *
175 db696021 2022-01-04 stsp pack_child_send_tempfiles(struct imsgbuf *ibuf, struct got_pack *pack)
177 db696021 2022-01-04 stsp const struct got_error *err;
178 57160834 2022-05-31 stsp int basefd = -1, accumfd = -1;
181 db696021 2022-01-04 stsp * For performance reasons, the child will keep reusing the
182 db696021 2022-01-04 stsp * same temporary files during every object request.
183 db696021 2022-01-04 stsp * Opening and closing new files for every object request is
184 db696021 2022-01-04 stsp * too expensive during operations such as 'gotadmin pack'.
186 db696021 2022-01-04 stsp if (pack->child_has_tempfiles)
187 db696021 2022-01-04 stsp return NULL;
189 57160834 2022-05-31 stsp basefd = dup(pack->basefd);
190 59d1e4a0 2021-03-10 stsp if (basefd == -1)
191 57160834 2022-05-31 stsp return got_error_from_errno("dup");
193 57160834 2022-05-31 stsp accumfd = dup(pack->accumfd);
194 57160834 2022-05-31 stsp if (accumfd == -1) {
195 57160834 2022-05-31 stsp err = got_error_from_errno("dup");
199 db696021 2022-01-04 stsp err = got_privsep_send_tmpfd(ibuf, basefd);
203 db696021 2022-01-04 stsp err = got_privsep_send_tmpfd(ibuf, accumfd);
206 57160834 2022-05-31 stsp if (basefd != -1)
207 57160834 2022-05-31 stsp close(basefd);
208 57160834 2022-05-31 stsp if (accumfd != -1)
209 57160834 2022-05-31 stsp close(accumfd);
211 57160834 2022-05-31 stsp pack->child_has_tempfiles = 1;
212 db696021 2022-01-04 stsp return NULL;
215 db696021 2022-01-04 stsp static const struct got_error *
216 db696021 2022-01-04 stsp request_packed_object_raw(uint8_t **outbuf, off_t *size, size_t *hdrlen,
217 db696021 2022-01-04 stsp int outfd, struct got_pack *pack, int idx, struct got_object_id *id)
219 db696021 2022-01-04 stsp const struct got_error *err = NULL;
220 db696021 2022-01-04 stsp struct imsgbuf *ibuf = pack->privsep_child->ibuf;
221 db696021 2022-01-04 stsp int outfd_child;
223 db696021 2022-01-04 stsp err = pack_child_send_tempfiles(ibuf, pack);
225 db696021 2022-01-04 stsp return err;
227 db696021 2022-01-04 stsp outfd_child = dup(outfd);
228 db696021 2022-01-04 stsp if (outfd_child == -1)
229 db696021 2022-01-04 stsp return got_error_from_errno("dup");
231 59d1e4a0 2021-03-10 stsp err = got_privsep_send_packed_raw_obj_req(ibuf, idx, id);
233 59d1e4a0 2021-03-10 stsp close(outfd_child);
234 59d1e4a0 2021-03-10 stsp return err;
237 59d1e4a0 2021-03-10 stsp err = got_privsep_send_raw_obj_outfd(ibuf, outfd_child);
239 59d1e4a0 2021-03-10 stsp return err;
241 59d1e4a0 2021-03-10 stsp err = got_privsep_recv_raw_obj(outbuf, size, hdrlen, ibuf);
243 59d1e4a0 2021-03-10 stsp return err;
245 59d1e4a0 2021-03-10 stsp return NULL;
248 711fb6e8 2018-12-23 stsp static const struct got_error *
249 711fb6e8 2018-12-23 stsp read_packed_object_privsep(struct got_object **obj,
250 711fb6e8 2018-12-23 stsp struct got_repository *repo, struct got_pack *pack,
251 711fb6e8 2018-12-23 stsp struct got_packidx *packidx, int idx, struct got_object_id *id)
253 711fb6e8 2018-12-23 stsp const struct got_error *err = NULL;
255 59d1e4a0 2021-03-10 stsp if (pack->privsep_child == NULL) {
256 3d589bee 2022-06-25 stsp err = got_pack_start_privsep_child(pack, packidx);
258 59d1e4a0 2021-03-10 stsp return err;
261 711fb6e8 2018-12-23 stsp return request_packed_object(obj, pack, idx, id);
264 59d1e4a0 2021-03-10 stsp static const struct got_error *
265 59d1e4a0 2021-03-10 stsp read_packed_object_raw_privsep(uint8_t **outbuf, off_t *size, size_t *hdrlen,
266 59d1e4a0 2021-03-10 stsp int outfd, struct got_pack *pack, struct got_packidx *packidx, int idx,
267 59d1e4a0 2021-03-10 stsp struct got_object_id *id)
269 59d1e4a0 2021-03-10 stsp const struct got_error *err = NULL;
271 59d1e4a0 2021-03-10 stsp if (pack->privsep_child == NULL) {
272 3d589bee 2022-06-25 stsp err = got_pack_start_privsep_child(pack, packidx);
274 59d1e4a0 2021-03-10 stsp return err;
277 59d1e4a0 2021-03-10 stsp return request_packed_object_raw(outbuf, size, hdrlen, outfd, pack,
281 b3d68e7f 2021-07-03 stsp const struct got_error *
282 b3d68e7f 2021-07-03 stsp got_object_open_packed(struct got_object **obj, struct got_object_id *id,
283 2090a03d 2018-09-09 stsp struct got_repository *repo)
285 2090a03d 2018-09-09 stsp const struct got_error *err = NULL;
286 2090a03d 2018-09-09 stsp struct got_pack *pack = NULL;
287 2090a03d 2018-09-09 stsp struct got_packidx *packidx = NULL;
289 2090a03d 2018-09-09 stsp char *path_packfile;
291 2090a03d 2018-09-09 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
293 2090a03d 2018-09-09 stsp return err;
295 aea75d87 2021-07-06 stsp err = got_packidx_get_packfile_path(&path_packfile,
296 aea75d87 2021-07-06 stsp packidx->path_packidx);
298 2090a03d 2018-09-09 stsp return err;
300 2090a03d 2018-09-09 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
301 2090a03d 2018-09-09 stsp if (pack == NULL) {
302 2090a03d 2018-09-09 stsp err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
307 a158c901 2018-12-23 stsp err = read_packed_object_privsep(obj, repo, pack, packidx, idx, id);
311 2090a03d 2018-09-09 stsp free(path_packfile);
312 4558fcd4 2018-01-14 stsp return err;
315 67fd6849 2022-02-13 stsp const struct got_error *
316 67fd6849 2022-02-13 stsp got_object_open_from_packfile(struct got_object **obj, struct got_object_id *id,
317 67fd6849 2022-02-13 stsp struct got_pack *pack, struct got_packidx *packidx, int obj_idx,
318 67fd6849 2022-02-13 stsp struct got_repository *repo)
320 67fd6849 2022-02-13 stsp return read_packed_object_privsep(obj, repo, pack, packidx,
321 67fd6849 2022-02-13 stsp obj_idx, id);
324 67fd6849 2022-02-13 stsp const struct got_error *
325 67fd6849 2022-02-13 stsp got_object_read_raw_delta(uint64_t *base_size, uint64_t *result_size,
326 2d9e6abf 2022-05-04 stsp off_t *delta_size, off_t *delta_compressed_size, off_t *delta_offset,
327 2d9e6abf 2022-05-04 stsp off_t *delta_out_offset, struct got_object_id **base_id, int delta_cache_fd,
328 67fd6849 2022-02-13 stsp struct got_packidx *packidx, int obj_idx, struct got_object_id *id,
329 67fd6849 2022-02-13 stsp struct got_repository *repo)
331 67fd6849 2022-02-13 stsp const struct got_error *err = NULL;
332 67fd6849 2022-02-13 stsp struct got_pack *pack = NULL;
333 67fd6849 2022-02-13 stsp char *path_packfile;
335 67fd6849 2022-02-13 stsp *base_size = 0;
336 67fd6849 2022-02-13 stsp *result_size = 0;
337 67fd6849 2022-02-13 stsp *delta_size = 0;
338 2d9e6abf 2022-05-04 stsp *delta_compressed_size = 0;
339 67fd6849 2022-02-13 stsp *delta_offset = 0;
340 67fd6849 2022-02-13 stsp *delta_out_offset = 0;
342 67fd6849 2022-02-13 stsp err = got_packidx_get_packfile_path(&path_packfile,
343 67fd6849 2022-02-13 stsp packidx->path_packidx);
345 67fd6849 2022-02-13 stsp return err;
347 67fd6849 2022-02-13 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
348 67fd6849 2022-02-13 stsp if (pack == NULL) {
349 67fd6849 2022-02-13 stsp err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
351 67fd6849 2022-02-13 stsp return err;
354 67fd6849 2022-02-13 stsp if (pack->privsep_child == NULL) {
355 3d589bee 2022-06-25 stsp err = got_pack_start_privsep_child(pack, packidx);
357 67fd6849 2022-02-13 stsp return err;
360 67fd6849 2022-02-13 stsp if (!pack->child_has_delta_outfd) {
361 67fd6849 2022-02-13 stsp int outfd_child;
362 67fd6849 2022-02-13 stsp outfd_child = dup(delta_cache_fd);
363 67fd6849 2022-02-13 stsp if (outfd_child == -1)
364 67fd6849 2022-02-13 stsp return got_error_from_errno("dup");
365 67fd6849 2022-02-13 stsp err = got_privsep_send_raw_delta_outfd(
366 67fd6849 2022-02-13 stsp pack->privsep_child->ibuf, outfd_child);
368 67fd6849 2022-02-13 stsp return err;
369 67fd6849 2022-02-13 stsp pack->child_has_delta_outfd = 1;
372 67fd6849 2022-02-13 stsp err = got_privsep_send_raw_delta_req(pack->privsep_child->ibuf,
373 67fd6849 2022-02-13 stsp obj_idx, id);
375 67fd6849 2022-02-13 stsp return err;
377 67fd6849 2022-02-13 stsp return got_privsep_recv_raw_delta(base_size, result_size, delta_size,
378 2d9e6abf 2022-05-04 stsp delta_compressed_size, delta_offset, delta_out_offset, base_id,
379 2d9e6abf 2022-05-04 stsp pack->privsep_child->ibuf);
382 9f2369b0 2018-12-24 stsp static const struct got_error *
383 d5c81d44 2021-07-08 stsp request_object(struct got_object **obj, struct got_object_id *id,
384 d5c81d44 2021-07-08 stsp struct got_repository *repo, int fd)
386 9f2369b0 2018-12-24 stsp const struct got_error *err = NULL;
387 9f2369b0 2018-12-24 stsp struct imsgbuf *ibuf;
389 9f2369b0 2018-12-24 stsp ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].ibuf;
391 d5c81d44 2021-07-08 stsp err = got_privsep_send_obj_req(ibuf, fd, id);
393 9f2369b0 2018-12-24 stsp return err;
395 9f2369b0 2018-12-24 stsp return got_privsep_recv_obj(obj, ibuf);
398 9f2369b0 2018-12-24 stsp static const struct got_error *
399 59d1e4a0 2021-03-10 stsp request_raw_object(uint8_t **outbuf, off_t *size, size_t *hdrlen, int outfd,
400 d5c81d44 2021-07-08 stsp struct got_object_id *id, struct got_repository *repo, int infd)
402 59d1e4a0 2021-03-10 stsp const struct got_error *err = NULL;
403 59d1e4a0 2021-03-10 stsp struct imsgbuf *ibuf;
404 59d1e4a0 2021-03-10 stsp int outfd_child;
406 59d1e4a0 2021-03-10 stsp ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].ibuf;
408 59d1e4a0 2021-03-10 stsp outfd_child = dup(outfd);
409 59d1e4a0 2021-03-10 stsp if (outfd_child == -1)
410 59d1e4a0 2021-03-10 stsp return got_error_from_errno("dup");
412 d5c81d44 2021-07-08 stsp err = got_privsep_send_raw_obj_req(ibuf, infd, id);
414 59d1e4a0 2021-03-10 stsp return err;
416 59d1e4a0 2021-03-10 stsp err = got_privsep_send_raw_obj_outfd(ibuf, outfd_child);
418 59d1e4a0 2021-03-10 stsp return err;
420 59d1e4a0 2021-03-10 stsp return got_privsep_recv_raw_obj(outbuf, size, hdrlen, ibuf);
423 59d1e4a0 2021-03-10 stsp static const struct got_error *
424 59d1e4a0 2021-03-10 stsp start_read_object_child(struct got_repository *repo)
426 59d1e4a0 2021-03-10 stsp const struct got_error *err = NULL;
427 9f2369b0 2018-12-24 stsp int imsg_fds[2];
429 9f2369b0 2018-12-24 stsp struct imsgbuf *ibuf;
431 9f2369b0 2018-12-24 stsp ibuf = calloc(1, sizeof(*ibuf));
432 9f2369b0 2018-12-24 stsp if (ibuf == NULL)
433 638f9024 2019-05-13 stsp return got_error_from_errno("calloc");
435 ddc7b220 2019-09-08 stsp if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
436 ddc7b220 2019-09-08 stsp err = got_error_from_errno("socketpair");
437 ddc7b220 2019-09-08 stsp free(ibuf);
438 ddc7b220 2019-09-08 stsp return err;
441 9f2369b0 2018-12-24 stsp pid = fork();
442 ddc7b220 2019-09-08 stsp if (pid == -1) {
443 ddc7b220 2019-09-08 stsp err = got_error_from_errno("fork");
444 ddc7b220 2019-09-08 stsp free(ibuf);
445 ddc7b220 2019-09-08 stsp return err;
447 9f2369b0 2018-12-24 stsp else if (pid == 0) {
448 aba9c984 2019-09-08 stsp got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_OBJECT,
449 9f2369b0 2018-12-24 stsp repo->path);
450 9f2369b0 2018-12-24 stsp /* not reached */
453 08578a35 2021-01-22 stsp if (close(imsg_fds[1]) == -1) {
454 ddc7b220 2019-09-08 stsp err = got_error_from_errno("close");
455 ddc7b220 2019-09-08 stsp free(ibuf);
456 ddc7b220 2019-09-08 stsp return err;
459 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].imsg_fd =
460 9f2369b0 2018-12-24 stsp imsg_fds[0];
461 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].pid = pid;
462 9f2369b0 2018-12-24 stsp imsg_init(ibuf, imsg_fds[0]);
463 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].ibuf = ibuf;
465 59d1e4a0 2021-03-10 stsp return NULL;
468 b3d68e7f 2021-07-03 stsp const struct got_error *
469 b3d68e7f 2021-07-03 stsp got_object_read_header_privsep(struct got_object **obj,
470 d5c81d44 2021-07-08 stsp struct got_object_id *id, struct got_repository *repo, int obj_fd)
472 59d1e4a0 2021-03-10 stsp const struct got_error *err;
474 59d1e4a0 2021-03-10 stsp if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].imsg_fd != -1)
475 d5c81d44 2021-07-08 stsp return request_object(obj, id, repo, obj_fd);
477 59d1e4a0 2021-03-10 stsp err = start_read_object_child(repo);
479 7495ec13 2021-04-04 stsp close(obj_fd);
480 59d1e4a0 2021-03-10 stsp return err;
483 d5c81d44 2021-07-08 stsp return request_object(obj, id, repo, obj_fd);
486 59d1e4a0 2021-03-10 stsp static const struct got_error *
487 59d1e4a0 2021-03-10 stsp read_object_raw_privsep(uint8_t **outbuf, off_t *size, size_t *hdrlen,
488 d5c81d44 2021-07-08 stsp int outfd, struct got_object_id *id, struct got_repository *repo,
489 d5c81d44 2021-07-08 stsp int obj_fd)
491 59d1e4a0 2021-03-10 stsp const struct got_error *err;
493 59d1e4a0 2021-03-10 stsp if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_OBJECT].imsg_fd != -1)
494 d5c81d44 2021-07-08 stsp return request_raw_object(outbuf, size, hdrlen, outfd, id,
495 d5c81d44 2021-07-08 stsp repo, obj_fd);
497 59d1e4a0 2021-03-10 stsp err = start_read_object_child(repo);
499 59d1e4a0 2021-03-10 stsp return err;
501 d5c81d44 2021-07-08 stsp return request_raw_object(outbuf, size, hdrlen, outfd, id, repo,
505 4558fcd4 2018-01-14 stsp const struct got_error *
506 4558fcd4 2018-01-14 stsp got_object_open(struct got_object **obj, struct got_repository *repo,
507 4558fcd4 2018-01-14 stsp struct got_object_id *id)
509 6c00b545 2018-01-17 stsp const struct got_error *err = NULL;
512 7bb0daa1 2018-06-21 stsp *obj = got_repo_get_cached_object(repo, id);
513 7bb0daa1 2018-06-21 stsp if (*obj != NULL) {
514 7bb0daa1 2018-06-21 stsp (*obj)->refcnt++;
515 7bb0daa1 2018-06-21 stsp return NULL;
518 b3d68e7f 2021-07-03 stsp err = got_object_open_packed(obj, id, repo);
519 e82b1d81 2019-07-27 stsp if (err && err->code != GOT_ERR_NO_OBJ)
520 e82b1d81 2019-07-27 stsp return err;
521 e82b1d81 2019-07-27 stsp if (*obj) {
522 e82b1d81 2019-07-27 stsp (*obj)->refcnt++;
523 e82b1d81 2019-07-27 stsp return got_repo_cache_object(repo, id, *obj);
526 762d73f4 2021-04-10 stsp err = got_object_open_loose_fd(&fd, id, repo);
528 762d73f4 2021-04-10 stsp if (err->code == GOT_ERR_ERRNO && errno == ENOENT)
529 762d73f4 2021-04-10 stsp err = got_error_no_obj(id);
530 762d73f4 2021-04-10 stsp return err;
533 d5c81d44 2021-07-08 stsp err = got_object_read_header_privsep(obj, id, repo, fd);
535 4558fcd4 2018-01-14 stsp return err;
537 762d73f4 2021-04-10 stsp memcpy((*obj)->id.sha1, id->sha1, SHA1_DIGEST_LENGTH);
539 59790a32 2018-09-15 stsp (*obj)->refcnt++;
540 762d73f4 2021-04-10 stsp return got_repo_cache_object(repo, id, *obj);
543 d3c116bf 2021-10-15 stsp /* *outfd must be initialized to -1 by caller */
544 59d1e4a0 2021-03-10 stsp const struct got_error *
545 d3c116bf 2021-10-15 stsp got_object_raw_open(struct got_raw_object **obj, int *outfd,
546 94dac27c 2021-10-15 stsp struct got_repository *repo, struct got_object_id *id)
548 59d1e4a0 2021-03-10 stsp const struct got_error *err = NULL;
549 59d1e4a0 2021-03-10 stsp struct got_packidx *packidx = NULL;
551 59d1e4a0 2021-03-10 stsp uint8_t *outbuf = NULL;
552 59d1e4a0 2021-03-10 stsp off_t size = 0;
553 59d1e4a0 2021-03-10 stsp size_t hdrlen = 0;
554 59d1e4a0 2021-03-10 stsp char *path_packfile = NULL;
556 d3c116bf 2021-10-15 stsp *obj = got_repo_get_cached_raw_object(repo, id);
557 d3c116bf 2021-10-15 stsp if (*obj != NULL) {
558 d3c116bf 2021-10-15 stsp (*obj)->refcnt++;
559 d3c116bf 2021-10-15 stsp return NULL;
562 d3c116bf 2021-10-15 stsp if (*outfd == -1) {
563 d3c116bf 2021-10-15 stsp *outfd = got_opentempfd();
564 d3c116bf 2021-10-15 stsp if (*outfd == -1)
565 d3c116bf 2021-10-15 stsp return got_error_from_errno("got_opentempfd");
568 59d1e4a0 2021-03-10 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
569 59d1e4a0 2021-03-10 stsp if (err == NULL) {
570 59d1e4a0 2021-03-10 stsp struct got_pack *pack = NULL;
572 aea75d87 2021-07-06 stsp err = got_packidx_get_packfile_path(&path_packfile,
573 aea75d87 2021-07-06 stsp packidx->path_packidx);
577 59d1e4a0 2021-03-10 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
578 59d1e4a0 2021-03-10 stsp if (pack == NULL) {
579 59d1e4a0 2021-03-10 stsp err = got_repo_cache_pack(&pack, repo, path_packfile,
584 59d1e4a0 2021-03-10 stsp err = read_packed_object_raw_privsep(&outbuf, &size, &hdrlen,
585 d3c116bf 2021-10-15 stsp *outfd, pack, packidx, idx, id);
588 59d1e4a0 2021-03-10 stsp } else if (err->code == GOT_ERR_NO_OBJ) {
591 762d73f4 2021-04-10 stsp err = got_object_open_loose_fd(&fd, id, repo);
594 d3c116bf 2021-10-15 stsp err = read_object_raw_privsep(&outbuf, &size, &hdrlen, *outfd,
595 d5c81d44 2021-07-08 stsp id, repo, fd);
600 59d1e4a0 2021-03-10 stsp *obj = calloc(1, sizeof(**obj));
601 59d1e4a0 2021-03-10 stsp if (*obj == NULL) {
602 59d1e4a0 2021-03-10 stsp err = got_error_from_errno("calloc");
605 64a8571e 2022-01-07 stsp (*obj)->fd = -1;
607 59d1e4a0 2021-03-10 stsp if (outbuf) {
608 59d1e4a0 2021-03-10 stsp (*obj)->data = outbuf;
610 59d1e4a0 2021-03-10 stsp struct stat sb;
611 d3c116bf 2021-10-15 stsp if (fstat(*outfd, &sb) == -1) {
612 59d1e4a0 2021-03-10 stsp err = got_error_from_errno("fstat");
616 a8591711 2021-06-18 stsp if (sb.st_size != hdrlen + size) {
617 59d1e4a0 2021-03-10 stsp err = got_error(GOT_ERR_PRIVSEP_LEN);
620 64a8571e 2022-01-07 stsp #ifndef GOT_PACK_NO_MMAP
621 64a8571e 2022-01-07 stsp if (hdrlen + size > 0) {
622 64a8571e 2022-01-07 stsp (*obj)->data = mmap(NULL, hdrlen + size, PROT_READ,
623 64a8571e 2022-01-07 stsp MAP_PRIVATE, *outfd, 0);
624 64a8571e 2022-01-07 stsp if ((*obj)->data == MAP_FAILED) {
625 64a8571e 2022-01-07 stsp if (errno != ENOMEM) {
626 64a8571e 2022-01-07 stsp err = got_error_from_errno("mmap");
629 64a8571e 2022-01-07 stsp (*obj)->data = NULL;
631 64a8571e 2022-01-07 stsp (*obj)->fd = *outfd;
632 64a8571e 2022-01-07 stsp *outfd = -1;
636 64a8571e 2022-01-07 stsp if (*outfd != -1) {
637 64a8571e 2022-01-07 stsp (*obj)->f = fdopen(*outfd, "r");
638 64a8571e 2022-01-07 stsp if ((*obj)->f == NULL) {
639 64a8571e 2022-01-07 stsp err = got_error_from_errno("fdopen");
642 64a8571e 2022-01-07 stsp *outfd = -1;
645 59d1e4a0 2021-03-10 stsp (*obj)->hdrlen = hdrlen;
646 59d1e4a0 2021-03-10 stsp (*obj)->size = size;
647 d3c116bf 2021-10-15 stsp err = got_repo_cache_raw_object(repo, id, *obj);
649 59d1e4a0 2021-03-10 stsp free(path_packfile);
651 59d1e4a0 2021-03-10 stsp if (*obj) {
652 59d1e4a0 2021-03-10 stsp got_object_raw_close(*obj);
653 59d1e4a0 2021-03-10 stsp *obj = NULL;
655 59d1e4a0 2021-03-10 stsp free(outbuf);
657 d3c116bf 2021-10-15 stsp (*obj)->refcnt++;
658 59d1e4a0 2021-03-10 stsp return err;
661 59d1e4a0 2021-03-10 stsp const struct got_error *
662 6dfa2fd3 2018-02-12 stsp got_object_open_by_id_str(struct got_object **obj, struct got_repository *repo,
663 6dfa2fd3 2018-02-12 stsp const char *id_str)
665 6dfa2fd3 2018-02-12 stsp struct got_object_id id;
667 6dfa2fd3 2018-02-12 stsp if (!got_parse_sha1_digest(id.sha1, id_str))
668 6dd1ece6 2019-11-10 stsp return got_error_path(id_str, GOT_ERR_BAD_OBJ_ID_STR);
670 6dfa2fd3 2018-02-12 stsp return got_object_open(obj, repo, &id);
673 15a94983 2018-12-23 stsp const struct got_error *
674 15a94983 2018-12-23 stsp got_object_resolve_id_str(struct got_object_id **id,
675 15a94983 2018-12-23 stsp struct got_repository *repo, const char *id_str)
677 15a94983 2018-12-23 stsp const struct got_error *err = NULL;
678 15a94983 2018-12-23 stsp struct got_object *obj;
680 15a94983 2018-12-23 stsp err = got_object_open_by_id_str(&obj, repo, id_str);
682 15a94983 2018-12-23 stsp return err;
684 15a94983 2018-12-23 stsp *id = got_object_id_dup(got_object_get_id(obj));
685 15a94983 2018-12-23 stsp got_object_close(obj);
686 15a94983 2018-12-23 stsp if (*id == NULL)
687 638f9024 2019-05-13 stsp return got_error_from_errno("got_object_id_dup");
689 15a94983 2018-12-23 stsp return NULL;
692 434025f3 2018-09-16 stsp static const struct got_error *
693 a158c901 2018-12-23 stsp request_packed_commit(struct got_commit_object **commit, struct got_pack *pack,
694 a158c901 2018-12-23 stsp int pack_idx, struct got_object_id *id)
696 a158c901 2018-12-23 stsp const struct got_error *err = NULL;
698 a158c901 2018-12-23 stsp err = got_privsep_send_commit_req(pack->privsep_child->ibuf, -1, id,
701 a158c901 2018-12-23 stsp return err;
703 ca6e02ac 2020-01-07 stsp err = got_privsep_recv_commit(commit, pack->privsep_child->ibuf);
705 ca6e02ac 2020-01-07 stsp return err;
707 ca6e02ac 2020-01-07 stsp (*commit)->flags |= GOT_COMMIT_FLAG_PACKED;
708 ca6e02ac 2020-01-07 stsp return NULL;
711 a158c901 2018-12-23 stsp static const struct got_error *
712 a158c901 2018-12-23 stsp read_packed_commit_privsep(struct got_commit_object **commit,
713 a158c901 2018-12-23 stsp struct got_pack *pack, struct got_packidx *packidx, int idx,
714 a158c901 2018-12-23 stsp struct got_object_id *id)
716 a158c901 2018-12-23 stsp const struct got_error *err = NULL;
718 a158c901 2018-12-23 stsp if (pack->privsep_child)
719 a158c901 2018-12-23 stsp return request_packed_commit(commit, pack, idx, id);
721 3d589bee 2022-06-25 stsp err = got_pack_start_privsep_child(pack, packidx);
723 a158c901 2018-12-23 stsp return err;
725 711fb6e8 2018-12-23 stsp return request_packed_commit(commit, pack, idx, id);
728 9f2369b0 2018-12-24 stsp static const struct got_error *
729 9f2369b0 2018-12-24 stsp request_commit(struct got_commit_object **commit, struct got_repository *repo,
730 d5c81d44 2021-07-08 stsp int fd, struct got_object_id *id)
732 9f2369b0 2018-12-24 stsp const struct got_error *err = NULL;
733 9f2369b0 2018-12-24 stsp struct imsgbuf *ibuf;
735 9f2369b0 2018-12-24 stsp ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].ibuf;
737 d5c81d44 2021-07-08 stsp err = got_privsep_send_commit_req(ibuf, fd, id, -1);
739 9f2369b0 2018-12-24 stsp return err;
741 9f2369b0 2018-12-24 stsp return got_privsep_recv_commit(commit, ibuf);
744 9f2369b0 2018-12-24 stsp static const struct got_error *
745 9f2369b0 2018-12-24 stsp read_commit_privsep(struct got_commit_object **commit, int obj_fd,
746 d5c81d44 2021-07-08 stsp struct got_object_id *id, struct got_repository *repo)
748 ddc7b220 2019-09-08 stsp const struct got_error *err;
749 9f2369b0 2018-12-24 stsp int imsg_fds[2];
751 9f2369b0 2018-12-24 stsp struct imsgbuf *ibuf;
753 9f2369b0 2018-12-24 stsp if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].imsg_fd != -1)
754 d5c81d44 2021-07-08 stsp return request_commit(commit, repo, obj_fd, id);
756 9f2369b0 2018-12-24 stsp ibuf = calloc(1, sizeof(*ibuf));
757 9f2369b0 2018-12-24 stsp if (ibuf == NULL)
758 638f9024 2019-05-13 stsp return got_error_from_errno("calloc");
760 ddc7b220 2019-09-08 stsp if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
761 ddc7b220 2019-09-08 stsp err = got_error_from_errno("socketpair");
762 ddc7b220 2019-09-08 stsp free(ibuf);
763 ddc7b220 2019-09-08 stsp return err;
766 9f2369b0 2018-12-24 stsp pid = fork();
767 ddc7b220 2019-09-08 stsp if (pid == -1) {
768 ddc7b220 2019-09-08 stsp err = got_error_from_errno("fork");
769 ddc7b220 2019-09-08 stsp free(ibuf);
770 ddc7b220 2019-09-08 stsp return err;
772 9f2369b0 2018-12-24 stsp else if (pid == 0) {
773 aba9c984 2019-09-08 stsp got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_COMMIT,
774 9f2369b0 2018-12-24 stsp repo->path);
775 9f2369b0 2018-12-24 stsp /* not reached */
778 08578a35 2021-01-22 stsp if (close(imsg_fds[1]) == -1) {
779 ddc7b220 2019-09-08 stsp err = got_error_from_errno("close");
780 ddc7b220 2019-09-08 stsp free(ibuf);
781 ddc7b220 2019-09-08 stsp return err;
783 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].imsg_fd =
784 9f2369b0 2018-12-24 stsp imsg_fds[0];
785 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].pid = pid;
786 9f2369b0 2018-12-24 stsp imsg_init(ibuf, imsg_fds[0]);
787 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].ibuf = ibuf;
789 d5c81d44 2021-07-08 stsp return request_commit(commit, repo, obj_fd, id);
793 a158c901 2018-12-23 stsp static const struct got_error *
794 434025f3 2018-09-16 stsp open_commit(struct got_commit_object **commit,
795 1785f84a 2018-12-23 stsp struct got_repository *repo, struct got_object_id *id, int check_cache)
797 434025f3 2018-09-16 stsp const struct got_error *err = NULL;
798 1785f84a 2018-12-23 stsp struct got_packidx *packidx = NULL;
800 8d2c5ea3 2019-08-13 stsp char *path_packfile = NULL;
802 434025f3 2018-09-16 stsp if (check_cache) {
803 1785f84a 2018-12-23 stsp *commit = got_repo_get_cached_commit(repo, id);
804 434025f3 2018-09-16 stsp if (*commit != NULL) {
805 434025f3 2018-09-16 stsp (*commit)->refcnt++;
806 434025f3 2018-09-16 stsp return NULL;
809 434025f3 2018-09-16 stsp *commit = NULL;
811 e82b1d81 2019-07-27 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
812 e82b1d81 2019-07-27 stsp if (err == NULL) {
813 1785f84a 2018-12-23 stsp struct got_pack *pack = NULL;
815 aea75d87 2021-07-06 stsp err = got_packidx_get_packfile_path(&path_packfile,
816 aea75d87 2021-07-06 stsp packidx->path_packidx);
818 1785f84a 2018-12-23 stsp return err;
820 1785f84a 2018-12-23 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
821 434025f3 2018-09-16 stsp if (pack == NULL) {
822 1785f84a 2018-12-23 stsp err = got_repo_cache_pack(&pack, repo, path_packfile,
827 a158c901 2018-12-23 stsp err = read_packed_commit_privsep(commit, pack,
828 1785f84a 2018-12-23 stsp packidx, idx, id);
829 e82b1d81 2019-07-27 stsp } else if (err->code == GOT_ERR_NO_OBJ) {
832 762d73f4 2021-04-10 stsp err = got_object_open_loose_fd(&fd, id, repo);
834 e82b1d81 2019-07-27 stsp return err;
835 d5c81d44 2021-07-08 stsp err = read_commit_privsep(commit, fd, id, repo);
838 434025f3 2018-09-16 stsp if (err == NULL) {
839 434025f3 2018-09-16 stsp (*commit)->refcnt++;
840 1785f84a 2018-12-23 stsp err = got_repo_cache_commit(repo, id, *commit);
843 8d2c5ea3 2019-08-13 stsp free(path_packfile);
844 e32baab7 2018-11-05 stsp return err;
847 e32baab7 2018-11-05 stsp const struct got_error *
848 e32baab7 2018-11-05 stsp got_object_open_as_commit(struct got_commit_object **commit,
849 e32baab7 2018-11-05 stsp struct got_repository *repo, struct got_object_id *id)
851 e32baab7 2018-11-05 stsp *commit = got_repo_get_cached_commit(repo, id);
852 e32baab7 2018-11-05 stsp if (*commit != NULL) {
853 e32baab7 2018-11-05 stsp (*commit)->refcnt++;
854 e32baab7 2018-11-05 stsp return NULL;
857 1785f84a 2018-12-23 stsp return open_commit(commit, repo, id, 0);
860 e32baab7 2018-11-05 stsp const struct got_error *
861 e32baab7 2018-11-05 stsp got_object_commit_open(struct got_commit_object **commit,
862 e32baab7 2018-11-05 stsp struct got_repository *repo, struct got_object *obj)
864 1785f84a 2018-12-23 stsp return open_commit(commit, repo, got_object_get_id(obj), 1);
867 434025f3 2018-09-16 stsp const struct got_error *
868 dbc6a6b6 2018-07-12 stsp got_object_qid_alloc(struct got_object_qid **qid, struct got_object_id *id)
870 dbc6a6b6 2018-07-12 stsp *qid = calloc(1, sizeof(**qid));
871 dbc6a6b6 2018-07-12 stsp if (*qid == NULL)
872 638f9024 2019-05-13 stsp return got_error_from_errno("calloc");
874 d7b5a0e8 2022-04-20 stsp memcpy(&(*qid)->id, id, sizeof((*qid)->id));
875 9ca9aafb 2021-06-18 stsp return NULL;
878 9ca9aafb 2021-06-18 stsp const struct got_error *
879 9ca9aafb 2021-06-18 stsp got_object_id_queue_copy(const struct got_object_id_queue *src,
880 9ca9aafb 2021-06-18 stsp struct got_object_id_queue *dest)
882 9ca9aafb 2021-06-18 stsp const struct got_error *err;
883 9ca9aafb 2021-06-18 stsp struct got_object_qid *qid;
885 dbdddfee 2021-06-23 naddy STAILQ_FOREACH(qid, src, entry) {
886 9ca9aafb 2021-06-18 stsp struct got_object_qid *new;
888 9ca9aafb 2021-06-18 stsp * Deep-copy the object ID only. Let the caller deal
889 9ca9aafb 2021-06-18 stsp * with setting up the new->data pointer if needed.
891 d7b5a0e8 2022-04-20 stsp err = got_object_qid_alloc(&new, &qid->id);
893 9ca9aafb 2021-06-18 stsp got_object_id_queue_free(dest);
894 9ca9aafb 2021-06-18 stsp return err;
896 dbdddfee 2021-06-23 naddy STAILQ_INSERT_TAIL(dest, new, entry);
899 dbc6a6b6 2018-07-12 stsp return NULL;
902 a158c901 2018-12-23 stsp static const struct got_error *
903 13c729f7 2018-12-24 stsp request_packed_tree(struct got_tree_object **tree, struct got_pack *pack,
904 13c729f7 2018-12-24 stsp int pack_idx, struct got_object_id *id)
906 a158c901 2018-12-23 stsp const struct got_error *err = NULL;
908 13c729f7 2018-12-24 stsp err = got_privsep_send_tree_req(pack->privsep_child->ibuf, -1, id,
911 a158c901 2018-12-23 stsp return err;
913 a158c901 2018-12-23 stsp return got_privsep_recv_tree(tree, pack->privsep_child->ibuf);
916 71eb0e7f 2018-09-16 stsp static const struct got_error *
917 13c729f7 2018-12-24 stsp read_packed_tree_privsep(struct got_tree_object **tree,
918 13c729f7 2018-12-24 stsp struct got_pack *pack, struct got_packidx *packidx, int idx,
919 13c729f7 2018-12-24 stsp struct got_object_id *id)
921 13c729f7 2018-12-24 stsp const struct got_error *err = NULL;
923 13c729f7 2018-12-24 stsp if (pack->privsep_child)
924 13c729f7 2018-12-24 stsp return request_packed_tree(tree, pack, idx, id);
926 3d589bee 2022-06-25 stsp err = got_pack_start_privsep_child(pack, packidx);
928 13c729f7 2018-12-24 stsp return err;
930 13c729f7 2018-12-24 stsp return request_packed_tree(tree, pack, idx, id);
933 13c729f7 2018-12-24 stsp static const struct got_error *
934 9f2369b0 2018-12-24 stsp request_tree(struct got_tree_object **tree, struct got_repository *repo,
935 d5c81d44 2021-07-08 stsp int fd, struct got_object_id *id)
937 9f2369b0 2018-12-24 stsp const struct got_error *err = NULL;
938 9f2369b0 2018-12-24 stsp struct imsgbuf *ibuf;
940 9f2369b0 2018-12-24 stsp ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].ibuf;
942 d5c81d44 2021-07-08 stsp err = got_privsep_send_tree_req(ibuf, fd, id, -1);
944 9f2369b0 2018-12-24 stsp return err;
946 9f2369b0 2018-12-24 stsp return got_privsep_recv_tree(tree, ibuf);
949 336075a4 2022-06-25 op static const struct got_error *
950 9f2369b0 2018-12-24 stsp read_tree_privsep(struct got_tree_object **tree, int obj_fd,
951 d5c81d44 2021-07-08 stsp struct got_object_id *id, struct got_repository *repo)
953 ddc7b220 2019-09-08 stsp const struct got_error *err;
954 9f2369b0 2018-12-24 stsp int imsg_fds[2];
956 9f2369b0 2018-12-24 stsp struct imsgbuf *ibuf;
958 9f2369b0 2018-12-24 stsp if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].imsg_fd != -1)
959 d5c81d44 2021-07-08 stsp return request_tree(tree, repo, obj_fd, id);
961 9f2369b0 2018-12-24 stsp ibuf = calloc(1, sizeof(*ibuf));
962 9f2369b0 2018-12-24 stsp if (ibuf == NULL)
963 638f9024 2019-05-13 stsp return got_error_from_errno("calloc");
965 ddc7b220 2019-09-08 stsp if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
966 ddc7b220 2019-09-08 stsp err = got_error_from_errno("socketpair");
967 ddc7b220 2019-09-08 stsp free(ibuf);
968 ddc7b220 2019-09-08 stsp return err;
971 9f2369b0 2018-12-24 stsp pid = fork();
972 ddc7b220 2019-09-08 stsp if (pid == -1) {
973 ddc7b220 2019-09-08 stsp err = got_error_from_errno("fork");
974 ddc7b220 2019-09-08 stsp free(ibuf);
975 ddc7b220 2019-09-08 stsp return err;
977 9f2369b0 2018-12-24 stsp else if (pid == 0) {
978 aba9c984 2019-09-08 stsp got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_TREE,
979 9f2369b0 2018-12-24 stsp repo->path);
980 9f2369b0 2018-12-24 stsp /* not reached */
983 08578a35 2021-01-22 stsp if (close(imsg_fds[1]) == -1) {
984 ddc7b220 2019-09-08 stsp err = got_error_from_errno("close");
985 ddc7b220 2019-09-08 stsp free(ibuf);
986 ddc7b220 2019-09-08 stsp return err;
988 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].imsg_fd =
989 9f2369b0 2018-12-24 stsp imsg_fds[0];
990 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].pid = pid;
991 9f2369b0 2018-12-24 stsp imsg_init(ibuf, imsg_fds[0]);
992 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].ibuf = ibuf;
995 d5c81d44 2021-07-08 stsp return request_tree(tree, repo, obj_fd, id);
998 9f2369b0 2018-12-24 stsp static const struct got_error *
999 13c729f7 2018-12-24 stsp open_tree(struct got_tree_object **tree, struct got_repository *repo,
1000 13c729f7 2018-12-24 stsp struct got_object_id *id, int check_cache)
1002 0ffeb3c2 2017-11-26 stsp const struct got_error *err = NULL;
1003 13c729f7 2018-12-24 stsp struct got_packidx *packidx = NULL;
1005 8d2c5ea3 2019-08-13 stsp char *path_packfile = NULL;
1007 71eb0e7f 2018-09-16 stsp if (check_cache) {
1008 13c729f7 2018-12-24 stsp *tree = got_repo_get_cached_tree(repo, id);
1009 71eb0e7f 2018-09-16 stsp if (*tree != NULL) {
1010 71eb0e7f 2018-09-16 stsp (*tree)->refcnt++;
1011 71eb0e7f 2018-09-16 stsp return NULL;
1014 71eb0e7f 2018-09-16 stsp *tree = NULL;
1016 e82b1d81 2019-07-27 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
1017 e82b1d81 2019-07-27 stsp if (err == NULL) {
1018 13c729f7 2018-12-24 stsp struct got_pack *pack = NULL;
1020 aea75d87 2021-07-06 stsp err = got_packidx_get_packfile_path(&path_packfile,
1021 aea75d87 2021-07-06 stsp packidx->path_packidx);
1023 13c729f7 2018-12-24 stsp return err;
1025 13c729f7 2018-12-24 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
1026 e7885405 2018-09-10 stsp if (pack == NULL) {
1027 e82b1d81 2019-07-27 stsp err = got_repo_cache_pack(&pack, repo, path_packfile,
1030 8d2c5ea3 2019-08-13 stsp goto done;
1032 13c729f7 2018-12-24 stsp err = read_packed_tree_privsep(tree, pack,
1033 13c729f7 2018-12-24 stsp packidx, idx, id);
1034 e82b1d81 2019-07-27 stsp } else if (err->code == GOT_ERR_NO_OBJ) {
1037 762d73f4 2021-04-10 stsp err = got_object_open_loose_fd(&fd, id, repo);
1039 e82b1d81 2019-07-27 stsp return err;
1040 d5c81d44 2021-07-08 stsp err = read_tree_privsep(tree, fd, id, repo);
1043 f6be5c30 2018-06-22 stsp if (err == NULL) {
1044 f6be5c30 2018-06-22 stsp (*tree)->refcnt++;
1045 13c729f7 2018-12-24 stsp err = got_repo_cache_tree(repo, id, *tree);
1048 8d2c5ea3 2019-08-13 stsp free(path_packfile);
1049 776d4d29 2018-06-17 stsp return err;
1052 776d4d29 2018-06-17 stsp const struct got_error *
1053 776d4d29 2018-06-17 stsp got_object_open_as_tree(struct got_tree_object **tree,
1054 776d4d29 2018-06-17 stsp struct got_repository *repo, struct got_object_id *id)
1056 e8eb494a 2018-09-16 stsp *tree = got_repo_get_cached_tree(repo, id);
1057 e8eb494a 2018-09-16 stsp if (*tree != NULL) {
1058 e8eb494a 2018-09-16 stsp (*tree)->refcnt++;
1059 e8eb494a 2018-09-16 stsp return NULL;
1062 13c729f7 2018-12-24 stsp return open_tree(tree, repo, id, 0);
1065 71eb0e7f 2018-09-16 stsp const struct got_error *
1066 71eb0e7f 2018-09-16 stsp got_object_tree_open(struct got_tree_object **tree,
1067 71eb0e7f 2018-09-16 stsp struct got_repository *repo, struct got_object *obj)
1069 13c729f7 2018-12-24 stsp return open_tree(tree, repo, got_object_get_id(obj), 1);
1073 56e0773d 2019-11-28 stsp got_object_tree_get_nentries(struct got_tree_object *tree)
1075 56e0773d 2019-11-28 stsp return tree->nentries;
1078 56e0773d 2019-11-28 stsp struct got_tree_entry *
1079 56e0773d 2019-11-28 stsp got_object_tree_get_first_entry(struct got_tree_object *tree)
1081 56e0773d 2019-11-28 stsp return got_object_tree_get_entry(tree, 0);
1084 56e0773d 2019-11-28 stsp struct got_tree_entry *
1085 56e0773d 2019-11-28 stsp got_object_tree_get_last_entry(struct got_tree_object *tree)
1087 56e0773d 2019-11-28 stsp return got_object_tree_get_entry(tree, tree->nentries - 1);
1090 56e0773d 2019-11-28 stsp struct got_tree_entry *
1091 56e0773d 2019-11-28 stsp got_object_tree_get_entry(struct got_tree_object *tree, int i)
1093 56e0773d 2019-11-28 stsp if (i < 0 || i >= tree->nentries)
1094 56e0773d 2019-11-28 stsp return NULL;
1095 56e0773d 2019-11-28 stsp return &tree->entries[i];
1099 56e0773d 2019-11-28 stsp got_tree_entry_get_mode(struct got_tree_entry *te)
1101 56e0773d 2019-11-28 stsp return te->mode;
1104 56e0773d 2019-11-28 stsp const char *
1105 56e0773d 2019-11-28 stsp got_tree_entry_get_name(struct got_tree_entry *te)
1107 56e0773d 2019-11-28 stsp return &te->name[0];
1110 56e0773d 2019-11-28 stsp struct got_object_id *
1111 56e0773d 2019-11-28 stsp got_tree_entry_get_id(struct got_tree_entry *te)
1113 56e0773d 2019-11-28 stsp return &te->id;
1116 0d6c6ee3 2020-05-20 stsp const struct got_error *
1117 af57b12a 2020-07-23 stsp got_object_blob_read_to_str(char **s, struct got_blob_object *blob)
1119 0d6c6ee3 2020-05-20 stsp const struct got_error *err = NULL;
1120 32596e16 2020-07-23 stsp size_t len, totlen, hdrlen, offset;
1122 aa092692 2020-07-23 stsp *s = NULL;
1124 659dc16e 2020-07-23 stsp hdrlen = got_object_blob_get_hdrlen(blob);
1125 659dc16e 2020-07-23 stsp totlen = 0;
1126 32596e16 2020-07-23 stsp offset = 0;
1130 659dc16e 2020-07-23 stsp err = got_object_blob_read_block(&len, blob);
1132 af57b12a 2020-07-23 stsp return err;
1134 659dc16e 2020-07-23 stsp if (len == 0)
1137 659dc16e 2020-07-23 stsp totlen += len - hdrlen;
1138 af57b12a 2020-07-23 stsp p = realloc(*s, totlen + 1);
1139 659dc16e 2020-07-23 stsp if (p == NULL) {
1140 659dc16e 2020-07-23 stsp err = got_error_from_errno("realloc");
1142 af57b12a 2020-07-23 stsp *s = NULL;
1143 af57b12a 2020-07-23 stsp return err;
1146 659dc16e 2020-07-23 stsp /* Skip blob object header first time around. */
1147 af57b12a 2020-07-23 stsp memcpy(*s + offset,
1148 f8f7c882 2020-07-23 stsp got_object_blob_get_read_buf(blob) + hdrlen, len - hdrlen);
1149 659dc16e 2020-07-23 stsp hdrlen = 0;
1150 32596e16 2020-07-23 stsp offset = totlen;
1151 659dc16e 2020-07-23 stsp } while (len > 0);
1153 af57b12a 2020-07-23 stsp (*s)[totlen] = '\0';
1154 af57b12a 2020-07-23 stsp return NULL;
1157 af57b12a 2020-07-23 stsp const struct got_error *
1158 af57b12a 2020-07-23 stsp got_tree_entry_get_symlink_target(char **link_target, struct got_tree_entry *te,
1159 af57b12a 2020-07-23 stsp struct got_repository *repo)
1161 af57b12a 2020-07-23 stsp const struct got_error *err = NULL;
1162 af57b12a 2020-07-23 stsp struct got_blob_object *blob = NULL;
1163 eb81bc23 2022-06-28 tracey int fd = -1;
1165 af57b12a 2020-07-23 stsp *link_target = NULL;
1167 af57b12a 2020-07-23 stsp if (!got_object_tree_entry_is_symlink(te))
1168 af57b12a 2020-07-23 stsp return got_error(GOT_ERR_TREE_ENTRY_TYPE);
1170 eb81bc23 2022-06-28 tracey fd = got_opentempfd();
1171 eb81bc23 2022-06-28 tracey if (fd == -1) {
1172 eb81bc23 2022-06-28 tracey err = got_error_from_errno("got_opentempfd");
1173 eb81bc23 2022-06-28 tracey goto done;
1176 eb81bc23 2022-06-28 tracey err = got_object_open_as_blob(&blob, repo,
1177 eb81bc23 2022-06-28 tracey got_tree_entry_get_id(te), PATH_MAX, fd);
1179 eb81bc23 2022-06-28 tracey goto done;
1181 af57b12a 2020-07-23 stsp err = got_object_blob_read_to_str(link_target, blob);
1183 eb81bc23 2022-06-28 tracey if (fd != -1 && close(fd) == -1 && err == NULL)
1184 eb81bc23 2022-06-28 tracey err = got_error_from_errno("close");
1185 eb81bc23 2022-06-28 tracey if (blob)
1186 eb81bc23 2022-06-28 tracey got_object_blob_close(blob);
1187 659dc16e 2020-07-23 stsp if (err) {
1188 659dc16e 2020-07-23 stsp free(*link_target);
1189 659dc16e 2020-07-23 stsp *link_target = NULL;
1191 0d6c6ee3 2020-05-20 stsp return err;
1195 56e0773d 2019-11-28 stsp got_tree_entry_get_index(struct got_tree_entry *te)
1197 56e0773d 2019-11-28 stsp return te->idx;
1200 56e0773d 2019-11-28 stsp struct got_tree_entry *
1201 56e0773d 2019-11-28 stsp got_tree_entry_get_next(struct got_tree_object *tree,
1202 56e0773d 2019-11-28 stsp struct got_tree_entry *te)
1204 56e0773d 2019-11-28 stsp return got_object_tree_get_entry(tree, te->idx + 1);
1207 56e0773d 2019-11-28 stsp struct got_tree_entry *
1208 56e0773d 2019-11-28 stsp got_tree_entry_get_prev(struct got_tree_object *tree,
1209 56e0773d 2019-11-28 stsp struct got_tree_entry *te)
1211 56e0773d 2019-11-28 stsp return got_object_tree_get_entry(tree, te->idx - 1);
1214 3840f4c9 2018-09-12 stsp static const struct got_error *
1215 ac544f8c 2019-01-13 stsp request_packed_blob(uint8_t **outbuf, size_t *size, size_t *hdrlen, int outfd,
1216 ebc55e2d 2018-12-24 stsp struct got_pack *pack, struct got_packidx *packidx, int idx,
1217 ebc55e2d 2018-12-24 stsp struct got_object_id *id)
1219 3840f4c9 2018-09-12 stsp const struct got_error *err = NULL;
1220 db696021 2022-01-04 stsp struct imsgbuf *ibuf = pack->privsep_child->ibuf;
1221 db696021 2022-01-04 stsp int outfd_child;
1223 db696021 2022-01-04 stsp err = pack_child_send_tempfiles(ibuf, pack);
1225 db696021 2022-01-04 stsp return err;
1227 3840f4c9 2018-09-12 stsp outfd_child = dup(outfd);
1228 3840f4c9 2018-09-12 stsp if (outfd_child == -1)
1229 638f9024 2019-05-13 stsp return got_error_from_errno("dup");
1231 ebc55e2d 2018-12-24 stsp err = got_privsep_send_blob_req(pack->privsep_child->ibuf, -1, id, idx);
1233 3840f4c9 2018-09-12 stsp return err;
1235 3840f4c9 2018-09-12 stsp err = got_privsep_send_blob_outfd(pack->privsep_child->ibuf,
1236 3840f4c9 2018-09-12 stsp outfd_child);
1237 3840f4c9 2018-09-12 stsp if (err) {
1238 3840f4c9 2018-09-12 stsp return err;
1241 ac544f8c 2019-01-13 stsp err = got_privsep_recv_blob(outbuf, size, hdrlen,
1242 ebc55e2d 2018-12-24 stsp pack->privsep_child->ibuf);
1244 3840f4c9 2018-09-12 stsp return err;
1246 3840f4c9 2018-09-12 stsp if (lseek(outfd, SEEK_SET, 0) == -1)
1247 638f9024 2019-05-13 stsp err = got_error_from_errno("lseek");
1249 3840f4c9 2018-09-12 stsp return err;
1252 ebc55e2d 2018-12-24 stsp static const struct got_error *
1253 ac544f8c 2019-01-13 stsp read_packed_blob_privsep(uint8_t **outbuf, size_t *size, size_t *hdrlen,
1254 ac544f8c 2019-01-13 stsp int outfd, struct got_pack *pack, struct got_packidx *packidx, int idx,
1255 ebc55e2d 2018-12-24 stsp struct got_object_id *id)
1257 68482ea3 2017-11-27 stsp const struct got_error *err = NULL;
1259 ebc55e2d 2018-12-24 stsp if (pack->privsep_child == NULL) {
1260 3d589bee 2022-06-25 stsp err = got_pack_start_privsep_child(pack, packidx);
1262 ebc55e2d 2018-12-24 stsp return err;
1265 ac544f8c 2019-01-13 stsp return request_packed_blob(outbuf, size, hdrlen, outfd, pack, packidx,
1269 9f2369b0 2018-12-24 stsp static const struct got_error *
1270 ac544f8c 2019-01-13 stsp request_blob(uint8_t **outbuf, size_t *size, size_t *hdrlen, int outfd,
1271 d5c81d44 2021-07-08 stsp int infd, struct got_object_id *id, struct imsgbuf *ibuf)
1273 9f2369b0 2018-12-24 stsp const struct got_error *err = NULL;
1274 9f2369b0 2018-12-24 stsp int outfd_child;
1276 9f2369b0 2018-12-24 stsp outfd_child = dup(outfd);
1277 9f2369b0 2018-12-24 stsp if (outfd_child == -1)
1278 638f9024 2019-05-13 stsp return got_error_from_errno("dup");
1280 d5c81d44 2021-07-08 stsp err = got_privsep_send_blob_req(ibuf, infd, id, -1);
1282 9f2369b0 2018-12-24 stsp return err;
1284 9f2369b0 2018-12-24 stsp err = got_privsep_send_blob_outfd(ibuf, outfd_child);
1286 9f2369b0 2018-12-24 stsp return err;
1288 ac544f8c 2019-01-13 stsp err = got_privsep_recv_blob(outbuf, size, hdrlen, ibuf);
1290 9f2369b0 2018-12-24 stsp return err;
1292 9f2369b0 2018-12-24 stsp if (lseek(outfd, SEEK_SET, 0) == -1)
1293 638f9024 2019-05-13 stsp return got_error_from_errno("lseek");
1295 9f2369b0 2018-12-24 stsp return err;
1298 9f2369b0 2018-12-24 stsp static const struct got_error *
1299 ac544f8c 2019-01-13 stsp read_blob_privsep(uint8_t **outbuf, size_t *size, size_t *hdrlen,
1300 d5c81d44 2021-07-08 stsp int outfd, int infd, struct got_object_id *id, struct got_repository *repo)
1302 ddc7b220 2019-09-08 stsp const struct got_error *err;
1303 9f2369b0 2018-12-24 stsp int imsg_fds[2];
1304 9f2369b0 2018-12-24 stsp pid_t pid;
1305 9f2369b0 2018-12-24 stsp struct imsgbuf *ibuf;
1307 9f2369b0 2018-12-24 stsp if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].imsg_fd != -1) {
1308 9f2369b0 2018-12-24 stsp ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].ibuf;
1309 d5c81d44 2021-07-08 stsp return request_blob(outbuf, size, hdrlen, outfd, infd, id,
1313 9f2369b0 2018-12-24 stsp ibuf = calloc(1, sizeof(*ibuf));
1314 9f2369b0 2018-12-24 stsp if (ibuf == NULL)
1315 638f9024 2019-05-13 stsp return got_error_from_errno("calloc");
1317 ddc7b220 2019-09-08 stsp if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
1318 ddc7b220 2019-09-08 stsp err = got_error_from_errno("socketpair");
1319 ddc7b220 2019-09-08 stsp free(ibuf);
1320 ddc7b220 2019-09-08 stsp return err;
1323 9f2369b0 2018-12-24 stsp pid = fork();
1324 ddc7b220 2019-09-08 stsp if (pid == -1) {
1325 ddc7b220 2019-09-08 stsp err = got_error_from_errno("fork");
1326 ddc7b220 2019-09-08 stsp free(ibuf);
1327 ddc7b220 2019-09-08 stsp return err;
1329 9f2369b0 2018-12-24 stsp else if (pid == 0) {
1330 aba9c984 2019-09-08 stsp got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_BLOB,
1331 9f2369b0 2018-12-24 stsp repo->path);
1332 9f2369b0 2018-12-24 stsp /* not reached */
1335 08578a35 2021-01-22 stsp if (close(imsg_fds[1]) == -1) {
1336 ddc7b220 2019-09-08 stsp err = got_error_from_errno("close");
1337 ddc7b220 2019-09-08 stsp free(ibuf);
1338 ddc7b220 2019-09-08 stsp return err;
1340 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].imsg_fd =
1341 9f2369b0 2018-12-24 stsp imsg_fds[0];
1342 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].pid = pid;
1343 9f2369b0 2018-12-24 stsp imsg_init(ibuf, imsg_fds[0]);
1344 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_BLOB].ibuf = ibuf;
1346 d5c81d44 2021-07-08 stsp return request_blob(outbuf, size, hdrlen, outfd, infd, id, ibuf);
1349 ebc55e2d 2018-12-24 stsp static const struct got_error *
1350 ebc55e2d 2018-12-24 stsp open_blob(struct got_blob_object **blob, struct got_repository *repo,
1351 eb81bc23 2022-06-28 tracey struct got_object_id *id, size_t blocksize, int outfd)
1353 ebc55e2d 2018-12-24 stsp const struct got_error *err = NULL;
1354 ebc55e2d 2018-12-24 stsp struct got_packidx *packidx = NULL;
1355 ce7556f2 2022-06-28 tracey int idx, dfd = -1;
1356 8d2c5ea3 2019-08-13 stsp char *path_packfile = NULL;
1357 ac544f8c 2019-01-13 stsp uint8_t *outbuf;
1358 ebc55e2d 2018-12-24 stsp size_t size, hdrlen;
1359 ebc55e2d 2018-12-24 stsp struct stat sb;
1361 68482ea3 2017-11-27 stsp *blob = calloc(1, sizeof(**blob));
1362 4558fcd4 2018-01-14 stsp if (*blob == NULL)
1363 638f9024 2019-05-13 stsp return got_error_from_errno("calloc");
1365 062ebb78 2018-07-12 stsp (*blob)->read_buf = malloc(blocksize);
1366 15c8b0e6 2018-04-24 stsp if ((*blob)->read_buf == NULL) {
1367 638f9024 2019-05-13 stsp err = got_error_from_errno("malloc");
1368 c7254d79 2018-04-24 stsp goto done;
1371 f9d37699 2022-06-28 stsp if (ftruncate(outfd, 0L) == -1) {
1372 f9d37699 2022-06-28 stsp err = got_error_from_errno("ftruncate");
1373 f9d37699 2022-06-28 stsp goto done;
1375 f9d37699 2022-06-28 stsp if (lseek(outfd, SEEK_SET, 0) == -1) {
1376 f9d37699 2022-06-28 stsp err = got_error_from_errno("lseek");
1377 f9d37699 2022-06-28 stsp goto done;
1380 e82b1d81 2019-07-27 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
1381 e82b1d81 2019-07-27 stsp if (err == NULL) {
1382 ebc55e2d 2018-12-24 stsp struct got_pack *pack = NULL;
1384 aea75d87 2021-07-06 stsp err = got_packidx_get_packfile_path(&path_packfile,
1385 aea75d87 2021-07-06 stsp packidx->path_packidx);
1387 ebc55e2d 2018-12-24 stsp goto done;
1389 ebc55e2d 2018-12-24 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
1390 55da3778 2018-09-10 stsp if (pack == NULL) {
1391 ebc55e2d 2018-12-24 stsp err = got_repo_cache_pack(&pack, repo, path_packfile,
1394 55da3778 2018-09-10 stsp goto done;
1396 ac544f8c 2019-01-13 stsp err = read_packed_blob_privsep(&outbuf, &size, &hdrlen, outfd,
1397 ac544f8c 2019-01-13 stsp pack, packidx, idx, id);
1398 e82b1d81 2019-07-27 stsp } else if (err->code == GOT_ERR_NO_OBJ) {
1401 762d73f4 2021-04-10 stsp err = got_object_open_loose_fd(&infd, id, repo);
1403 e82b1d81 2019-07-27 stsp goto done;
1404 ac544f8c 2019-01-13 stsp err = read_blob_privsep(&outbuf, &size, &hdrlen, outfd, infd,
1405 d5c81d44 2021-07-08 stsp id, repo);
1408 55da3778 2018-09-10 stsp goto done;
1410 de060dff 2018-12-24 stsp if (hdrlen > size) {
1411 ebc55e2d 2018-12-24 stsp err = got_error(GOT_ERR_BAD_OBJ_HDR);
1412 ebc55e2d 2018-12-24 stsp goto done;
1415 ac544f8c 2019-01-13 stsp if (outbuf) {
1416 ac544f8c 2019-01-13 stsp (*blob)->f = fmemopen(outbuf, size, "rb");
1417 ac544f8c 2019-01-13 stsp if ((*blob)->f == NULL) {
1418 638f9024 2019-05-13 stsp err = got_error_from_errno("fmemopen");
1419 ac544f8c 2019-01-13 stsp free(outbuf);
1420 ac544f8c 2019-01-13 stsp goto done;
1422 ac544f8c 2019-01-13 stsp (*blob)->data = outbuf;
1424 ac544f8c 2019-01-13 stsp if (fstat(outfd, &sb) == -1) {
1425 638f9024 2019-05-13 stsp err = got_error_from_errno("fstat");
1426 ac544f8c 2019-01-13 stsp goto done;
1429 ac544f8c 2019-01-13 stsp if (sb.st_size != size) {
1430 ac544f8c 2019-01-13 stsp err = got_error(GOT_ERR_PRIVSEP_LEN);
1431 ce7556f2 2022-06-28 tracey goto done;
1434 ce7556f2 2022-06-28 tracey dfd = dup(outfd);
1435 ce7556f2 2022-06-28 tracey if (dfd == -1) {
1436 ce7556f2 2022-06-28 tracey err = got_error_from_errno("dup");
1437 ac544f8c 2019-01-13 stsp goto done;
1440 7a13e6e5 2022-06-28 stsp (*blob)->f = fdopen(dfd, "rb");
1441 ac544f8c 2019-01-13 stsp if ((*blob)->f == NULL) {
1442 638f9024 2019-05-13 stsp err = got_error_from_errno("fdopen");
1443 ce7556f2 2022-06-28 tracey close(dfd);
1444 ce7556f2 2022-06-28 tracey dfd = -1;
1445 ac544f8c 2019-01-13 stsp goto done;
1449 ebc55e2d 2018-12-24 stsp (*blob)->hdrlen = hdrlen;
1450 eb651edf 2018-02-11 stsp (*blob)->blocksize = blocksize;
1451 ebc55e2d 2018-12-24 stsp memcpy(&(*blob)->id.sha1, id->sha1, SHA1_DIGEST_LENGTH);
1454 8d2c5ea3 2019-08-13 stsp free(path_packfile);
1455 55da3778 2018-09-10 stsp if (err) {
1456 55da3778 2018-09-10 stsp if (*blob) {
1457 7baf5860 2019-03-19 stsp got_object_blob_close(*blob);
1458 55da3778 2018-09-10 stsp *blob = NULL;
1461 a19581a2 2018-06-21 stsp return err;
1464 a19581a2 2018-06-21 stsp const struct got_error *
1465 a19581a2 2018-06-21 stsp got_object_open_as_blob(struct got_blob_object **blob,
1466 eb81bc23 2022-06-28 tracey struct got_repository *repo, struct got_object_id *id, size_t blocksize,
1467 eb81bc23 2022-06-28 tracey int outfd)
1469 eb81bc23 2022-06-28 tracey return open_blob(blob, repo, id, blocksize, outfd);
1472 ebc55e2d 2018-12-24 stsp const struct got_error *
1473 ebc55e2d 2018-12-24 stsp got_object_blob_open(struct got_blob_object **blob,
1474 eb81bc23 2022-06-28 tracey struct got_repository *repo, struct got_object *obj, size_t blocksize,
1475 eb81bc23 2022-06-28 tracey int outfd)
1477 eb81bc23 2022-06-28 tracey return open_blob(blob, repo, got_object_get_id(obj), blocksize, outfd);
1480 fb43ecf1 2019-02-11 stsp const struct got_error *
1481 68482ea3 2017-11-27 stsp got_object_blob_close(struct got_blob_object *blob)
1483 fb43ecf1 2019-02-11 stsp const struct got_error *err = NULL;
1484 15c8b0e6 2018-04-24 stsp free(blob->read_buf);
1485 56b63ca4 2021-01-22 stsp if (blob->f && fclose(blob->f) == EOF)
1486 638f9024 2019-05-13 stsp err = got_error_from_errno("fclose");
1487 ac544f8c 2019-01-13 stsp free(blob->data);
1488 68482ea3 2017-11-27 stsp free(blob);
1489 fb43ecf1 2019-02-11 stsp return err;
1493 8ba819a3 2020-07-23 stsp got_object_blob_rewind(struct got_blob_object *blob)
1495 8ba819a3 2020-07-23 stsp if (blob->f)
1496 8ba819a3 2020-07-23 stsp rewind(blob->f);
1500 f934cf2c 2018-02-12 stsp got_object_blob_id_str(struct got_blob_object *blob, char *buf, size_t size)
1502 f934cf2c 2018-02-12 stsp return got_sha1_digest_to_str(blob->id.sha1, buf, size);
1506 f934cf2c 2018-02-12 stsp got_object_blob_get_hdrlen(struct got_blob_object *blob)
1508 f934cf2c 2018-02-12 stsp return blob->hdrlen;
1511 f934cf2c 2018-02-12 stsp const uint8_t *
1512 f934cf2c 2018-02-12 stsp got_object_blob_get_read_buf(struct got_blob_object *blob)
1514 f934cf2c 2018-02-12 stsp return blob->read_buf;
1517 68482ea3 2017-11-27 stsp const struct got_error *
1518 eb651edf 2018-02-11 stsp got_object_blob_read_block(size_t *outlenp, struct got_blob_object *blob)
1522 eb651edf 2018-02-11 stsp n = fread(blob->read_buf, 1, blob->blocksize, blob->f);
1523 eb651edf 2018-02-11 stsp if (n == 0 && ferror(blob->f))
1524 eb651edf 2018-02-11 stsp return got_ferror(blob->f, GOT_ERR_IO);
1525 eb651edf 2018-02-11 stsp *outlenp = n;
1526 35e9ba5d 2018-06-21 stsp return NULL;
1529 35e9ba5d 2018-06-21 stsp const struct got_error *
1530 be659d10 2020-11-18 stsp got_object_blob_dump_to_file(off_t *filesize, int *nlines,
1531 6c4c42e0 2019-06-24 stsp off_t **line_offsets, FILE *outfile, struct got_blob_object *blob)
1533 35e9ba5d 2018-06-21 stsp const struct got_error *err = NULL;
1534 b6752625 2018-12-24 stsp size_t n, len, hdrlen;
1535 84451b3e 2018-07-10 stsp const uint8_t *buf;
1537 c33ebc60 2020-11-18 stsp const int alloc_chunksz = 512;
1538 c33ebc60 2020-11-18 stsp size_t nalloc = 0;
1539 f595d9bd 2019-08-14 stsp off_t off = 0, total_len = 0;
1541 6c4c42e0 2019-06-24 stsp if (line_offsets)
1542 6c4c42e0 2019-06-24 stsp *line_offsets = NULL;
1543 f595d9bd 2019-08-14 stsp if (filesize)
1544 f595d9bd 2019-08-14 stsp *filesize = 0;
1545 84451b3e 2018-07-10 stsp if (nlines)
1546 84451b3e 2018-07-10 stsp *nlines = 0;
1548 35e9ba5d 2018-06-21 stsp hdrlen = got_object_blob_get_hdrlen(blob);
1550 35e9ba5d 2018-06-21 stsp err = got_object_blob_read_block(&len, blob);
1552 35e9ba5d 2018-06-21 stsp return err;
1553 35e9ba5d 2018-06-21 stsp if (len == 0)
1555 84451b3e 2018-07-10 stsp buf = got_object_blob_get_read_buf(blob);
1556 b02560ec 2019-08-19 stsp i = hdrlen;
1557 f1cbc3bc 2020-11-18 stsp if (nlines) {
1558 f1cbc3bc 2020-11-18 stsp if (line_offsets && *line_offsets == NULL) {
1559 78695fb7 2019-08-12 stsp /* Have some data but perhaps no '\n'. */
1560 78695fb7 2019-08-12 stsp *nlines = 1;
1561 c33ebc60 2020-11-18 stsp nalloc = alloc_chunksz;
1562 c33ebc60 2020-11-18 stsp *line_offsets = calloc(nalloc,
1563 c33ebc60 2020-11-18 stsp sizeof(**line_offsets));
1564 78695fb7 2019-08-12 stsp if (*line_offsets == NULL)
1565 845785d4 2020-02-02 tracey return got_error_from_errno("calloc");
1567 b02560ec 2019-08-19 stsp /* Skip forward over end of first line. */
1568 b02560ec 2019-08-19 stsp while (i < len) {
1569 b02560ec 2019-08-19 stsp if (buf[i] == '\n')
1574 b02560ec 2019-08-19 stsp /* Scan '\n' offsets in remaining chunk of data. */
1575 b02560ec 2019-08-19 stsp while (i < len) {
1576 b02560ec 2019-08-19 stsp if (buf[i] != '\n') {
1580 f595d9bd 2019-08-14 stsp (*nlines)++;
1581 c33ebc60 2020-11-18 stsp if (line_offsets && nalloc < *nlines) {
1582 c33ebc60 2020-11-18 stsp size_t n = *nlines + alloc_chunksz;
1583 78695fb7 2019-08-12 stsp off_t *o = recallocarray(*line_offsets,
1584 c33ebc60 2020-11-18 stsp nalloc, n, sizeof(**line_offsets));
1585 78695fb7 2019-08-12 stsp if (o == NULL) {
1586 78695fb7 2019-08-12 stsp free(*line_offsets);
1587 78695fb7 2019-08-12 stsp *line_offsets = NULL;
1588 78695fb7 2019-08-12 stsp return got_error_from_errno(
1589 78695fb7 2019-08-12 stsp "recallocarray");
1591 78695fb7 2019-08-12 stsp *line_offsets = o;
1592 c33ebc60 2020-11-18 stsp nalloc = n;
1594 f1cbc3bc 2020-11-18 stsp if (line_offsets) {
1595 f1cbc3bc 2020-11-18 stsp off = total_len + i - hdrlen + 1;
1596 f1cbc3bc 2020-11-18 stsp (*line_offsets)[*nlines - 1] = off;
1601 35e9ba5d 2018-06-21 stsp /* Skip blob object header first time around. */
1602 454a6b59 2018-12-24 stsp n = fwrite(buf + hdrlen, 1, len - hdrlen, outfile);
1603 b6752625 2018-12-24 stsp if (n != len - hdrlen)
1604 b6752625 2018-12-24 stsp return got_ferror(outfile, GOT_ERR_IO);
1605 f595d9bd 2019-08-14 stsp total_len += len - hdrlen;
1606 35e9ba5d 2018-06-21 stsp hdrlen = 0;
1607 35e9ba5d 2018-06-21 stsp } while (len != 0);
1609 cbe7f848 2019-02-11 stsp if (fflush(outfile) != 0)
1610 638f9024 2019-05-13 stsp return got_error_from_errno("fflush");
1611 35e9ba5d 2018-06-21 stsp rewind(outfile);
1613 f595d9bd 2019-08-14 stsp if (filesize)
1614 f595d9bd 2019-08-14 stsp *filesize = total_len;
1616 776d4d29 2018-06-17 stsp return NULL;
1619 f4a881ce 2018-11-17 stsp static const struct got_error *
1620 268f7291 2018-12-24 stsp request_packed_tag(struct got_tag_object **tag, struct got_pack *pack,
1621 268f7291 2018-12-24 stsp int pack_idx, struct got_object_id *id)
1623 a158c901 2018-12-23 stsp const struct got_error *err = NULL;
1625 268f7291 2018-12-24 stsp err = got_privsep_send_tag_req(pack->privsep_child->ibuf, -1, id,
1626 268f7291 2018-12-24 stsp pack_idx);
1628 a158c901 2018-12-23 stsp return err;
1630 a158c901 2018-12-23 stsp return got_privsep_recv_tag(tag, pack->privsep_child->ibuf);
1633 268f7291 2018-12-24 stsp static const struct got_error *
1634 268f7291 2018-12-24 stsp read_packed_tag_privsep(struct got_tag_object **tag,
1635 268f7291 2018-12-24 stsp struct got_pack *pack, struct got_packidx *packidx, int idx,
1636 268f7291 2018-12-24 stsp struct got_object_id *id)
1638 268f7291 2018-12-24 stsp const struct got_error *err = NULL;
1640 268f7291 2018-12-24 stsp if (pack->privsep_child)
1641 268f7291 2018-12-24 stsp return request_packed_tag(tag, pack, idx, id);
1643 3d589bee 2022-06-25 stsp err = got_pack_start_privsep_child(pack, packidx);
1645 268f7291 2018-12-24 stsp return err;
1647 268f7291 2018-12-24 stsp return request_packed_tag(tag, pack, idx, id);
1650 9f2369b0 2018-12-24 stsp static const struct got_error *
1651 9f2369b0 2018-12-24 stsp request_tag(struct got_tag_object **tag, struct got_repository *repo,
1652 d5c81d44 2021-07-08 stsp int fd, struct got_object_id *id)
1654 9f2369b0 2018-12-24 stsp const struct got_error *err = NULL;
1655 9f2369b0 2018-12-24 stsp struct imsgbuf *ibuf;
1657 9f2369b0 2018-12-24 stsp ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].ibuf;
1659 d5c81d44 2021-07-08 stsp err = got_privsep_send_tag_req(ibuf, fd, id, -1);
1661 9f2369b0 2018-12-24 stsp return err;
1663 9f2369b0 2018-12-24 stsp return got_privsep_recv_tag(tag, ibuf);
1666 9f2369b0 2018-12-24 stsp static const struct got_error *
1667 9f2369b0 2018-12-24 stsp read_tag_privsep(struct got_tag_object **tag, int obj_fd,
1668 d5c81d44 2021-07-08 stsp struct got_object_id *id, struct got_repository *repo)
1670 ddc7b220 2019-09-08 stsp const struct got_error *err;
1671 9f2369b0 2018-12-24 stsp int imsg_fds[2];
1672 9f2369b0 2018-12-24 stsp pid_t pid;
1673 9f2369b0 2018-12-24 stsp struct imsgbuf *ibuf;
1675 9f2369b0 2018-12-24 stsp if (repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].imsg_fd != -1)
1676 d5c81d44 2021-07-08 stsp return request_tag(tag, repo, obj_fd, id);
1678 9f2369b0 2018-12-24 stsp ibuf = calloc(1, sizeof(*ibuf));
1679 9f2369b0 2018-12-24 stsp if (ibuf == NULL)
1680 638f9024 2019-05-13 stsp return got_error_from_errno("calloc");
1682 ddc7b220 2019-09-08 stsp if (socketpair(AF_UNIX, SOCK_STREAM, PF_UNSPEC, imsg_fds) == -1) {
1683 ddc7b220 2019-09-08 stsp err = got_error_from_errno("socketpair");
1684 ddc7b220 2019-09-08 stsp free(ibuf);
1685 ddc7b220 2019-09-08 stsp return err;
1688 9f2369b0 2018-12-24 stsp pid = fork();
1689 ddc7b220 2019-09-08 stsp if (pid == -1) {
1690 ddc7b220 2019-09-08 stsp err = got_error_from_errno("fork");
1691 ddc7b220 2019-09-08 stsp free(ibuf);
1692 ddc7b220 2019-09-08 stsp return err;
1694 9f2369b0 2018-12-24 stsp else if (pid == 0) {
1695 aba9c984 2019-09-08 stsp got_privsep_exec_child(imsg_fds, GOT_PATH_PROG_READ_TAG,
1696 9f2369b0 2018-12-24 stsp repo->path);
1697 9f2369b0 2018-12-24 stsp /* not reached */
1700 08578a35 2021-01-22 stsp if (close(imsg_fds[1]) == -1) {
1701 ddc7b220 2019-09-08 stsp err = got_error_from_errno("close");
1702 ddc7b220 2019-09-08 stsp free(ibuf);
1703 ddc7b220 2019-09-08 stsp return err;
1705 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].imsg_fd =
1706 9f2369b0 2018-12-24 stsp imsg_fds[0];
1707 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].pid = pid;
1708 9f2369b0 2018-12-24 stsp imsg_init(ibuf, imsg_fds[0]);
1709 9f2369b0 2018-12-24 stsp repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TAG].ibuf = ibuf;
1711 d5c81d44 2021-07-08 stsp return request_tag(tag, repo, obj_fd, id);
1714 a158c901 2018-12-23 stsp static const struct got_error *
1715 268f7291 2018-12-24 stsp open_tag(struct got_tag_object **tag, struct got_repository *repo,
1716 268f7291 2018-12-24 stsp struct got_object_id *id, int check_cache)
1718 f4a881ce 2018-11-17 stsp const struct got_error *err = NULL;
1719 268f7291 2018-12-24 stsp struct got_packidx *packidx = NULL;
1721 8d2c5ea3 2019-08-13 stsp char *path_packfile = NULL;
1722 5d844a1e 2019-08-13 stsp struct got_object *obj = NULL;
1723 5d844a1e 2019-08-13 stsp int obj_type = GOT_OBJ_TYPE_ANY;
1725 f4a881ce 2018-11-17 stsp if (check_cache) {
1726 268f7291 2018-12-24 stsp *tag = got_repo_get_cached_tag(repo, id);
1727 f4a881ce 2018-11-17 stsp if (*tag != NULL) {
1728 f4a881ce 2018-11-17 stsp (*tag)->refcnt++;
1729 f4a881ce 2018-11-17 stsp return NULL;
1732 f4a881ce 2018-11-17 stsp *tag = NULL;
1734 e82b1d81 2019-07-27 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
1735 e82b1d81 2019-07-27 stsp if (err == NULL) {
1736 268f7291 2018-12-24 stsp struct got_pack *pack = NULL;
1738 aea75d87 2021-07-06 stsp err = got_packidx_get_packfile_path(&path_packfile,
1739 aea75d87 2021-07-06 stsp packidx->path_packidx);
1741 268f7291 2018-12-24 stsp return err;
1743 268f7291 2018-12-24 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
1744 f4a881ce 2018-11-17 stsp if (pack == NULL) {
1745 e82b1d81 2019-07-27 stsp err = got_repo_cache_pack(&pack, repo, path_packfile,
1748 8d2c5ea3 2019-08-13 stsp goto done;
1751 992eb9d8 2020-02-07 tracey /* Beware of "lightweight" tags: Check object type first. */
1752 5d844a1e 2019-08-13 stsp err = read_packed_object_privsep(&obj, repo, pack, packidx,
1755 5d844a1e 2019-08-13 stsp goto done;
1756 5d844a1e 2019-08-13 stsp obj_type = obj->type;
1757 5d844a1e 2019-08-13 stsp got_object_close(obj);
1758 5d844a1e 2019-08-13 stsp if (obj_type != GOT_OBJ_TYPE_TAG) {
1759 5d844a1e 2019-08-13 stsp err = got_error(GOT_ERR_OBJ_TYPE);
1760 5d844a1e 2019-08-13 stsp goto done;
1762 5d844a1e 2019-08-13 stsp err = read_packed_tag_privsep(tag, pack, packidx, idx, id);
1763 e82b1d81 2019-07-27 stsp } else if (err->code == GOT_ERR_NO_OBJ) {
1766 762d73f4 2021-04-10 stsp err = got_object_open_loose_fd(&fd, id, repo);
1768 e82b1d81 2019-07-27 stsp return err;
1769 d5c81d44 2021-07-08 stsp err = got_object_read_header_privsep(&obj, id, repo, fd);
1771 5d844a1e 2019-08-13 stsp return err;
1772 5d844a1e 2019-08-13 stsp obj_type = obj->type;
1773 5d844a1e 2019-08-13 stsp got_object_close(obj);
1774 5d844a1e 2019-08-13 stsp if (obj_type != GOT_OBJ_TYPE_TAG)
1775 5d844a1e 2019-08-13 stsp return got_error(GOT_ERR_OBJ_TYPE);
1777 762d73f4 2021-04-10 stsp err = got_object_open_loose_fd(&fd, id, repo);
1779 5d844a1e 2019-08-13 stsp return err;
1780 d5c81d44 2021-07-08 stsp err = read_tag_privsep(tag, fd, id, repo);
1783 f4a881ce 2018-11-17 stsp if (err == NULL) {
1784 f4a881ce 2018-11-17 stsp (*tag)->refcnt++;
1785 268f7291 2018-12-24 stsp err = got_repo_cache_tag(repo, id, *tag);
1788 8d2c5ea3 2019-08-13 stsp free(path_packfile);
1789 f4a881ce 2018-11-17 stsp return err;
1792 f4a881ce 2018-11-17 stsp const struct got_error *
1793 f4a881ce 2018-11-17 stsp got_object_open_as_tag(struct got_tag_object **tag,
1794 f4a881ce 2018-11-17 stsp struct got_repository *repo, struct got_object_id *id)
1796 f4a881ce 2018-11-17 stsp *tag = got_repo_get_cached_tag(repo, id);
1797 f4a881ce 2018-11-17 stsp if (*tag != NULL) {
1798 f4a881ce 2018-11-17 stsp (*tag)->refcnt++;
1799 f4a881ce 2018-11-17 stsp return NULL;
1802 268f7291 2018-12-24 stsp return open_tag(tag, repo, id, 0);
1805 f4a881ce 2018-11-17 stsp const struct got_error *
1806 f4a881ce 2018-11-17 stsp got_object_tag_open(struct got_tag_object **tag,
1807 f4a881ce 2018-11-17 stsp struct got_repository *repo, struct got_object *obj)
1809 268f7291 2018-12-24 stsp return open_tag(tag, repo, got_object_get_id(obj), 1);
1812 d24820bf 2019-08-11 stsp const char *
1813 d24820bf 2019-08-11 stsp got_object_tag_get_name(struct got_tag_object *tag)
1815 d24820bf 2019-08-11 stsp return tag->tag;
1819 0bd18d37 2019-02-01 stsp got_object_tag_get_object_type(struct got_tag_object *tag)
1821 0bd18d37 2019-02-01 stsp return tag->obj_type;
1824 0bd18d37 2019-02-01 stsp struct got_object_id *
1825 0bd18d37 2019-02-01 stsp got_object_tag_get_object_id(struct got_tag_object *tag)
1827 0bd18d37 2019-02-01 stsp return &tag->id;
1831 01073a5d 2019-08-22 stsp got_object_tag_get_tagger_time(struct got_tag_object *tag)
1833 01073a5d 2019-08-22 stsp return tag->tagger_time;
1837 01073a5d 2019-08-22 stsp got_object_tag_get_tagger_gmtoff(struct got_tag_object *tag)
1839 01073a5d 2019-08-22 stsp return tag->tagger_gmtoff;
1842 01073a5d 2019-08-22 stsp const char *
1843 01073a5d 2019-08-22 stsp got_object_tag_get_tagger(struct got_tag_object *tag)
1845 01073a5d 2019-08-22 stsp return tag->tagger;
1848 01073a5d 2019-08-22 stsp const char *
1849 01073a5d 2019-08-22 stsp got_object_tag_get_message(struct got_tag_object *tag)
1851 01073a5d 2019-08-22 stsp return tag->tagmsg;
1854 776d4d29 2018-06-17 stsp static struct got_tree_entry *
1855 65a9bbe9 2018-09-15 stsp find_entry_by_name(struct got_tree_object *tree, const char *name, size_t len)
1859 63da309a 2018-11-07 stsp /* Note that tree entries are sorted in strncmp() order. */
1860 56e0773d 2019-11-28 stsp for (i = 0; i < tree->nentries; i++) {
1861 56e0773d 2019-11-28 stsp struct got_tree_entry *te = &tree->entries[i];
1862 63da309a 2018-11-07 stsp int cmp = strncmp(te->name, name, len);
1863 63da309a 2018-11-07 stsp if (cmp < 0)
1865 63da309a 2018-11-07 stsp if (cmp > 0)
1867 63da309a 2018-11-07 stsp if (te->name[len] == '\0')
1868 776d4d29 2018-06-17 stsp return te;
1870 eb651edf 2018-02-11 stsp return NULL;
1873 56e0773d 2019-11-28 stsp struct got_tree_entry *
1874 a129376b 2019-03-28 stsp got_object_tree_find_entry(struct got_tree_object *tree, const char *name)
1876 a129376b 2019-03-28 stsp return find_entry_by_name(tree, name, strlen(name));
1879 776d4d29 2018-06-17 stsp const struct got_error *
1880 67b631c9 2021-10-10 stsp got_object_tree_find_path(struct got_object_id **id, mode_t *mode,
1881 67b631c9 2021-10-10 stsp struct got_repository *repo, struct got_tree_object *tree,
1882 67b631c9 2021-10-10 stsp const char *path)
1884 776d4d29 2018-06-17 stsp const struct got_error *err = NULL;
1885 67b631c9 2021-10-10 stsp struct got_tree_object *subtree = NULL;
1886 db37e2c0 2018-06-21 stsp struct got_tree_entry *te = NULL;
1887 65a9bbe9 2018-09-15 stsp const char *seg, *s;
1888 b7cd37e5 2018-11-18 stsp size_t seglen;
1890 27d434c2 2018-09-15 stsp *id = NULL;
1893 5e54fb30 2019-05-31 stsp while (s[0] == '/')
1896 65a9bbe9 2018-09-15 stsp seglen = 0;
1897 67b631c9 2021-10-10 stsp subtree = tree;
1898 b7cd37e5 2018-11-18 stsp while (*s) {
1899 776d4d29 2018-06-17 stsp struct got_tree_object *next_tree;
1901 776d4d29 2018-06-17 stsp if (*s != '/') {
1908 67b631c9 2021-10-10 stsp te = find_entry_by_name(subtree, seg, seglen);
1909 db37e2c0 2018-06-21 stsp if (te == NULL) {
1910 b66cd6f3 2020-07-31 stsp err = got_error_path(path, GOT_ERR_NO_TREE_ENTRY);
1911 776d4d29 2018-06-17 stsp goto done;
1914 b7cd37e5 2018-11-18 stsp if (*s == '\0')
1917 776d4d29 2018-06-17 stsp seg = s + 1;
1918 65a9bbe9 2018-09-15 stsp seglen = 0;
1921 776d4d29 2018-06-17 stsp err = got_object_open_as_tree(&next_tree, repo,
1923 db37e2c0 2018-06-21 stsp te = NULL;
1925 776d4d29 2018-06-17 stsp goto done;
1926 67b631c9 2021-10-10 stsp if (subtree != tree)
1927 67b631c9 2021-10-10 stsp got_object_tree_close(subtree);
1928 67b631c9 2021-10-10 stsp subtree = next_tree;
1933 56e0773d 2019-11-28 stsp *id = got_object_id_dup(&te->id);
1934 27d434c2 2018-09-15 stsp if (*id == NULL)
1935 638f9024 2019-05-13 stsp return got_error_from_errno("got_object_id_dup");
1937 67b631c9 2021-10-10 stsp *mode = te->mode;
1939 b66cd6f3 2020-07-31 stsp err = got_error_path(path, GOT_ERR_NO_TREE_ENTRY);
1941 67b631c9 2021-10-10 stsp if (subtree && subtree != tree)
1942 67b631c9 2021-10-10 stsp got_object_tree_close(subtree);
1943 67b631c9 2021-10-10 stsp return err;
1945 67b631c9 2021-10-10 stsp const struct got_error *
1946 67b631c9 2021-10-10 stsp got_object_id_by_path(struct got_object_id **id, struct got_repository *repo,
1947 a44927cc 2022-04-07 stsp struct got_commit_object *commit, const char *path)
1949 67b631c9 2021-10-10 stsp const struct got_error *err = NULL;
1950 67b631c9 2021-10-10 stsp struct got_tree_object *tree = NULL;
1952 67b631c9 2021-10-10 stsp *id = NULL;
1954 67b631c9 2021-10-10 stsp /* Handle opening of root of commit's tree. */
1955 67b631c9 2021-10-10 stsp if (got_path_is_root_dir(path)) {
1956 67b631c9 2021-10-10 stsp *id = got_object_id_dup(commit->tree_id);
1957 67b631c9 2021-10-10 stsp if (*id == NULL)
1958 67b631c9 2021-10-10 stsp err = got_error_from_errno("got_object_id_dup");
1960 67b631c9 2021-10-10 stsp err = got_object_open_as_tree(&tree, repo, commit->tree_id);
1962 67b631c9 2021-10-10 stsp goto done;
1963 67b631c9 2021-10-10 stsp err = got_object_tree_find_path(id, NULL, repo, tree, path);
1967 776d4d29 2018-06-17 stsp got_object_tree_close(tree);
1968 776d4d29 2018-06-17 stsp return err;
1972 ac5f2b26 2020-05-05 stsp * Normalize file mode bits to avoid false positive tree entry differences
1973 ac5f2b26 2020-05-05 stsp * in case tree entries have unexpected mode bits set.
1975 ac5f2b26 2020-05-05 stsp static mode_t
1976 ac5f2b26 2020-05-05 stsp normalize_mode_for_comparison(mode_t mode)
1979 ac5f2b26 2020-05-05 stsp * For directories, the only relevant bit is the IFDIR bit.
1980 ac5f2b26 2020-05-05 stsp * This allows us to detect paths changing from a directory
1981 ac5f2b26 2020-05-05 stsp * to a file and vice versa.
1983 ac5f2b26 2020-05-05 stsp if (S_ISDIR(mode))
1984 ac5f2b26 2020-05-05 stsp return mode & S_IFDIR;
1987 40dde666 2020-07-23 stsp * For symlinks, the only relevant bit is the IFLNK bit.
1988 40dde666 2020-07-23 stsp * This allows us to detect paths changing from a symlinks
1989 40dde666 2020-07-23 stsp * to a file or directory and vice versa.
1991 40dde666 2020-07-23 stsp if (S_ISLNK(mode))
1992 40dde666 2020-07-23 stsp return mode & S_IFLNK;
1994 ac5f2b26 2020-05-05 stsp /* For files, the only change we care about is the executable bit. */
1995 ac5f2b26 2020-05-05 stsp return mode & S_IXUSR;
1998 07862c20 2018-09-15 stsp const struct got_error *
1999 07862c20 2018-09-15 stsp got_object_tree_path_changed(int *changed,
2000 07862c20 2018-09-15 stsp struct got_tree_object *tree01, struct got_tree_object *tree02,
2001 07862c20 2018-09-15 stsp const char *path, struct got_repository *repo)
2003 07862c20 2018-09-15 stsp const struct got_error *err = NULL;
2004 07862c20 2018-09-15 stsp struct got_tree_object *tree1 = NULL, *tree2 = NULL;
2005 07862c20 2018-09-15 stsp struct got_tree_entry *te1 = NULL, *te2 = NULL;
2006 65a9bbe9 2018-09-15 stsp const char *seg, *s;
2007 3b7f9878 2018-11-18 stsp size_t seglen;
2009 07862c20 2018-09-15 stsp *changed = 0;
2011 07862c20 2018-09-15 stsp /* We not do support comparing the root path. */
2012 61a7d79f 2020-02-29 stsp if (got_path_is_root_dir(path))
2013 63f810e6 2020-02-29 stsp return got_error_path(path, GOT_ERR_BAD_PATH);
2015 07862c20 2018-09-15 stsp tree1 = tree01;
2016 07862c20 2018-09-15 stsp tree2 = tree02;
2018 61a7d79f 2020-02-29 stsp while (*s == '/')
2021 65a9bbe9 2018-09-15 stsp seglen = 0;
2022 3b7f9878 2018-11-18 stsp while (*s) {
2023 07862c20 2018-09-15 stsp struct got_tree_object *next_tree1, *next_tree2;
2024 ac5f2b26 2020-05-05 stsp mode_t mode1, mode2;
2026 07862c20 2018-09-15 stsp if (*s != '/') {
2033 65a9bbe9 2018-09-15 stsp te1 = find_entry_by_name(tree1, seg, seglen);
2034 07862c20 2018-09-15 stsp if (te1 == NULL) {
2035 07862c20 2018-09-15 stsp err = got_error(GOT_ERR_NO_OBJ);
2036 07862c20 2018-09-15 stsp goto done;
2039 e8bfb8f3 2020-12-18 stsp if (tree2)
2040 e8bfb8f3 2020-12-18 stsp te2 = find_entry_by_name(tree2, seg, seglen);
2042 e8bfb8f3 2020-12-18 stsp if (te2) {
2043 e8bfb8f3 2020-12-18 stsp mode1 = normalize_mode_for_comparison(te1->mode);
2044 e8bfb8f3 2020-12-18 stsp mode2 = normalize_mode_for_comparison(te2->mode);
2045 e8bfb8f3 2020-12-18 stsp if (mode1 != mode2) {
2046 e8bfb8f3 2020-12-18 stsp *changed = 1;
2047 e8bfb8f3 2020-12-18 stsp goto done;
2050 e8bfb8f3 2020-12-18 stsp if (got_object_id_cmp(&te1->id, &te2->id) == 0) {
2051 e8bfb8f3 2020-12-18 stsp *changed = 0;
2052 e8bfb8f3 2020-12-18 stsp goto done;
2056 3b7f9878 2018-11-18 stsp if (*s == '\0') { /* final path element */
2057 07862c20 2018-09-15 stsp *changed = 1;
2058 07862c20 2018-09-15 stsp goto done;
2061 07862c20 2018-09-15 stsp seg = s + 1;
2063 65a9bbe9 2018-09-15 stsp seglen = 0;
2065 07862c20 2018-09-15 stsp err = got_object_open_as_tree(&next_tree1, repo,
2066 56e0773d 2019-11-28 stsp &te1->id);
2067 07862c20 2018-09-15 stsp te1 = NULL;
2069 07862c20 2018-09-15 stsp goto done;
2070 a31cea73 2018-09-15 stsp if (tree1 != tree01)
2071 a31cea73 2018-09-15 stsp got_object_tree_close(tree1);
2072 07862c20 2018-09-15 stsp tree1 = next_tree1;
2074 e8bfb8f3 2020-12-18 stsp if (te2) {
2075 e8bfb8f3 2020-12-18 stsp err = got_object_open_as_tree(&next_tree2, repo,
2076 e8bfb8f3 2020-12-18 stsp &te2->id);
2077 e8bfb8f3 2020-12-18 stsp te2 = NULL;
2079 e8bfb8f3 2020-12-18 stsp goto done;
2080 e8bfb8f3 2020-12-18 stsp if (tree2 != tree02)
2081 e8bfb8f3 2020-12-18 stsp got_object_tree_close(tree2);
2082 e8bfb8f3 2020-12-18 stsp tree2 = next_tree2;
2083 e8bfb8f3 2020-12-18 stsp } else if (tree2) {
2084 e8bfb8f3 2020-12-18 stsp if (tree2 != tree02)
2085 e8bfb8f3 2020-12-18 stsp got_object_tree_close(tree2);
2086 e8bfb8f3 2020-12-18 stsp tree2 = NULL;
2091 a31cea73 2018-09-15 stsp if (tree1 && tree1 != tree01)
2092 07862c20 2018-09-15 stsp got_object_tree_close(tree1);
2093 a31cea73 2018-09-15 stsp if (tree2 && tree2 != tree02)
2094 07862c20 2018-09-15 stsp got_object_tree_close(tree2);
2095 77880158 2018-11-04 stsp return err;
2098 ed175427 2019-05-09 stsp const struct got_error *
2099 ed175427 2019-05-09 stsp got_object_tree_entry_dup(struct got_tree_entry **new_te,
2100 ed175427 2019-05-09 stsp struct got_tree_entry *te)
2102 ed175427 2019-05-09 stsp const struct got_error *err = NULL;
2104 ed175427 2019-05-09 stsp *new_te = calloc(1, sizeof(**new_te));
2105 ed175427 2019-05-09 stsp if (*new_te == NULL)
2106 638f9024 2019-05-13 stsp return got_error_from_errno("calloc");
2108 ed175427 2019-05-09 stsp (*new_te)->mode = te->mode;
2109 56e0773d 2019-11-28 stsp memcpy((*new_te)->name, te->name, sizeof((*new_te)->name));
2110 56e0773d 2019-11-28 stsp memcpy(&(*new_te)->id, &te->id, sizeof((*new_te)->id));
2111 8c4eabf2 2019-05-10 stsp return err;
2115 56e0773d 2019-11-28 stsp got_object_tree_entry_is_submodule(struct got_tree_entry *te)
2117 63c5ca5d 2019-08-24 stsp return (te->mode & S_IFMT) == (S_IFDIR | S_IFLNK);
2121 e40622f4 2020-07-23 stsp got_object_tree_entry_is_symlink(struct got_tree_entry *te)
2123 e40622f4 2020-07-23 stsp /* S_IFDIR check avoids confusing symlinks with submodules. */
2124 e40622f4 2020-07-23 stsp return ((te->mode & (S_IFDIR | S_IFLNK)) == S_IFLNK);
2127 e40622f4 2020-07-23 stsp static const struct got_error *
2128 e40622f4 2020-07-23 stsp resolve_symlink(char **link_target, const char *path,
2129 a44927cc 2022-04-07 stsp struct got_commit_object *commit, struct got_repository *repo)
2131 e40622f4 2020-07-23 stsp const struct got_error *err = NULL;
2132 dbdd6209 2020-10-19 stsp char buf[PATH_MAX];
2133 e40622f4 2020-07-23 stsp char *name, *parent_path = NULL;
2134 e40622f4 2020-07-23 stsp struct got_object_id *tree_obj_id = NULL;
2135 e40622f4 2020-07-23 stsp struct got_tree_object *tree = NULL;
2136 e40622f4 2020-07-23 stsp struct got_tree_entry *te = NULL;
2138 e40622f4 2020-07-23 stsp *link_target = NULL;
2140 dbdd6209 2020-10-19 stsp if (strlcpy(buf, path, sizeof(buf)) >= sizeof(buf))
2141 dbdd6209 2020-10-19 stsp return got_error(GOT_ERR_NO_SPACE);
2143 dbdd6209 2020-10-19 stsp name = basename(buf);
2144 e40622f4 2020-07-23 stsp if (name == NULL)
2145 e40622f4 2020-07-23 stsp return got_error_from_errno2("basename", path);
2147 e40622f4 2020-07-23 stsp err = got_path_dirname(&parent_path, path);
2149 e40622f4 2020-07-23 stsp return err;
2151 a44927cc 2022-04-07 stsp err = got_object_id_by_path(&tree_obj_id, repo, commit,
2152 e40622f4 2020-07-23 stsp parent_path);
2153 e40622f4 2020-07-23 stsp if (err) {
2154 e40622f4 2020-07-23 stsp if (err->code == GOT_ERR_NO_TREE_ENTRY) {
2155 e40622f4 2020-07-23 stsp /* Display the complete path in error message. */
2156 e40622f4 2020-07-23 stsp err = got_error_path(path, err->code);
2158 e40622f4 2020-07-23 stsp goto done;
2161 e40622f4 2020-07-23 stsp err = got_object_open_as_tree(&tree, repo, tree_obj_id);
2163 e40622f4 2020-07-23 stsp goto done;
2165 e40622f4 2020-07-23 stsp te = got_object_tree_find_entry(tree, name);
2166 e40622f4 2020-07-23 stsp if (te == NULL) {
2167 e40622f4 2020-07-23 stsp err = got_error_path(path, GOT_ERR_NO_TREE_ENTRY);
2168 e40622f4 2020-07-23 stsp goto done;
2171 e40622f4 2020-07-23 stsp if (got_object_tree_entry_is_symlink(te)) {
2172 e40622f4 2020-07-23 stsp err = got_tree_entry_get_symlink_target(link_target, te, repo);
2174 e40622f4 2020-07-23 stsp goto done;
2175 e40622f4 2020-07-23 stsp if (!got_path_is_absolute(*link_target)) {
2176 e40622f4 2020-07-23 stsp char *abspath;
2177 e40622f4 2020-07-23 stsp if (asprintf(&abspath, "%s/%s", parent_path,
2178 e40622f4 2020-07-23 stsp *link_target) == -1) {
2179 e40622f4 2020-07-23 stsp err = got_error_from_errno("asprintf");
2180 e40622f4 2020-07-23 stsp goto done;
2182 e40622f4 2020-07-23 stsp free(*link_target);
2183 e40622f4 2020-07-23 stsp *link_target = malloc(PATH_MAX);
2184 e40622f4 2020-07-23 stsp if (*link_target == NULL) {
2185 e40622f4 2020-07-23 stsp err = got_error_from_errno("malloc");
2186 e40622f4 2020-07-23 stsp goto done;
2188 e40622f4 2020-07-23 stsp err = got_canonpath(abspath, *link_target, PATH_MAX);
2189 e40622f4 2020-07-23 stsp free(abspath);
2191 e40622f4 2020-07-23 stsp goto done;
2195 e40622f4 2020-07-23 stsp free(tree_obj_id);
2197 e40622f4 2020-07-23 stsp got_object_tree_close(tree);
2198 e40622f4 2020-07-23 stsp if (err) {
2199 e40622f4 2020-07-23 stsp free(*link_target);
2200 e40622f4 2020-07-23 stsp *link_target = NULL;
2202 e40622f4 2020-07-23 stsp return err;
2205 ca6e02ac 2020-01-07 stsp const struct got_error *
2206 e40622f4 2020-07-23 stsp got_object_resolve_symlinks(char **link_target, const char *path,
2207 a44927cc 2022-04-07 stsp struct got_commit_object *commit, struct got_repository *repo)
2209 e40622f4 2020-07-23 stsp const struct got_error *err = NULL;
2210 e40622f4 2020-07-23 stsp char *next_target = NULL;
2211 e40622f4 2020-07-23 stsp int max_recursion = 40; /* matches Git */
2213 e40622f4 2020-07-23 stsp *link_target = NULL;
2216 e40622f4 2020-07-23 stsp err = resolve_symlink(&next_target,
2217 a44927cc 2022-04-07 stsp *link_target ? *link_target : path, commit, repo);
2220 e40622f4 2020-07-23 stsp if (next_target) {
2221 e40622f4 2020-07-23 stsp free(*link_target);
2222 e40622f4 2020-07-23 stsp if (--max_recursion == 0) {
2223 e40622f4 2020-07-23 stsp err = got_error_path(path, GOT_ERR_RECURSION);
2224 e40622f4 2020-07-23 stsp *link_target = NULL;
2227 e40622f4 2020-07-23 stsp *link_target = next_target;
2229 e40622f4 2020-07-23 stsp } while (next_target);
2231 e40622f4 2020-07-23 stsp return err;
2234 e40622f4 2020-07-23 stsp const struct got_error *
2235 ca6e02ac 2020-01-07 stsp got_traverse_packed_commits(struct got_object_id_queue *traversed_commits,
2236 ca6e02ac 2020-01-07 stsp struct got_object_id *commit_id, const char *path,
2237 ca6e02ac 2020-01-07 stsp struct got_repository *repo)
2239 ca6e02ac 2020-01-07 stsp const struct got_error *err = NULL;
2240 ca6e02ac 2020-01-07 stsp struct got_pack *pack = NULL;
2241 ca6e02ac 2020-01-07 stsp struct got_packidx *packidx = NULL;
2242 ca6e02ac 2020-01-07 stsp char *path_packfile = NULL;
2243 ca6e02ac 2020-01-07 stsp struct got_commit_object *changed_commit = NULL;
2244 ca6e02ac 2020-01-07 stsp struct got_object_id *changed_commit_id = NULL;
2247 ca6e02ac 2020-01-07 stsp err = got_repo_search_packidx(&packidx, &idx, repo, commit_id);
2248 ca6e02ac 2020-01-07 stsp if (err) {
2249 ca6e02ac 2020-01-07 stsp if (err->code != GOT_ERR_NO_OBJ)
2250 ca6e02ac 2020-01-07 stsp return err;
2251 ca6e02ac 2020-01-07 stsp return NULL;
2254 aea75d87 2021-07-06 stsp err = got_packidx_get_packfile_path(&path_packfile,
2255 aea75d87 2021-07-06 stsp packidx->path_packidx);
2257 ca6e02ac 2020-01-07 stsp return err;
2259 ca6e02ac 2020-01-07 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
2260 ca6e02ac 2020-01-07 stsp if (pack == NULL) {
2261 ca6e02ac 2020-01-07 stsp err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
2263 ca6e02ac 2020-01-07 stsp goto done;
2266 ca6e02ac 2020-01-07 stsp if (pack->privsep_child == NULL) {
2267 3d589bee 2022-06-25 stsp err = got_pack_start_privsep_child(pack, packidx);
2269 ca6e02ac 2020-01-07 stsp goto done;
2272 ca6e02ac 2020-01-07 stsp err = got_privsep_send_commit_traversal_request(
2273 ca6e02ac 2020-01-07 stsp pack->privsep_child->ibuf, commit_id, idx, path);
2275 ca6e02ac 2020-01-07 stsp goto done;
2277 ca6e02ac 2020-01-07 stsp err = got_privsep_recv_traversed_commits(&changed_commit,
2278 ca6e02ac 2020-01-07 stsp &changed_commit_id, traversed_commits, pack->privsep_child->ibuf);
2280 ca6e02ac 2020-01-07 stsp goto done;
2282 ca6e02ac 2020-01-07 stsp if (changed_commit) {
2284 ca6e02ac 2020-01-07 stsp * Cache the commit in which the path was changed.
2285 ca6e02ac 2020-01-07 stsp * This commit might be opened again soon.
2287 ca6e02ac 2020-01-07 stsp changed_commit->refcnt++;
2288 ca6e02ac 2020-01-07 stsp err = got_repo_cache_commit(repo, changed_commit_id,
2289 ca6e02ac 2020-01-07 stsp changed_commit);
2290 ca6e02ac 2020-01-07 stsp got_object_commit_close(changed_commit);
2293 ca6e02ac 2020-01-07 stsp free(path_packfile);
2294 ca6e02ac 2020-01-07 stsp free(changed_commit_id);
2295 ca6e02ac 2020-01-07 stsp return err;
2298 0ab4c957 2022-06-13 stsp const struct got_error *
2299 db9b9b1c 2022-06-14 stsp got_object_enumerate(int *found_all_objects,
2300 db9b9b1c 2022-06-14 stsp got_object_enumerate_commit_cb cb_commit,
2301 0ab4c957 2022-06-13 stsp got_object_enumerate_tree_cb cb_tree, void *cb_arg,
2302 0ab4c957 2022-06-13 stsp struct got_object_id **ours, int nours,
2303 0ab4c957 2022-06-13 stsp struct got_object_id **theirs, int ntheirs,
2304 0ab4c957 2022-06-13 stsp struct got_packidx *packidx, struct got_repository *repo)
2306 0ab4c957 2022-06-13 stsp const struct got_error *err = NULL;
2307 0ab4c957 2022-06-13 stsp struct got_pack *pack;
2308 0ab4c957 2022-06-13 stsp char *path_packfile = NULL;
2310 0ab4c957 2022-06-13 stsp err = got_packidx_get_packfile_path(&path_packfile,
2311 0ab4c957 2022-06-13 stsp packidx->path_packidx);
2313 0ab4c957 2022-06-13 stsp return err;
2315 0ab4c957 2022-06-13 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
2316 0ab4c957 2022-06-13 stsp if (pack == NULL) {
2317 0ab4c957 2022-06-13 stsp err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
2319 0ab4c957 2022-06-13 stsp goto done;
2322 0ab4c957 2022-06-13 stsp if (pack->privsep_child == NULL) {
2323 3d589bee 2022-06-25 stsp err = got_pack_start_privsep_child(pack, packidx);
2325 0ab4c957 2022-06-13 stsp goto done;
2328 0ab4c957 2022-06-13 stsp err = got_privsep_send_object_enumeration_request(
2329 0ab4c957 2022-06-13 stsp pack->privsep_child->ibuf);
2331 0ab4c957 2022-06-13 stsp goto done;
2333 0ab4c957 2022-06-13 stsp err = got_privsep_send_object_idlist(pack->privsep_child->ibuf,
2334 0ab4c957 2022-06-13 stsp ours, nours);
2336 0ab4c957 2022-06-13 stsp goto done;
2337 0ab4c957 2022-06-13 stsp err = got_privsep_send_object_idlist_done(pack->privsep_child->ibuf);
2339 0ab4c957 2022-06-13 stsp goto done;
2341 0ab4c957 2022-06-13 stsp err = got_privsep_send_object_idlist(pack->privsep_child->ibuf,
2342 0ab4c957 2022-06-13 stsp theirs, ntheirs);
2344 0ab4c957 2022-06-13 stsp goto done;
2345 0ab4c957 2022-06-13 stsp err = got_privsep_send_object_idlist_done(pack->privsep_child->ibuf);
2347 0ab4c957 2022-06-13 stsp goto done;
2349 db9b9b1c 2022-06-14 stsp err = got_privsep_recv_enumerated_objects(found_all_objects,
2350 db9b9b1c 2022-06-14 stsp pack->privsep_child->ibuf, cb_commit, cb_tree, cb_arg, repo);
2352 0ab4c957 2022-06-13 stsp free(path_packfile);
2353 0ab4c957 2022-06-13 stsp return err;