Blame


1 3efd8e31 2022-10-23 thomas /*
2 3efd8e31 2022-10-23 thomas * Copyright (c) 2020 Ori Bernstein
3 3efd8e31 2022-10-23 thomas * Copyright (c) 2021, 2022 Stefan Sperling <stsp@openbsd.org>
4 3efd8e31 2022-10-23 thomas *
5 3efd8e31 2022-10-23 thomas * Permission to use, copy, modify, and distribute this software for any
6 3efd8e31 2022-10-23 thomas * purpose with or without fee is hereby granted, provided that the above
7 3efd8e31 2022-10-23 thomas * copyright notice and this permission notice appear in all copies.
8 3efd8e31 2022-10-23 thomas *
9 3efd8e31 2022-10-23 thomas * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 3efd8e31 2022-10-23 thomas * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 3efd8e31 2022-10-23 thomas * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 3efd8e31 2022-10-23 thomas * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 3efd8e31 2022-10-23 thomas * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 3efd8e31 2022-10-23 thomas * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 3efd8e31 2022-10-23 thomas * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 3efd8e31 2022-10-23 thomas */
17 4efc8dcb 2023-08-29 thomas
18 4efc8dcb 2023-08-29 thomas #include "got_compat.h"
19 3efd8e31 2022-10-23 thomas
20 3efd8e31 2022-10-23 thomas #include <sys/types.h>
21 3efd8e31 2022-10-23 thomas #include <sys/queue.h>
22 3efd8e31 2022-10-23 thomas #include <sys/uio.h>
23 3efd8e31 2022-10-23 thomas
24 3efd8e31 2022-10-23 thomas #include <limits.h>
25 3efd8e31 2022-10-23 thomas #include <stdio.h>
26 3efd8e31 2022-10-23 thomas #include <stdint.h>
27 3efd8e31 2022-10-23 thomas #include <stdlib.h>
28 3efd8e31 2022-10-23 thomas #include <string.h>
29 3efd8e31 2022-10-23 thomas #include <time.h>
30 3efd8e31 2022-10-23 thomas #include <imsg.h>
31 3efd8e31 2022-10-23 thomas #include <inttypes.h>
32 3efd8e31 2022-10-23 thomas #include <unistd.h>
33 3efd8e31 2022-10-23 thomas
34 3efd8e31 2022-10-23 thomas #include "got_error.h"
35 3efd8e31 2022-10-23 thomas #include "got_cancel.h"
36 3efd8e31 2022-10-23 thomas #include "got_object.h"
37 3efd8e31 2022-10-23 thomas #include "got_reference.h"
38 3efd8e31 2022-10-23 thomas #include "got_repository_admin.h"
39 3efd8e31 2022-10-23 thomas #include "got_path.h"
40 3efd8e31 2022-10-23 thomas
41 3efd8e31 2022-10-23 thomas #include "got_lib_delta.h"
42 3efd8e31 2022-10-23 thomas #include "got_lib_object.h"
43 3efd8e31 2022-10-23 thomas #include "got_lib_object_cache.h"
44 3efd8e31 2022-10-23 thomas #include "got_lib_object_idset.h"
45 3efd8e31 2022-10-23 thomas #include "got_lib_ratelimit.h"
46 3efd8e31 2022-10-23 thomas #include "got_lib_pack.h"
47 3efd8e31 2022-10-23 thomas #include "got_lib_pack_create.h"
48 3efd8e31 2022-10-23 thomas #include "got_lib_repository.h"
49 3efd8e31 2022-10-23 thomas
50 3efd8e31 2022-10-23 thomas static const struct got_error *
51 3efd8e31 2022-10-23 thomas get_base_object_id(struct got_object_id *base_id, struct got_packidx *packidx,
52 3efd8e31 2022-10-23 thomas off_t base_offset)
53 3efd8e31 2022-10-23 thomas {
54 3efd8e31 2022-10-23 thomas const struct got_error *err;
55 3efd8e31 2022-10-23 thomas int idx;
56 3efd8e31 2022-10-23 thomas
57 3efd8e31 2022-10-23 thomas err = got_packidx_get_offset_idx(&idx, packidx, base_offset);
58 3efd8e31 2022-10-23 thomas if (err)
59 3efd8e31 2022-10-23 thomas return err;
60 3efd8e31 2022-10-23 thomas if (idx == -1)
61 3efd8e31 2022-10-23 thomas return got_error(GOT_ERR_BAD_PACKIDX);
62 3efd8e31 2022-10-23 thomas
63 3efd8e31 2022-10-23 thomas return got_packidx_get_object_id(base_id, packidx, idx);
64 3efd8e31 2022-10-23 thomas }
65 3efd8e31 2022-10-23 thomas
66 3efd8e31 2022-10-23 thomas struct search_deltas_arg {
67 3efd8e31 2022-10-23 thomas struct got_pack_metavec *v;
68 3efd8e31 2022-10-23 thomas struct got_packidx *packidx;
69 3efd8e31 2022-10-23 thomas struct got_pack *pack;
70 3efd8e31 2022-10-23 thomas struct got_object_idset *idset;
71 3efd8e31 2022-10-23 thomas int ncolored, nfound, ntrees, ncommits;
72 3efd8e31 2022-10-23 thomas got_pack_progress_cb progress_cb;
73 3efd8e31 2022-10-23 thomas void *progress_arg;
74 3efd8e31 2022-10-23 thomas struct got_ratelimit *rl;
75 3efd8e31 2022-10-23 thomas got_cancel_cb cancel_cb;
76 3efd8e31 2022-10-23 thomas void *cancel_arg;
77 3efd8e31 2022-10-23 thomas };
78 3efd8e31 2022-10-23 thomas
79 3efd8e31 2022-10-23 thomas static const struct got_error *
80 3efd8e31 2022-10-23 thomas search_delta_for_object(struct got_object_id *id, void *data, void *arg)
81 3efd8e31 2022-10-23 thomas {
82 3efd8e31 2022-10-23 thomas const struct got_error *err;
83 3efd8e31 2022-10-23 thomas struct search_deltas_arg *a = arg;
84 3efd8e31 2022-10-23 thomas int obj_idx;
85 3efd8e31 2022-10-23 thomas uint8_t *delta_buf = NULL;
86 3efd8e31 2022-10-23 thomas uint64_t base_size, result_size;
87 3efd8e31 2022-10-23 thomas size_t delta_size, delta_compressed_size;
88 c44c7d6e 2022-12-04 thomas off_t delta_offset, delta_data_offset, base_offset;
89 3efd8e31 2022-10-23 thomas struct got_object_id base_id;
90 3efd8e31 2022-10-23 thomas
91 3efd8e31 2022-10-23 thomas if (a->cancel_cb) {
92 3efd8e31 2022-10-23 thomas err = a->cancel_cb(a->cancel_arg);
93 3efd8e31 2022-10-23 thomas if (err)
94 3efd8e31 2022-10-23 thomas return err;
95 3efd8e31 2022-10-23 thomas }
96 3efd8e31 2022-10-23 thomas
97 3efd8e31 2022-10-23 thomas obj_idx = got_packidx_get_object_idx(a->packidx, id);
98 3efd8e31 2022-10-23 thomas if (obj_idx == -1)
99 3efd8e31 2022-10-23 thomas return NULL; /* object not present in our pack file */
100 3efd8e31 2022-10-23 thomas
101 3efd8e31 2022-10-23 thomas err = got_packfile_extract_raw_delta(&delta_buf, &delta_size,
102 c44c7d6e 2022-12-04 thomas &delta_compressed_size, &delta_offset, &delta_data_offset,
103 c44c7d6e 2022-12-04 thomas &base_offset, &base_id, &base_size, &result_size,
104 c44c7d6e 2022-12-04 thomas a->pack, a->packidx, obj_idx);
105 3efd8e31 2022-10-23 thomas if (err) {
106 3efd8e31 2022-10-23 thomas if (err->code == GOT_ERR_OBJ_TYPE)
107 3efd8e31 2022-10-23 thomas return NULL; /* object not stored as a delta */
108 3efd8e31 2022-10-23 thomas return err;
109 3efd8e31 2022-10-23 thomas }
110 3efd8e31 2022-10-23 thomas
111 3efd8e31 2022-10-23 thomas /*
112 3efd8e31 2022-10-23 thomas * If this is an offset delta we must determine the base
113 3efd8e31 2022-10-23 thomas * object ID ourselves.
114 3efd8e31 2022-10-23 thomas */
115 3efd8e31 2022-10-23 thomas if (base_offset != 0) {
116 3efd8e31 2022-10-23 thomas err = get_base_object_id(&base_id, a->packidx, base_offset);
117 3efd8e31 2022-10-23 thomas if (err)
118 3efd8e31 2022-10-23 thomas goto done;
119 3efd8e31 2022-10-23 thomas }
120 3efd8e31 2022-10-23 thomas
121 3efd8e31 2022-10-23 thomas if (got_object_idset_contains(a->idset, &base_id)) {
122 3efd8e31 2022-10-23 thomas struct got_pack_meta *m, *base;
123 3efd8e31 2022-10-23 thomas
124 3efd8e31 2022-10-23 thomas m = got_object_idset_get(a->idset, id);
125 3efd8e31 2022-10-23 thomas if (m == NULL) {
126 3efd8e31 2022-10-23 thomas err = got_error_msg(GOT_ERR_NO_OBJ,
127 3efd8e31 2022-10-23 thomas "delta object not found");
128 3efd8e31 2022-10-23 thomas goto done;
129 3efd8e31 2022-10-23 thomas }
130 3efd8e31 2022-10-23 thomas
131 3efd8e31 2022-10-23 thomas base = got_object_idset_get(a->idset, &base_id);
132 3efd8e31 2022-10-23 thomas if (m == NULL) {
133 3efd8e31 2022-10-23 thomas err = got_error_msg(GOT_ERR_NO_OBJ,
134 3efd8e31 2022-10-23 thomas "delta base object not found");
135 3efd8e31 2022-10-23 thomas goto done;
136 3efd8e31 2022-10-23 thomas }
137 3efd8e31 2022-10-23 thomas
138 3efd8e31 2022-10-23 thomas m->base_obj_id = got_object_id_dup(&base_id);
139 3efd8e31 2022-10-23 thomas if (m->base_obj_id == NULL) {
140 3efd8e31 2022-10-23 thomas err = got_error_from_errno("got_object_id_dup");
141 3efd8e31 2022-10-23 thomas goto done;
142 3efd8e31 2022-10-23 thomas }
143 3efd8e31 2022-10-23 thomas
144 3efd8e31 2022-10-23 thomas m->prev = base;
145 3efd8e31 2022-10-23 thomas m->size = result_size;
146 3efd8e31 2022-10-23 thomas m->delta_len = delta_size;
147 3efd8e31 2022-10-23 thomas m->delta_compressed_len = delta_compressed_size;
148 c44c7d6e 2022-12-04 thomas m->reused_delta_offset = delta_data_offset;
149 c44c7d6e 2022-12-04 thomas m->delta_offset = 0;
150 3efd8e31 2022-10-23 thomas
151 3efd8e31 2022-10-23 thomas err = got_pack_add_meta(m, a->v);
152 3efd8e31 2022-10-23 thomas if (err)
153 3efd8e31 2022-10-23 thomas goto done;
154 3efd8e31 2022-10-23 thomas
155 3efd8e31 2022-10-23 thomas err = got_pack_report_progress(a->progress_cb, a->progress_arg,
156 3efd8e31 2022-10-23 thomas a->rl, a->ncolored, a->nfound, a->ntrees, 0L, a->ncommits,
157 3efd8e31 2022-10-23 thomas got_object_idset_num_elements(a->idset), a->v->nmeta, 0);
158 3efd8e31 2022-10-23 thomas if (err)
159 3efd8e31 2022-10-23 thomas goto done;
160 3efd8e31 2022-10-23 thomas }
161 3efd8e31 2022-10-23 thomas done:
162 3efd8e31 2022-10-23 thomas free(delta_buf);
163 3efd8e31 2022-10-23 thomas return err;
164 3efd8e31 2022-10-23 thomas }
165 3efd8e31 2022-10-23 thomas
166 3efd8e31 2022-10-23 thomas const struct got_error *
167 c44c7d6e 2022-12-04 thomas got_pack_search_deltas(struct got_packidx **packidx, struct got_pack **pack,
168 c44c7d6e 2022-12-04 thomas struct got_pack_metavec *v, struct got_object_idset *idset,
169 3efd8e31 2022-10-23 thomas int ncolored, int nfound, int ntrees, int ncommits,
170 3efd8e31 2022-10-23 thomas struct got_repository *repo,
171 3efd8e31 2022-10-23 thomas got_pack_progress_cb progress_cb, void *progress_arg,
172 3efd8e31 2022-10-23 thomas struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg)
173 3efd8e31 2022-10-23 thomas {
174 3efd8e31 2022-10-23 thomas const struct got_error *err = NULL;
175 3efd8e31 2022-10-23 thomas struct search_deltas_arg sda;
176 3efd8e31 2022-10-23 thomas
177 c44c7d6e 2022-12-04 thomas *packidx = NULL;
178 c44c7d6e 2022-12-04 thomas *pack = NULL;
179 c44c7d6e 2022-12-04 thomas
180 c44c7d6e 2022-12-04 thomas err = got_pack_find_pack_for_reuse(packidx, repo);
181 3efd8e31 2022-10-23 thomas if (err)
182 3efd8e31 2022-10-23 thomas return err;
183 3efd8e31 2022-10-23 thomas
184 c44c7d6e 2022-12-04 thomas if (*packidx == NULL)
185 3efd8e31 2022-10-23 thomas return NULL;
186 3efd8e31 2022-10-23 thomas
187 c44c7d6e 2022-12-04 thomas err = got_pack_cache_pack_for_packidx(pack, *packidx, repo);
188 3efd8e31 2022-10-23 thomas if (err)
189 3efd8e31 2022-10-23 thomas return err;
190 3efd8e31 2022-10-23 thomas
191 3efd8e31 2022-10-23 thomas memset(&sda, 0, sizeof(sda));
192 3efd8e31 2022-10-23 thomas sda.v = v;
193 3efd8e31 2022-10-23 thomas sda.idset = idset;
194 c44c7d6e 2022-12-04 thomas sda.pack = *pack;
195 c44c7d6e 2022-12-04 thomas sda.packidx = *packidx;
196 3efd8e31 2022-10-23 thomas sda.ncolored = ncolored;
197 3efd8e31 2022-10-23 thomas sda.nfound = nfound;
198 3efd8e31 2022-10-23 thomas sda.ntrees = ntrees;
199 3efd8e31 2022-10-23 thomas sda.ncommits = ncommits;
200 3efd8e31 2022-10-23 thomas sda.progress_cb = progress_cb;
201 3efd8e31 2022-10-23 thomas sda.progress_arg = progress_arg;
202 3efd8e31 2022-10-23 thomas sda.rl = rl;
203 3efd8e31 2022-10-23 thomas sda.cancel_cb = cancel_cb;
204 3efd8e31 2022-10-23 thomas sda.cancel_arg = cancel_arg;
205 3efd8e31 2022-10-23 thomas return got_object_idset_for_each(idset, search_delta_for_object, &sda);
206 3efd8e31 2022-10-23 thomas }
207 3efd8e31 2022-10-23 thomas
208 3efd8e31 2022-10-23 thomas const struct got_error *
209 3efd8e31 2022-10-23 thomas got_pack_load_packed_object_ids(int *found_all_objects,
210 3efd8e31 2022-10-23 thomas struct got_object_id **ours, int nours,
211 3efd8e31 2022-10-23 thomas struct got_object_id **theirs, int ntheirs,
212 3efd8e31 2022-10-23 thomas int want_meta, uint32_t seed, struct got_object_idset *idset,
213 3efd8e31 2022-10-23 thomas struct got_object_idset *idset_exclude, int loose_obj_only,
214 3efd8e31 2022-10-23 thomas struct got_repository *repo, struct got_packidx *packidx,
215 3efd8e31 2022-10-23 thomas int *ncolored, int *nfound, int *ntrees,
216 3efd8e31 2022-10-23 thomas got_pack_progress_cb progress_cb, void *progress_arg,
217 3efd8e31 2022-10-23 thomas struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg)
218 3efd8e31 2022-10-23 thomas {
219 3efd8e31 2022-10-23 thomas /* We do not need this optimized traversal while using direct I/O. */
220 3efd8e31 2022-10-23 thomas *found_all_objects = 0;
221 3efd8e31 2022-10-23 thomas return NULL;
222 3efd8e31 2022-10-23 thomas }
223 3efd8e31 2022-10-23 thomas
224 3efd8e31 2022-10-23 thomas const struct got_error *
225 3efd8e31 2022-10-23 thomas got_pack_paint_commits(int *ncolored, struct got_object_id_queue *ids, int nids,
226 3efd8e31 2022-10-23 thomas struct got_object_idset *keep, struct got_object_idset *drop,
227 3efd8e31 2022-10-23 thomas struct got_object_idset *skip, struct got_repository *repo,
228 3efd8e31 2022-10-23 thomas got_pack_progress_cb progress_cb, void *progress_arg,
229 3efd8e31 2022-10-23 thomas struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg)
230 3efd8e31 2022-10-23 thomas {
231 3efd8e31 2022-10-23 thomas const struct got_error *err = NULL;
232 3efd8e31 2022-10-23 thomas struct got_commit_object *commit = NULL;
233 3efd8e31 2022-10-23 thomas struct got_packidx *packidx = NULL;
234 3efd8e31 2022-10-23 thomas struct got_pack *pack = NULL;
235 3efd8e31 2022-10-23 thomas const struct got_object_id_queue *parents;
236 3efd8e31 2022-10-23 thomas struct got_object_qid *qid = NULL;
237 3efd8e31 2022-10-23 thomas int nqueued = nids, nskip = 0;
238 3efd8e31 2022-10-23 thomas
239 3efd8e31 2022-10-23 thomas while (!STAILQ_EMPTY(ids) && nskip != nqueued) {
240 3efd8e31 2022-10-23 thomas intptr_t color;
241 3efd8e31 2022-10-23 thomas
242 3efd8e31 2022-10-23 thomas if (cancel_cb) {
243 3efd8e31 2022-10-23 thomas err = cancel_cb(cancel_arg);
244 3efd8e31 2022-10-23 thomas if (err)
245 3efd8e31 2022-10-23 thomas break;
246 3efd8e31 2022-10-23 thomas }
247 3efd8e31 2022-10-23 thomas
248 3efd8e31 2022-10-23 thomas qid = STAILQ_FIRST(ids);
249 3efd8e31 2022-10-23 thomas STAILQ_REMOVE_HEAD(ids, entry);
250 3efd8e31 2022-10-23 thomas nqueued--;
251 3efd8e31 2022-10-23 thomas color = (intptr_t)qid->data;
252 3efd8e31 2022-10-23 thomas if (color == COLOR_SKIP)
253 3efd8e31 2022-10-23 thomas nskip--;
254 3efd8e31 2022-10-23 thomas
255 3efd8e31 2022-10-23 thomas if (got_object_idset_contains(skip, &qid->id)) {
256 3efd8e31 2022-10-23 thomas got_object_qid_free(qid);
257 3efd8e31 2022-10-23 thomas qid = NULL;
258 3efd8e31 2022-10-23 thomas continue;
259 3efd8e31 2022-10-23 thomas }
260 3efd8e31 2022-10-23 thomas if (color == COLOR_KEEP &&
261 3efd8e31 2022-10-23 thomas got_object_idset_contains(keep, &qid->id)) {
262 3efd8e31 2022-10-23 thomas got_object_qid_free(qid);
263 3efd8e31 2022-10-23 thomas qid = NULL;
264 3efd8e31 2022-10-23 thomas continue;
265 3efd8e31 2022-10-23 thomas }
266 3efd8e31 2022-10-23 thomas if (color == COLOR_DROP &&
267 3efd8e31 2022-10-23 thomas got_object_idset_contains(drop, &qid->id)) {
268 3efd8e31 2022-10-23 thomas got_object_qid_free(qid);
269 3efd8e31 2022-10-23 thomas qid = NULL;
270 3efd8e31 2022-10-23 thomas continue;
271 3efd8e31 2022-10-23 thomas }
272 3efd8e31 2022-10-23 thomas
273 3efd8e31 2022-10-23 thomas switch (color) {
274 3efd8e31 2022-10-23 thomas case COLOR_KEEP:
275 3efd8e31 2022-10-23 thomas if (got_object_idset_contains(drop, &qid->id)) {
276 3efd8e31 2022-10-23 thomas err = got_pack_paint_commit(qid, COLOR_SKIP);
277 3efd8e31 2022-10-23 thomas if (err)
278 3efd8e31 2022-10-23 thomas goto done;
279 3efd8e31 2022-10-23 thomas } else
280 3efd8e31 2022-10-23 thomas (*ncolored)++;
281 3efd8e31 2022-10-23 thomas err = got_object_idset_add(keep, &qid->id, NULL);
282 3efd8e31 2022-10-23 thomas if (err)
283 3efd8e31 2022-10-23 thomas goto done;
284 3efd8e31 2022-10-23 thomas break;
285 3efd8e31 2022-10-23 thomas case COLOR_DROP:
286 3efd8e31 2022-10-23 thomas if (got_object_idset_contains(keep, &qid->id)) {
287 3efd8e31 2022-10-23 thomas err = got_pack_paint_commit(qid, COLOR_SKIP);
288 3efd8e31 2022-10-23 thomas if (err)
289 3efd8e31 2022-10-23 thomas goto done;
290 3efd8e31 2022-10-23 thomas } else
291 3efd8e31 2022-10-23 thomas (*ncolored)++;
292 3efd8e31 2022-10-23 thomas err = got_object_idset_add(drop, &qid->id, NULL);
293 3efd8e31 2022-10-23 thomas if (err)
294 3efd8e31 2022-10-23 thomas goto done;
295 3efd8e31 2022-10-23 thomas break;
296 3efd8e31 2022-10-23 thomas case COLOR_SKIP:
297 3efd8e31 2022-10-23 thomas if (!got_object_idset_contains(skip, &qid->id)) {
298 3efd8e31 2022-10-23 thomas err = got_object_idset_add(skip, &qid->id,
299 3efd8e31 2022-10-23 thomas NULL);
300 3efd8e31 2022-10-23 thomas if (err)
301 3efd8e31 2022-10-23 thomas goto done;
302 3efd8e31 2022-10-23 thomas }
303 3efd8e31 2022-10-23 thomas break;
304 3efd8e31 2022-10-23 thomas default:
305 3efd8e31 2022-10-23 thomas /* should not happen */
306 3efd8e31 2022-10-23 thomas err = got_error_fmt(GOT_ERR_NOT_IMPL,
307 3efd8e31 2022-10-23 thomas "%s invalid commit color %"PRIdPTR, __func__,
308 3efd8e31 2022-10-23 thomas color);
309 3efd8e31 2022-10-23 thomas goto done;
310 3efd8e31 2022-10-23 thomas }
311 3efd8e31 2022-10-23 thomas
312 3efd8e31 2022-10-23 thomas err = got_pack_report_progress(progress_cb, progress_arg, rl,
313 3efd8e31 2022-10-23 thomas *ncolored, 0, 0, 0L, 0, 0, 0, 0);
314 3efd8e31 2022-10-23 thomas if (err)
315 3efd8e31 2022-10-23 thomas break;
316 3efd8e31 2022-10-23 thomas
317 3efd8e31 2022-10-23 thomas err = got_object_open_as_commit(&commit, repo, &qid->id);
318 3efd8e31 2022-10-23 thomas if (err)
319 3efd8e31 2022-10-23 thomas break;
320 3efd8e31 2022-10-23 thomas
321 3efd8e31 2022-10-23 thomas parents = got_object_commit_get_parent_ids(commit);
322 3efd8e31 2022-10-23 thomas if (parents) {
323 3efd8e31 2022-10-23 thomas struct got_object_qid *pid;
324 3efd8e31 2022-10-23 thomas color = (intptr_t)qid->data;
325 3efd8e31 2022-10-23 thomas STAILQ_FOREACH(pid, parents, entry) {
326 3efd8e31 2022-10-23 thomas err = got_pack_queue_commit_id(ids, &pid->id,
327 3efd8e31 2022-10-23 thomas color, repo);
328 3efd8e31 2022-10-23 thomas if (err)
329 3efd8e31 2022-10-23 thomas break;
330 3efd8e31 2022-10-23 thomas nqueued++;
331 3efd8e31 2022-10-23 thomas if (color == COLOR_SKIP)
332 3efd8e31 2022-10-23 thomas nskip++;
333 3efd8e31 2022-10-23 thomas }
334 3efd8e31 2022-10-23 thomas }
335 3efd8e31 2022-10-23 thomas
336 3efd8e31 2022-10-23 thomas if (pack == NULL && (commit->flags & GOT_COMMIT_FLAG_PACKED)) {
337 3efd8e31 2022-10-23 thomas /*
338 3efd8e31 2022-10-23 thomas * We now know that at least one pack file exists.
339 3efd8e31 2022-10-23 thomas * Pin a suitable pack to ensure it remains cached
340 3efd8e31 2022-10-23 thomas * while we are churning through commit history.
341 3efd8e31 2022-10-23 thomas */
342 3efd8e31 2022-10-23 thomas if (packidx == NULL) {
343 3efd8e31 2022-10-23 thomas err = got_pack_find_pack_for_commit_painting(
344 3efd8e31 2022-10-23 thomas &packidx, ids, nqueued, repo);
345 3efd8e31 2022-10-23 thomas if (err)
346 3efd8e31 2022-10-23 thomas goto done;
347 3efd8e31 2022-10-23 thomas }
348 3efd8e31 2022-10-23 thomas if (packidx != NULL) {
349 3efd8e31 2022-10-23 thomas err = got_pack_cache_pack_for_packidx(&pack,
350 3efd8e31 2022-10-23 thomas packidx, repo);
351 3efd8e31 2022-10-23 thomas if (err)
352 3efd8e31 2022-10-23 thomas goto done;
353 3efd8e31 2022-10-23 thomas err = got_repo_pin_pack(repo, packidx, pack);
354 3efd8e31 2022-10-23 thomas if (err)
355 3efd8e31 2022-10-23 thomas goto done;
356 3efd8e31 2022-10-23 thomas }
357 3efd8e31 2022-10-23 thomas }
358 3efd8e31 2022-10-23 thomas
359 3efd8e31 2022-10-23 thomas got_object_commit_close(commit);
360 3efd8e31 2022-10-23 thomas commit = NULL;
361 3efd8e31 2022-10-23 thomas
362 3efd8e31 2022-10-23 thomas got_object_qid_free(qid);
363 3efd8e31 2022-10-23 thomas qid = NULL;
364 3efd8e31 2022-10-23 thomas }
365 3efd8e31 2022-10-23 thomas done:
366 3efd8e31 2022-10-23 thomas if (commit)
367 3efd8e31 2022-10-23 thomas got_object_commit_close(commit);
368 3efd8e31 2022-10-23 thomas got_object_qid_free(qid);
369 3efd8e31 2022-10-23 thomas got_repo_unpin_pack(repo);
370 3efd8e31 2022-10-23 thomas return err;
371 3efd8e31 2022-10-23 thomas }