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