Blame


1 e6bcace5 2021-06-22 stsp /*
2 e6bcace5 2021-06-22 stsp * Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
3 e6bcace5 2021-06-22 stsp *
4 e6bcace5 2021-06-22 stsp * Permission to use, copy, modify, and distribute this software for any
5 e6bcace5 2021-06-22 stsp * purpose with or without fee is hereby granted, provided that the above
6 e6bcace5 2021-06-22 stsp * copyright notice and this permission notice appear in all copies.
7 e6bcace5 2021-06-22 stsp *
8 e6bcace5 2021-06-22 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 e6bcace5 2021-06-22 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 e6bcace5 2021-06-22 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 e6bcace5 2021-06-22 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 e6bcace5 2021-06-22 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 e6bcace5 2021-06-22 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 e6bcace5 2021-06-22 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 e6bcace5 2021-06-22 stsp */
16 e6bcace5 2021-06-22 stsp
17 e6bcace5 2021-06-22 stsp /*
18 e6bcace5 2021-06-22 stsp * Write pack file data into the provided open packfile handle, for all
19 e6bcace5 2021-06-22 stsp * objects reachable via the commits listed in 'ours'.
20 e6bcace5 2021-06-22 stsp * Exclude any objects for commits listed in 'theirs' if 'theirs' is not NULL.
21 e6bcace5 2021-06-22 stsp * Return the SHA1 digest of the resulting pack file in pack_sha1 which must
22 e6bcace5 2021-06-22 stsp * be pre-allocated by the caller with at least SHA1_DIGEST_LENGTH bytes.
23 e6bcace5 2021-06-22 stsp */
24 20a7d452 2022-10-16 thomas const struct got_error *got_pack_create(uint8_t *pack_sha1, int packfd,
25 05fa7118 2022-10-16 thomas FILE *delta_cache, struct got_object_id **theirs, int ntheirs,
26 e6bcace5 2021-06-22 stsp struct got_object_id **ours, int nours,
27 f8a36e22 2021-08-26 stsp struct got_repository *repo, int loose_obj_only, int allow_empty,
28 d8253374 2023-02-17 thomas int force_refdelta, got_pack_progress_cb progress_cb, void *progress_arg,
29 abd46894 2022-10-18 thomas struct got_ratelimit *, got_cancel_cb cancel_cb, void *cancel_arg);
30 097b408a 2022-10-17 thomas
31 097b408a 2022-10-17 thomas const struct got_error *
32 097b408a 2022-10-17 thomas got_pack_cache_pack_for_packidx(struct got_pack **pack,
33 097b408a 2022-10-17 thomas struct got_packidx *packidx, struct got_repository *repo);
34 097b408a 2022-10-17 thomas
35 097b408a 2022-10-17 thomas const struct got_error *
36 097b408a 2022-10-17 thomas got_pack_find_pack_for_commit_painting(struct got_packidx **best_packidx,
37 097b408a 2022-10-17 thomas struct got_object_id_queue *ids, int nids, struct got_repository *repo);
38 097b408a 2022-10-17 thomas const struct got_error *got_pack_find_pack_for_reuse(
39 097b408a 2022-10-17 thomas struct got_packidx **best_packidx, struct got_repository *repo);
40 097b408a 2022-10-17 thomas
41 097b408a 2022-10-17 thomas struct got_ratelimit;
42 097b408a 2022-10-17 thomas const struct got_error *got_pack_paint_commits(int *ncolored,
43 097b408a 2022-10-17 thomas struct got_object_id_queue *ids, int nids,
44 097b408a 2022-10-17 thomas struct got_object_idset *keep, struct got_object_idset *drop,
45 097b408a 2022-10-17 thomas struct got_object_idset *skip, struct got_repository *repo,
46 097b408a 2022-10-17 thomas got_pack_progress_cb progress_cb, void *progress_arg,
47 097b408a 2022-10-17 thomas struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg);
48 097b408a 2022-10-17 thomas
49 097b408a 2022-10-17 thomas enum got_pack_findtwixt_color {
50 097b408a 2022-10-17 thomas COLOR_KEEP = 0,
51 097b408a 2022-10-17 thomas COLOR_DROP,
52 097b408a 2022-10-17 thomas COLOR_SKIP,
53 097b408a 2022-10-17 thomas COLOR_MAX,
54 097b408a 2022-10-17 thomas };
55 097b408a 2022-10-17 thomas
56 097b408a 2022-10-17 thomas const struct got_error *got_pack_paint_commit(struct got_object_qid *qid,
57 097b408a 2022-10-17 thomas intptr_t color);
58 097b408a 2022-10-17 thomas const struct got_error *got_pack_queue_commit_id(
59 097b408a 2022-10-17 thomas struct got_object_id_queue *ids, struct got_object_id *id, intptr_t color,
60 097b408a 2022-10-17 thomas struct got_repository *repo);
61 097b408a 2022-10-17 thomas
62 097b408a 2022-10-17 thomas struct got_pack_metavec {
63 097b408a 2022-10-17 thomas struct got_pack_meta **meta;
64 097b408a 2022-10-17 thomas int nmeta;
65 097b408a 2022-10-17 thomas int metasz;
66 097b408a 2022-10-17 thomas };
67 097b408a 2022-10-17 thomas
68 097b408a 2022-10-17 thomas struct got_pack_meta {
69 097b408a 2022-10-17 thomas struct got_object_id id;
70 097b408a 2022-10-17 thomas uint32_t path_hash;
71 097b408a 2022-10-17 thomas int obj_type;
72 097b408a 2022-10-17 thomas off_t size;
73 097b408a 2022-10-17 thomas time_t mtime;
74 097b408a 2022-10-17 thomas
75 097b408a 2022-10-17 thomas /* The best delta we picked */
76 097b408a 2022-10-17 thomas struct got_pack_meta *head;
77 097b408a 2022-10-17 thomas struct got_pack_meta *prev;
78 097b408a 2022-10-17 thomas unsigned char *delta_buf; /* if encoded in memory (compressed) */
79 097b408a 2022-10-17 thomas off_t delta_offset; /* offset in delta cache file (compressed) */
80 097b408a 2022-10-17 thomas off_t delta_len; /* encoded delta length */
81 097b408a 2022-10-17 thomas off_t delta_compressed_len; /* encoded+compressed delta length */
82 097b408a 2022-10-17 thomas int nchain;
83 097b408a 2022-10-17 thomas
84 097b408a 2022-10-17 thomas off_t reused_delta_offset; /* offset of delta in reused pack file */
85 097b408a 2022-10-17 thomas struct got_object_id *base_obj_id;
86 097b408a 2022-10-17 thomas
87 097b408a 2022-10-17 thomas /* Only used for delta window */
88 097b408a 2022-10-17 thomas struct got_delta_table *dtab;
89 097b408a 2022-10-17 thomas
90 097b408a 2022-10-17 thomas /* Only used for writing offset deltas */
91 097b408a 2022-10-17 thomas off_t off;
92 097b408a 2022-10-17 thomas };
93 097b408a 2022-10-17 thomas
94 097b408a 2022-10-17 thomas const struct got_error *got_pack_add_meta(struct got_pack_meta *m,
95 097b408a 2022-10-17 thomas struct got_pack_metavec *v);
96 097b408a 2022-10-17 thomas
97 097b408a 2022-10-17 thomas const struct got_error *
98 c44c7d6e 2022-12-04 thomas got_pack_search_deltas(struct got_packidx **packidx, struct got_pack **pack,
99 c44c7d6e 2022-12-04 thomas struct got_pack_metavec *v, struct got_object_idset *idset,
100 097b408a 2022-10-17 thomas int ncolored, int nfound, int ntrees, int ncommits,
101 097b408a 2022-10-17 thomas struct got_repository *repo,
102 097b408a 2022-10-17 thomas got_pack_progress_cb progress_cb, void *progress_arg,
103 097b408a 2022-10-17 thomas struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg);
104 097b408a 2022-10-17 thomas
105 097b408a 2022-10-17 thomas const struct got_error *
106 097b408a 2022-10-17 thomas got_pack_report_progress(got_pack_progress_cb progress_cb, void *progress_arg,
107 097b408a 2022-10-17 thomas struct got_ratelimit *rl, int ncolored, int nfound, int ntrees,
108 097b408a 2022-10-17 thomas off_t packfile_size, int ncommits, int nobj_total, int obj_deltify,
109 097b408a 2022-10-17 thomas int nobj_written);
110 097b408a 2022-10-17 thomas
111 097b408a 2022-10-17 thomas const struct got_error *
112 097b408a 2022-10-17 thomas got_pack_load_packed_object_ids(int *found_all_objects,
113 097b408a 2022-10-17 thomas struct got_object_id **ours, int nours,
114 097b408a 2022-10-17 thomas struct got_object_id **theirs, int ntheirs,
115 097b408a 2022-10-17 thomas int want_meta, uint32_t seed, struct got_object_idset *idset,
116 097b408a 2022-10-17 thomas struct got_object_idset *idset_exclude, int loose_obj_only,
117 097b408a 2022-10-17 thomas struct got_repository *repo, struct got_packidx *packidx,
118 097b408a 2022-10-17 thomas int *ncolored, int *nfound, int *ntrees,
119 097b408a 2022-10-17 thomas got_pack_progress_cb progress_cb, void *progress_arg,
120 097b408a 2022-10-17 thomas struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg);
121 097b408a 2022-10-17 thomas
122 097b408a 2022-10-17 thomas const struct got_error *
123 097b408a 2022-10-17 thomas got_pack_load_tree_entries(struct got_object_id_queue *ids, int want_meta,
124 097b408a 2022-10-17 thomas struct got_object_idset *idset, struct got_object_idset *idset_exclude,
125 097b408a 2022-10-17 thomas struct got_tree_object *tree,
126 097b408a 2022-10-17 thomas const char *dpath, time_t mtime, uint32_t seed, struct got_repository *repo,
127 097b408a 2022-10-17 thomas int loose_obj_only, int *ncolored, int *nfound, int *ntrees,
128 097b408a 2022-10-17 thomas got_pack_progress_cb progress_cb, void *progress_arg,
129 097b408a 2022-10-17 thomas struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg);
130 097b408a 2022-10-17 thomas
131 097b408a 2022-10-17 thomas const struct got_error *
132 097b408a 2022-10-17 thomas got_pack_load_tree(int want_meta, struct got_object_idset *idset,
133 097b408a 2022-10-17 thomas struct got_object_idset *idset_exclude,
134 097b408a 2022-10-17 thomas struct got_object_id *tree_id, const char *dpath, time_t mtime,
135 097b408a 2022-10-17 thomas uint32_t seed, struct got_repository *repo, int loose_obj_only,
136 097b408a 2022-10-17 thomas int *ncolored, int *nfound, int *ntrees,
137 097b408a 2022-10-17 thomas got_pack_progress_cb progress_cb, void *progress_arg,
138 097b408a 2022-10-17 thomas struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg);
139 097b408a 2022-10-17 thomas
140 097b408a 2022-10-17 thomas const struct got_error *
141 097b408a 2022-10-17 thomas got_pack_add_object(int want_meta, struct got_object_idset *idset,
142 097b408a 2022-10-17 thomas struct got_object_id *id, const char *path, int obj_type,
143 097b408a 2022-10-17 thomas time_t mtime, uint32_t seed, int loose_obj_only,
144 097b408a 2022-10-17 thomas struct got_repository *repo, int *ncolored, int *nfound, int *ntrees,
145 097b408a 2022-10-17 thomas got_pack_progress_cb progress_cb, void *progress_arg,
146 097b408a 2022-10-17 thomas struct got_ratelimit *rl);