2 13b2bc37 2022-10-23 stsp * Copyright (c) 2022 Stefan Sperling <stsp@openbsd.org>
4 13b2bc37 2022-10-23 stsp * Permission to use, copy, modify, and distribute this software for any
5 13b2bc37 2022-10-23 stsp * purpose with or without fee is hereby granted, provided that the above
6 13b2bc37 2022-10-23 stsp * copyright notice and this permission notice appear in all copies.
8 13b2bc37 2022-10-23 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 13b2bc37 2022-10-23 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 13b2bc37 2022-10-23 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 13b2bc37 2022-10-23 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 13b2bc37 2022-10-23 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 13b2bc37 2022-10-23 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 13b2bc37 2022-10-23 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 13b2bc37 2022-10-23 stsp #include <sys/queue.h>
18 13b2bc37 2022-10-23 stsp #include <sys/tree.h>
19 13b2bc37 2022-10-23 stsp #include <sys/stat.h>
21 13b2bc37 2022-10-23 stsp #include <errno.h>
22 13b2bc37 2022-10-23 stsp #include <limits.h>
23 13b2bc37 2022-10-23 stsp #include <sha1.h>
24 5822e79e 2023-02-23 op #include <sha2.h>
25 13b2bc37 2022-10-23 stsp #include <stdio.h>
26 13b2bc37 2022-10-23 stsp #include <stdlib.h>
27 13b2bc37 2022-10-23 stsp #include <string.h>
28 13b2bc37 2022-10-23 stsp #include <unistd.h>
29 05fd3169 2024-03-19 stsp #include <zlib.h>
31 13b2bc37 2022-10-23 stsp #include "got_error.h"
32 13b2bc37 2022-10-23 stsp #include "got_object.h"
33 13b2bc37 2022-10-23 stsp #include "got_repository.h"
34 13b2bc37 2022-10-23 stsp #include "got_path.h"
36 13b2bc37 2022-10-23 stsp #include "got_lib_delta.h"
37 13b2bc37 2022-10-23 stsp #include "got_lib_object.h"
38 13b2bc37 2022-10-23 stsp #include "got_lib_object_cache.h"
39 13b2bc37 2022-10-23 stsp #include "got_lib_object_parse.h"
40 13b2bc37 2022-10-23 stsp #include "got_lib_pack.h"
41 13b2bc37 2022-10-23 stsp #include "got_lib_repository.h"
42 05fd3169 2024-03-19 stsp #include "got_lib_inflate.h"
43 05fd3169 2024-03-19 stsp #include "got_lib_hash.h"
45 13b2bc37 2022-10-23 stsp const struct got_error *
46 13b2bc37 2022-10-23 stsp got_object_open_packed(struct got_object **obj, struct got_object_id *id,
47 13b2bc37 2022-10-23 stsp struct got_repository *repo)
49 13b2bc37 2022-10-23 stsp const struct got_error *err = NULL;
50 13b2bc37 2022-10-23 stsp struct got_pack *pack = NULL;
51 13b2bc37 2022-10-23 stsp struct got_packidx *packidx = NULL;
53 13b2bc37 2022-10-23 stsp char *path_packfile;
55 13b2bc37 2022-10-23 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
59 13b2bc37 2022-10-23 stsp err = got_packidx_get_packfile_path(&path_packfile,
60 13b2bc37 2022-10-23 stsp packidx->path_packidx);
64 13b2bc37 2022-10-23 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
65 13b2bc37 2022-10-23 stsp if (pack == NULL) {
66 13b2bc37 2022-10-23 stsp err = got_repo_cache_pack(&pack, repo, path_packfile, packidx);
71 13b2bc37 2022-10-23 stsp err = got_packfile_open_object(obj, pack, packidx, idx, id);
74 13b2bc37 2022-10-23 stsp (*obj)->refcnt++;
76 13b2bc37 2022-10-23 stsp err = got_repo_cache_object(repo, id, *obj);
78 13b2bc37 2022-10-23 stsp if (err->code == GOT_ERR_OBJ_EXISTS ||
79 13b2bc37 2022-10-23 stsp err->code == GOT_ERR_OBJ_TOO_LARGE)
83 13b2bc37 2022-10-23 stsp free(path_packfile);
87 13b2bc37 2022-10-23 stsp const struct got_error *
88 13b2bc37 2022-10-23 stsp got_object_open_from_packfile(struct got_object **obj, struct got_object_id *id,
89 13b2bc37 2022-10-23 stsp struct got_pack *pack, struct got_packidx *packidx, int obj_idx,
90 13b2bc37 2022-10-23 stsp struct got_repository *repo)
92 9afa3de2 2023-04-04 stsp const struct got_error *err;
94 9afa3de2 2023-04-04 stsp *obj = got_repo_get_cached_object(repo, id);
95 9afa3de2 2023-04-04 stsp if (*obj != NULL) {
96 9afa3de2 2023-04-04 stsp (*obj)->refcnt++;
97 9afa3de2 2023-04-04 stsp return NULL;
100 9afa3de2 2023-04-04 stsp err = got_packfile_open_object(obj, pack, packidx, obj_idx, id);
102 9afa3de2 2023-04-04 stsp return err;
103 9afa3de2 2023-04-04 stsp (*obj)->refcnt++;
105 9afa3de2 2023-04-04 stsp err = got_repo_cache_object(repo, id, *obj);
107 9afa3de2 2023-04-04 stsp if (err->code == GOT_ERR_OBJ_EXISTS ||
108 9afa3de2 2023-04-04 stsp err->code == GOT_ERR_OBJ_TOO_LARGE)
109 9afa3de2 2023-04-04 stsp err = NULL;
110 9afa3de2 2023-04-04 stsp return err;
112 9afa3de2 2023-04-04 stsp (*obj)->refcnt++;
113 9afa3de2 2023-04-04 stsp return NULL;
116 13b2bc37 2022-10-23 stsp const struct got_error *
117 13b2bc37 2022-10-23 stsp got_object_read_raw_delta(uint64_t *base_size, uint64_t *result_size,
118 13b2bc37 2022-10-23 stsp off_t *delta_size, off_t *delta_compressed_size, off_t *delta_offset,
119 13b2bc37 2022-10-23 stsp off_t *delta_out_offset, struct got_object_id **base_id, int delta_cache_fd,
120 13b2bc37 2022-10-23 stsp struct got_packidx *packidx, int obj_idx, struct got_object_id *id,
121 13b2bc37 2022-10-23 stsp struct got_repository *repo)
123 13b2bc37 2022-10-23 stsp return got_error(GOT_ERR_NOT_IMPL);
126 13b2bc37 2022-10-23 stsp const struct got_error *
127 13b2bc37 2022-10-23 stsp got_object_open(struct got_object **obj, struct got_repository *repo,
128 13b2bc37 2022-10-23 stsp struct got_object_id *id)
130 13b2bc37 2022-10-23 stsp const struct got_error *err = NULL;
133 13b2bc37 2022-10-23 stsp *obj = got_repo_get_cached_object(repo, id);
134 13b2bc37 2022-10-23 stsp if (*obj != NULL) {
135 13b2bc37 2022-10-23 stsp (*obj)->refcnt++;
136 13b2bc37 2022-10-23 stsp return NULL;
139 13b2bc37 2022-10-23 stsp err = got_object_open_packed(obj, id, repo);
141 13b2bc37 2022-10-23 stsp if (err->code != GOT_ERR_NO_OBJ)
142 13b2bc37 2022-10-23 stsp return err;
144 13b2bc37 2022-10-23 stsp return NULL;
146 13b2bc37 2022-10-23 stsp err = got_object_open_loose_fd(&fd, id, repo);
148 13b2bc37 2022-10-23 stsp if (err->code == GOT_ERR_ERRNO && errno == ENOENT)
149 13b2bc37 2022-10-23 stsp err = got_error_no_obj(id);
150 13b2bc37 2022-10-23 stsp return err;
153 13b2bc37 2022-10-23 stsp err = got_object_read_header(obj, fd);
157 13b2bc37 2022-10-23 stsp memcpy(&(*obj)->id, id, sizeof((*obj)->id));
158 13b2bc37 2022-10-23 stsp (*obj)->refcnt++;
160 13b2bc37 2022-10-23 stsp err = got_repo_cache_object(repo, id, *obj);
162 13b2bc37 2022-10-23 stsp if (err->code == GOT_ERR_OBJ_EXISTS ||
163 13b2bc37 2022-10-23 stsp err->code == GOT_ERR_OBJ_TOO_LARGE)
164 13b2bc37 2022-10-23 stsp err = NULL;
167 13b2bc37 2022-10-23 stsp if (close(fd) == -1 && err == NULL)
168 13b2bc37 2022-10-23 stsp err = got_error_from_errno("close");
169 13b2bc37 2022-10-23 stsp return err;
172 13b2bc37 2022-10-23 stsp static const struct got_error *
173 13b2bc37 2022-10-23 stsp wrap_fd(FILE **f, int wrapped_fd)
175 13b2bc37 2022-10-23 stsp const struct got_error *err = NULL;
178 13b2bc37 2022-10-23 stsp if (ftruncate(wrapped_fd, 0L) == -1)
179 13b2bc37 2022-10-23 stsp return got_error_from_errno("ftruncate");
181 13b2bc37 2022-10-23 stsp if (lseek(wrapped_fd, 0L, SEEK_SET) == -1)
182 13b2bc37 2022-10-23 stsp return got_error_from_errno("lseek");
184 13b2bc37 2022-10-23 stsp fd = dup(wrapped_fd);
185 13b2bc37 2022-10-23 stsp if (fd == -1)
186 13b2bc37 2022-10-23 stsp return got_error_from_errno("dup");
188 13b2bc37 2022-10-23 stsp *f = fdopen(fd, "w+");
189 13b2bc37 2022-10-23 stsp if (*f == NULL) {
190 13b2bc37 2022-10-23 stsp err = got_error_from_errno("fdopen");
193 13b2bc37 2022-10-23 stsp return err;
196 13b2bc37 2022-10-23 stsp static const struct got_error *
197 13b2bc37 2022-10-23 stsp read_packed_object_raw(uint8_t **outbuf, off_t *size, size_t *hdrlen,
198 13b2bc37 2022-10-23 stsp int outfd, struct got_pack *pack, struct got_packidx *packidx, int idx,
199 13b2bc37 2022-10-23 stsp struct got_object_id *id)
201 13b2bc37 2022-10-23 stsp const struct got_error *err = NULL;
202 13b2bc37 2022-10-23 stsp uint64_t raw_size = 0;
203 13b2bc37 2022-10-23 stsp struct got_object *obj;
204 13b2bc37 2022-10-23 stsp FILE *outfile = NULL, *basefile = NULL, *accumfile = NULL;
206 13b2bc37 2022-10-23 stsp *outbuf = NULL;
208 13b2bc37 2022-10-23 stsp *hdrlen = 0;
210 13b2bc37 2022-10-23 stsp err = got_packfile_open_object(&obj, pack, packidx, idx, id);
212 13b2bc37 2022-10-23 stsp return err;
214 13b2bc37 2022-10-23 stsp if (obj->flags & GOT_OBJ_FLAG_DELTIFIED) {
215 13b2bc37 2022-10-23 stsp err = got_pack_get_max_delta_object_size(&raw_size, obj, pack);
219 13b2bc37 2022-10-23 stsp raw_size = obj->size;
221 13b2bc37 2022-10-23 stsp if (raw_size <= GOT_DELTA_RESULT_SIZE_CACHED_MAX) {
222 13b2bc37 2022-10-23 stsp size_t len;
223 13b2bc37 2022-10-23 stsp err = got_packfile_extract_object_to_mem(outbuf, &len,
224 13b2bc37 2022-10-23 stsp obj, pack);
227 13b2bc37 2022-10-23 stsp *size = (off_t)len;
230 13b2bc37 2022-10-23 stsp * XXX This uses 3 file extra descriptors for no good reason.
231 13b2bc37 2022-10-23 stsp * We should have got_packfile_extract_object_to_fd().
233 13b2bc37 2022-10-23 stsp err = wrap_fd(&outfile, outfd);
236 13b2bc37 2022-10-23 stsp err = wrap_fd(&basefile, pack->basefd);
239 13b2bc37 2022-10-23 stsp err = wrap_fd(&accumfile, pack->accumfd);
242 13b2bc37 2022-10-23 stsp err = got_packfile_extract_object(pack, obj, outfile, basefile,
243 13b2bc37 2022-10-23 stsp accumfile);
246 95bdb85d 2023-01-09 stsp *size = obj->size;
249 13b2bc37 2022-10-23 stsp *hdrlen = obj->hdrlen;
251 13b2bc37 2022-10-23 stsp got_object_close(obj);
252 13b2bc37 2022-10-23 stsp if (outfile && fclose(outfile) == EOF && err == NULL)
253 13b2bc37 2022-10-23 stsp err = got_error_from_errno("fclose");
254 13b2bc37 2022-10-23 stsp if (basefile && fclose(basefile) == EOF && err == NULL)
255 13b2bc37 2022-10-23 stsp err = got_error_from_errno("fclose");
256 13b2bc37 2022-10-23 stsp if (accumfile && fclose(accumfile) == EOF && err == NULL)
257 13b2bc37 2022-10-23 stsp err = got_error_from_errno("fclose");
258 13b2bc37 2022-10-23 stsp return err;
262 13b2bc37 2022-10-23 stsp static void
263 13b2bc37 2022-10-23 stsp put_raw_object_tempfile(struct got_raw_object *obj)
265 13b2bc37 2022-10-23 stsp struct got_repository *repo = obj->close_arg;
267 13b2bc37 2022-10-23 stsp if (obj->tempfile_idx != -1)
268 13b2bc37 2022-10-23 stsp got_repo_temp_fds_put(obj->tempfile_idx, repo);
271 13b2bc37 2022-10-23 stsp /* *outfd must be initialized to -1 by caller */
272 13b2bc37 2022-10-23 stsp const struct got_error *
273 13b2bc37 2022-10-23 stsp got_object_raw_open(struct got_raw_object **obj, int *outfd,
274 13b2bc37 2022-10-23 stsp struct got_repository *repo, struct got_object_id *id)
276 13b2bc37 2022-10-23 stsp const struct got_error *err = NULL;
277 13b2bc37 2022-10-23 stsp struct got_packidx *packidx = NULL;
278 3a975a9f 2023-01-09 stsp int idx, tempfd, tempfile_idx;
279 13b2bc37 2022-10-23 stsp uint8_t *outbuf = NULL;
280 13b2bc37 2022-10-23 stsp off_t size = 0;
281 13b2bc37 2022-10-23 stsp size_t hdrlen = 0;
282 13b2bc37 2022-10-23 stsp char *path_packfile = NULL;
284 13b2bc37 2022-10-23 stsp *obj = got_repo_get_cached_raw_object(repo, id);
285 13b2bc37 2022-10-23 stsp if (*obj != NULL) {
286 13b2bc37 2022-10-23 stsp (*obj)->refcnt++;
287 13b2bc37 2022-10-23 stsp return NULL;
290 3a975a9f 2023-01-09 stsp err = got_repo_temp_fds_get(&tempfd, &tempfile_idx, repo);
292 3a975a9f 2023-01-09 stsp return err;
294 13b2bc37 2022-10-23 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
295 13b2bc37 2022-10-23 stsp if (err == NULL) {
296 13b2bc37 2022-10-23 stsp struct got_pack *pack = NULL;
298 13b2bc37 2022-10-23 stsp err = got_packidx_get_packfile_path(&path_packfile,
299 13b2bc37 2022-10-23 stsp packidx->path_packidx);
303 13b2bc37 2022-10-23 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
304 13b2bc37 2022-10-23 stsp if (pack == NULL) {
305 13b2bc37 2022-10-23 stsp err = got_repo_cache_pack(&pack, repo, path_packfile,
310 13b2bc37 2022-10-23 stsp err = read_packed_object_raw(&outbuf, &size, &hdrlen,
311 3a975a9f 2023-01-09 stsp tempfd, pack, packidx, idx, id);
314 13b2bc37 2022-10-23 stsp } else if (err->code == GOT_ERR_NO_OBJ) {
317 13b2bc37 2022-10-23 stsp err = got_object_open_loose_fd(&fd, id, repo);
320 13b2bc37 2022-10-23 stsp err = got_object_read_raw(&outbuf, &size, &hdrlen,
321 3a975a9f 2023-01-09 stsp GOT_DELTA_RESULT_SIZE_CACHED_MAX, tempfd, id, fd);
322 13b2bc37 2022-10-23 stsp if (close(fd) == -1 && err == NULL)
323 13b2bc37 2022-10-23 stsp err = got_error_from_errno("close");
328 3a975a9f 2023-01-09 stsp if (outbuf == NULL) {
329 3a975a9f 2023-01-09 stsp if (*outfd != -1) {
330 3a975a9f 2023-01-09 stsp err = got_error_msg(GOT_ERR_NOT_IMPL, "bad outfd");
335 3a975a9f 2023-01-09 stsp * Duplicate tempfile descriptor to allow use of
336 3a975a9f 2023-01-09 stsp * fdopen(3) inside got_object_raw_alloc().
338 3a975a9f 2023-01-09 stsp *outfd = dup(tempfd);
339 3a975a9f 2023-01-09 stsp if (*outfd == -1) {
340 3a975a9f 2023-01-09 stsp err = got_error_from_errno("dup");
345 60c140ae 2023-01-09 stsp err = got_object_raw_alloc(obj, outbuf, outfd,
346 60c140ae 2023-01-09 stsp GOT_DELTA_RESULT_SIZE_CACHED_MAX, hdrlen, size);
350 13b2bc37 2022-10-23 stsp err = got_repo_cache_raw_object(repo, id, *obj);
352 13b2bc37 2022-10-23 stsp if (err->code == GOT_ERR_OBJ_EXISTS ||
353 13b2bc37 2022-10-23 stsp err->code == GOT_ERR_OBJ_TOO_LARGE)
354 13b2bc37 2022-10-23 stsp err = NULL;
357 13b2bc37 2022-10-23 stsp free(path_packfile);
359 13b2bc37 2022-10-23 stsp if (*obj) {
360 13b2bc37 2022-10-23 stsp got_object_raw_close(*obj);
361 13b2bc37 2022-10-23 stsp *obj = NULL;
363 13b2bc37 2022-10-23 stsp free(outbuf);
364 3a975a9f 2023-01-09 stsp got_repo_temp_fds_put(tempfile_idx, repo);
365 3a975a9f 2023-01-09 stsp if (*outfd != -1) {
366 3a975a9f 2023-01-09 stsp close(*outfd);
367 3a975a9f 2023-01-09 stsp *outfd = -1;
370 3a975a9f 2023-01-09 stsp if (((*obj)->f == NULL && (*obj)->fd == -1)) {
371 3a975a9f 2023-01-09 stsp /* This raw object is not backed by a file. */
372 3a975a9f 2023-01-09 stsp got_repo_temp_fds_put(tempfile_idx, repo);
373 3a975a9f 2023-01-09 stsp if (*outfd != -1) {
374 3a975a9f 2023-01-09 stsp close(*outfd);
375 3a975a9f 2023-01-09 stsp *outfd = -1;
378 3a975a9f 2023-01-09 stsp (*obj)->tempfile_idx = tempfile_idx;
379 3a975a9f 2023-01-09 stsp (*obj)->close_cb = put_raw_object_tempfile;
380 3a975a9f 2023-01-09 stsp (*obj)->close_arg = repo;
383 13b2bc37 2022-10-23 stsp return err;
386 13b2bc37 2022-10-23 stsp static const struct got_error *
387 13b2bc37 2022-10-23 stsp open_commit(struct got_commit_object **commit,
388 13b2bc37 2022-10-23 stsp struct got_repository *repo, struct got_object_id *id, int check_cache)
390 13b2bc37 2022-10-23 stsp const struct got_error *err = NULL;
391 13b2bc37 2022-10-23 stsp struct got_packidx *packidx = NULL;
393 13b2bc37 2022-10-23 stsp char *path_packfile = NULL;
395 13b2bc37 2022-10-23 stsp if (check_cache) {
396 13b2bc37 2022-10-23 stsp *commit = got_repo_get_cached_commit(repo, id);
397 13b2bc37 2022-10-23 stsp if (*commit != NULL) {
398 13b2bc37 2022-10-23 stsp (*commit)->refcnt++;
399 13b2bc37 2022-10-23 stsp return NULL;
402 13b2bc37 2022-10-23 stsp *commit = NULL;
404 13b2bc37 2022-10-23 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
405 13b2bc37 2022-10-23 stsp if (err == NULL) {
406 13b2bc37 2022-10-23 stsp struct got_pack *pack = NULL;
407 13b2bc37 2022-10-23 stsp struct got_object *obj;
408 13b2bc37 2022-10-23 stsp uint8_t *buf;
409 13b2bc37 2022-10-23 stsp size_t len;
411 13b2bc37 2022-10-23 stsp err = got_packidx_get_packfile_path(&path_packfile,
412 13b2bc37 2022-10-23 stsp packidx->path_packidx);
414 13b2bc37 2022-10-23 stsp return err;
416 13b2bc37 2022-10-23 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
417 13b2bc37 2022-10-23 stsp if (pack == NULL) {
418 13b2bc37 2022-10-23 stsp err = got_repo_cache_pack(&pack, repo, path_packfile,
423 13b2bc37 2022-10-23 stsp err = got_packfile_open_object(&obj, pack, packidx, idx, id);
426 13b2bc37 2022-10-23 stsp err = got_packfile_extract_object_to_mem(&buf, &len,
427 13b2bc37 2022-10-23 stsp obj, pack);
428 13b2bc37 2022-10-23 stsp got_object_close(obj);
431 13b2bc37 2022-10-23 stsp err = got_object_parse_commit(commit, buf, len);
433 13b2bc37 2022-10-23 stsp } else if (err->code == GOT_ERR_NO_OBJ) {
436 13b2bc37 2022-10-23 stsp err = got_object_open_loose_fd(&fd, id, repo);
438 13b2bc37 2022-10-23 stsp return err;
439 13b2bc37 2022-10-23 stsp err = got_object_read_commit(commit, fd, id, 0);
440 13b2bc37 2022-10-23 stsp if (close(fd) == -1 && err == NULL)
441 13b2bc37 2022-10-23 stsp err = got_error_from_errno("close");
443 13b2bc37 2022-10-23 stsp return err;
446 13b2bc37 2022-10-23 stsp if (err == NULL) {
447 13b2bc37 2022-10-23 stsp (*commit)->refcnt++;
448 13b2bc37 2022-10-23 stsp err = got_repo_cache_commit(repo, id, *commit);
450 13b2bc37 2022-10-23 stsp if (err->code == GOT_ERR_OBJ_EXISTS ||
451 13b2bc37 2022-10-23 stsp err->code == GOT_ERR_OBJ_TOO_LARGE)
452 13b2bc37 2022-10-23 stsp err = NULL;
456 13b2bc37 2022-10-23 stsp free(path_packfile);
457 13b2bc37 2022-10-23 stsp return err;
460 13b2bc37 2022-10-23 stsp const struct got_error *
461 13b2bc37 2022-10-23 stsp got_object_open_as_commit(struct got_commit_object **commit,
462 13b2bc37 2022-10-23 stsp struct got_repository *repo, struct got_object_id *id)
464 13b2bc37 2022-10-23 stsp *commit = got_repo_get_cached_commit(repo, id);
465 13b2bc37 2022-10-23 stsp if (*commit != NULL) {
466 13b2bc37 2022-10-23 stsp (*commit)->refcnt++;
467 13b2bc37 2022-10-23 stsp return NULL;
470 13b2bc37 2022-10-23 stsp return open_commit(commit, repo, id, 0);
473 13b2bc37 2022-10-23 stsp const struct got_error *
474 13b2bc37 2022-10-23 stsp got_object_commit_open(struct got_commit_object **commit,
475 13b2bc37 2022-10-23 stsp struct got_repository *repo, struct got_object *obj)
477 13b2bc37 2022-10-23 stsp return open_commit(commit, repo, got_object_get_id(obj), 1);
480 13b2bc37 2022-10-23 stsp static const struct got_error *
481 13b2bc37 2022-10-23 stsp open_tree(struct got_tree_object **tree,
482 13b2bc37 2022-10-23 stsp struct got_repository *repo, struct got_object_id *id, int check_cache)
484 13b2bc37 2022-10-23 stsp const struct got_error *err = NULL;
485 13b2bc37 2022-10-23 stsp struct got_packidx *packidx = NULL;
487 13b2bc37 2022-10-23 stsp char *path_packfile = NULL;
488 13b2bc37 2022-10-23 stsp struct got_parsed_tree_entry *entries = NULL;
489 13b2bc37 2022-10-23 stsp size_t nentries = 0, nentries_alloc = 0, i;
490 13b2bc37 2022-10-23 stsp uint8_t *buf = NULL;
492 13b2bc37 2022-10-23 stsp if (check_cache) {
493 13b2bc37 2022-10-23 stsp *tree = got_repo_get_cached_tree(repo, id);
494 13b2bc37 2022-10-23 stsp if (*tree != NULL) {
495 13b2bc37 2022-10-23 stsp (*tree)->refcnt++;
496 13b2bc37 2022-10-23 stsp return NULL;
499 13b2bc37 2022-10-23 stsp *tree = NULL;
501 13b2bc37 2022-10-23 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
502 13b2bc37 2022-10-23 stsp if (err == NULL) {
503 13b2bc37 2022-10-23 stsp struct got_pack *pack = NULL;
504 13b2bc37 2022-10-23 stsp struct got_object *obj;
505 13b2bc37 2022-10-23 stsp size_t len;
507 13b2bc37 2022-10-23 stsp err = got_packidx_get_packfile_path(&path_packfile,
508 13b2bc37 2022-10-23 stsp packidx->path_packidx);
510 13b2bc37 2022-10-23 stsp return err;
512 13b2bc37 2022-10-23 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
513 13b2bc37 2022-10-23 stsp if (pack == NULL) {
514 13b2bc37 2022-10-23 stsp err = got_repo_cache_pack(&pack, repo, path_packfile,
519 13b2bc37 2022-10-23 stsp err = got_packfile_open_object(&obj, pack, packidx, idx, id);
522 13b2bc37 2022-10-23 stsp err = got_packfile_extract_object_to_mem(&buf, &len,
523 13b2bc37 2022-10-23 stsp obj, pack);
524 13b2bc37 2022-10-23 stsp got_object_close(obj);
527 13b2bc37 2022-10-23 stsp err = got_object_parse_tree(&entries, &nentries,
528 13b2bc37 2022-10-23 stsp &nentries_alloc, buf, len);
531 13b2bc37 2022-10-23 stsp } else if (err->code == GOT_ERR_NO_OBJ) {
534 13b2bc37 2022-10-23 stsp err = got_object_open_loose_fd(&fd, id, repo);
536 13b2bc37 2022-10-23 stsp return err;
537 13b2bc37 2022-10-23 stsp err = got_object_read_tree(&entries, &nentries,
538 13b2bc37 2022-10-23 stsp &nentries_alloc, &buf, fd, id);
539 13b2bc37 2022-10-23 stsp if (close(fd) == -1 && err == NULL)
540 13b2bc37 2022-10-23 stsp err = got_error_from_errno("close");
546 13b2bc37 2022-10-23 stsp *tree = malloc(sizeof(**tree));
547 13b2bc37 2022-10-23 stsp if (*tree == NULL) {
548 13b2bc37 2022-10-23 stsp err = got_error_from_errno("malloc");
551 13b2bc37 2022-10-23 stsp (*tree)->entries = calloc(nentries, sizeof(struct got_tree_entry));
552 13b2bc37 2022-10-23 stsp if ((*tree)->entries == NULL) {
553 13b2bc37 2022-10-23 stsp err = got_error_from_errno("malloc");
556 13b2bc37 2022-10-23 stsp (*tree)->nentries = nentries;
557 13b2bc37 2022-10-23 stsp (*tree)->refcnt = 0;
559 13b2bc37 2022-10-23 stsp for (i = 0; i < nentries; i++) {
560 13b2bc37 2022-10-23 stsp struct got_parsed_tree_entry *pe = &entries[i];
561 13b2bc37 2022-10-23 stsp struct got_tree_entry *te = &(*tree)->entries[i];
563 13b2bc37 2022-10-23 stsp if (strlcpy(te->name, pe->name,
564 13b2bc37 2022-10-23 stsp sizeof(te->name)) >= sizeof(te->name)) {
565 13b2bc37 2022-10-23 stsp err = got_error(GOT_ERR_NO_SPACE);
568 13b2bc37 2022-10-23 stsp memcpy(te->id.sha1, pe->id, SHA1_DIGEST_LENGTH);
569 13b2bc37 2022-10-23 stsp te->mode = pe->mode;
570 13b2bc37 2022-10-23 stsp te->idx = i;
573 13b2bc37 2022-10-23 stsp free(path_packfile);
574 13b2bc37 2022-10-23 stsp free(entries);
576 13b2bc37 2022-10-23 stsp if (err == NULL) {
577 13b2bc37 2022-10-23 stsp (*tree)->refcnt++;
578 13b2bc37 2022-10-23 stsp err = got_repo_cache_tree(repo, id, *tree);
580 13b2bc37 2022-10-23 stsp if (err->code == GOT_ERR_OBJ_EXISTS ||
581 13b2bc37 2022-10-23 stsp err->code == GOT_ERR_OBJ_TOO_LARGE)
582 13b2bc37 2022-10-23 stsp err = NULL;
587 13b2bc37 2022-10-23 stsp free((*tree)->entries);
588 13b2bc37 2022-10-23 stsp free(*tree);
589 13b2bc37 2022-10-23 stsp *tree = NULL;
591 13b2bc37 2022-10-23 stsp return err;
594 13b2bc37 2022-10-23 stsp const struct got_error *
595 13b2bc37 2022-10-23 stsp got_object_open_as_tree(struct got_tree_object **tree,
596 13b2bc37 2022-10-23 stsp struct got_repository *repo, struct got_object_id *id)
598 13b2bc37 2022-10-23 stsp *tree = got_repo_get_cached_tree(repo, id);
599 13b2bc37 2022-10-23 stsp if (*tree != NULL) {
600 13b2bc37 2022-10-23 stsp (*tree)->refcnt++;
601 13b2bc37 2022-10-23 stsp return NULL;
604 13b2bc37 2022-10-23 stsp return open_tree(tree, repo, id, 0);
607 13b2bc37 2022-10-23 stsp const struct got_error *
608 13b2bc37 2022-10-23 stsp got_object_tree_open(struct got_tree_object **tree,
609 13b2bc37 2022-10-23 stsp struct got_repository *repo, struct got_object *obj)
611 13b2bc37 2022-10-23 stsp return open_tree(tree, repo, got_object_get_id(obj), 1);
614 05fd3169 2024-03-19 stsp static const struct got_error *
615 05fd3169 2024-03-19 stsp read_packed_blob(uint8_t **outbuf, size_t *size, size_t *hdrlen,
616 05fd3169 2024-03-19 stsp int outfd, struct got_pack *pack, struct got_packidx *packidx, int idx,
617 05fd3169 2024-03-19 stsp struct got_object_id *id, struct got_repository *repo)
619 05fd3169 2024-03-19 stsp const struct got_error *err = NULL;
620 05fd3169 2024-03-19 stsp struct got_object *obj;
621 05fd3169 2024-03-19 stsp FILE *outfile = NULL, *basefile = NULL, *accumfile = NULL;
622 05fd3169 2024-03-19 stsp uint64_t blob_size;
624 05fd3169 2024-03-19 stsp *hdrlen = 0;
626 05fd3169 2024-03-19 stsp err = got_object_open_from_packfile(&obj, id, pack, packidx, idx,
629 05fd3169 2024-03-19 stsp return err;
631 05fd3169 2024-03-19 stsp if (obj->flags & GOT_OBJ_FLAG_DELTIFIED) {
632 05fd3169 2024-03-19 stsp err = got_pack_get_max_delta_object_size(&blob_size, obj,
637 05fd3169 2024-03-19 stsp blob_size = obj->size;
639 05fd3169 2024-03-19 stsp if (blob_size <= GOT_DELTA_RESULT_SIZE_CACHED_MAX) {
640 05fd3169 2024-03-19 stsp err = got_packfile_extract_object_to_mem(outbuf, size,
641 05fd3169 2024-03-19 stsp obj, pack);
644 05fd3169 2024-03-19 stsp * XXX This uses 3 file extra descriptors for no good reason.
645 05fd3169 2024-03-19 stsp * We should have got_packfile_extract_object_to_fd().
647 05fd3169 2024-03-19 stsp err = wrap_fd(&outfile, outfd);
650 05fd3169 2024-03-19 stsp err = wrap_fd(&basefile, pack->basefd);
653 05fd3169 2024-03-19 stsp err = wrap_fd(&accumfile, pack->accumfd);
656 05fd3169 2024-03-19 stsp err = got_packfile_extract_object(pack, obj, outfile, basefile,
657 05fd3169 2024-03-19 stsp accumfile);
660 05fd3169 2024-03-19 stsp *size = obj->size;
663 05fd3169 2024-03-19 stsp /* XXX verify checksum? */
665 05fd3169 2024-03-19 stsp got_object_close(obj);
666 05fd3169 2024-03-19 stsp if (outfile && fclose(outfile) == EOF && err == NULL)
667 05fd3169 2024-03-19 stsp err = got_error_from_errno("fclose");
668 05fd3169 2024-03-19 stsp if (basefile && fclose(basefile) == EOF && err == NULL)
669 05fd3169 2024-03-19 stsp err = got_error_from_errno("fclose");
670 05fd3169 2024-03-19 stsp if (accumfile && fclose(accumfile) == EOF && err == NULL)
671 05fd3169 2024-03-19 stsp err = got_error_from_errno("fclose");
672 05fd3169 2024-03-19 stsp return err;
675 05fd3169 2024-03-19 stsp static const struct got_error *
676 05fd3169 2024-03-19 stsp read_blob(uint8_t **outbuf, size_t *size, size_t *hdrlen, int outfd, int infd,
677 05fd3169 2024-03-19 stsp struct got_object_id *id, struct got_repository *repo)
679 05fd3169 2024-03-19 stsp const struct got_error *err = NULL;
680 05fd3169 2024-03-19 stsp struct got_object *obj = NULL;
681 05fd3169 2024-03-19 stsp FILE *f = NULL;
682 05fd3169 2024-03-19 stsp struct got_object_id expected_id;
683 05fd3169 2024-03-19 stsp struct got_inflate_checksum csum;
684 05fd3169 2024-03-19 stsp struct got_hash ctx;
686 05fd3169 2024-03-19 stsp got_hash_init(&ctx, GOT_HASH_SHA1);
687 05fd3169 2024-03-19 stsp memset(&csum, 0, sizeof(csum));
688 05fd3169 2024-03-19 stsp csum.output_ctx = &ctx;
690 05fd3169 2024-03-19 stsp memcpy(&expected_id, id, sizeof(expected_id));
692 05fd3169 2024-03-19 stsp err = got_object_read_header(&obj, infd);
696 05fd3169 2024-03-19 stsp if (lseek(infd, SEEK_SET, 0) == -1) {
697 05fd3169 2024-03-19 stsp err = got_error_from_errno("lseek");
701 05fd3169 2024-03-19 stsp f = fdopen(infd, "rb");
702 05fd3169 2024-03-19 stsp if (f == NULL) {
703 05fd3169 2024-03-19 stsp err = got_error_from_errno("fdopen");
708 05fd3169 2024-03-19 stsp if (obj->size + obj->hdrlen <= GOT_DELTA_RESULT_SIZE_CACHED_MAX) {
709 05fd3169 2024-03-19 stsp err = got_inflate_to_mem(outbuf, size, NULL, &csum, f);
713 05fd3169 2024-03-19 stsp err = got_inflate_to_fd(size, f, &csum, outfd);
718 05fd3169 2024-03-19 stsp if (*size < obj->hdrlen) {
719 05fd3169 2024-03-19 stsp err = got_error(GOT_ERR_BAD_OBJ_HDR);
723 05fd3169 2024-03-19 stsp *hdrlen = obj->hdrlen;
725 05fd3169 2024-03-19 stsp got_hash_final_object_id(&ctx, id);
726 05fd3169 2024-03-19 stsp if (got_object_id_cmp(&expected_id, id) != 0) {
727 05fd3169 2024-03-19 stsp err = got_error_checksum(&expected_id);
731 05fd3169 2024-03-19 stsp if (f && fclose(f) == EOF && err == NULL)
732 05fd3169 2024-03-19 stsp err = got_error_from_errno("fclose");
733 05fd3169 2024-03-19 stsp if (infd != -1 && close(infd) == -1 && err == NULL)
734 05fd3169 2024-03-19 stsp err = got_error_from_errno("close");
736 05fd3169 2024-03-19 stsp return err;
739 05fd3169 2024-03-19 stsp static const struct got_error *
740 05fd3169 2024-03-19 stsp open_blob(struct got_blob_object **blob, struct got_repository *repo,
741 05fd3169 2024-03-19 stsp struct got_object_id *id, size_t blocksize, int outfd)
743 05fd3169 2024-03-19 stsp const struct got_error *err = NULL;
744 05fd3169 2024-03-19 stsp struct got_packidx *packidx = NULL;
745 05fd3169 2024-03-19 stsp int idx, dfd = -1;
746 05fd3169 2024-03-19 stsp char *path_packfile = NULL;
747 05fd3169 2024-03-19 stsp uint8_t *outbuf;
748 05fd3169 2024-03-19 stsp size_t size, hdrlen;
749 05fd3169 2024-03-19 stsp struct stat sb;
751 05fd3169 2024-03-19 stsp *blob = calloc(1, sizeof(**blob));
752 05fd3169 2024-03-19 stsp if (*blob == NULL)
753 05fd3169 2024-03-19 stsp return got_error_from_errno("calloc");
755 05fd3169 2024-03-19 stsp (*blob)->read_buf = malloc(blocksize);
756 05fd3169 2024-03-19 stsp if ((*blob)->read_buf == NULL) {
757 05fd3169 2024-03-19 stsp err = got_error_from_errno("malloc");
761 05fd3169 2024-03-19 stsp if (ftruncate(outfd, 0L) == -1) {
762 05fd3169 2024-03-19 stsp err = got_error_from_errno("ftruncate");
765 05fd3169 2024-03-19 stsp if (lseek(outfd, SEEK_SET, 0) == -1) {
766 05fd3169 2024-03-19 stsp err = got_error_from_errno("lseek");
770 05fd3169 2024-03-19 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
771 05fd3169 2024-03-19 stsp if (err == NULL) {
772 05fd3169 2024-03-19 stsp struct got_pack *pack = NULL;
774 05fd3169 2024-03-19 stsp err = got_packidx_get_packfile_path(&path_packfile,
775 05fd3169 2024-03-19 stsp packidx->path_packidx);
779 05fd3169 2024-03-19 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
780 05fd3169 2024-03-19 stsp if (pack == NULL) {
781 05fd3169 2024-03-19 stsp err = got_repo_cache_pack(&pack, repo, path_packfile,
786 05fd3169 2024-03-19 stsp err = read_packed_blob(&outbuf, &size, &hdrlen, outfd,
787 05fd3169 2024-03-19 stsp pack, packidx, idx, id, repo);
788 05fd3169 2024-03-19 stsp } else if (err->code == GOT_ERR_NO_OBJ) {
791 05fd3169 2024-03-19 stsp err = got_object_open_loose_fd(&infd, id, repo);
794 05fd3169 2024-03-19 stsp err = read_blob(&outbuf, &size, &hdrlen, outfd, infd,
800 05fd3169 2024-03-19 stsp if (hdrlen > size) {
801 05fd3169 2024-03-19 stsp err = got_error(GOT_ERR_BAD_OBJ_HDR);
805 05fd3169 2024-03-19 stsp if (outbuf) {
806 05fd3169 2024-03-19 stsp (*blob)->f = fmemopen(outbuf, size, "rb");
807 05fd3169 2024-03-19 stsp if ((*blob)->f == NULL) {
808 05fd3169 2024-03-19 stsp err = got_error_from_errno("fmemopen");
809 05fd3169 2024-03-19 stsp free(outbuf);
812 05fd3169 2024-03-19 stsp (*blob)->data = outbuf;
814 05fd3169 2024-03-19 stsp if (fstat(outfd, &sb) == -1) {
815 05fd3169 2024-03-19 stsp err = got_error_from_errno("fstat");
819 05fd3169 2024-03-19 stsp if (sb.st_size != size) {
820 05fd3169 2024-03-19 stsp err = got_error(GOT_ERR_PRIVSEP_LEN);
824 05fd3169 2024-03-19 stsp dfd = dup(outfd);
825 05fd3169 2024-03-19 stsp if (dfd == -1) {
826 05fd3169 2024-03-19 stsp err = got_error_from_errno("dup");
830 05fd3169 2024-03-19 stsp (*blob)->f = fdopen(dfd, "rb");
831 05fd3169 2024-03-19 stsp if ((*blob)->f == NULL) {
832 05fd3169 2024-03-19 stsp err = got_error_from_errno("fdopen");
833 05fd3169 2024-03-19 stsp close(dfd);
839 05fd3169 2024-03-19 stsp (*blob)->hdrlen = hdrlen;
840 05fd3169 2024-03-19 stsp (*blob)->blocksize = blocksize;
841 05fd3169 2024-03-19 stsp memcpy(&(*blob)->id, id, sizeof(*id));
844 05fd3169 2024-03-19 stsp free(path_packfile);
846 05fd3169 2024-03-19 stsp if (*blob) {
847 05fd3169 2024-03-19 stsp got_object_blob_close(*blob);
848 05fd3169 2024-03-19 stsp *blob = NULL;
851 05fd3169 2024-03-19 stsp return err;
854 13b2bc37 2022-10-23 stsp const struct got_error *
855 13b2bc37 2022-10-23 stsp got_object_open_as_blob(struct got_blob_object **blob,
856 13b2bc37 2022-10-23 stsp struct got_repository *repo, struct got_object_id *id, size_t blocksize,
859 05fd3169 2024-03-19 stsp return open_blob(blob, repo, id, blocksize, outfd);
862 13b2bc37 2022-10-23 stsp const struct got_error *
863 13b2bc37 2022-10-23 stsp got_object_blob_open(struct got_blob_object **blob,
864 13b2bc37 2022-10-23 stsp struct got_repository *repo, struct got_object *obj, size_t blocksize,
867 05fd3169 2024-03-19 stsp return open_blob(blob, repo, got_object_get_id(obj), blocksize, outfd);
870 13b2bc37 2022-10-23 stsp static const struct got_error *
871 13b2bc37 2022-10-23 stsp open_tag(struct got_tag_object **tag, struct got_repository *repo,
872 13b2bc37 2022-10-23 stsp struct got_object_id *id, int check_cache)
874 13b2bc37 2022-10-23 stsp const struct got_error *err = NULL;
875 13b2bc37 2022-10-23 stsp struct got_packidx *packidx = NULL;
877 13b2bc37 2022-10-23 stsp char *path_packfile = NULL;
878 13b2bc37 2022-10-23 stsp struct got_object *obj = NULL;
879 13b2bc37 2022-10-23 stsp int obj_type = GOT_OBJ_TYPE_ANY;
881 13b2bc37 2022-10-23 stsp if (check_cache) {
882 13b2bc37 2022-10-23 stsp *tag = got_repo_get_cached_tag(repo, id);
883 13b2bc37 2022-10-23 stsp if (*tag != NULL) {
884 13b2bc37 2022-10-23 stsp (*tag)->refcnt++;
885 13b2bc37 2022-10-23 stsp return NULL;
888 13b2bc37 2022-10-23 stsp *tag = NULL;
890 13b2bc37 2022-10-23 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
891 13b2bc37 2022-10-23 stsp if (err == NULL) {
892 13b2bc37 2022-10-23 stsp struct got_pack *pack = NULL;
893 13b2bc37 2022-10-23 stsp uint8_t *buf = NULL;
894 13b2bc37 2022-10-23 stsp size_t len;
896 13b2bc37 2022-10-23 stsp err = got_packidx_get_packfile_path(&path_packfile,
897 13b2bc37 2022-10-23 stsp packidx->path_packidx);
899 13b2bc37 2022-10-23 stsp return err;
901 13b2bc37 2022-10-23 stsp pack = got_repo_get_cached_pack(repo, path_packfile);
902 13b2bc37 2022-10-23 stsp if (pack == NULL) {
903 13b2bc37 2022-10-23 stsp err = got_repo_cache_pack(&pack, repo, path_packfile,
909 13b2bc37 2022-10-23 stsp /* Beware of "lightweight" tags: Check object type first. */
910 13b2bc37 2022-10-23 stsp err = got_packfile_open_object(&obj, pack, packidx, idx, id);
913 13b2bc37 2022-10-23 stsp obj_type = obj->type;
914 13b2bc37 2022-10-23 stsp if (obj_type != GOT_OBJ_TYPE_TAG) {
915 13b2bc37 2022-10-23 stsp err = got_error(GOT_ERR_OBJ_TYPE);
916 13b2bc37 2022-10-23 stsp got_object_close(obj);
919 13b2bc37 2022-10-23 stsp err = got_packfile_extract_object_to_mem(&buf, &len,
920 13b2bc37 2022-10-23 stsp obj, pack);
921 13b2bc37 2022-10-23 stsp got_object_close(obj);
924 13b2bc37 2022-10-23 stsp err = got_object_parse_tag(tag, buf, len);
926 13b2bc37 2022-10-23 stsp } else if (err->code == GOT_ERR_NO_OBJ) {
929 13b2bc37 2022-10-23 stsp err = got_object_open_loose_fd(&fd, id, repo);
931 13b2bc37 2022-10-23 stsp return err;
932 13b2bc37 2022-10-23 stsp err = got_object_read_header(&obj, fd);
933 13b2bc37 2022-10-23 stsp if (close(fd) == -1 && err == NULL)
934 13b2bc37 2022-10-23 stsp err = got_error_from_errno("close");
936 13b2bc37 2022-10-23 stsp return err;
937 13b2bc37 2022-10-23 stsp obj_type = obj->type;
938 13b2bc37 2022-10-23 stsp got_object_close(obj);
939 13b2bc37 2022-10-23 stsp if (obj_type != GOT_OBJ_TYPE_TAG)
940 13b2bc37 2022-10-23 stsp return got_error(GOT_ERR_OBJ_TYPE);
942 13b2bc37 2022-10-23 stsp err = got_object_open_loose_fd(&fd, id, repo);
944 13b2bc37 2022-10-23 stsp return err;
945 13b2bc37 2022-10-23 stsp err = got_object_read_tag(tag, fd, id, 0);
946 13b2bc37 2022-10-23 stsp if (close(fd) == -1 && err == NULL)
947 13b2bc37 2022-10-23 stsp err = got_error_from_errno("close");
949 13b2bc37 2022-10-23 stsp return err;
952 13b2bc37 2022-10-23 stsp if (err == NULL) {
953 13b2bc37 2022-10-23 stsp (*tag)->refcnt++;
954 13b2bc37 2022-10-23 stsp err = got_repo_cache_tag(repo, id, *tag);
956 13b2bc37 2022-10-23 stsp if (err->code == GOT_ERR_OBJ_EXISTS ||
957 13b2bc37 2022-10-23 stsp err->code == GOT_ERR_OBJ_TOO_LARGE)
958 13b2bc37 2022-10-23 stsp err = NULL;
962 13b2bc37 2022-10-23 stsp free(path_packfile);
963 13b2bc37 2022-10-23 stsp return err;
966 13b2bc37 2022-10-23 stsp const struct got_error *
967 13b2bc37 2022-10-23 stsp got_object_open_as_tag(struct got_tag_object **tag,
968 13b2bc37 2022-10-23 stsp struct got_repository *repo, struct got_object_id *id)
970 13b2bc37 2022-10-23 stsp *tag = got_repo_get_cached_tag(repo, id);
971 13b2bc37 2022-10-23 stsp if (*tag != NULL) {
972 13b2bc37 2022-10-23 stsp (*tag)->refcnt++;
973 13b2bc37 2022-10-23 stsp return NULL;
976 13b2bc37 2022-10-23 stsp return open_tag(tag, repo, id, 0);
979 13b2bc37 2022-10-23 stsp const struct got_error *
980 13b2bc37 2022-10-23 stsp got_object_tag_open(struct got_tag_object **tag,
981 13b2bc37 2022-10-23 stsp struct got_repository *repo, struct got_object *obj)
983 13b2bc37 2022-10-23 stsp return open_tag(tag, repo, got_object_get_id(obj), 1);