2 e6bcace5 2021-06-22 stsp * Copyright (c) 2020 Ori Bernstein
3 e6bcace5 2021-06-22 stsp * Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
5 e6bcace5 2021-06-22 stsp * Permission to use, copy, modify, and distribute this software for any
6 e6bcace5 2021-06-22 stsp * purpose with or without fee is hereby granted, provided that the above
7 e6bcace5 2021-06-22 stsp * copyright notice and this permission notice appear in all copies.
9 e6bcace5 2021-06-22 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 e6bcace5 2021-06-22 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 e6bcace5 2021-06-22 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 e6bcace5 2021-06-22 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 e6bcace5 2021-06-22 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 e6bcace5 2021-06-22 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 e6bcace5 2021-06-22 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 08736cf9 2021-06-23 stsp #include <sys/types.h>
19 e6bcace5 2021-06-22 stsp #include <sys/queue.h>
20 f8b19efd 2021-10-13 stsp #include <sys/tree.h>
21 08736cf9 2021-06-23 stsp #include <sys/uio.h>
22 e6bcace5 2021-06-22 stsp #include <sys/stat.h>
23 211cfef0 2022-01-05 stsp #include <sys/time.h>
25 08736cf9 2021-06-23 stsp #include <stdint.h>
26 05118f5a 2021-06-22 stsp #include <imsg.h>
27 e6bcace5 2021-06-22 stsp #include <stdio.h>
28 e6bcace5 2021-06-22 stsp #include <stdlib.h>
29 e6bcace5 2021-06-22 stsp #include <string.h>
30 e6bcace5 2021-06-22 stsp #include <sha1.h>
31 211cfef0 2022-01-05 stsp #include <time.h>
32 e6bcace5 2021-06-22 stsp #include <limits.h>
33 e6bcace5 2021-06-22 stsp #include <zlib.h>
35 e6bcace5 2021-06-22 stsp #include "got_error.h"
36 e6bcace5 2021-06-22 stsp #include "got_cancel.h"
37 e6bcace5 2021-06-22 stsp #include "got_object.h"
38 f8b19efd 2021-10-13 stsp #include "got_path.h"
39 05118f5a 2021-06-22 stsp #include "got_reference.h"
40 05118f5a 2021-06-22 stsp #include "got_repository_admin.h"
41 08347b73 2021-10-14 stsp #include "got_opentemp.h"
43 e6bcace5 2021-06-22 stsp #include "got_lib_deltify.h"
44 e6bcace5 2021-06-22 stsp #include "got_lib_delta.h"
45 e6bcace5 2021-06-22 stsp #include "got_lib_object.h"
46 e6bcace5 2021-06-22 stsp #include "got_lib_object_idset.h"
47 05118f5a 2021-06-22 stsp #include "got_lib_object_cache.h"
48 e6bcace5 2021-06-22 stsp #include "got_lib_deflate.h"
49 e6bcace5 2021-06-22 stsp #include "got_lib_pack.h"
50 05118f5a 2021-06-22 stsp #include "got_lib_privsep.h"
51 05118f5a 2021-06-22 stsp #include "got_lib_repository.h"
52 211cfef0 2022-01-05 stsp #include "got_lib_ratelimit.h"
55 74881701 2021-10-15 stsp #define MIN(_a,_b) ((_a) < (_b) ? (_a) : (_b))
59 e6bcace5 2021-06-22 stsp #define MAX(_a,_b) ((_a) > (_b) ? (_a) : (_b))
62 e6bcace5 2021-06-22 stsp struct got_pack_meta {
63 e6bcace5 2021-06-22 stsp struct got_object_id id;
65 e6bcace5 2021-06-22 stsp int obj_type;
67 e6bcace5 2021-06-22 stsp time_t mtime;
69 e6bcace5 2021-06-22 stsp /* The best delta we picked */
70 e6bcace5 2021-06-22 stsp struct got_pack_meta *head;
71 e6bcace5 2021-06-22 stsp struct got_pack_meta *prev;
72 74881701 2021-10-15 stsp off_t delta_offset; /* offset in delta cache file */
73 74881701 2021-10-15 stsp off_t delta_len; /* length in delta cache file */
76 e6bcace5 2021-06-22 stsp /* Only used for delta window */
77 e6bcace5 2021-06-22 stsp struct got_delta_table *dtab;
79 e6bcace5 2021-06-22 stsp /* Only used for writing offset deltas */
83 e6bcace5 2021-06-22 stsp struct got_pack_metavec {
84 e6bcace5 2021-06-22 stsp struct got_pack_meta **meta;
89 e6bcace5 2021-06-22 stsp static const struct got_error *
90 e6bcace5 2021-06-22 stsp alloc_meta(struct got_pack_meta **new, struct got_object_id *id,
91 e6bcace5 2021-06-22 stsp const char *path, int obj_type, time_t mtime)
93 e6bcace5 2021-06-22 stsp const struct got_error *err = NULL;
94 e6bcace5 2021-06-22 stsp struct got_pack_meta *m;
96 e6bcace5 2021-06-22 stsp *new = NULL;
98 e6bcace5 2021-06-22 stsp m = calloc(1, sizeof(*m));
99 e6bcace5 2021-06-22 stsp if (m == NULL)
100 1d19226a 2021-10-13 stsp return got_error_from_errno("calloc");
102 e6bcace5 2021-06-22 stsp memcpy(&m->id, id, sizeof(m->id));
104 e6bcace5 2021-06-22 stsp m->path = strdup(path);
105 e6bcace5 2021-06-22 stsp if (m->path == NULL) {
106 e6bcace5 2021-06-22 stsp err = got_error_from_errno("strdup");
108 e6bcace5 2021-06-22 stsp return err;
111 e6bcace5 2021-06-22 stsp m->obj_type = obj_type;
112 e6bcace5 2021-06-22 stsp m->mtime = mtime;
114 e6bcace5 2021-06-22 stsp return NULL;
117 e6bcace5 2021-06-22 stsp static void
118 e6bcace5 2021-06-22 stsp clear_meta(struct got_pack_meta *meta)
120 e6bcace5 2021-06-22 stsp if (meta == NULL)
122 e6bcace5 2021-06-22 stsp free(meta->path);
123 e6bcace5 2021-06-22 stsp meta->path = NULL;
126 e6bcace5 2021-06-22 stsp static void
127 e6bcace5 2021-06-22 stsp free_nmeta(struct got_pack_meta **meta, int nmeta)
131 e6bcace5 2021-06-22 stsp for (i = 0; i < nmeta; i++)
132 e6bcace5 2021-06-22 stsp clear_meta(meta[i]);
133 e6bcace5 2021-06-22 stsp free(meta);
137 e6bcace5 2021-06-22 stsp delta_order_cmp(const void *pa, const void *pb)
139 e6bcace5 2021-06-22 stsp struct got_pack_meta *a, *b;
142 e6bcace5 2021-06-22 stsp a = *(struct got_pack_meta **)pa;
143 e6bcace5 2021-06-22 stsp b = *(struct got_pack_meta **)pb;
145 e6bcace5 2021-06-22 stsp if (a->obj_type != b->obj_type)
146 e6bcace5 2021-06-22 stsp return a->obj_type - b->obj_type;
147 e6bcace5 2021-06-22 stsp cmp = strcmp(a->path, b->path);
148 e6bcace5 2021-06-22 stsp if (cmp != 0)
149 e6bcace5 2021-06-22 stsp return cmp;
150 e6bcace5 2021-06-22 stsp if (a->mtime != b->mtime)
151 e6bcace5 2021-06-22 stsp return a->mtime - b->mtime;
152 e6bcace5 2021-06-22 stsp return got_object_id_cmp(&a->id, &b->id);
156 e6bcace5 2021-06-22 stsp delta_size(struct got_delta_instruction *deltas, int ndeltas)
158 e6bcace5 2021-06-22 stsp int i, size = 32;
159 e6bcace5 2021-06-22 stsp for (i = 0; i < ndeltas; i++) {
160 e6bcace5 2021-06-22 stsp if (deltas[i].copy)
161 e6bcace5 2021-06-22 stsp size += GOT_DELTA_SIZE_SHIFT;
163 e6bcace5 2021-06-22 stsp size += deltas[i].len + 1;
165 e6bcace5 2021-06-22 stsp return size;
168 74881701 2021-10-15 stsp static const struct got_error *
169 74881701 2021-10-15 stsp encode_delta(struct got_pack_meta *m, struct got_raw_object *o,
170 74881701 2021-10-15 stsp struct got_delta_instruction *deltas, int ndeltas,
171 a319ca8c 2021-10-15 stsp off_t base_size, FILE *f)
173 a319ca8c 2021-10-15 stsp unsigned char buf[16], *bp;
177 a319ca8c 2021-10-15 stsp struct got_delta_instruction *d;
179 a319ca8c 2021-10-15 stsp /* base object size */
180 a319ca8c 2021-10-15 stsp buf[0] = base_size & GOT_DELTA_SIZE_VAL_MASK;
181 a319ca8c 2021-10-15 stsp n = base_size >> GOT_DELTA_SIZE_SHIFT;
182 a319ca8c 2021-10-15 stsp for (i = 1; n > 0; i++) {
183 a319ca8c 2021-10-15 stsp buf[i - 1] |= GOT_DELTA_SIZE_MORE;
184 a319ca8c 2021-10-15 stsp buf[i] = n & GOT_DELTA_SIZE_VAL_MASK;
185 a319ca8c 2021-10-15 stsp n >>= GOT_DELTA_SIZE_SHIFT;
187 a319ca8c 2021-10-15 stsp w = fwrite(buf, 1, i, f);
188 a319ca8c 2021-10-15 stsp if (w != i)
189 a319ca8c 2021-10-15 stsp return got_ferror(f, GOT_ERR_IO);
191 a319ca8c 2021-10-15 stsp /* target object size */
192 a319ca8c 2021-10-15 stsp buf[0] = o->size & GOT_DELTA_SIZE_VAL_MASK;
193 a319ca8c 2021-10-15 stsp n = o->size >> GOT_DELTA_SIZE_SHIFT;
194 a319ca8c 2021-10-15 stsp for (i = 1; n > 0; i++) {
195 a319ca8c 2021-10-15 stsp buf[i - 1] |= GOT_DELTA_SIZE_MORE;
196 a319ca8c 2021-10-15 stsp buf[i] = n & GOT_DELTA_SIZE_VAL_MASK;
197 a319ca8c 2021-10-15 stsp n >>= GOT_DELTA_SIZE_SHIFT;
199 a319ca8c 2021-10-15 stsp w = fwrite(buf, 1, i, f);
200 a319ca8c 2021-10-15 stsp if (w != i)
201 a319ca8c 2021-10-15 stsp return got_ferror(f, GOT_ERR_IO);
203 a319ca8c 2021-10-15 stsp for (j = 0; j < ndeltas; j++) {
204 a319ca8c 2021-10-15 stsp d = &deltas[j];
205 a319ca8c 2021-10-15 stsp if (d->copy) {
206 a319ca8c 2021-10-15 stsp n = d->offset;
207 a319ca8c 2021-10-15 stsp bp = &buf[1];
208 a319ca8c 2021-10-15 stsp buf[0] = GOT_DELTA_BASE_COPY;
209 a319ca8c 2021-10-15 stsp for (i = 0; i < 4; i++) {
210 a319ca8c 2021-10-15 stsp /* DELTA_COPY_OFF1 ... DELTA_COPY_OFF4 */
211 a319ca8c 2021-10-15 stsp buf[0] |= 1 << i;
212 a319ca8c 2021-10-15 stsp *bp++ = n & 0xff;
214 a319ca8c 2021-10-15 stsp if (n == 0)
218 a319ca8c 2021-10-15 stsp n = d->len;
219 a319ca8c 2021-10-15 stsp if (n != GOT_DELTA_COPY_DEFAULT_LEN) {
220 a319ca8c 2021-10-15 stsp /* DELTA_COPY_LEN1 ... DELTA_COPY_LEN3 */
221 a319ca8c 2021-10-15 stsp for (i = 0; i < 3 && n > 0; i++) {
222 a319ca8c 2021-10-15 stsp buf[0] |= 1 << (i + 4);
223 a319ca8c 2021-10-15 stsp *bp++ = n & 0xff;
227 a319ca8c 2021-10-15 stsp w = fwrite(buf, 1, bp - buf, f);
228 a319ca8c 2021-10-15 stsp if (w != bp - buf)
229 a319ca8c 2021-10-15 stsp return got_ferror(f, GOT_ERR_IO);
231 a319ca8c 2021-10-15 stsp char content[128];
233 a319ca8c 2021-10-15 stsp if (fseeko(o->f, o->hdrlen + d->offset, SEEK_SET) == -1)
234 a319ca8c 2021-10-15 stsp return got_error_from_errno("fseeko");
236 a319ca8c 2021-10-15 stsp while (n != d->len) {
237 a319ca8c 2021-10-15 stsp buf[0] = (d->len - n < 127) ? d->len - n : 127;
238 a319ca8c 2021-10-15 stsp w = fwrite(buf, 1, 1, f);
239 a319ca8c 2021-10-15 stsp if (w != 1)
240 a319ca8c 2021-10-15 stsp return got_ferror(f, GOT_ERR_IO);
241 a319ca8c 2021-10-15 stsp r = fread(content, 1, buf[0], o->f);
242 a319ca8c 2021-10-15 stsp if (r != buf[0])
243 a319ca8c 2021-10-15 stsp return got_ferror(o->f, GOT_ERR_IO);
244 a319ca8c 2021-10-15 stsp w = fwrite(content, 1, buf[0], f);
245 a319ca8c 2021-10-15 stsp if (w != buf[0])
246 a319ca8c 2021-10-15 stsp return got_ferror(f, GOT_ERR_IO);
247 a319ca8c 2021-10-15 stsp n += buf[0];
252 a319ca8c 2021-10-15 stsp return NULL;
255 211cfef0 2022-01-05 stsp static const struct got_error *
256 211cfef0 2022-01-05 stsp report_progress(got_pack_progress_cb progress_cb, void *progress_arg,
257 211cfef0 2022-01-05 stsp struct got_ratelimit *rl, off_t packfile_size, int ncommits,
258 211cfef0 2022-01-05 stsp int nobj_total, int obj_deltify, int nobj_written)
260 211cfef0 2022-01-05 stsp const struct got_error *err;
261 211cfef0 2022-01-05 stsp int elapsed;
263 211cfef0 2022-01-05 stsp if (progress_cb == NULL)
264 211cfef0 2022-01-05 stsp return NULL;
266 211cfef0 2022-01-05 stsp err = got_ratelimit_check(&elapsed, rl);
267 211cfef0 2022-01-05 stsp if (err || !elapsed)
268 211cfef0 2022-01-05 stsp return err;
270 211cfef0 2022-01-05 stsp return progress_cb(progress_arg, packfile_size, ncommits,
271 211cfef0 2022-01-05 stsp nobj_total, obj_deltify, nobj_written);
274 e6bcace5 2021-06-22 stsp static const struct got_error *
275 05118f5a 2021-06-22 stsp pick_deltas(struct got_pack_meta **meta, int nmeta, int nours,
276 74881701 2021-10-15 stsp FILE *delta_cache, struct got_repository *repo,
277 05118f5a 2021-06-22 stsp got_pack_progress_cb progress_cb, void *progress_arg,
278 211cfef0 2022-01-05 stsp struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg)
280 e6bcace5 2021-06-22 stsp const struct got_error *err = NULL;
281 e6bcace5 2021-06-22 stsp struct got_pack_meta *m = NULL, *base = NULL;
282 e6bcace5 2021-06-22 stsp struct got_raw_object *raw = NULL, *base_raw = NULL;
283 74881701 2021-10-15 stsp struct got_delta_instruction *deltas = NULL, *best_deltas = NULL;
284 74881701 2021-10-15 stsp int i, j, size, best_size, ndeltas, best_ndeltas;
285 4f4d853e 2021-10-24 stsp const int max_base_candidates = 3;
286 cc7a354a 2021-10-15 stsp int outfd = -1;
288 e6bcace5 2021-06-22 stsp qsort(meta, nmeta, sizeof(struct got_pack_meta *), delta_order_cmp);
289 e6bcace5 2021-06-22 stsp for (i = 0; i < nmeta; i++) {
290 e6bcace5 2021-06-22 stsp if (cancel_cb) {
291 e6bcace5 2021-06-22 stsp err = (*cancel_cb)(cancel_arg);
295 211cfef0 2022-01-05 stsp err = report_progress(progress_cb, progress_arg, rl,
296 211cfef0 2022-01-05 stsp 0L, nours, nmeta, i, 0);
299 e6bcace5 2021-06-22 stsp m = meta[i];
301 e6bcace5 2021-06-22 stsp if (m->obj_type == GOT_OBJ_TYPE_COMMIT ||
302 e6bcace5 2021-06-22 stsp m->obj_type == GOT_OBJ_TYPE_TAG)
305 94dac27c 2021-10-15 stsp err = got_object_raw_open(&raw, &outfd, repo, &m->id);
308 600b755e 2021-10-14 stsp m->size = raw->size;
310 e6bcace5 2021-06-22 stsp err = got_deltify_init(&m->dtab, raw->f, raw->hdrlen,
311 e6bcace5 2021-06-22 stsp raw->size + raw->hdrlen);
315 e6bcace5 2021-06-22 stsp if (i > max_base_candidates) {
316 e6bcace5 2021-06-22 stsp struct got_pack_meta *n = NULL;
317 e6bcace5 2021-06-22 stsp n = meta[i - (max_base_candidates + 1)];
318 e6bcace5 2021-06-22 stsp got_deltify_free(n->dtab);
319 e6bcace5 2021-06-22 stsp n->dtab = NULL;
322 74881701 2021-10-15 stsp best_size = raw->size;
323 74881701 2021-10-15 stsp best_ndeltas = 0;
324 e6bcace5 2021-06-22 stsp for (j = MAX(0, i - max_base_candidates); j < i; j++) {
325 e6bcace5 2021-06-22 stsp if (cancel_cb) {
326 e6bcace5 2021-06-22 stsp err = (*cancel_cb)(cancel_arg);
330 e6bcace5 2021-06-22 stsp base = meta[j];
331 e6bcace5 2021-06-22 stsp /* long chains make unpacking slow, avoid such bases */
332 22edbce7 2021-10-24 stsp if (base->nchain >= 128 ||
333 e6bcace5 2021-06-22 stsp base->obj_type != m->obj_type)
336 d3c116bf 2021-10-15 stsp err = got_object_raw_open(&base_raw, &outfd, repo,
337 94dac27c 2021-10-15 stsp &base->id);
340 e6bcace5 2021-06-22 stsp err = got_deltify(&deltas, &ndeltas,
341 e6bcace5 2021-06-22 stsp raw->f, raw->hdrlen, raw->size + raw->hdrlen,
342 e6bcace5 2021-06-22 stsp base->dtab, base_raw->f, base_raw->hdrlen,
343 e6bcace5 2021-06-22 stsp base_raw->size + base_raw->hdrlen);
344 e6bcace5 2021-06-22 stsp got_object_raw_close(base_raw);
345 e6bcace5 2021-06-22 stsp base_raw = NULL;
349 e6bcace5 2021-06-22 stsp size = delta_size(deltas, ndeltas);
350 74881701 2021-10-15 stsp if (size + 32 < best_size){
352 e6bcace5 2021-06-22 stsp * if we already picked a best delta,
353 e6bcace5 2021-06-22 stsp * replace it.
355 74881701 2021-10-15 stsp best_size = size;
356 74881701 2021-10-15 stsp free(best_deltas);
357 74881701 2021-10-15 stsp best_deltas = deltas;
358 74881701 2021-10-15 stsp best_ndeltas = ndeltas;
359 74881701 2021-10-15 stsp deltas = NULL;
360 e6bcace5 2021-06-22 stsp m->nchain = base->nchain + 1;
361 e6bcace5 2021-06-22 stsp m->prev = base;
362 e6bcace5 2021-06-22 stsp m->head = base->head;
363 e6bcace5 2021-06-22 stsp if (m->head == NULL)
364 e6bcace5 2021-06-22 stsp m->head = base;
366 e6bcace5 2021-06-22 stsp free(deltas);
367 e6bcace5 2021-06-22 stsp deltas = NULL;
368 e6bcace5 2021-06-22 stsp ndeltas = 0;
372 74881701 2021-10-15 stsp if (best_ndeltas > 0) {
373 74881701 2021-10-15 stsp m->delta_offset = ftello(delta_cache);
374 74881701 2021-10-15 stsp err = encode_delta(m, raw, best_deltas,
375 74881701 2021-10-15 stsp best_ndeltas, m->prev->size, delta_cache);
376 74881701 2021-10-15 stsp free(best_deltas);
377 74881701 2021-10-15 stsp best_deltas = NULL;
378 74881701 2021-10-15 stsp best_ndeltas = 0;
381 74881701 2021-10-15 stsp m->delta_len = ftello(delta_cache) - m->delta_offset;
384 e6bcace5 2021-06-22 stsp got_object_raw_close(raw);
385 e6bcace5 2021-06-22 stsp raw = NULL;
388 e6bcace5 2021-06-22 stsp for (i = MAX(0, nmeta - max_base_candidates); i < nmeta; i++) {
389 e6bcace5 2021-06-22 stsp got_deltify_free(meta[i]->dtab);
390 e6bcace5 2021-06-22 stsp meta[i]->dtab = NULL;
393 e6bcace5 2021-06-22 stsp got_object_raw_close(raw);
394 e6bcace5 2021-06-22 stsp if (base_raw)
395 e6bcace5 2021-06-22 stsp got_object_raw_close(base_raw);
396 cc7a354a 2021-10-15 stsp if (outfd != -1 && close(outfd) == -1 && err == NULL)
397 cc7a354a 2021-10-15 stsp err = got_error_from_errno("close");
398 74881701 2021-10-15 stsp free(deltas);
399 74881701 2021-10-15 stsp free(best_deltas);
400 e6bcace5 2021-06-22 stsp return err;
403 e6bcace5 2021-06-22 stsp static const struct got_error *
404 05118f5a 2021-06-22 stsp search_packidx(int *found, struct got_object_id *id,
405 05118f5a 2021-06-22 stsp struct got_repository *repo)
407 05118f5a 2021-06-22 stsp const struct got_error *err = NULL;
408 05118f5a 2021-06-22 stsp struct got_packidx *packidx = NULL;
411 05118f5a 2021-06-22 stsp *found = 0;
413 05118f5a 2021-06-22 stsp err = got_repo_search_packidx(&packidx, &idx, repo, id);
414 05118f5a 2021-06-22 stsp if (err == NULL)
415 05118f5a 2021-06-22 stsp *found = 1; /* object is already packed */
416 05118f5a 2021-06-22 stsp else if (err->code == GOT_ERR_NO_OBJ)
417 05118f5a 2021-06-22 stsp err = NULL;
418 05118f5a 2021-06-22 stsp return err;
421 07165b17 2021-07-01 stsp static const int obj_types[] = {
422 07165b17 2021-07-01 stsp GOT_OBJ_TYPE_ANY,
423 07165b17 2021-07-01 stsp GOT_OBJ_TYPE_COMMIT,
424 07165b17 2021-07-01 stsp GOT_OBJ_TYPE_TREE,
425 07165b17 2021-07-01 stsp GOT_OBJ_TYPE_BLOB,
426 07165b17 2021-07-01 stsp GOT_OBJ_TYPE_TAG,
427 07165b17 2021-07-01 stsp GOT_OBJ_TYPE_OFFSET_DELTA,
428 07165b17 2021-07-01 stsp GOT_OBJ_TYPE_REF_DELTA
431 05118f5a 2021-06-22 stsp static const struct got_error *
432 e6bcace5 2021-06-22 stsp add_meta(struct got_pack_metavec *v, struct got_object_idset *idset,
433 e6bcace5 2021-06-22 stsp struct got_object_id *id, const char *path, int obj_type,
434 05118f5a 2021-06-22 stsp time_t mtime, int loose_obj_only, struct got_repository *repo)
436 e6bcace5 2021-06-22 stsp const struct got_error *err;
437 e6bcace5 2021-06-22 stsp struct got_pack_meta *m;
439 05118f5a 2021-06-22 stsp if (loose_obj_only) {
440 05118f5a 2021-06-22 stsp int is_packed;
441 05118f5a 2021-06-22 stsp err = search_packidx(&is_packed, id, repo);
443 05118f5a 2021-06-22 stsp return err;
444 05118f5a 2021-06-22 stsp if (is_packed)
445 05118f5a 2021-06-22 stsp return NULL;
448 07165b17 2021-07-01 stsp err = got_object_idset_add(idset, id, (void *)&obj_types[obj_type]);
450 e6bcace5 2021-06-22 stsp return err;
452 e6bcace5 2021-06-22 stsp if (v == NULL)
453 e6bcace5 2021-06-22 stsp return NULL;
455 e6bcace5 2021-06-22 stsp err = alloc_meta(&m, id, path, obj_type, mtime);
459 e6bcace5 2021-06-22 stsp if (v->nmeta == v->metasz){
460 e6bcace5 2021-06-22 stsp size_t newsize = 2 * v->metasz;
461 e6bcace5 2021-06-22 stsp struct got_pack_meta **new;
462 e6bcace5 2021-06-22 stsp new = reallocarray(v->meta, newsize, sizeof(*new));
463 e6bcace5 2021-06-22 stsp if (new == NULL) {
464 e6bcace5 2021-06-22 stsp err = got_error_from_errno("reallocarray");
467 e6bcace5 2021-06-22 stsp v->meta = new;
468 e6bcace5 2021-06-22 stsp v->metasz = newsize;
472 e6bcace5 2021-06-22 stsp clear_meta(m);
475 e6bcace5 2021-06-22 stsp v->meta[v->nmeta++] = m;
477 e6bcace5 2021-06-22 stsp return err;
480 e6bcace5 2021-06-22 stsp static const struct got_error *
481 e6bcace5 2021-06-22 stsp load_tree_entries(struct got_object_id_queue *ids, struct got_pack_metavec *v,
482 e6bcace5 2021-06-22 stsp struct got_object_idset *idset, struct got_object_id *tree_id,
483 e6bcace5 2021-06-22 stsp const char *dpath, time_t mtime, struct got_repository *repo,
484 05118f5a 2021-06-22 stsp int loose_obj_only, got_cancel_cb cancel_cb, void *cancel_arg)
486 e6bcace5 2021-06-22 stsp const struct got_error *err;
487 e6bcace5 2021-06-22 stsp struct got_tree_object *tree;
488 e6bcace5 2021-06-22 stsp char *p = NULL;
491 e6bcace5 2021-06-22 stsp err = got_object_open_as_tree(&tree, repo, tree_id);
493 e6bcace5 2021-06-22 stsp return err;
495 e6bcace5 2021-06-22 stsp for (i = 0; i < got_object_tree_get_nentries(tree); i++) {
496 e6bcace5 2021-06-22 stsp struct got_tree_entry *e = got_object_tree_get_entry(tree, i);
497 e6bcace5 2021-06-22 stsp struct got_object_id *id = got_tree_entry_get_id(e);
498 e6bcace5 2021-06-22 stsp mode_t mode = got_tree_entry_get_mode(e);
500 e6bcace5 2021-06-22 stsp if (cancel_cb) {
501 e6bcace5 2021-06-22 stsp err = (*cancel_cb)(cancel_arg);
506 3af9de88 2021-09-22 stsp if (got_object_tree_entry_is_submodule(e) ||
507 e6bcace5 2021-06-22 stsp got_object_idset_contains(idset, id))
510 e6bcace5 2021-06-22 stsp if (asprintf(&p, "%s%s%s", dpath, dpath[0] != '\0' ? "/" : "",
511 e6bcace5 2021-06-22 stsp got_tree_entry_get_name(e)) == -1) {
512 e6bcace5 2021-06-22 stsp err = got_error_from_errno("asprintf");
516 e6bcace5 2021-06-22 stsp if (S_ISDIR(mode)) {
517 e6bcace5 2021-06-22 stsp struct got_object_qid *qid;
518 e6bcace5 2021-06-22 stsp err = got_object_qid_alloc(&qid, id);
521 dbdddfee 2021-06-23 naddy STAILQ_INSERT_TAIL(ids, qid, entry);
522 3af9de88 2021-09-22 stsp } else if (S_ISREG(mode) || S_ISLNK(mode)) {
523 e6bcace5 2021-06-22 stsp err = add_meta(v, idset, id, p, GOT_OBJ_TYPE_BLOB,
524 05118f5a 2021-06-22 stsp mtime, loose_obj_only, repo);
532 e6bcace5 2021-06-22 stsp got_object_tree_close(tree);
534 e6bcace5 2021-06-22 stsp return err;
537 e6bcace5 2021-06-22 stsp static const struct got_error *
538 e6bcace5 2021-06-22 stsp load_tree(struct got_pack_metavec *v, struct got_object_idset *idset,
539 e6bcace5 2021-06-22 stsp struct got_object_id *tree_id, const char *dpath, time_t mtime,
540 05118f5a 2021-06-22 stsp int loose_obj_only, struct got_repository *repo,
541 05118f5a 2021-06-22 stsp got_cancel_cb cancel_cb, void *cancel_arg)
543 e6bcace5 2021-06-22 stsp const struct got_error *err = NULL;
544 e6bcace5 2021-06-22 stsp struct got_object_id_queue tree_ids;
545 e6bcace5 2021-06-22 stsp struct got_object_qid *qid;
547 e6bcace5 2021-06-22 stsp if (got_object_idset_contains(idset, tree_id))
548 e6bcace5 2021-06-22 stsp return NULL;
550 e6bcace5 2021-06-22 stsp err = got_object_qid_alloc(&qid, tree_id);
552 e6bcace5 2021-06-22 stsp return err;
554 dbdddfee 2021-06-23 naddy STAILQ_INIT(&tree_ids);
555 dbdddfee 2021-06-23 naddy STAILQ_INSERT_TAIL(&tree_ids, qid, entry);
557 dbdddfee 2021-06-23 naddy while (!STAILQ_EMPTY(&tree_ids)) {
558 e6bcace5 2021-06-22 stsp if (cancel_cb) {
559 e6bcace5 2021-06-22 stsp err = (*cancel_cb)(cancel_arg);
564 dbdddfee 2021-06-23 naddy qid = STAILQ_FIRST(&tree_ids);
565 dbdddfee 2021-06-23 naddy STAILQ_REMOVE_HEAD(&tree_ids, entry);
567 e6bcace5 2021-06-22 stsp if (got_object_idset_contains(idset, qid->id)) {
568 e6bcace5 2021-06-22 stsp got_object_qid_free(qid);
572 e6bcace5 2021-06-22 stsp err = add_meta(v, idset, qid->id, dpath, GOT_OBJ_TYPE_TREE,
573 05118f5a 2021-06-22 stsp mtime, loose_obj_only, repo);
575 e6bcace5 2021-06-22 stsp got_object_qid_free(qid);
579 e6bcace5 2021-06-22 stsp err = load_tree_entries(&tree_ids, v, idset, qid->id, dpath,
580 05118f5a 2021-06-22 stsp mtime, repo, loose_obj_only, cancel_cb, cancel_arg);
581 e6bcace5 2021-06-22 stsp got_object_qid_free(qid);
586 e6bcace5 2021-06-22 stsp got_object_id_queue_free(&tree_ids);
587 e6bcace5 2021-06-22 stsp return err;
590 e6bcace5 2021-06-22 stsp static const struct got_error *
591 e6bcace5 2021-06-22 stsp load_commit(struct got_pack_metavec *v, struct got_object_idset *idset,
592 05118f5a 2021-06-22 stsp struct got_object_id *id, struct got_repository *repo, int loose_obj_only,
593 e6bcace5 2021-06-22 stsp got_cancel_cb cancel_cb, void *cancel_arg)
595 e6bcace5 2021-06-22 stsp const struct got_error *err;
596 e6bcace5 2021-06-22 stsp struct got_commit_object *commit;
598 e6bcace5 2021-06-22 stsp if (got_object_idset_contains(idset, id))
599 e6bcace5 2021-06-22 stsp return NULL;
601 05118f5a 2021-06-22 stsp if (loose_obj_only) {
602 05118f5a 2021-06-22 stsp int is_packed;
603 05118f5a 2021-06-22 stsp err = search_packidx(&is_packed, id, repo);
605 05118f5a 2021-06-22 stsp return err;
606 05118f5a 2021-06-22 stsp if (is_packed)
607 05118f5a 2021-06-22 stsp return NULL;
610 e6bcace5 2021-06-22 stsp err = got_object_open_as_commit(&commit, repo, id);
612 e6bcace5 2021-06-22 stsp return err;
614 e6bcace5 2021-06-22 stsp err = add_meta(v, idset, id, "", GOT_OBJ_TYPE_COMMIT,
615 05118f5a 2021-06-22 stsp got_object_commit_get_committer_time(commit),
616 05118f5a 2021-06-22 stsp loose_obj_only, repo);
620 e6bcace5 2021-06-22 stsp err = load_tree(v, idset, got_object_commit_get_tree_id(commit),
621 05118f5a 2021-06-22 stsp "", got_object_commit_get_committer_time(commit),
622 05118f5a 2021-06-22 stsp loose_obj_only, repo, cancel_cb, cancel_arg);
624 e6bcace5 2021-06-22 stsp got_object_commit_close(commit);
625 e6bcace5 2021-06-22 stsp return err;
628 05118f5a 2021-06-22 stsp static const struct got_error *
629 05118f5a 2021-06-22 stsp load_tag(struct got_pack_metavec *v, struct got_object_idset *idset,
630 05118f5a 2021-06-22 stsp struct got_object_id *id, struct got_repository *repo, int loose_obj_only,
631 05118f5a 2021-06-22 stsp got_cancel_cb cancel_cb, void *cancel_arg)
633 05118f5a 2021-06-22 stsp const struct got_error *err;
634 05118f5a 2021-06-22 stsp struct got_tag_object *tag = NULL;
636 05118f5a 2021-06-22 stsp if (got_object_idset_contains(idset, id))
637 05118f5a 2021-06-22 stsp return NULL;
639 05118f5a 2021-06-22 stsp if (loose_obj_only) {
640 05118f5a 2021-06-22 stsp int is_packed;
641 05118f5a 2021-06-22 stsp err = search_packidx(&is_packed, id, repo);
643 05118f5a 2021-06-22 stsp return err;
644 05118f5a 2021-06-22 stsp if (is_packed)
645 05118f5a 2021-06-22 stsp return NULL;
648 05118f5a 2021-06-22 stsp err = got_object_open_as_tag(&tag, repo, id);
650 05118f5a 2021-06-22 stsp return err;
652 05118f5a 2021-06-22 stsp err = add_meta(v, idset, id, "", GOT_OBJ_TYPE_TAG,
653 05118f5a 2021-06-22 stsp got_object_tag_get_tagger_time(tag),
654 05118f5a 2021-06-22 stsp loose_obj_only, repo);
658 05118f5a 2021-06-22 stsp switch (got_object_tag_get_object_type(tag)) {
659 05118f5a 2021-06-22 stsp case GOT_OBJ_TYPE_COMMIT:
660 26960ff7 2021-09-14 stsp err = load_commit(v, idset,
661 05118f5a 2021-06-22 stsp got_object_tag_get_object_id(tag), repo,
662 05118f5a 2021-06-22 stsp loose_obj_only, cancel_cb, cancel_arg);
664 05118f5a 2021-06-22 stsp case GOT_OBJ_TYPE_TREE:
665 05118f5a 2021-06-22 stsp err = load_tree(v, idset, got_object_tag_get_object_id(tag),
666 05118f5a 2021-06-22 stsp "", got_object_tag_get_tagger_time(tag),
667 05118f5a 2021-06-22 stsp loose_obj_only, repo, cancel_cb, cancel_arg);
674 05118f5a 2021-06-22 stsp got_object_tag_close(tag);
675 05118f5a 2021-06-22 stsp return err;
678 e6bcace5 2021-06-22 stsp enum findtwixt_color {
679 e6bcace5 2021-06-22 stsp COLOR_KEEP = 0,
680 e6bcace5 2021-06-22 stsp COLOR_DROP,
681 e6bcace5 2021-06-22 stsp COLOR_BLANK,
683 e6bcace5 2021-06-22 stsp static const int findtwixt_colors[] = {
684 e6bcace5 2021-06-22 stsp COLOR_KEEP,
685 e6bcace5 2021-06-22 stsp COLOR_DROP,
686 e6bcace5 2021-06-22 stsp COLOR_BLANK
689 e6bcace5 2021-06-22 stsp static const struct got_error *
690 e6bcace5 2021-06-22 stsp queue_commit_id(struct got_object_id_queue *ids, struct got_object_id *id,
691 e6bcace5 2021-06-22 stsp int color, struct got_repository *repo)
693 e6bcace5 2021-06-22 stsp const struct got_error *err;
694 e6bcace5 2021-06-22 stsp struct got_object_qid *qid;
696 e6bcace5 2021-06-22 stsp err = got_object_qid_alloc(&qid, id);
698 e6bcace5 2021-06-22 stsp return err;
700 dbdddfee 2021-06-23 naddy STAILQ_INSERT_TAIL(ids, qid, entry);
701 e6bcace5 2021-06-22 stsp qid->data = (void *)&findtwixt_colors[color];
702 e6bcace5 2021-06-22 stsp return NULL;
705 e6bcace5 2021-06-22 stsp static const struct got_error *
706 e6bcace5 2021-06-22 stsp drop_commit(struct got_object_idset *keep, struct got_object_idset *drop,
707 e6bcace5 2021-06-22 stsp struct got_object_id *id, struct got_repository *repo,
708 e6bcace5 2021-06-22 stsp got_cancel_cb cancel_cb, void *cancel_arg)
710 e6bcace5 2021-06-22 stsp const struct got_error *err = NULL;
711 e6bcace5 2021-06-22 stsp struct got_commit_object *commit;
712 e6bcace5 2021-06-22 stsp const struct got_object_id_queue *parents;
713 e6bcace5 2021-06-22 stsp struct got_object_id_queue ids;
714 e6bcace5 2021-06-22 stsp struct got_object_qid *qid;
716 dbdddfee 2021-06-23 naddy STAILQ_INIT(&ids);
718 e6bcace5 2021-06-22 stsp err = got_object_qid_alloc(&qid, id);
720 e6bcace5 2021-06-22 stsp return err;
721 dbdddfee 2021-06-23 naddy STAILQ_INSERT_HEAD(&ids, qid, entry);
723 dbdddfee 2021-06-23 naddy while (!STAILQ_EMPTY(&ids)) {
724 e6bcace5 2021-06-22 stsp if (cancel_cb) {
725 e6bcace5 2021-06-22 stsp err = (*cancel_cb)(cancel_arg);
730 dbdddfee 2021-06-23 naddy qid = STAILQ_FIRST(&ids);
731 dbdddfee 2021-06-23 naddy STAILQ_REMOVE_HEAD(&ids, entry);
733 e6bcace5 2021-06-22 stsp if (got_object_idset_contains(drop, qid->id)) {
734 e6bcace5 2021-06-22 stsp got_object_qid_free(qid);
738 07165b17 2021-07-01 stsp err = got_object_idset_add(drop, qid->id,
739 07165b17 2021-07-01 stsp (void *)&obj_types[GOT_OBJ_TYPE_COMMIT]);
741 e6bcace5 2021-06-22 stsp got_object_qid_free(qid);
745 e6bcace5 2021-06-22 stsp if (!got_object_idset_contains(keep, qid->id)) {
746 e6bcace5 2021-06-22 stsp got_object_qid_free(qid);
750 e6bcace5 2021-06-22 stsp err = got_object_open_as_commit(&commit, repo, qid->id);
751 e6bcace5 2021-06-22 stsp got_object_qid_free(qid);
755 e6bcace5 2021-06-22 stsp parents = got_object_commit_get_parent_ids(commit);
756 e6bcace5 2021-06-22 stsp if (parents) {
757 e6bcace5 2021-06-22 stsp err = got_object_id_queue_copy(parents, &ids);
759 e6bcace5 2021-06-22 stsp got_object_commit_close(commit);
763 e6bcace5 2021-06-22 stsp got_object_commit_close(commit);
766 e6bcace5 2021-06-22 stsp got_object_id_queue_free(&ids);
767 e6bcace5 2021-06-22 stsp return err;
770 e6bcace5 2021-06-22 stsp struct append_id_arg {
771 e6bcace5 2021-06-22 stsp struct got_object_id **array;
775 e6bcace5 2021-06-22 stsp static const struct got_error *
776 e6bcace5 2021-06-22 stsp append_id(struct got_object_id *id, void *data, void *arg)
778 e6bcace5 2021-06-22 stsp struct append_id_arg *a = arg;
780 e6bcace5 2021-06-22 stsp a->array[a->idx] = got_object_id_dup(id);
781 e6bcace5 2021-06-22 stsp if (a->array[a->idx] == NULL)
782 e6bcace5 2021-06-22 stsp return got_error_from_errno("got_object_id_dup");
785 e6bcace5 2021-06-22 stsp return NULL;
788 e6bcace5 2021-06-22 stsp static const struct got_error *
789 e6bcace5 2021-06-22 stsp findtwixt(struct got_object_id ***res, int *nres,
790 e6bcace5 2021-06-22 stsp struct got_object_id **head, int nhead,
791 e6bcace5 2021-06-22 stsp struct got_object_id **tail, int ntail,
792 e6bcace5 2021-06-22 stsp struct got_repository *repo,
793 e6bcace5 2021-06-22 stsp got_cancel_cb cancel_cb, void *cancel_arg)
795 e6bcace5 2021-06-22 stsp const struct got_error *err = NULL;
796 e6bcace5 2021-06-22 stsp struct got_object_id_queue ids;
797 e6bcace5 2021-06-22 stsp struct got_object_idset *keep, *drop;
798 e6bcace5 2021-06-22 stsp struct got_object_qid *qid;
799 05118f5a 2021-06-22 stsp int i, ncolor, nkeep, obj_type;
801 dbdddfee 2021-06-23 naddy STAILQ_INIT(&ids);
802 e6bcace5 2021-06-22 stsp *res = NULL;
805 e6bcace5 2021-06-22 stsp keep = got_object_idset_alloc();
806 e6bcace5 2021-06-22 stsp if (keep == NULL)
807 e6bcace5 2021-06-22 stsp return got_error_from_errno("got_object_idset_alloc");
809 e6bcace5 2021-06-22 stsp drop = got_object_idset_alloc();
810 e6bcace5 2021-06-22 stsp if (drop == NULL) {
811 e6bcace5 2021-06-22 stsp err = got_error_from_errno("got_object_idset_alloc");
815 05118f5a 2021-06-22 stsp for (i = 0; i < nhead; i++) {
816 05118f5a 2021-06-22 stsp struct got_object_id *id = head[i];
817 05118f5a 2021-06-22 stsp if (id == NULL)
819 05118f5a 2021-06-22 stsp err = got_object_get_type(&obj_type, repo, id);
821 05118f5a 2021-06-22 stsp return err;
822 05118f5a 2021-06-22 stsp if (obj_type != GOT_OBJ_TYPE_COMMIT)
824 05118f5a 2021-06-22 stsp err = queue_commit_id(&ids, id, COLOR_KEEP, repo);
828 05118f5a 2021-06-22 stsp for (i = 0; i < ntail; i++) {
829 05118f5a 2021-06-22 stsp struct got_object_id *id = tail[i];
830 05118f5a 2021-06-22 stsp if (id == NULL)
832 05118f5a 2021-06-22 stsp err = got_object_get_type(&obj_type, repo, id);
834 05118f5a 2021-06-22 stsp return err;
835 05118f5a 2021-06-22 stsp if (obj_type != GOT_OBJ_TYPE_COMMIT)
837 05118f5a 2021-06-22 stsp err = queue_commit_id(&ids, id, COLOR_DROP, repo);
842 dbdddfee 2021-06-23 naddy while (!STAILQ_EMPTY(&ids)) {
843 e6bcace5 2021-06-22 stsp int qcolor;
844 dbdddfee 2021-06-23 naddy qid = STAILQ_FIRST(&ids);
845 e6bcace5 2021-06-22 stsp qcolor = *((int *)qid->data);
847 e6bcace5 2021-06-22 stsp if (got_object_idset_contains(drop, qid->id))
848 e6bcace5 2021-06-22 stsp ncolor = COLOR_DROP;
849 e6bcace5 2021-06-22 stsp else if (got_object_idset_contains(keep, qid->id))
850 e6bcace5 2021-06-22 stsp ncolor = COLOR_KEEP;
852 e6bcace5 2021-06-22 stsp ncolor = COLOR_BLANK;
854 e6bcace5 2021-06-22 stsp if (ncolor == COLOR_DROP || (ncolor == COLOR_KEEP &&
855 e6bcace5 2021-06-22 stsp qcolor == COLOR_KEEP)) {
856 dbdddfee 2021-06-23 naddy STAILQ_REMOVE_HEAD(&ids, entry);
857 e6bcace5 2021-06-22 stsp got_object_qid_free(qid);
861 e6bcace5 2021-06-22 stsp if (ncolor == COLOR_KEEP && qcolor == COLOR_DROP) {
862 e6bcace5 2021-06-22 stsp err = drop_commit(keep, drop, qid->id, repo,
863 e6bcace5 2021-06-22 stsp cancel_cb, cancel_arg);
866 e6bcace5 2021-06-22 stsp } else if (ncolor == COLOR_BLANK) {
867 e6bcace5 2021-06-22 stsp struct got_commit_object *commit;
868 e6bcace5 2021-06-22 stsp struct got_object_id *id;
869 e6bcace5 2021-06-22 stsp const struct got_object_id_queue *parents;
870 e6bcace5 2021-06-22 stsp struct got_object_qid *pid;
872 e6bcace5 2021-06-22 stsp id = got_object_id_dup(qid->id);
873 e6bcace5 2021-06-22 stsp if (id == NULL) {
874 e6bcace5 2021-06-22 stsp err = got_error_from_errno("got_object_id_dup");
877 e6bcace5 2021-06-22 stsp if (qcolor == COLOR_KEEP)
878 07165b17 2021-07-01 stsp err = got_object_idset_add(keep, id,
879 07165b17 2021-07-01 stsp (void *)&obj_types[GOT_OBJ_TYPE_COMMIT]);
881 07165b17 2021-07-01 stsp err = got_object_idset_add(drop, id,
882 07165b17 2021-07-01 stsp (void *)&obj_types[GOT_OBJ_TYPE_COMMIT]);
888 e6bcace5 2021-06-22 stsp err = got_object_open_as_commit(&commit, repo, id);
893 e6bcace5 2021-06-22 stsp parents = got_object_commit_get_parent_ids(commit);
894 e6bcace5 2021-06-22 stsp if (parents) {
895 dbdddfee 2021-06-23 naddy STAILQ_FOREACH(pid, parents, entry) {
896 e6bcace5 2021-06-22 stsp err = queue_commit_id(&ids, pid->id,
897 e6bcace5 2021-06-22 stsp qcolor, repo);
904 e6bcace5 2021-06-22 stsp got_object_commit_close(commit);
905 e6bcace5 2021-06-22 stsp commit = NULL;
907 e6bcace5 2021-06-22 stsp /* should not happen */
908 e6bcace5 2021-06-22 stsp err = got_error_fmt(GOT_ERR_NOT_IMPL,
909 e6bcace5 2021-06-22 stsp "%s ncolor=%d qcolor=%d", __func__, ncolor, qcolor);
913 dbdddfee 2021-06-23 naddy STAILQ_REMOVE_HEAD(&ids, entry);
914 e6bcace5 2021-06-22 stsp got_object_qid_free(qid);
917 e6bcace5 2021-06-22 stsp nkeep = got_object_idset_num_elements(keep);
918 e6bcace5 2021-06-22 stsp if (nkeep > 0) {
919 e6bcace5 2021-06-22 stsp struct append_id_arg arg;
920 e6bcace5 2021-06-22 stsp arg.array = calloc(nkeep, sizeof(struct got_object_id *));
921 e6bcace5 2021-06-22 stsp if (arg.array == NULL) {
922 e6bcace5 2021-06-22 stsp err = got_error_from_errno("calloc");
925 e6bcace5 2021-06-22 stsp arg.idx = 0;
926 e6bcace5 2021-06-22 stsp err = got_object_idset_for_each(keep, append_id, &arg);
928 e6bcace5 2021-06-22 stsp free(arg.array);
931 e6bcace5 2021-06-22 stsp *res = arg.array;
932 e6bcace5 2021-06-22 stsp *nres = nkeep;
935 e6bcace5 2021-06-22 stsp got_object_idset_free(keep);
936 e6bcace5 2021-06-22 stsp got_object_idset_free(drop);
937 e6bcace5 2021-06-22 stsp got_object_id_queue_free(&ids);
938 e6bcace5 2021-06-22 stsp return err;
941 e6bcace5 2021-06-22 stsp static const struct got_error *
942 e6bcace5 2021-06-22 stsp read_meta(struct got_pack_meta ***meta, int *nmeta,
943 e6bcace5 2021-06-22 stsp struct got_object_id **theirs, int ntheirs,
944 e6bcace5 2021-06-22 stsp struct got_object_id **ours, int nours, struct got_repository *repo,
945 05118f5a 2021-06-22 stsp int loose_obj_only, got_pack_progress_cb progress_cb, void *progress_arg,
946 211cfef0 2022-01-05 stsp struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg)
948 e6bcace5 2021-06-22 stsp const struct got_error *err = NULL;
949 e6bcace5 2021-06-22 stsp struct got_object_id **ids = NULL;
950 e6bcace5 2021-06-22 stsp struct got_object_idset *idset;
951 05118f5a 2021-06-22 stsp int i, nobj = 0, obj_type;
952 e6bcace5 2021-06-22 stsp struct got_pack_metavec v;
954 e6bcace5 2021-06-22 stsp *meta = NULL;
955 e6bcace5 2021-06-22 stsp *nmeta = 0;
957 e6bcace5 2021-06-22 stsp idset = got_object_idset_alloc();
958 e6bcace5 2021-06-22 stsp if (idset == NULL)
959 e6bcace5 2021-06-22 stsp return got_error_from_errno("got_object_idset_alloc");
961 e6bcace5 2021-06-22 stsp v.nmeta = 0;
962 e6bcace5 2021-06-22 stsp v.metasz = 64;
963 e6bcace5 2021-06-22 stsp v.meta = calloc(v.metasz, sizeof(struct got_pack_meta *));
964 e6bcace5 2021-06-22 stsp if (v.meta == NULL) {
965 1d19226a 2021-10-13 stsp err = got_error_from_errno("calloc");
969 e6bcace5 2021-06-22 stsp err = findtwixt(&ids, &nobj, ours, nours, theirs, ntheirs, repo,
970 e6bcace5 2021-06-22 stsp cancel_cb, cancel_arg);
971 e6bcace5 2021-06-22 stsp if (err || nobj == 0)
974 e6bcace5 2021-06-22 stsp for (i = 0; i < ntheirs; i++) {
975 05118f5a 2021-06-22 stsp struct got_object_id *id = theirs[i];
976 05118f5a 2021-06-22 stsp if (id == NULL)
978 05118f5a 2021-06-22 stsp err = got_object_get_type(&obj_type, repo, id);
980 05118f5a 2021-06-22 stsp return err;
981 05118f5a 2021-06-22 stsp if (obj_type != GOT_OBJ_TYPE_COMMIT)
983 05118f5a 2021-06-22 stsp err = load_commit(NULL, idset, id, repo,
984 05118f5a 2021-06-22 stsp loose_obj_only, cancel_cb, cancel_arg);
987 211cfef0 2022-01-05 stsp err = report_progress(progress_cb, progress_arg, rl,
988 211cfef0 2022-01-05 stsp 0L, nours, v.nmeta, 0, 0);
993 05118f5a 2021-06-22 stsp for (i = 0; i < ntheirs; i++) {
994 f4a2ff2d 2021-07-01 stsp struct got_object_id *id = theirs[i];
995 07165b17 2021-07-01 stsp int *cached_type;
996 05118f5a 2021-06-22 stsp if (id == NULL)
998 07165b17 2021-07-01 stsp cached_type = got_object_idset_get(idset, id);
999 07165b17 2021-07-01 stsp if (cached_type == NULL) {
1000 07165b17 2021-07-01 stsp err = got_object_get_type(&obj_type, repo, id);
1002 07165b17 2021-07-01 stsp goto done;
1004 07165b17 2021-07-01 stsp obj_type = *cached_type;
1005 05118f5a 2021-06-22 stsp if (obj_type != GOT_OBJ_TYPE_TAG)
1007 05118f5a 2021-06-22 stsp err = load_tag(NULL, idset, id, repo,
1008 05118f5a 2021-06-22 stsp loose_obj_only, cancel_cb, cancel_arg);
1010 05118f5a 2021-06-22 stsp goto done;
1011 211cfef0 2022-01-05 stsp err = report_progress(progress_cb, progress_arg, rl,
1012 211cfef0 2022-01-05 stsp 0L, nours, v.nmeta, 0, 0);
1014 211cfef0 2022-01-05 stsp goto done;
1017 eca70f98 2021-09-03 stsp for (i = 0; i < nobj; i++) {
1018 eca70f98 2021-09-03 stsp err = load_commit(&v, idset, ids[i], repo,
1019 eca70f98 2021-09-03 stsp loose_obj_only, cancel_cb, cancel_arg);
1021 eca70f98 2021-09-03 stsp goto done;
1023 211cfef0 2022-01-05 stsp goto done;
1024 211cfef0 2022-01-05 stsp err = report_progress(progress_cb, progress_arg, rl,
1025 211cfef0 2022-01-05 stsp 0L, nours, v.nmeta, 0, 0);
1027 211cfef0 2022-01-05 stsp goto done;
1030 05118f5a 2021-06-22 stsp for (i = 0; i < nours; i++) {
1031 05118f5a 2021-06-22 stsp struct got_object_id *id = ours[i];
1032 07165b17 2021-07-01 stsp int *cached_type;
1033 05118f5a 2021-06-22 stsp if (id == NULL)
1035 07165b17 2021-07-01 stsp cached_type = got_object_idset_get(idset, id);
1036 07165b17 2021-07-01 stsp if (cached_type == NULL) {
1037 07165b17 2021-07-01 stsp err = got_object_get_type(&obj_type, repo, id);
1039 07165b17 2021-07-01 stsp goto done;
1041 07165b17 2021-07-01 stsp obj_type = *cached_type;
1042 05118f5a 2021-06-22 stsp if (obj_type != GOT_OBJ_TYPE_TAG)
1044 05118f5a 2021-06-22 stsp err = load_tag(&v, idset, id, repo,
1045 05118f5a 2021-06-22 stsp loose_obj_only, cancel_cb, cancel_arg);
1047 e6bcace5 2021-06-22 stsp goto done;
1048 211cfef0 2022-01-05 stsp err = report_progress(progress_cb, progress_arg, rl,
1049 211cfef0 2022-01-05 stsp 0L, nours, v.nmeta, 0, 0);
1051 211cfef0 2022-01-05 stsp goto done;
1054 211cfef0 2022-01-05 stsp if (progress_cb) {
1055 211cfef0 2022-01-05 stsp err = progress_cb(progress_arg, 0L, nours, v.nmeta, 0, 0);
1057 211cfef0 2022-01-05 stsp goto done;
1060 e6bcace5 2021-06-22 stsp for (i = 0; i < nobj; i++) {
1061 e6bcace5 2021-06-22 stsp free(ids[i]);
1063 e6bcace5 2021-06-22 stsp free(ids);
1064 e6bcace5 2021-06-22 stsp got_object_idset_free(idset);
1065 e6bcace5 2021-06-22 stsp if (err == NULL) {
1066 e6bcace5 2021-06-22 stsp *meta = v.meta;
1067 e6bcace5 2021-06-22 stsp *nmeta = v.nmeta;
1069 e6bcace5 2021-06-22 stsp free(v.meta);
1071 e6bcace5 2021-06-22 stsp return err;
1074 e6bcace5 2021-06-22 stsp const struct got_error *
1075 e6bcace5 2021-06-22 stsp hwrite(FILE *f, void *buf, int len, SHA1_CTX *ctx)
1079 e6bcace5 2021-06-22 stsp SHA1Update(ctx, buf, len);
1080 e6bcace5 2021-06-22 stsp n = fwrite(buf, 1, len, f);
1081 e6bcace5 2021-06-22 stsp if (n != len)
1082 e6bcace5 2021-06-22 stsp return got_ferror(f, GOT_ERR_IO);
1083 e6bcace5 2021-06-22 stsp return NULL;
1086 e6bcace5 2021-06-22 stsp static void
1087 e6bcace5 2021-06-22 stsp putbe32(char *b, uint32_t n)
1089 e6bcace5 2021-06-22 stsp b[0] = n >> 24;
1090 e6bcace5 2021-06-22 stsp b[1] = n >> 16;
1091 e6bcace5 2021-06-22 stsp b[2] = n >> 8;
1092 e6bcace5 2021-06-22 stsp b[3] = n >> 0;
1095 e6bcace5 2021-06-22 stsp static int
1096 e6bcace5 2021-06-22 stsp write_order_cmp(const void *pa, const void *pb)
1098 e6bcace5 2021-06-22 stsp struct got_pack_meta *a, *b, *ahd, *bhd;
1100 e6bcace5 2021-06-22 stsp a = *(struct got_pack_meta **)pa;
1101 e6bcace5 2021-06-22 stsp b = *(struct got_pack_meta **)pb;
1102 e6bcace5 2021-06-22 stsp ahd = (a->head == NULL) ? a : a->head;
1103 e6bcace5 2021-06-22 stsp bhd = (b->head == NULL) ? b : b->head;
1104 e6bcace5 2021-06-22 stsp if (ahd->mtime != bhd->mtime)
1105 e6bcace5 2021-06-22 stsp return bhd->mtime - ahd->mtime;
1106 e6bcace5 2021-06-22 stsp if (ahd != bhd)
1107 e6bcace5 2021-06-22 stsp return (uintptr_t)bhd - (uintptr_t)ahd;
1108 e6bcace5 2021-06-22 stsp if (a->nchain != b->nchain)
1109 e6bcace5 2021-06-22 stsp return a->nchain - b->nchain;
1110 e6bcace5 2021-06-22 stsp return a->mtime - b->mtime;
1113 e6bcace5 2021-06-22 stsp static const struct got_error *
1114 e6bcace5 2021-06-22 stsp packhdr(int *hdrlen, char *hdr, size_t bufsize, int obj_type, size_t len)
1118 e6bcace5 2021-06-22 stsp *hdrlen = 0;
1120 e6bcace5 2021-06-22 stsp hdr[0] = obj_type << 4;
1121 e6bcace5 2021-06-22 stsp hdr[0] |= len & 0xf;
1122 e6bcace5 2021-06-22 stsp len >>= 4;
1123 e6bcace5 2021-06-22 stsp for (i = 1; len != 0; i++){
1124 e6bcace5 2021-06-22 stsp if (i >= bufsize)
1125 e6bcace5 2021-06-22 stsp return got_error(GOT_ERR_NO_SPACE);
1126 e6bcace5 2021-06-22 stsp hdr[i - 1] |= GOT_DELTA_SIZE_MORE;
1127 e6bcace5 2021-06-22 stsp hdr[i] = len & GOT_DELTA_SIZE_VAL_MASK;
1128 e6bcace5 2021-06-22 stsp len >>= GOT_DELTA_SIZE_SHIFT;
1131 e6bcace5 2021-06-22 stsp *hdrlen = i;
1132 e6bcace5 2021-06-22 stsp return NULL;
1135 e6bcace5 2021-06-22 stsp static int
1136 e6bcace5 2021-06-22 stsp packoff(char *hdr, off_t off)
1139 e6bcace5 2021-06-22 stsp char rbuf[8];
1141 e6bcace5 2021-06-22 stsp rbuf[0] = off & GOT_DELTA_SIZE_VAL_MASK;
1142 e6bcace5 2021-06-22 stsp for (i = 1; (off >>= GOT_DELTA_SIZE_SHIFT) != 0; i++) {
1143 e6bcace5 2021-06-22 stsp rbuf[i] = (--off & GOT_DELTA_SIZE_VAL_MASK) |
1144 e6bcace5 2021-06-22 stsp GOT_DELTA_SIZE_MORE;
1148 e6bcace5 2021-06-22 stsp while (i > 0)
1149 e6bcace5 2021-06-22 stsp hdr[j++] = rbuf[--i];
1153 e6bcace5 2021-06-22 stsp static const struct got_error *
1154 74881701 2021-10-15 stsp genpack(uint8_t *pack_sha1, FILE *packfile, FILE *delta_cache,
1155 05118f5a 2021-06-22 stsp struct got_pack_meta **meta, int nmeta, int nours,
1156 05118f5a 2021-06-22 stsp int use_offset_deltas, struct got_repository *repo,
1157 05118f5a 2021-06-22 stsp got_pack_progress_cb progress_cb, void *progress_arg,
1158 211cfef0 2022-01-05 stsp struct got_ratelimit *rl,
1159 05118f5a 2021-06-22 stsp got_cancel_cb cancel_cb, void *cancel_arg)
1161 e6bcace5 2021-06-22 stsp const struct got_error *err = NULL;
1162 08347b73 2021-10-14 stsp int i, nh;
1163 e6bcace5 2021-06-22 stsp SHA1_CTX ctx;
1164 e6bcace5 2021-06-22 stsp struct got_pack_meta *m;
1165 600b755e 2021-10-14 stsp struct got_raw_object *raw = NULL;
1166 08347b73 2021-10-14 stsp FILE *delta_file = NULL;
1167 08347b73 2021-10-14 stsp char buf[32];
1168 e6bcace5 2021-06-22 stsp size_t outlen, n;
1169 e6bcace5 2021-06-22 stsp struct got_deflate_checksum csum;
1170 05118f5a 2021-06-22 stsp off_t packfile_size = 0;
1171 cc7a354a 2021-10-15 stsp int outfd = -1;
1173 e6bcace5 2021-06-22 stsp SHA1Init(&ctx);
1174 e6bcace5 2021-06-22 stsp csum.output_sha1 = &ctx;
1175 e6bcace5 2021-06-22 stsp csum.output_crc = NULL;
1177 e6bcace5 2021-06-22 stsp err = hwrite(packfile, "PACK", 4, &ctx);
1179 e6bcace5 2021-06-22 stsp return err;
1180 e6bcace5 2021-06-22 stsp putbe32(buf, GOT_PACKFILE_VERSION);
1181 e6bcace5 2021-06-22 stsp err = hwrite(packfile, buf, 4, &ctx);
1183 e6bcace5 2021-06-22 stsp goto done;
1184 e6bcace5 2021-06-22 stsp putbe32(buf, nmeta);
1185 e6bcace5 2021-06-22 stsp err = hwrite(packfile, buf, 4, &ctx);
1187 e6bcace5 2021-06-22 stsp goto done;
1188 e6bcace5 2021-06-22 stsp qsort(meta, nmeta, sizeof(struct got_pack_meta *), write_order_cmp);
1189 05118f5a 2021-06-22 stsp for (i = 0; i < nmeta; i++) {
1190 211cfef0 2022-01-05 stsp err = report_progress(progress_cb, progress_arg, rl,
1191 211cfef0 2022-01-05 stsp packfile_size, nours, nmeta, nmeta, i);
1193 211cfef0 2022-01-05 stsp goto done;
1194 e6bcace5 2021-06-22 stsp m = meta[i];
1195 e6bcace5 2021-06-22 stsp m->off = ftello(packfile);
1196 94dac27c 2021-10-15 stsp err = got_object_raw_open(&raw, &outfd, repo, &m->id);
1198 e6bcace5 2021-06-22 stsp goto done;
1199 74881701 2021-10-15 stsp if (m->delta_len == 0) {
1200 e6bcace5 2021-06-22 stsp err = packhdr(&nh, buf, sizeof(buf),
1201 e6bcace5 2021-06-22 stsp m->obj_type, raw->size);
1203 e6bcace5 2021-06-22 stsp goto done;
1204 e6bcace5 2021-06-22 stsp err = hwrite(packfile, buf, nh, &ctx);
1206 e6bcace5 2021-06-22 stsp goto done;
1207 05118f5a 2021-06-22 stsp packfile_size += nh;
1208 e6bcace5 2021-06-22 stsp if (fseeko(raw->f, raw->hdrlen, SEEK_SET) == -1) {
1209 e6bcace5 2021-06-22 stsp err = got_error_from_errno("fseeko");
1210 e6bcace5 2021-06-22 stsp goto done;
1212 e6bcace5 2021-06-22 stsp err = got_deflate_to_file(&outlen, raw->f, packfile,
1215 e6bcace5 2021-06-22 stsp goto done;
1216 05118f5a 2021-06-22 stsp packfile_size += outlen;
1218 74881701 2021-10-15 stsp off_t remain;
1219 08347b73 2021-10-14 stsp if (delta_file == NULL) {
1220 08347b73 2021-10-14 stsp delta_file = got_opentemp();
1221 08347b73 2021-10-14 stsp if (delta_file == NULL) {
1222 08347b73 2021-10-14 stsp err = got_error_from_errno(
1223 08347b73 2021-10-14 stsp "got_opentemp");
1224 08347b73 2021-10-14 stsp goto done;
1227 08347b73 2021-10-14 stsp if (ftruncate(fileno(delta_file), 0L) == -1) {
1228 08347b73 2021-10-14 stsp err = got_error_from_errno("ftruncate");
1229 08347b73 2021-10-14 stsp goto done;
1231 08347b73 2021-10-14 stsp if (fseeko(delta_file, 0L, SEEK_SET) == -1) {
1232 08347b73 2021-10-14 stsp err = got_error_from_errno("fseeko");
1233 08347b73 2021-10-14 stsp goto done;
1235 74881701 2021-10-15 stsp if (fseeko(delta_cache, m->delta_offset, SEEK_SET)
1237 08347b73 2021-10-14 stsp err = got_error_from_errno("fseeko");
1238 08347b73 2021-10-14 stsp goto done;
1240 74881701 2021-10-15 stsp remain = m->delta_len;
1241 74881701 2021-10-15 stsp while (remain > 0) {
1242 74881701 2021-10-15 stsp char delta_buf[8192];
1243 74881701 2021-10-15 stsp size_t r, w, n;
1244 74881701 2021-10-15 stsp n = MIN(remain, sizeof(delta_buf));
1245 74881701 2021-10-15 stsp r = fread(delta_buf, 1, n, delta_cache);
1246 74881701 2021-10-15 stsp if (r != n) {
1247 74881701 2021-10-15 stsp err = got_ferror(delta_cache,
1248 74881701 2021-10-15 stsp GOT_ERR_IO);
1249 74881701 2021-10-15 stsp goto done;
1251 74881701 2021-10-15 stsp w = fwrite(delta_buf, 1, n, delta_file);
1252 74881701 2021-10-15 stsp if (w != n) {
1253 74881701 2021-10-15 stsp err = got_ferror(delta_file,
1254 74881701 2021-10-15 stsp GOT_ERR_IO);
1255 74881701 2021-10-15 stsp goto done;
1257 74881701 2021-10-15 stsp remain -= n;
1259 e6bcace5 2021-06-22 stsp if (use_offset_deltas && m->prev->off != 0) {
1260 e6bcace5 2021-06-22 stsp err = packhdr(&nh, buf, sizeof(buf),
1261 74881701 2021-10-15 stsp GOT_OBJ_TYPE_OFFSET_DELTA, m->delta_len);
1263 e6bcace5 2021-06-22 stsp goto done;
1264 e6bcace5 2021-06-22 stsp nh += packoff(buf + nh,
1265 e6bcace5 2021-06-22 stsp m->off - m->prev->off);
1266 e6bcace5 2021-06-22 stsp err = hwrite(packfile, buf, nh, &ctx);
1268 e6bcace5 2021-06-22 stsp goto done;
1269 05118f5a 2021-06-22 stsp packfile_size += nh;
1271 e6bcace5 2021-06-22 stsp err = packhdr(&nh, buf, sizeof(buf),
1272 74881701 2021-10-15 stsp GOT_OBJ_TYPE_REF_DELTA, m->delta_len);
1273 e6bcace5 2021-06-22 stsp err = hwrite(packfile, buf, nh, &ctx);
1275 e6bcace5 2021-06-22 stsp goto done;
1276 05118f5a 2021-06-22 stsp packfile_size += nh;
1277 e6bcace5 2021-06-22 stsp err = hwrite(packfile, m->prev->id.sha1,
1278 e6bcace5 2021-06-22 stsp sizeof(m->prev->id.sha1), &ctx);
1279 05118f5a 2021-06-22 stsp packfile_size += sizeof(m->prev->id.sha1);
1281 e6bcace5 2021-06-22 stsp goto done;
1283 74881701 2021-10-15 stsp if (fseeko(delta_file, 0L, SEEK_SET) == -1) {
1284 74881701 2021-10-15 stsp err = got_error_from_errno("fseeko");
1285 74881701 2021-10-15 stsp goto done;
1287 e6bcace5 2021-06-22 stsp err = got_deflate_to_file(&outlen, delta_file,
1288 e6bcace5 2021-06-22 stsp packfile, &csum);
1290 e6bcace5 2021-06-22 stsp goto done;
1291 05118f5a 2021-06-22 stsp packfile_size += outlen;
1293 e6bcace5 2021-06-22 stsp got_object_raw_close(raw);
1294 e6bcace5 2021-06-22 stsp raw = NULL;
1296 e6bcace5 2021-06-22 stsp SHA1Final(pack_sha1, &ctx);
1297 e6bcace5 2021-06-22 stsp n = fwrite(pack_sha1, 1, SHA1_DIGEST_LENGTH, packfile);
1298 e6bcace5 2021-06-22 stsp if (n != SHA1_DIGEST_LENGTH)
1299 e6bcace5 2021-06-22 stsp err = got_ferror(packfile, GOT_ERR_IO);
1300 05118f5a 2021-06-22 stsp packfile_size += SHA1_DIGEST_LENGTH;
1301 dc7edd42 2021-08-22 stsp packfile_size += sizeof(struct got_packfile_hdr);
1302 211cfef0 2022-01-05 stsp if (progress_cb) {
1303 211cfef0 2022-01-05 stsp err = progress_cb(progress_arg, packfile_size, nours,
1304 211cfef0 2022-01-05 stsp nmeta, nmeta, nmeta);
1306 211cfef0 2022-01-05 stsp goto done;
1309 08347b73 2021-10-14 stsp if (delta_file && fclose(delta_file) == EOF && err == NULL)
1310 08347b73 2021-10-14 stsp err = got_error_from_errno("fclose");
1312 08347b73 2021-10-14 stsp got_object_raw_close(raw);
1313 cc7a354a 2021-10-15 stsp if (outfd != -1 && close(outfd) == -1 && err == NULL)
1314 cc7a354a 2021-10-15 stsp err = got_error_from_errno("close");
1315 e6bcace5 2021-06-22 stsp return err;
1318 e6bcace5 2021-06-22 stsp const struct got_error *
1319 e6bcace5 2021-06-22 stsp got_pack_create(uint8_t *packsha1, FILE *packfile,
1320 e6bcace5 2021-06-22 stsp struct got_object_id **theirs, int ntheirs,
1321 e6bcace5 2021-06-22 stsp struct got_object_id **ours, int nours,
1322 f8a36e22 2021-08-26 stsp struct got_repository *repo, int loose_obj_only, int allow_empty,
1323 05118f5a 2021-06-22 stsp got_pack_progress_cb progress_cb, void *progress_arg,
1324 05118f5a 2021-06-22 stsp got_cancel_cb cancel_cb, void *cancel_arg)
1326 e6bcace5 2021-06-22 stsp const struct got_error *err;
1327 e6bcace5 2021-06-22 stsp struct got_pack_meta **meta;
1328 e6bcace5 2021-06-22 stsp int nmeta;
1329 74881701 2021-10-15 stsp FILE *delta_cache = NULL;
1330 211cfef0 2022-01-05 stsp struct got_ratelimit rl;
1332 211cfef0 2022-01-05 stsp got_ratelimit_init(&rl, 0, 500);
1334 e6bcace5 2021-06-22 stsp err = read_meta(&meta, &nmeta, theirs, ntheirs, ours, nours, repo,
1335 211cfef0 2022-01-05 stsp loose_obj_only, progress_cb, progress_arg, &rl,
1336 211cfef0 2022-01-05 stsp cancel_cb, cancel_arg);
1338 e6bcace5 2021-06-22 stsp return err;
1340 f8a36e22 2021-08-26 stsp if (nmeta == 0 && !allow_empty) {
1341 05118f5a 2021-06-22 stsp err = got_error(GOT_ERR_CANNOT_PACK);
1342 05118f5a 2021-06-22 stsp goto done;
1345 74881701 2021-10-15 stsp delta_cache = got_opentemp();
1346 74881701 2021-10-15 stsp if (delta_cache == NULL) {
1347 74881701 2021-10-15 stsp err = got_error_from_errno("got_opentemp");
1348 74881701 2021-10-15 stsp goto done;
1351 f8a36e22 2021-08-26 stsp if (nmeta > 0) {
1352 74881701 2021-10-15 stsp err = pick_deltas(meta, nmeta, nours, delta_cache, repo,
1353 211cfef0 2022-01-05 stsp progress_cb, progress_arg, &rl, cancel_cb, cancel_arg);
1355 f8a36e22 2021-08-26 stsp goto done;
1356 74881701 2021-10-15 stsp if (fseeko(delta_cache, 0L, SEEK_SET) == -1) {
1357 74881701 2021-10-15 stsp err = got_error_from_errno("fseeko");
1358 74881701 2021-10-15 stsp goto done;
1362 74881701 2021-10-15 stsp err = genpack(packsha1, packfile, delta_cache, meta, nmeta, nours, 1,
1363 211cfef0 2022-01-05 stsp repo, progress_cb, progress_arg, &rl, cancel_cb, cancel_arg);
1365 e6bcace5 2021-06-22 stsp goto done;
1367 e6bcace5 2021-06-22 stsp free_nmeta(meta, nmeta);
1368 74881701 2021-10-15 stsp if (delta_cache && fclose(delta_cache) == EOF && err == NULL)
1369 74881701 2021-10-15 stsp err = got_error_from_errno("fclose");
1370 e6bcace5 2021-06-22 stsp return err;