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