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