2 0a0a3048 2018-01-10 stsp * Copyright (c) 2018 Stefan Sperling <stsp@openbsd.org>
4 0a0a3048 2018-01-10 stsp * Permission to use, copy, modify, and distribute this software for any
5 0a0a3048 2018-01-10 stsp * purpose with or without fee is hereby granted, provided that the above
6 0a0a3048 2018-01-10 stsp * copyright notice and this permission notice appear in all copies.
8 0a0a3048 2018-01-10 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 0a0a3048 2018-01-10 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 0a0a3048 2018-01-10 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 0a0a3048 2018-01-10 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 0a0a3048 2018-01-10 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 0a0a3048 2018-01-10 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 0a0a3048 2018-01-10 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 a1fd68d8 2018-01-12 stsp #include <sys/types.h>
18 0a0a3048 2018-01-10 stsp #include <sys/stat.h>
19 a1fd68d8 2018-01-12 stsp #include <sys/queue.h>
21 a1fd68d8 2018-01-12 stsp #include <dirent.h>
22 7e656b93 2018-03-17 stsp #include <fcntl.h>
23 a1fd68d8 2018-01-12 stsp #include <errno.h>
24 0a0a3048 2018-01-10 stsp #include <stdio.h>
25 a1fd68d8 2018-01-12 stsp #include <stdint.h>
26 0a0a3048 2018-01-10 stsp #include <stdlib.h>
27 0a0a3048 2018-01-10 stsp #include <string.h>
28 0a0a3048 2018-01-10 stsp #include <limits.h>
29 0a0a3048 2018-01-10 stsp #include <sha1.h>
30 0a0a3048 2018-01-10 stsp #include <endian.h>
31 a1fd68d8 2018-01-12 stsp #include <zlib.h>
33 0a0a3048 2018-01-10 stsp #include "got_error.h"
34 a1fd68d8 2018-01-12 stsp #include "got_object.h"
35 a1fd68d8 2018-01-12 stsp #include "got_repository.h"
37 718b3ab0 2018-03-17 stsp #include "got_lib_sha1.h"
38 718b3ab0 2018-03-17 stsp #include "got_lib_pack.h"
39 718b3ab0 2018-03-17 stsp #include "got_lib_path.h"
40 718b3ab0 2018-03-17 stsp #include "got_lib_delta.h"
41 718b3ab0 2018-03-17 stsp #include "got_lib_zbuf.h"
42 718b3ab0 2018-03-17 stsp #include "got_lib_object.h"
43 718b3ab0 2018-03-17 stsp #include "got_lib_repository.h"
45 79b11c62 2018-03-09 stsp #ifndef nitems
46 79b11c62 2018-03-09 stsp #define nitems(_a) (sizeof(_a) / sizeof((_a)[0]))
49 a1fd68d8 2018-01-12 stsp #define GOT_PACK_PREFIX "pack-"
50 a1fd68d8 2018-01-12 stsp #define GOT_PACKFILE_SUFFIX ".pack"
51 a1fd68d8 2018-01-12 stsp #define GOT_PACKIDX_SUFFIX ".idx"
52 a1fd68d8 2018-01-12 stsp #define GOT_PACKFILE_NAMELEN (strlen(GOT_PACK_PREFIX) + \
53 a1fd68d8 2018-01-12 stsp SHA1_DIGEST_STRING_LENGTH - 1 + \
54 a1fd68d8 2018-01-12 stsp strlen(GOT_PACKFILE_SUFFIX))
55 a1fd68d8 2018-01-12 stsp #define GOT_PACKIDX_NAMELEN (strlen(GOT_PACK_PREFIX) + \
56 a1fd68d8 2018-01-12 stsp SHA1_DIGEST_STRING_LENGTH - 1 + \
57 a1fd68d8 2018-01-12 stsp strlen(GOT_PACKIDX_SUFFIX))
60 a1fd68d8 2018-01-12 stsp #define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
63 0a0a3048 2018-01-10 stsp static const struct got_error *
64 0a0a3048 2018-01-10 stsp verify_fanout_table(uint32_t *fanout_table)
68 0a0a3048 2018-01-10 stsp for (i = 0; i < 0xff - 1; i++) {
69 a1fd68d8 2018-01-12 stsp if (be32toh(fanout_table[i]) > be32toh(fanout_table[i + 1]))
70 0a0a3048 2018-01-10 stsp return got_error(GOT_ERR_BAD_PACKIDX);
73 0a0a3048 2018-01-10 stsp return NULL;
76 24541888 2018-01-10 stsp static const struct got_error *
77 0a0a3048 2018-01-10 stsp get_packfile_size(size_t *size, const char *path_idx)
79 0a0a3048 2018-01-10 stsp struct stat sb;
80 0a0a3048 2018-01-10 stsp char *path_pack;
81 0a0a3048 2018-01-10 stsp char base_path[PATH_MAX];
84 0a0a3048 2018-01-10 stsp if (strlcpy(base_path, path_idx, PATH_MAX) > PATH_MAX)
85 0a0a3048 2018-01-10 stsp return got_error(GOT_ERR_NO_SPACE);
87 0a0a3048 2018-01-10 stsp dot = strrchr(base_path, '.');
88 0a0a3048 2018-01-10 stsp if (dot == NULL)
89 0a0a3048 2018-01-10 stsp return got_error(GOT_ERR_BAD_PATH);
90 0a0a3048 2018-01-10 stsp *dot = '\0';
91 0a0a3048 2018-01-10 stsp if (asprintf(&path_pack, "%s.pack", base_path) == -1)
92 0a585a0d 2018-03-17 stsp return got_error_from_errno();
94 0a0a3048 2018-01-10 stsp if (stat(path_pack, &sb) != 0) {
95 0a0a3048 2018-01-10 stsp free(path_pack);
96 8251fdbc 2018-01-12 stsp return got_error_from_errno();
99 0a0a3048 2018-01-10 stsp free(path_pack);
100 0a0a3048 2018-01-10 stsp *size = sb.st_size;
104 0a0a3048 2018-01-10 stsp const struct got_error *
105 0a0a3048 2018-01-10 stsp got_packidx_open(struct got_packidx_v2_hdr **packidx, const char *path)
107 0a0a3048 2018-01-10 stsp struct got_packidx_v2_hdr *p;
109 0a0a3048 2018-01-10 stsp const struct got_error *err = NULL;
110 0a0a3048 2018-01-10 stsp size_t n, nobj, packfile_size;
111 0ebaf008 2018-01-10 stsp SHA1_CTX ctx;
112 0ebaf008 2018-01-10 stsp uint8_t sha1[SHA1_DIGEST_LENGTH];
114 0ebaf008 2018-01-10 stsp SHA1Init(&ctx);
116 0a0a3048 2018-01-10 stsp f = fopen(path, "rb");
117 0a0a3048 2018-01-10 stsp if (f == NULL)
118 9feb4ff2 2018-03-14 stsp return got_error_from_errno();
120 0a0a3048 2018-01-10 stsp err = get_packfile_size(&packfile_size, path);
122 0a0a3048 2018-01-10 stsp return err;
124 0a0a3048 2018-01-10 stsp p = calloc(1, sizeof(*p));
125 0a0a3048 2018-01-10 stsp if (p == NULL) {
126 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
130 0a0a3048 2018-01-10 stsp n = fread(&p->magic, sizeof(p->magic), 1, f);
131 0a0a3048 2018-01-10 stsp if (n != 1) {
132 8251fdbc 2018-01-12 stsp err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
136 0a0a3048 2018-01-10 stsp if (betoh32(p->magic) != GOT_PACKIDX_V2_MAGIC) {
137 0a0a3048 2018-01-10 stsp err = got_error(GOT_ERR_BAD_PACKIDX);
141 0ebaf008 2018-01-10 stsp SHA1Update(&ctx, (uint8_t *)&p->magic, sizeof(p->magic));
143 0a0a3048 2018-01-10 stsp n = fread(&p->version, sizeof(p->version), 1, f);
144 0a0a3048 2018-01-10 stsp if (n != 1) {
145 8251fdbc 2018-01-12 stsp err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
149 0a0a3048 2018-01-10 stsp if (betoh32(p->version) != GOT_PACKIDX_VERSION) {
150 0a0a3048 2018-01-10 stsp err = got_error(GOT_ERR_BAD_PACKIDX);
154 0ebaf008 2018-01-10 stsp SHA1Update(&ctx, (uint8_t *)&p->version, sizeof(p->version));
156 0a0a3048 2018-01-10 stsp n = fread(&p->fanout_table, sizeof(p->fanout_table), 1, f);
157 0a0a3048 2018-01-10 stsp if (n != 1) {
158 8251fdbc 2018-01-12 stsp err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
162 0a0a3048 2018-01-10 stsp err = verify_fanout_table(p->fanout_table);
166 0ebaf008 2018-01-10 stsp SHA1Update(&ctx, (uint8_t *)p->fanout_table, sizeof(p->fanout_table));
168 0a0a3048 2018-01-10 stsp nobj = betoh32(p->fanout_table[0xff]);
170 0a0a3048 2018-01-10 stsp p->sorted_ids = calloc(nobj, sizeof(*p->sorted_ids));
171 0a0a3048 2018-01-10 stsp if (p->sorted_ids == NULL) {
172 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
176 0a0a3048 2018-01-10 stsp n = fread(p->sorted_ids, sizeof(*p->sorted_ids), nobj, f);
177 0a0a3048 2018-01-10 stsp if (n != nobj) {
178 8251fdbc 2018-01-12 stsp err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
182 0ebaf008 2018-01-10 stsp SHA1Update(&ctx, (uint8_t *)p->sorted_ids,
183 0ebaf008 2018-01-10 stsp nobj * sizeof(*p->sorted_ids));
185 a1fd68d8 2018-01-12 stsp p->crc32 = calloc(nobj, sizeof(*p->crc32));
186 a1fd68d8 2018-01-12 stsp if (p->crc32 == NULL) {
187 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
191 a1fd68d8 2018-01-12 stsp n = fread(p->crc32, sizeof(*p->crc32), nobj, f);
192 0a0a3048 2018-01-10 stsp if (n != nobj) {
193 8251fdbc 2018-01-12 stsp err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
197 a1fd68d8 2018-01-12 stsp SHA1Update(&ctx, (uint8_t *)p->crc32, nobj * sizeof(*p->crc32));
199 a1fd68d8 2018-01-12 stsp p->offsets = calloc(nobj, sizeof(*p->offsets));
200 a1fd68d8 2018-01-12 stsp if (p->offsets == NULL) {
201 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
205 a1fd68d8 2018-01-12 stsp n = fread(p->offsets, sizeof(*p->offsets), nobj, f);
206 0a0a3048 2018-01-10 stsp if (n != nobj) {
207 8251fdbc 2018-01-12 stsp err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
211 a1fd68d8 2018-01-12 stsp SHA1Update(&ctx, (uint8_t *)p->offsets, nobj * sizeof(*p->offsets));
213 0a0a3048 2018-01-10 stsp /* Large file offsets are contained only in files > 2GB. */
214 b0517dd0 2018-01-10 stsp if (packfile_size <= 0x80000000)
215 0a0a3048 2018-01-10 stsp goto checksum;
217 0a0a3048 2018-01-10 stsp p->large_offsets = calloc(nobj, sizeof(*p->large_offsets));
218 0a0a3048 2018-01-10 stsp if (p->large_offsets == NULL) {
219 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
223 0a0a3048 2018-01-10 stsp n = fread(p->large_offsets, sizeof(*p->large_offsets), nobj, f);
224 0a0a3048 2018-01-10 stsp if (n != nobj) {
225 8251fdbc 2018-01-12 stsp err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
229 0ebaf008 2018-01-10 stsp SHA1Update(&ctx, (uint8_t*)p->large_offsets,
230 0ebaf008 2018-01-10 stsp nobj * sizeof(*p->large_offsets));
233 0a0a3048 2018-01-10 stsp n = fread(&p->trailer, sizeof(p->trailer), 1, f);
234 0a0a3048 2018-01-10 stsp if (n != 1) {
235 8251fdbc 2018-01-12 stsp err = got_ferror(f, GOT_ERR_BAD_PACKIDX);
239 a1fd68d8 2018-01-12 stsp SHA1Update(&ctx, p->trailer.packfile_sha1, SHA1_DIGEST_LENGTH);
240 0ebaf008 2018-01-10 stsp SHA1Final(sha1, &ctx);
241 a1fd68d8 2018-01-12 stsp if (memcmp(p->trailer.packidx_sha1, sha1, SHA1_DIGEST_LENGTH) != 0)
242 0ebaf008 2018-01-10 stsp err = got_error(GOT_ERR_PACKIDX_CSUM);
246 0a0a3048 2018-01-10 stsp got_packidx_close(p);
248 0a0a3048 2018-01-10 stsp *packidx = p;
249 0a0a3048 2018-01-10 stsp return err;
253 0a0a3048 2018-01-10 stsp got_packidx_close(struct got_packidx_v2_hdr *packidx)
255 0a0a3048 2018-01-10 stsp free(packidx->sorted_ids);
256 0a0a3048 2018-01-10 stsp free(packidx->offsets);
257 0a0a3048 2018-01-10 stsp free(packidx->crc32);
258 0a0a3048 2018-01-10 stsp free(packidx->large_offsets);
259 0a0a3048 2018-01-10 stsp free(packidx);
263 a1fd68d8 2018-01-12 stsp is_packidx_filename(const char *name, size_t len)
265 a1fd68d8 2018-01-12 stsp if (len != GOT_PACKIDX_NAMELEN)
268 a1fd68d8 2018-01-12 stsp if (strncmp(name, GOT_PACK_PREFIX, strlen(GOT_PACK_PREFIX)) != 0)
271 a1fd68d8 2018-01-12 stsp if (strcmp(name + strlen(GOT_PACK_PREFIX) +
272 a1fd68d8 2018-01-12 stsp SHA1_DIGEST_STRING_LENGTH - 1, GOT_PACKIDX_SUFFIX) != 0)
278 a1fd68d8 2018-01-12 stsp static off_t
279 a1fd68d8 2018-01-12 stsp get_object_offset(struct got_packidx_v2_hdr *packidx, int idx)
281 a1fd68d8 2018-01-12 stsp uint32_t totobj = betoh32(packidx->fanout_table[0xff]);
282 a1fd68d8 2018-01-12 stsp uint32_t offset = betoh32(packidx->offsets[idx]);
283 a1fd68d8 2018-01-12 stsp if (offset & GOT_PACKIDX_OFFSET_VAL_IS_LARGE_IDX) {
284 a1fd68d8 2018-01-12 stsp uint64_t loffset;
285 a1fd68d8 2018-01-12 stsp idx = offset & GOT_PACKIDX_OFFSET_VAL_MASK;
286 a1fd68d8 2018-01-12 stsp if (idx < 0 || idx > totobj || packidx->large_offsets == NULL)
288 a1fd68d8 2018-01-12 stsp loffset = betoh64(packidx->large_offsets[idx]);
289 a1fd68d8 2018-01-12 stsp return (loffset > INT64_MAX ? -1 : (off_t)loffset);
291 a1fd68d8 2018-01-12 stsp return (off_t)(offset & GOT_PACKIDX_OFFSET_VAL_MASK);
294 72eb3431 2018-04-01 stsp static const struct got_error *
295 72eb3431 2018-04-01 stsp get_packfile_path(char **path_packfile, struct got_repository *repo,
296 72eb3431 2018-04-01 stsp struct got_packidx_v2_hdr *packidx);
299 72eb3431 2018-04-01 stsp get_object_idx(struct got_packidx_v2_hdr *packidx, struct got_object_id *id, struct got_repository *repo)
301 a1fd68d8 2018-01-12 stsp u_int8_t id0 = id->sha1[0];
302 a1fd68d8 2018-01-12 stsp uint32_t totobj = betoh32(packidx->fanout_table[0xff]);
305 a1fd68d8 2018-01-12 stsp if (id0 > 0)
306 a1fd68d8 2018-01-12 stsp i = betoh32(packidx->fanout_table[id0 - 1]);
308 a1fd68d8 2018-01-12 stsp while (i < totobj) {
309 6c00b545 2018-01-17 stsp struct got_object_id *oid = &packidx->sorted_ids[i];
310 2b2ca9f0 2018-01-13 stsp int cmp = got_object_id_cmp(id, oid);
312 16dcbf91 2018-04-01 stsp if (cmp == 0)
320 79b11c62 2018-03-09 stsp static struct got_packidx_v2_hdr *
321 79b11c62 2018-03-09 stsp dup_packidx(struct got_packidx_v2_hdr *packidx)
323 79b11c62 2018-03-09 stsp struct got_packidx_v2_hdr *p;
324 79b11c62 2018-03-09 stsp size_t nobj;
326 79b11c62 2018-03-09 stsp p = calloc(1, sizeof(*p));
327 79b11c62 2018-03-09 stsp if (p == NULL)
328 79b11c62 2018-03-09 stsp return NULL;
330 79b11c62 2018-03-09 stsp memcpy(p, packidx, sizeof(*p));
331 79b11c62 2018-03-09 stsp p->sorted_ids = NULL;
332 79b11c62 2018-03-09 stsp p->crc32 = NULL;
333 79b11c62 2018-03-09 stsp p->offsets = NULL;
334 79b11c62 2018-03-09 stsp p->large_offsets = NULL;
336 79b11c62 2018-03-09 stsp nobj = betoh32(p->fanout_table[0xff]);
338 79b11c62 2018-03-09 stsp p->sorted_ids = calloc(nobj, sizeof(*p->sorted_ids));
339 79b11c62 2018-03-09 stsp if (p->sorted_ids == NULL)
341 79b11c62 2018-03-09 stsp memcpy(p->sorted_ids, packidx->sorted_ids, nobj * sizeof(*p->sorted_ids));
343 79b11c62 2018-03-09 stsp p->crc32 = calloc(nobj, sizeof(*p->crc32));
344 79b11c62 2018-03-09 stsp if (p->crc32 == NULL)
346 79b11c62 2018-03-09 stsp memcpy(p->crc32, packidx->crc32, nobj * sizeof(*p->crc32));
348 79b11c62 2018-03-09 stsp p->offsets = calloc(nobj, sizeof(*p->offsets));
349 79b11c62 2018-03-09 stsp if (p->offsets == NULL)
351 79b11c62 2018-03-09 stsp memcpy(p->offsets, packidx->offsets, nobj * sizeof(*p->offsets));
353 79b11c62 2018-03-09 stsp if (p->large_offsets) {
354 79b11c62 2018-03-09 stsp p->large_offsets = calloc(nobj, sizeof(*p->large_offsets));
355 79b11c62 2018-03-09 stsp if (p->large_offsets == NULL)
357 79b11c62 2018-03-09 stsp memcpy(p->large_offsets, packidx->large_offsets,
358 79b11c62 2018-03-09 stsp nobj * sizeof(*p->large_offsets));
364 79b11c62 2018-03-09 stsp free(p->large_offsets);
365 79b11c62 2018-03-09 stsp free(p->offsets);
366 79b11c62 2018-03-09 stsp free(p->crc32);
367 79b11c62 2018-03-09 stsp free(p->sorted_ids);
369 79b11c62 2018-03-09 stsp return NULL;
372 65cf1e80 2018-03-16 stsp static void
373 65cf1e80 2018-03-16 stsp cache_packidx(struct got_packidx_v2_hdr *packidx, struct got_repository *repo)
377 65cf1e80 2018-03-16 stsp for (i = 0; i < nitems(repo->packidx_cache); i++) {
378 65cf1e80 2018-03-16 stsp if (repo->packidx_cache[i] == NULL)
382 65cf1e80 2018-03-16 stsp if (i == nitems(repo->packidx_cache)) {
383 65cf1e80 2018-03-16 stsp got_packidx_close(repo->packidx_cache[i - 1]);
384 65cf1e80 2018-03-16 stsp memmove(&repo->packidx_cache[1], &repo->packidx_cache[0],
385 65cf1e80 2018-03-16 stsp sizeof(repo->packidx_cache) -
386 65cf1e80 2018-03-16 stsp sizeof(repo->packidx_cache[0]));
390 65cf1e80 2018-03-16 stsp repo->packidx_cache[i] = dup_packidx(packidx);
393 6b9c9673 2018-01-23 stsp static const struct got_error *
394 6b9c9673 2018-01-23 stsp search_packidx(struct got_packidx_v2_hdr **packidx, int *idx,
395 6b9c9673 2018-01-23 stsp struct got_repository *repo, struct got_object_id *id)
397 6b9c9673 2018-01-23 stsp const struct got_error *err;
398 6b9c9673 2018-01-23 stsp char *path_packdir;
399 6b9c9673 2018-01-23 stsp DIR *packdir;
400 6b9c9673 2018-01-23 stsp struct dirent *dent;
401 6b9c9673 2018-01-23 stsp char *path_packidx;
404 65cf1e80 2018-03-16 stsp /* Search pack index cache. */
405 65cf1e80 2018-03-16 stsp for (i = 0; i < nitems(repo->packidx_cache); i++) {
406 65cf1e80 2018-03-16 stsp if (repo->packidx_cache[i] == NULL)
408 72eb3431 2018-04-01 stsp *idx = get_object_idx(repo->packidx_cache[i], id, repo);
409 79b11c62 2018-03-09 stsp if (*idx != -1) {
410 6bb255dc 2018-03-17 stsp *packidx = repo->packidx_cache[i];
411 79b11c62 2018-03-09 stsp return NULL;
414 79b11c62 2018-03-09 stsp /* No luck. Search the filesystem. */
416 6b9c9673 2018-01-23 stsp path_packdir = got_repo_get_path_objects_pack(repo);
417 6b9c9673 2018-01-23 stsp if (path_packdir == NULL)
418 0a585a0d 2018-03-17 stsp return got_error_from_errno();
420 6b9c9673 2018-01-23 stsp packdir = opendir(path_packdir);
421 6b9c9673 2018-01-23 stsp if (packdir == NULL) {
422 6b9c9673 2018-01-23 stsp err = got_error_from_errno();
426 6b9c9673 2018-01-23 stsp while ((dent = readdir(packdir)) != NULL) {
427 6b9c9673 2018-01-23 stsp if (!is_packidx_filename(dent->d_name, dent->d_namlen))
430 6b9c9673 2018-01-23 stsp if (asprintf(&path_packidx, "%s/%s", path_packdir,
431 6b9c9673 2018-01-23 stsp dent->d_name) == -1) {
432 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
436 6b9c9673 2018-01-23 stsp err = got_packidx_open(packidx, path_packidx);
437 6b9c9673 2018-01-23 stsp free(path_packidx);
441 72eb3431 2018-04-01 stsp *idx = get_object_idx(*packidx, id, repo);
442 6b9c9673 2018-01-23 stsp if (*idx != -1) {
443 6b9c9673 2018-01-23 stsp err = NULL; /* found the object */
444 65cf1e80 2018-03-16 stsp cache_packidx(*packidx, repo);
448 6b9c9673 2018-01-23 stsp got_packidx_close(*packidx);
449 6b9c9673 2018-01-23 stsp *packidx = NULL;
452 6b9c9673 2018-01-23 stsp err = got_error(GOT_ERR_NO_OBJ);
454 6b9c9673 2018-01-23 stsp free(path_packdir);
455 ef715580 2018-01-26 stsp if (packdir && closedir(packdir) != 0 && err == 0)
456 6b9c9673 2018-01-23 stsp err = got_error_from_errno();
457 6b9c9673 2018-01-23 stsp return err;
460 c7fe698a 2018-01-23 stsp static const struct got_error *
461 65cf1e80 2018-03-16 stsp get_packfile_path(char **path_packfile, struct got_repository *repo,
462 65cf1e80 2018-03-16 stsp struct got_packidx_v2_hdr *packidx)
464 65cf1e80 2018-03-16 stsp char *path_packdir;
465 65cf1e80 2018-03-16 stsp char hex[SHA1_DIGEST_STRING_LENGTH];
466 65cf1e80 2018-03-16 stsp char *sha1str;
468 65cf1e80 2018-03-16 stsp path_packdir = got_repo_get_path_objects_pack(repo);
469 65cf1e80 2018-03-16 stsp if (path_packdir == NULL)
470 0a585a0d 2018-03-17 stsp return got_error_from_errno();
472 65cf1e80 2018-03-16 stsp sha1str = got_sha1_digest_to_str(packidx->trailer.packfile_sha1,
473 65cf1e80 2018-03-16 stsp hex, sizeof(hex));
474 65cf1e80 2018-03-16 stsp if (sha1str == NULL)
475 65cf1e80 2018-03-16 stsp return got_error(GOT_ERR_PACKIDX_CSUM);
477 65cf1e80 2018-03-16 stsp if (asprintf(path_packfile, "%s/%s%s%s", path_packdir,
478 65cf1e80 2018-03-16 stsp GOT_PACK_PREFIX, sha1str, GOT_PACKFILE_SUFFIX) == -1) {
479 65cf1e80 2018-03-16 stsp *path_packfile = NULL;
480 0a585a0d 2018-03-17 stsp return got_error_from_errno();
483 65cf1e80 2018-03-16 stsp return NULL;
486 65cf1e80 2018-03-16 stsp const struct got_error *
487 65cf1e80 2018-03-16 stsp read_packfile_hdr(FILE *f, struct got_packidx_v2_hdr *packidx)
489 65cf1e80 2018-03-16 stsp const struct got_error *err = NULL;
490 65cf1e80 2018-03-16 stsp uint32_t totobj = betoh32(packidx->fanout_table[0xff]);
491 65cf1e80 2018-03-16 stsp struct got_packfile_hdr hdr;
494 65cf1e80 2018-03-16 stsp n = fread(&hdr, sizeof(hdr), 1, f);
495 65cf1e80 2018-03-16 stsp if (n != 1)
496 65cf1e80 2018-03-16 stsp return got_ferror(f, GOT_ERR_BAD_PACKIDX);
498 65cf1e80 2018-03-16 stsp if (betoh32(hdr.signature) != GOT_PACKFILE_SIGNATURE ||
499 65cf1e80 2018-03-16 stsp betoh32(hdr.version) != GOT_PACKFILE_VERSION ||
500 65cf1e80 2018-03-16 stsp betoh32(hdr.nobjects) != totobj)
501 65cf1e80 2018-03-16 stsp err = got_error(GOT_ERR_BAD_PACKFILE);
503 65cf1e80 2018-03-16 stsp return err;
506 7e656b93 2018-03-17 stsp static const struct got_error *
507 7e656b93 2018-03-17 stsp open_packfile(FILE **packfile, const char *path_packfile,
508 7e656b93 2018-03-17 stsp struct got_repository *repo, struct got_packidx_v2_hdr *packidx)
510 7e656b93 2018-03-17 stsp const struct got_error *err = NULL;
512 7e656b93 2018-03-17 stsp *packfile = NULL;
514 7e656b93 2018-03-17 stsp *packfile = fopen(path_packfile, "rb");
515 7e656b93 2018-03-17 stsp if (*packfile == NULL) {
516 7e656b93 2018-03-17 stsp err = got_error_from_errno();
517 7e656b93 2018-03-17 stsp return err;
520 7e656b93 2018-03-17 stsp if (packidx) {
521 7e656b93 2018-03-17 stsp err = read_packfile_hdr(*packfile, packidx);
523 7e656b93 2018-03-17 stsp fclose(*packfile);
524 7e656b93 2018-03-17 stsp *packfile = NULL;
527 7e656b93 2018-03-17 stsp return err;
531 7e656b93 2018-03-17 stsp got_pack_close(struct got_pack *pack)
533 4589e373 2018-03-17 stsp fclose(pack->packfile);
534 4589e373 2018-03-17 stsp pack->packfile = NULL;
535 4589e373 2018-03-17 stsp free(pack->path_packfile);
536 4589e373 2018-03-17 stsp pack->path_packfile = NULL;
537 4589e373 2018-03-17 stsp pack->filesize = 0;
540 7e656b93 2018-03-17 stsp static const struct got_error *
541 7e656b93 2018-03-17 stsp cache_pack(struct got_pack **packp, const char *path_packfile,
542 7e656b93 2018-03-17 stsp struct got_packidx_v2_hdr *packidx, struct got_repository *repo)
544 7e656b93 2018-03-17 stsp const struct got_error *err = NULL;
545 7e656b93 2018-03-17 stsp struct got_pack *pack = NULL;
549 7e656b93 2018-03-17 stsp *packp = NULL;
551 7e656b93 2018-03-17 stsp for (i = 0; i < nitems(repo->packs); i++) {
552 7e656b93 2018-03-17 stsp pack = &repo->packs[i];
553 7e656b93 2018-03-17 stsp if (pack->path_packfile == NULL)
555 7e656b93 2018-03-17 stsp if (strcmp(pack->path_packfile, path_packfile) == 0)
556 7e656b93 2018-03-17 stsp return NULL;
559 7e656b93 2018-03-17 stsp if (i == nitems(repo->packs) - 1) {
560 7e656b93 2018-03-17 stsp got_pack_close(&repo->packs[i - 1]);
561 7e656b93 2018-03-17 stsp memmove(&repo->packs[1], &repo->packs[0],
562 7e656b93 2018-03-17 stsp sizeof(repo->packs) - sizeof(repo->packs[0]));
566 7e656b93 2018-03-17 stsp pack = &repo->packs[i];
568 7e656b93 2018-03-17 stsp pack->path_packfile = strdup(path_packfile);
569 7e656b93 2018-03-17 stsp if (pack->path_packfile == NULL) {
570 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
574 7e656b93 2018-03-17 stsp err = open_packfile(&pack->packfile, path_packfile, repo, packidx);
578 7e656b93 2018-03-17 stsp err = get_packfile_size(&pack->filesize, path_packfile);
582 7e656b93 2018-03-17 stsp free(pack->path_packfile);
583 7e656b93 2018-03-17 stsp free(pack);
584 7e656b93 2018-03-17 stsp } else if (packp)
585 7e656b93 2018-03-17 stsp *packp = pack;
586 c7fe698a 2018-01-23 stsp return err;
589 7e656b93 2018-03-17 stsp struct got_pack *
590 7e656b93 2018-03-17 stsp get_cached_pack(const char *path_packfile, struct got_repository *repo)
592 7e656b93 2018-03-17 stsp struct got_pack *pack = NULL;
595 7e656b93 2018-03-17 stsp for (i = 0; i < nitems(repo->packs); i++) {
596 7e656b93 2018-03-17 stsp pack = &repo->packs[i];
597 7e656b93 2018-03-17 stsp if (pack->path_packfile == NULL)
599 7e656b93 2018-03-17 stsp if (strcmp(pack->path_packfile, path_packfile) == 0)
600 7e656b93 2018-03-17 stsp return pack;
603 7e656b93 2018-03-17 stsp return NULL;
606 c7fe698a 2018-01-23 stsp static const struct got_error *
607 348f621c 2018-01-23 stsp parse_object_type_and_size(uint8_t *type, uint64_t *size, size_t *len,
608 c3703302 2018-01-23 stsp FILE *packfile)
610 a487c1d0 2018-01-14 stsp uint8_t t = 0;
611 a487c1d0 2018-01-14 stsp uint64_t s = 0;
612 a487c1d0 2018-01-14 stsp uint8_t sizeN;
617 a1fd68d8 2018-01-12 stsp /* We do not support size values which don't fit in 64 bit. */
619 a487c1d0 2018-01-14 stsp return got_error(GOT_ERR_NO_SPACE);
621 a1fd68d8 2018-01-12 stsp n = fread(&sizeN, sizeof(sizeN), 1, packfile);
622 a487c1d0 2018-01-14 stsp if (n != 1)
623 a487c1d0 2018-01-14 stsp return got_ferror(packfile, GOT_ERR_BAD_PACKIDX);
625 a1fd68d8 2018-01-12 stsp if (i == 0) {
626 a487c1d0 2018-01-14 stsp t = (sizeN & GOT_PACK_OBJ_SIZE0_TYPE_MASK) >>
627 a1fd68d8 2018-01-12 stsp GOT_PACK_OBJ_SIZE0_TYPE_MASK_SHIFT;
628 a487c1d0 2018-01-14 stsp s = (sizeN & GOT_PACK_OBJ_SIZE0_VAL_MASK);
630 a1fd68d8 2018-01-12 stsp size_t shift = 4 + 7 * (i - 1);
631 a487c1d0 2018-01-14 stsp s |= ((sizeN & GOT_PACK_OBJ_SIZE_VAL_MASK) << shift);
634 a1fd68d8 2018-01-12 stsp } while (sizeN & GOT_PACK_OBJ_SIZE_MORE);
638 3ee5fc21 2018-01-17 stsp *len = i * sizeof(sizeN);
639 a487c1d0 2018-01-14 stsp return NULL;
642 a1fd68d8 2018-01-12 stsp static const struct got_error *
643 9710aac2 2018-01-19 stsp open_plain_object(struct got_object **obj, const char *path_packfile,
644 6ccb713b 2018-01-19 stsp struct got_object_id *id, uint8_t type, off_t offset, size_t size)
646 6ccb713b 2018-01-19 stsp *obj = calloc(1, sizeof(**obj));
647 6ccb713b 2018-01-19 stsp if (*obj == NULL)
648 0a585a0d 2018-03-17 stsp return got_error_from_errno();
650 6ccb713b 2018-01-19 stsp (*obj)->path_packfile = strdup(path_packfile);
651 6ccb713b 2018-01-19 stsp if ((*obj)->path_packfile == NULL) {
652 0a585a0d 2018-03-17 stsp const struct got_error *err = got_error_from_errno();
653 6ccb713b 2018-01-19 stsp free(*obj);
654 6ccb713b 2018-01-19 stsp *obj = NULL;
655 0a585a0d 2018-03-17 stsp return err;
658 6ccb713b 2018-01-19 stsp (*obj)->type = type;
659 6ccb713b 2018-01-19 stsp (*obj)->flags = GOT_OBJ_FLAG_PACKED;
660 6ccb713b 2018-01-19 stsp (*obj)->hdrlen = 0;
661 6ccb713b 2018-01-19 stsp (*obj)->size = size;
662 6ccb713b 2018-01-19 stsp memcpy(&(*obj)->id, id, sizeof((*obj)->id));
663 6ccb713b 2018-01-19 stsp (*obj)->pack_offset = offset;
665 b107e67f 2018-01-19 stsp return NULL;
668 b107e67f 2018-01-19 stsp static const struct got_error *
669 348f621c 2018-01-23 stsp parse_negative_offset(int64_t *offset, size_t *len, FILE *packfile)
671 b107e67f 2018-01-19 stsp int64_t o = 0;
672 b107e67f 2018-01-19 stsp uint8_t offN;
677 b107e67f 2018-01-19 stsp /* We do not support offset values which don't fit in 64 bit. */
679 b107e67f 2018-01-19 stsp return got_error(GOT_ERR_NO_SPACE);
681 b107e67f 2018-01-19 stsp n = fread(&offN, sizeof(offN), 1, packfile);
682 b107e67f 2018-01-19 stsp if (n != 1)
683 b107e67f 2018-01-19 stsp return got_ferror(packfile, GOT_ERR_BAD_PACKIDX);
685 b107e67f 2018-01-19 stsp if (i == 0)
686 b107e67f 2018-01-19 stsp o = (offN & GOT_PACK_OBJ_DELTA_OFF_VAL_MASK);
690 cecc778e 2018-01-23 stsp o += (offN & GOT_PACK_OBJ_DELTA_OFF_VAL_MASK);
693 b107e67f 2018-01-19 stsp } while (offN & GOT_PACK_OBJ_DELTA_OFF_MORE);
695 b107e67f 2018-01-19 stsp *offset = o;
696 b107e67f 2018-01-19 stsp *len = i * sizeof(offN);
697 6ccb713b 2018-01-19 stsp return NULL;
700 6ccb713b 2018-01-19 stsp static const struct got_error *
701 96f5e8b3 2018-01-23 stsp parse_offset_delta(off_t *base_offset, FILE *packfile, off_t offset)
703 96f5e8b3 2018-01-23 stsp const struct got_error *err;
704 b107e67f 2018-01-19 stsp int64_t negoffset;
705 b107e67f 2018-01-19 stsp size_t negofflen;
707 348f621c 2018-01-23 stsp err = parse_negative_offset(&negoffset, &negofflen, packfile);
709 b107e67f 2018-01-19 stsp return err;
711 b107e67f 2018-01-19 stsp /* Compute the base object's offset (must be in the same pack file). */
712 96f5e8b3 2018-01-23 stsp *base_offset = (offset - negoffset);
713 96f5e8b3 2018-01-23 stsp if (*base_offset <= 0)
714 b107e67f 2018-01-19 stsp return got_error(GOT_ERR_BAD_PACKFILE);
716 96f5e8b3 2018-01-23 stsp return NULL;
719 0e22967e 2018-02-11 stsp static const struct got_error *
720 0e22967e 2018-02-11 stsp resolve_delta_chain(struct got_delta_chain *, struct got_repository *,
721 0e22967e 2018-02-11 stsp FILE *, const char *, off_t, size_t, int, size_t);
723 96f5e8b3 2018-01-23 stsp static const struct got_error *
724 bdd2fbb3 2018-02-11 stsp add_delta(struct got_delta_chain *deltas, const char *path_packfile,
725 bdd2fbb3 2018-02-11 stsp off_t delta_offset, size_t tslen, int delta_type, size_t delta_size,
726 a53d2f13 2018-03-17 stsp size_t delta_data_offset, uint8_t *delta_buf, size_t delta_len)
728 bdd2fbb3 2018-02-11 stsp struct got_delta *delta;
730 bdd2fbb3 2018-02-11 stsp delta = got_delta_open(path_packfile, delta_offset, tslen,
731 a53d2f13 2018-03-17 stsp delta_type, delta_size, delta_data_offset, delta_buf,
732 a53d2f13 2018-03-17 stsp delta_len);
733 bdd2fbb3 2018-02-11 stsp if (delta == NULL)
734 0a585a0d 2018-03-17 stsp return got_error_from_errno();
735 bdd2fbb3 2018-02-11 stsp /* delta is freed in got_object_close() */
736 bdd2fbb3 2018-02-11 stsp deltas->nentries++;
737 bdd2fbb3 2018-02-11 stsp SIMPLEQ_INSERT_HEAD(&deltas->entries, delta, entry);
738 bdd2fbb3 2018-02-11 stsp return NULL;
741 bdd2fbb3 2018-02-11 stsp static const struct got_error *
742 6b9c9673 2018-01-23 stsp resolve_offset_delta(struct got_delta_chain *deltas,
743 6b9c9673 2018-01-23 stsp struct got_repository *repo, FILE *packfile, const char *path_packfile,
744 bdd2fbb3 2018-02-11 stsp off_t delta_offset,size_t tslen, int delta_type, size_t delta_size)
747 a3500804 2018-01-23 stsp const struct got_error *err;
748 c3703302 2018-01-23 stsp off_t base_offset;
749 c3703302 2018-01-23 stsp uint8_t base_type;
750 c3703302 2018-01-23 stsp uint64_t base_size;
751 c3703302 2018-01-23 stsp size_t base_tslen;
752 bdd2fbb3 2018-02-11 stsp off_t delta_data_offset;
753 a53d2f13 2018-03-17 stsp uint8_t *delta_buf;
754 a53d2f13 2018-03-17 stsp size_t delta_len;
756 c3703302 2018-01-23 stsp err = parse_offset_delta(&base_offset, packfile, delta_offset);
758 a3500804 2018-01-23 stsp return err;
760 bdd2fbb3 2018-02-11 stsp delta_data_offset = ftello(packfile);
761 bdd2fbb3 2018-02-11 stsp if (delta_data_offset == -1)
762 bdd2fbb3 2018-02-11 stsp return got_error_from_errno();
764 a53d2f13 2018-03-17 stsp err = got_inflate_to_mem(&delta_buf, &delta_len, packfile);
766 a53d2f13 2018-03-17 stsp return err;
768 bdd2fbb3 2018-02-11 stsp err = add_delta(deltas, path_packfile, delta_offset, tslen,
769 a53d2f13 2018-03-17 stsp delta_type, delta_size, delta_data_offset, delta_buf, delta_len);
771 bdd2fbb3 2018-02-11 stsp return err;
773 c3703302 2018-01-23 stsp /* An offset delta must be in the same packfile. */
774 c3703302 2018-01-23 stsp if (fseeko(packfile, base_offset, SEEK_SET) != 0)
775 b107e67f 2018-01-19 stsp return got_error_from_errno();
777 348f621c 2018-01-23 stsp err = parse_object_type_and_size(&base_type, &base_size, &base_tslen,
780 b107e67f 2018-01-19 stsp return err;
782 6b9c9673 2018-01-23 stsp return resolve_delta_chain(deltas, repo, packfile, path_packfile,
783 0e22967e 2018-02-11 stsp base_offset, base_tslen, base_type, base_size);
786 c3703302 2018-01-23 stsp static const struct got_error *
787 6b9c9673 2018-01-23 stsp resolve_ref_delta(struct got_delta_chain *deltas, struct got_repository *repo,
788 bdd2fbb3 2018-02-11 stsp FILE *packfile, const char *path_packfile, off_t delta_offset,
789 bdd2fbb3 2018-02-11 stsp size_t tslen, int delta_type, size_t delta_size)
791 6b9c9673 2018-01-23 stsp const struct got_error *err;
792 6b9c9673 2018-01-23 stsp struct got_object_id id;
793 6b9c9673 2018-01-23 stsp struct got_packidx_v2_hdr *packidx;
795 6b9c9673 2018-01-23 stsp off_t base_offset;
796 6b9c9673 2018-01-23 stsp uint8_t base_type;
797 6b9c9673 2018-01-23 stsp uint64_t base_size;
798 6b9c9673 2018-01-23 stsp size_t base_tslen;
800 65cf1e80 2018-03-16 stsp char *path_base_packfile;
801 999f19f6 2018-03-17 stsp struct got_pack *base_pack;
802 bdd2fbb3 2018-02-11 stsp off_t delta_data_offset;
803 a53d2f13 2018-03-17 stsp uint8_t *delta_buf;
804 a53d2f13 2018-03-17 stsp size_t delta_len;
806 6b9c9673 2018-01-23 stsp n = fread(&id, sizeof(id), 1, packfile);
807 6b9c9673 2018-01-23 stsp if (n != 1)
808 6b9c9673 2018-01-23 stsp return got_ferror(packfile, GOT_ERR_IO);
810 bdd2fbb3 2018-02-11 stsp delta_data_offset = ftello(packfile);
811 bdd2fbb3 2018-02-11 stsp if (delta_data_offset == -1)
812 bdd2fbb3 2018-02-11 stsp return got_error_from_errno();
814 a53d2f13 2018-03-17 stsp err = got_inflate_to_mem(&delta_buf, &delta_len, packfile);
816 a53d2f13 2018-03-17 stsp return err;
818 bdd2fbb3 2018-02-11 stsp err = add_delta(deltas, path_packfile, delta_offset, tslen,
819 a53d2f13 2018-03-17 stsp delta_type, delta_size, delta_data_offset, delta_buf, delta_len);
821 bdd2fbb3 2018-02-11 stsp return err;
823 6b9c9673 2018-01-23 stsp err = search_packidx(&packidx, &idx, repo, &id);
825 6b9c9673 2018-01-23 stsp return err;
827 6b9c9673 2018-01-23 stsp base_offset = get_object_offset(packidx, idx);
828 6b9c9673 2018-01-23 stsp if (base_offset == (uint64_t)-1) {
829 6b9c9673 2018-01-23 stsp return got_error(GOT_ERR_BAD_PACKIDX);
832 7e656b93 2018-03-17 stsp err = get_packfile_path(&path_base_packfile, repo, packidx);
834 7e656b93 2018-03-17 stsp return err;
836 999f19f6 2018-03-17 stsp base_pack = get_cached_pack(path_base_packfile, repo);
837 999f19f6 2018-03-17 stsp if (base_pack == NULL) {
838 999f19f6 2018-03-17 stsp err = cache_pack(&base_pack, path_base_packfile, NULL, repo);
843 999f19f6 2018-03-17 stsp if (fseeko(base_pack->packfile, base_offset, SEEK_SET) != 0) {
844 6b9c9673 2018-01-23 stsp err = got_error_from_errno();
848 6b9c9673 2018-01-23 stsp err = parse_object_type_and_size(&base_type, &base_size, &base_tslen,
849 999f19f6 2018-03-17 stsp base_pack->packfile);
853 999f19f6 2018-03-17 stsp err = resolve_delta_chain(deltas, repo, base_pack->packfile,
854 0e22967e 2018-02-11 stsp path_base_packfile, base_offset, base_tslen, base_type,
855 0e22967e 2018-02-11 stsp base_size);
857 65cf1e80 2018-03-16 stsp free(path_base_packfile);
858 6b9c9673 2018-01-23 stsp return err;
861 6b9c9673 2018-01-23 stsp static const struct got_error *
862 6b9c9673 2018-01-23 stsp resolve_delta_chain(struct got_delta_chain *deltas, struct got_repository *repo,
863 0e22967e 2018-02-11 stsp FILE *packfile, const char *path_packfile, off_t delta_offset, size_t tslen,
864 0e22967e 2018-02-11 stsp int delta_type, size_t delta_size)
866 c3703302 2018-01-23 stsp const struct got_error *err = NULL;
868 c3703302 2018-01-23 stsp switch (delta_type) {
869 4e8cda55 2018-01-19 stsp case GOT_OBJ_TYPE_COMMIT:
870 4e8cda55 2018-01-19 stsp case GOT_OBJ_TYPE_TREE:
871 4e8cda55 2018-01-19 stsp case GOT_OBJ_TYPE_BLOB:
872 4e8cda55 2018-01-19 stsp case GOT_OBJ_TYPE_TAG:
873 c3703302 2018-01-23 stsp /* Plain types are the final delta base. Recursion ends. */
874 bdd2fbb3 2018-02-11 stsp err = add_delta(deltas, path_packfile, delta_offset, tslen,
875 a53d2f13 2018-03-17 stsp delta_type, delta_size, 0, NULL, 0);
877 a3500804 2018-01-23 stsp case GOT_OBJ_TYPE_OFFSET_DELTA:
878 6b9c9673 2018-01-23 stsp err = resolve_offset_delta(deltas, repo, packfile,
879 bdd2fbb3 2018-02-11 stsp path_packfile, delta_offset, tslen, delta_type,
880 bdd2fbb3 2018-02-11 stsp delta_size);
882 4e8cda55 2018-01-19 stsp case GOT_OBJ_TYPE_REF_DELTA:
883 bdd2fbb3 2018-02-11 stsp err = resolve_ref_delta(deltas, repo, packfile,
884 bdd2fbb3 2018-02-11 stsp path_packfile, delta_offset, tslen, delta_type,
885 bdd2fbb3 2018-02-11 stsp delta_size);
888 4e8cda55 2018-01-19 stsp return got_error(GOT_ERR_NOT_IMPL);
891 96f5e8b3 2018-01-23 stsp return err;
894 96f5e8b3 2018-01-23 stsp static const struct got_error *
895 a48db7e5 2018-01-23 stsp open_delta_object(struct got_object **obj, struct got_repository *repo,
896 a48db7e5 2018-01-23 stsp struct got_packidx_v2_hdr *packidx, const char *path_packfile,
897 a48db7e5 2018-01-23 stsp FILE *packfile, struct got_object_id *id, off_t offset, size_t tslen,
898 a48db7e5 2018-01-23 stsp int delta_type, size_t delta_size)
900 96f5e8b3 2018-01-23 stsp const struct got_error *err = NULL;
901 96f5e8b3 2018-01-23 stsp int resolved_type;
903 b107e67f 2018-01-19 stsp *obj = calloc(1, sizeof(**obj));
904 b107e67f 2018-01-19 stsp if (*obj == NULL)
905 0a585a0d 2018-03-17 stsp return got_error_from_errno();
907 96f5e8b3 2018-01-23 stsp (*obj)->flags = 0;
908 b107e67f 2018-01-19 stsp (*obj)->hdrlen = 0;
909 39e73dc9 2018-03-03 stsp (*obj)->size = 0; /* Not known because deltas aren't applied yet. */
910 b107e67f 2018-01-19 stsp memcpy(&(*obj)->id, id, sizeof((*obj)->id));
911 cecc778e 2018-01-23 stsp (*obj)->pack_offset = offset + tslen;
913 96f5e8b3 2018-01-23 stsp (*obj)->path_packfile = strdup(path_packfile);
914 96f5e8b3 2018-01-23 stsp if ((*obj)->path_packfile == NULL) {
915 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
918 96f5e8b3 2018-01-23 stsp (*obj)->flags |= GOT_OBJ_FLAG_PACKED;
920 96f5e8b3 2018-01-23 stsp SIMPLEQ_INIT(&(*obj)->deltas.entries);
921 96f5e8b3 2018-01-23 stsp (*obj)->flags |= GOT_OBJ_FLAG_DELTIFIED;
923 6b9c9673 2018-01-23 stsp err = resolve_delta_chain(&(*obj)->deltas, repo, packfile,
924 0e22967e 2018-02-11 stsp path_packfile, offset, tslen, delta_type, delta_size);
928 96f5e8b3 2018-01-23 stsp err = got_delta_chain_get_base_type(&resolved_type, &(*obj)->deltas);
931 96f5e8b3 2018-01-23 stsp (*obj)->type = resolved_type;
935 96f5e8b3 2018-01-23 stsp got_object_close(*obj);
936 96f5e8b3 2018-01-23 stsp *obj = NULL;
938 96f5e8b3 2018-01-23 stsp return err;
941 b107e67f 2018-01-19 stsp static const struct got_error *
942 6c00b545 2018-01-17 stsp open_packed_object(struct got_object **obj, struct got_repository *repo,
943 6b9c9673 2018-01-23 stsp struct got_packidx_v2_hdr *packidx, int idx, struct got_object_id *id)
945 a1fd68d8 2018-01-12 stsp const struct got_error *err = NULL;
946 a1fd68d8 2018-01-12 stsp off_t offset;
947 65cf1e80 2018-03-16 stsp char *path_packfile;
948 6d89869a 2018-03-17 stsp struct got_pack *pack;
949 6c00b545 2018-01-17 stsp uint8_t type;
950 6c00b545 2018-01-17 stsp uint64_t size;
951 3ee5fc21 2018-01-17 stsp size_t tslen;
953 6c00b545 2018-01-17 stsp *obj = NULL;
955 a1fd68d8 2018-01-12 stsp offset = get_object_offset(packidx, idx);
956 a1fd68d8 2018-01-12 stsp if (offset == (uint64_t)-1)
957 a1fd68d8 2018-01-12 stsp return got_error(GOT_ERR_BAD_PACKIDX);
959 7e656b93 2018-03-17 stsp err = get_packfile_path(&path_packfile, repo, packidx);
961 6b9c9673 2018-01-23 stsp return err;
963 6d89869a 2018-03-17 stsp pack = get_cached_pack(path_packfile, repo);
964 6d89869a 2018-03-17 stsp if (pack == NULL) {
965 6d89869a 2018-03-17 stsp err = cache_pack(&pack, path_packfile, packidx, repo);
970 6d89869a 2018-03-17 stsp if (fseeko(pack->packfile, offset, SEEK_SET) != 0) {
971 6c00b545 2018-01-17 stsp err = got_error_from_errno();
975 6d89869a 2018-03-17 stsp err = parse_object_type_and_size(&type, &size, &tslen, pack->packfile);
979 6c00b545 2018-01-17 stsp switch (type) {
980 6c00b545 2018-01-17 stsp case GOT_OBJ_TYPE_COMMIT:
981 6c00b545 2018-01-17 stsp case GOT_OBJ_TYPE_TREE:
982 6c00b545 2018-01-17 stsp case GOT_OBJ_TYPE_BLOB:
983 d33fc9ef 2018-01-23 stsp case GOT_OBJ_TYPE_TAG:
984 9710aac2 2018-01-19 stsp err = open_plain_object(obj, path_packfile, id, type,
985 6ccb713b 2018-01-19 stsp offset + tslen, size);
988 b107e67f 2018-01-19 stsp case GOT_OBJ_TYPE_OFFSET_DELTA:
989 a48db7e5 2018-01-23 stsp case GOT_OBJ_TYPE_REF_DELTA:
990 a48db7e5 2018-01-23 stsp err = open_delta_object(obj, repo, packidx, path_packfile,
991 6d89869a 2018-03-17 stsp pack->packfile, id, offset, tslen, type, size);
995 6c00b545 2018-01-17 stsp err = got_error(GOT_ERR_NOT_IMPL);
999 65cf1e80 2018-03-16 stsp free(path_packfile);
1000 a1fd68d8 2018-01-12 stsp return err;
1003 a1fd68d8 2018-01-12 stsp const struct got_error *
1004 6c00b545 2018-01-17 stsp got_packfile_open_object(struct got_object **obj, struct got_object_id *id,
1005 a1fd68d8 2018-01-12 stsp struct got_repository *repo)
1007 a1fd68d8 2018-01-12 stsp const struct got_error *err = NULL;
1008 6b9c9673 2018-01-23 stsp struct got_packidx_v2_hdr *packidx = NULL;
1011 6b9c9673 2018-01-23 stsp err = search_packidx(&packidx, &idx, repo, id);
1013 6b9c9673 2018-01-23 stsp return err;
1015 6b9c9673 2018-01-23 stsp err = open_packed_object(obj, repo, packidx, idx, id);
1017 7e656b93 2018-03-17 stsp return err;
1019 7e656b93 2018-03-17 stsp err = cache_pack(NULL, (*obj)->path_packfile, packidx, repo);
1020 3ee5fc21 2018-01-17 stsp return err;
1023 efd2a263 2018-01-19 stsp static const struct got_error *
1024 40426839 2018-03-17 stsp get_delta_chain_max_size(uint64_t *max_size, struct got_delta_chain *deltas)
1026 22484865 2018-03-13 stsp struct got_delta *delta;
1027 22484865 2018-03-13 stsp uint64_t base_size = 0, result_size = 0;
1029 22484865 2018-03-13 stsp *max_size = 0;
1030 22484865 2018-03-13 stsp SIMPLEQ_FOREACH(delta, &deltas->entries, entry) {
1031 22484865 2018-03-13 stsp /* Plain object types are the delta base. */
1032 22484865 2018-03-13 stsp if (delta->type != GOT_OBJ_TYPE_COMMIT &&
1033 22484865 2018-03-13 stsp delta->type != GOT_OBJ_TYPE_TREE &&
1034 22484865 2018-03-13 stsp delta->type != GOT_OBJ_TYPE_BLOB &&
1035 22484865 2018-03-13 stsp delta->type != GOT_OBJ_TYPE_TAG) {
1036 22484865 2018-03-13 stsp const struct got_error *err;
1037 a53d2f13 2018-03-17 stsp err = got_delta_get_sizes(&base_size, &result_size,
1038 a53d2f13 2018-03-17 stsp delta->delta_buf, delta->delta_len);
1040 22484865 2018-03-13 stsp return err;
1042 22484865 2018-03-13 stsp base_size = delta->size;
1043 22484865 2018-03-13 stsp if (base_size > *max_size)
1044 22484865 2018-03-13 stsp *max_size = base_size;
1045 22484865 2018-03-13 stsp if (result_size > *max_size)
1046 22484865 2018-03-13 stsp *max_size = result_size;
1049 9feb4ff2 2018-03-14 stsp return NULL;
1052 22484865 2018-03-13 stsp static const struct got_error *
1053 b29656e2 2018-03-16 stsp dump_delta_chain_to_file(size_t *result_size, struct got_delta_chain *deltas,
1054 72eb3431 2018-04-01 stsp FILE *outfile, struct got_repository *repo)
1056 efd2a263 2018-01-19 stsp const struct got_error *err = NULL;
1057 6691714a 2018-01-23 stsp struct got_delta *delta;
1058 22484865 2018-03-13 stsp FILE *base_file = NULL, *accum_file = NULL;
1059 8628c62d 2018-03-15 stsp uint8_t *base_buf = NULL, *accum_buf = NULL;
1060 b29656e2 2018-03-16 stsp size_t accum_size = 0;
1061 22484865 2018-03-13 stsp uint64_t max_size;
1062 6691714a 2018-01-23 stsp int n = 0;
1064 b29656e2 2018-03-16 stsp *result_size = 0;
1066 710bb5ca 2018-01-23 stsp if (SIMPLEQ_EMPTY(&deltas->entries))
1067 6691714a 2018-01-23 stsp return got_error(GOT_ERR_BAD_DELTA_CHAIN);
1069 8628c62d 2018-03-15 stsp /* We process small enough files entirely in memory for speed. */
1070 40426839 2018-03-17 stsp err = get_delta_chain_max_size(&max_size, deltas);
1072 22484865 2018-03-13 stsp return err;
1073 8628c62d 2018-03-15 stsp if (max_size < GOT_DELTA_RESULT_SIZE_CACHED_MAX) {
1074 8628c62d 2018-03-15 stsp accum_buf = malloc(max_size);
1075 8628c62d 2018-03-15 stsp if (accum_buf == NULL)
1076 0a585a0d 2018-03-17 stsp return got_error_from_errno();
1078 22484865 2018-03-13 stsp base_file = got_opentemp();
1079 8628c62d 2018-03-15 stsp if (base_file == NULL)
1080 8628c62d 2018-03-15 stsp return got_error_from_errno();
1082 22484865 2018-03-13 stsp accum_file = got_opentemp();
1083 8628c62d 2018-03-15 stsp if (accum_file == NULL) {
1084 8628c62d 2018-03-15 stsp err = got_error_from_errno();
1085 8628c62d 2018-03-15 stsp fclose(base_file);
1086 8628c62d 2018-03-15 stsp return err;
1090 6691714a 2018-01-23 stsp /* Deltas are ordered in ascending order. */
1091 710bb5ca 2018-01-23 stsp SIMPLEQ_FOREACH(delta, &deltas->entries, entry) {
1092 a6b158cc 2018-02-11 stsp if (n == 0) {
1093 72eb3431 2018-04-01 stsp struct got_pack *pack;
1094 8628c62d 2018-03-15 stsp size_t base_len;
1096 a6b158cc 2018-02-11 stsp /* Plain object types are the delta base. */
1097 a6b158cc 2018-02-11 stsp if (delta->type != GOT_OBJ_TYPE_COMMIT &&
1098 a6b158cc 2018-02-11 stsp delta->type != GOT_OBJ_TYPE_TREE &&
1099 a6b158cc 2018-02-11 stsp delta->type != GOT_OBJ_TYPE_BLOB &&
1100 a6b158cc 2018-02-11 stsp delta->type != GOT_OBJ_TYPE_TAG) {
1101 72eb3431 2018-04-01 stsp err = got_error(GOT_ERR_BAD_DELTA_CHAIN);
1102 72eb3431 2018-04-01 stsp goto done;
1105 72eb3431 2018-04-01 stsp pack = get_cached_pack(delta->path_packfile, repo);
1106 72eb3431 2018-04-01 stsp if (pack == NULL) {
1107 a6b158cc 2018-02-11 stsp err = got_error(GOT_ERR_BAD_DELTA_CHAIN);
1108 a6b158cc 2018-02-11 stsp goto done;
1111 f7e127f3 2018-03-17 stsp if (fseeko(pack->packfile, delta->offset + delta->tslen,
1112 bdd2fbb3 2018-02-11 stsp SEEK_SET) != 0) {
1113 bdd2fbb3 2018-02-11 stsp err = got_error_from_errno();
1114 bdd2fbb3 2018-02-11 stsp goto done;
1116 8628c62d 2018-03-15 stsp if (base_file)
1117 7e656b93 2018-03-17 stsp err = got_inflate_to_file(&base_len,
1118 f7e127f3 2018-03-17 stsp pack->packfile, base_file);
1120 8628c62d 2018-03-15 stsp err = got_inflate_to_mem(&base_buf, &base_len,
1121 f7e127f3 2018-03-17 stsp pack->packfile);
1122 8628c62d 2018-03-15 stsp if (base_len < max_size) {
1123 8628c62d 2018-03-15 stsp uint8_t *p;
1124 8628c62d 2018-03-15 stsp p = reallocarray(base_buf, 1, max_size);
1125 8628c62d 2018-03-15 stsp if (p == NULL) {
1126 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
1127 8628c62d 2018-03-15 stsp goto done;
1129 8628c62d 2018-03-15 stsp base_buf = p;
1133 a6b158cc 2018-02-11 stsp goto done;
1135 8628c62d 2018-03-15 stsp if (base_file)
1136 8628c62d 2018-03-15 stsp rewind(base_file);
1140 8628c62d 2018-03-15 stsp if (base_buf) {
1141 a53d2f13 2018-03-17 stsp err = got_delta_apply_in_mem(base_buf, delta->delta_buf,
1142 a53d2f13 2018-03-17 stsp delta->delta_len, accum_buf, &accum_size);
1145 a53d2f13 2018-03-17 stsp err = got_delta_apply(base_file, delta->delta_buf,
1146 a53d2f13 2018-03-17 stsp delta->delta_len,
1147 8628c62d 2018-03-15 stsp /* Final delta application writes to output file. */
1148 b29656e2 2018-03-16 stsp ++n < deltas->nentries ? accum_file : outfile,
1149 b29656e2 2018-03-16 stsp &accum_size);
1152 6691714a 2018-01-23 stsp goto done;
1154 710bb5ca 2018-01-23 stsp if (n < deltas->nentries) {
1155 6691714a 2018-01-23 stsp /* Accumulated delta becomes the new base. */
1156 8628c62d 2018-03-15 stsp if (base_buf) {
1157 8628c62d 2018-03-15 stsp uint8_t *tmp = accum_buf;
1158 8628c62d 2018-03-15 stsp accum_buf = base_buf;
1159 8628c62d 2018-03-15 stsp base_buf = tmp;
1161 8628c62d 2018-03-15 stsp FILE *tmp = accum_file;
1162 8628c62d 2018-03-15 stsp accum_file = base_file;
1163 8628c62d 2018-03-15 stsp base_file = tmp;
1164 8628c62d 2018-03-15 stsp rewind(base_file);
1165 8628c62d 2018-03-15 stsp rewind(accum_file);
1171 8628c62d 2018-03-15 stsp free(base_buf);
1172 8628c62d 2018-03-15 stsp if (accum_buf) {
1173 8628c62d 2018-03-15 stsp size_t len = fwrite(accum_buf, 1, accum_size, outfile);
1174 8628c62d 2018-03-15 stsp free(accum_buf);
1175 8628c62d 2018-03-15 stsp if (len != accum_size)
1176 8628c62d 2018-03-15 stsp return got_ferror(outfile, GOT_ERR_IO);
1178 8628c62d 2018-03-15 stsp if (base_file)
1179 8628c62d 2018-03-15 stsp fclose(base_file);
1180 8628c62d 2018-03-15 stsp if (accum_file)
1181 8628c62d 2018-03-15 stsp fclose(accum_file);
1182 6691714a 2018-01-23 stsp rewind(outfile);
1183 b29656e2 2018-03-16 stsp if (err == NULL)
1184 b29656e2 2018-03-16 stsp *result_size = accum_size;
1185 e0ab43e7 2018-03-16 stsp return err;
1188 e0ab43e7 2018-03-16 stsp static const struct got_error *
1189 e0ab43e7 2018-03-16 stsp dump_delta_chain_to_mem(uint8_t **outbuf, size_t *outlen,
1190 72eb3431 2018-04-01 stsp struct got_delta_chain *deltas, struct got_repository *repo)
1192 e0ab43e7 2018-03-16 stsp const struct got_error *err = NULL;
1193 e0ab43e7 2018-03-16 stsp struct got_delta *delta;
1194 e0ab43e7 2018-03-16 stsp uint8_t *base_buf = NULL, *accum_buf = NULL;
1195 e0ab43e7 2018-03-16 stsp size_t accum_size;
1196 e0ab43e7 2018-03-16 stsp uint64_t max_size;
1197 e0ab43e7 2018-03-16 stsp int n = 0;
1199 e0ab43e7 2018-03-16 stsp *outbuf = NULL;
1200 e0ab43e7 2018-03-16 stsp *outlen = 0;
1202 e0ab43e7 2018-03-16 stsp if (SIMPLEQ_EMPTY(&deltas->entries))
1203 e0ab43e7 2018-03-16 stsp return got_error(GOT_ERR_BAD_DELTA_CHAIN);
1205 40426839 2018-03-17 stsp err = get_delta_chain_max_size(&max_size, deltas);
1207 e0ab43e7 2018-03-16 stsp return err;
1208 e0ab43e7 2018-03-16 stsp accum_buf = malloc(max_size);
1209 e0ab43e7 2018-03-16 stsp if (accum_buf == NULL)
1210 0a585a0d 2018-03-17 stsp return got_error_from_errno();
1212 e0ab43e7 2018-03-16 stsp /* Deltas are ordered in ascending order. */
1213 e0ab43e7 2018-03-16 stsp SIMPLEQ_FOREACH(delta, &deltas->entries, entry) {
1214 e0ab43e7 2018-03-16 stsp if (n == 0) {
1215 72eb3431 2018-04-01 stsp struct got_pack *pack;
1216 e0ab43e7 2018-03-16 stsp size_t base_len;
1218 e0ab43e7 2018-03-16 stsp /* Plain object types are the delta base. */
1219 e0ab43e7 2018-03-16 stsp if (delta->type != GOT_OBJ_TYPE_COMMIT &&
1220 e0ab43e7 2018-03-16 stsp delta->type != GOT_OBJ_TYPE_TREE &&
1221 e0ab43e7 2018-03-16 stsp delta->type != GOT_OBJ_TYPE_BLOB &&
1222 e0ab43e7 2018-03-16 stsp delta->type != GOT_OBJ_TYPE_TAG) {
1223 72eb3431 2018-04-01 stsp err = got_error(GOT_ERR_BAD_DELTA_CHAIN);
1224 72eb3431 2018-04-01 stsp goto done;
1227 72eb3431 2018-04-01 stsp pack = get_cached_pack(delta->path_packfile, repo);
1228 72eb3431 2018-04-01 stsp if (pack == NULL) {
1229 e0ab43e7 2018-03-16 stsp err = got_error(GOT_ERR_BAD_DELTA_CHAIN);
1230 e0ab43e7 2018-03-16 stsp goto done;
1233 f7e127f3 2018-03-17 stsp if (fseeko(pack->packfile, delta->offset + delta->tslen,
1234 e0ab43e7 2018-03-16 stsp SEEK_SET) != 0) {
1235 e0ab43e7 2018-03-16 stsp err = got_error_from_errno();
1236 e0ab43e7 2018-03-16 stsp goto done;
1238 e0ab43e7 2018-03-16 stsp err = got_inflate_to_mem(&base_buf, &base_len,
1239 f7e127f3 2018-03-17 stsp pack->packfile);
1240 e0ab43e7 2018-03-16 stsp if (base_len < max_size) {
1241 e0ab43e7 2018-03-16 stsp uint8_t *p;
1242 e0ab43e7 2018-03-16 stsp p = reallocarray(base_buf, 1, max_size);
1243 e0ab43e7 2018-03-16 stsp if (p == NULL) {
1244 0a585a0d 2018-03-17 stsp err = got_error_from_errno();
1245 e0ab43e7 2018-03-16 stsp goto done;
1247 e0ab43e7 2018-03-16 stsp base_buf = p;
1250 e0ab43e7 2018-03-16 stsp goto done;
1255 a53d2f13 2018-03-17 stsp err = got_delta_apply_in_mem(base_buf, delta->delta_buf,
1256 a53d2f13 2018-03-17 stsp delta->delta_len, accum_buf, &accum_size);
1259 e0ab43e7 2018-03-16 stsp goto done;
1261 e0ab43e7 2018-03-16 stsp if (n < deltas->nentries) {
1262 e0ab43e7 2018-03-16 stsp /* Accumulated delta becomes the new base. */
1263 e0ab43e7 2018-03-16 stsp uint8_t *tmp = accum_buf;
1264 e0ab43e7 2018-03-16 stsp accum_buf = base_buf;
1265 e0ab43e7 2018-03-16 stsp base_buf = tmp;
1270 e0ab43e7 2018-03-16 stsp free(base_buf);
1271 e0ab43e7 2018-03-16 stsp if (err) {
1272 e0ab43e7 2018-03-16 stsp free(accum_buf);
1273 e0ab43e7 2018-03-16 stsp *outbuf = NULL;
1274 e0ab43e7 2018-03-16 stsp *outlen = 0;
1276 e0ab43e7 2018-03-16 stsp *outbuf = accum_buf;
1277 e0ab43e7 2018-03-16 stsp *outlen = accum_size;
1279 efd2a263 2018-01-19 stsp return err;
1282 3ee5fc21 2018-01-17 stsp const struct got_error *
1283 3ee5fc21 2018-01-17 stsp got_packfile_extract_object(FILE **f, struct got_object *obj,
1284 3ee5fc21 2018-01-17 stsp struct got_repository *repo)
1286 3ee5fc21 2018-01-17 stsp const struct got_error *err = NULL;
1288 3ee5fc21 2018-01-17 stsp if ((obj->flags & GOT_OBJ_FLAG_PACKED) == 0)
1289 3ee5fc21 2018-01-17 stsp return got_error(GOT_ERR_OBJ_NOT_PACKED);
1291 040bf4a1 2018-04-01 stsp *f = got_opentemp();
1292 040bf4a1 2018-04-01 stsp if (*f == NULL) {
1293 040bf4a1 2018-04-01 stsp err = got_error(GOT_ERR_FILE_OPEN);
1294 040bf4a1 2018-04-01 stsp goto done;
1297 ef2bccd9 2018-03-16 stsp if ((obj->flags & GOT_OBJ_FLAG_DELTIFIED) == 0) {
1298 72eb3431 2018-04-01 stsp struct got_pack *pack;
1300 72eb3431 2018-04-01 stsp pack = get_cached_pack(obj->path_packfile, repo);
1301 72eb3431 2018-04-01 stsp if (pack == NULL) {
1302 72eb3431 2018-04-01 stsp err = cache_pack(&pack, obj->path_packfile, NULL, repo);
1304 72eb3431 2018-04-01 stsp goto done;
1307 7e656b93 2018-03-17 stsp if (fseeko(pack->packfile, obj->pack_offset, SEEK_SET) != 0) {
1308 6691714a 2018-01-23 stsp err = got_error_from_errno();
1309 c52ac529 2018-03-17 stsp goto done;
1312 7e656b93 2018-03-17 stsp err = got_inflate_to_file(&obj->size, pack->packfile, *f);
1314 b29656e2 2018-03-16 stsp err = dump_delta_chain_to_file(&obj->size, &obj->deltas, *f,
1317 d0f3be7c 2018-03-17 stsp if (err && *f) {
1318 3ee5fc21 2018-01-17 stsp fclose(*f);
1319 d0f3be7c 2018-03-17 stsp *f = NULL;
1321 a1fd68d8 2018-01-12 stsp return err;
1324 e0ab43e7 2018-03-16 stsp const struct got_error *
1325 e0ab43e7 2018-03-16 stsp got_packfile_extract_object_to_mem(uint8_t **buf, size_t *len,
1326 e0ab43e7 2018-03-16 stsp struct got_object *obj, struct got_repository *repo)
1328 e0ab43e7 2018-03-16 stsp const struct got_error *err = NULL;
1330 e0ab43e7 2018-03-16 stsp if ((obj->flags & GOT_OBJ_FLAG_PACKED) == 0)
1331 e0ab43e7 2018-03-16 stsp return got_error(GOT_ERR_OBJ_NOT_PACKED);
1333 ef2bccd9 2018-03-16 stsp if ((obj->flags & GOT_OBJ_FLAG_DELTIFIED) == 0) {
1334 72eb3431 2018-04-01 stsp struct got_pack *pack;
1336 72eb3431 2018-04-01 stsp pack = get_cached_pack(obj->path_packfile, repo);
1337 72eb3431 2018-04-01 stsp if (pack == NULL) {
1338 72eb3431 2018-04-01 stsp err = cache_pack(&pack, obj->path_packfile, NULL, repo);
1340 72eb3431 2018-04-01 stsp goto done;
1343 7e656b93 2018-03-17 stsp if (fseeko(pack->packfile, obj->pack_offset, SEEK_SET) != 0) {
1344 e0ab43e7 2018-03-16 stsp err = got_error_from_errno();
1345 e0ab43e7 2018-03-16 stsp goto done;
1348 7e656b93 2018-03-17 stsp err = got_inflate_to_mem(buf, len, pack->packfile);
1350 72eb3431 2018-04-01 stsp err = dump_delta_chain_to_mem(buf, len, &obj->deltas, repo);
1352 e0ab43e7 2018-03-16 stsp return err;