fix pack exclusion via an ancestor commit
[got-portable.git] / lib / got_lib_pack_create.h
blobca45026cc97b8e4d57488732f016db3ca87aaf80
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 hash digest of the resulting pack file in pack_hash which must
22 * be pre-allocated by the caller with at least GOT_HASH_DIGEST_MAXLEN bytes.
24 const struct got_error *got_pack_create(struct got_object_id *pack_hash,
25 int packfd, 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 int force_refdelta, 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_repaint_parent_commits(
59 struct got_object_id *commit_id, int color, struct got_object_idset *set,
60 struct got_object_idset *skip, struct got_repository *repo);
61 const struct got_error *got_pack_queue_commit_id(
62 struct got_object_id_queue *ids, struct got_object_id *id, intptr_t color,
63 struct got_repository *repo);
65 struct got_pack_metavec {
66 struct got_pack_meta **meta;
67 int nmeta;
68 int metasz;
71 struct got_pack_meta {
72 struct got_object_id id;
73 uint32_t path_hash;
74 int obj_type;
75 off_t size;
76 time_t mtime;
78 /* The best delta we picked */
79 struct got_pack_meta *head;
80 struct got_pack_meta *prev;
81 unsigned char *delta_buf; /* if encoded in memory (compressed) */
82 off_t delta_offset; /* offset in delta cache file (compressed) */
83 off_t delta_len; /* encoded delta length */
84 off_t delta_compressed_len; /* encoded+compressed delta length */
85 int nchain;
87 off_t reused_delta_offset; /* offset of delta in reused pack file */
88 struct got_object_id *base_obj_id;
90 /* Only used for delta window */
91 struct got_delta_table *dtab;
93 /* Only used for writing offset deltas */
94 off_t off;
97 const struct got_error *got_pack_add_meta(struct got_pack_meta *m,
98 struct got_pack_metavec *v);
100 const struct got_error *
101 got_pack_search_deltas(struct got_packidx **packidx, struct got_pack **pack,
102 struct got_pack_metavec *v, struct got_object_idset *idset,
103 int ncolored, int nfound, int ntrees, int ncommits,
104 struct got_repository *repo,
105 got_pack_progress_cb progress_cb, void *progress_arg,
106 struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg);
108 const struct got_error *
109 got_pack_report_progress(got_pack_progress_cb progress_cb, void *progress_arg,
110 struct got_ratelimit *rl, int ncolored, int nfound, int ntrees,
111 off_t packfile_size, int ncommits, int nobj_total, int obj_deltify,
112 int nobj_written, int pack_done);
114 const struct got_error *
115 got_pack_load_packed_object_ids(int *found_all_objects,
116 struct got_object_id **ours, int nours,
117 struct got_object_id **theirs, int ntheirs,
118 int want_meta, uint32_t seed, struct got_object_idset *idset,
119 struct got_object_idset *idset_exclude, int loose_obj_only,
120 struct got_repository *repo, struct got_packidx *packidx,
121 int *ncolored, int *nfound, int *ntrees,
122 got_pack_progress_cb progress_cb, void *progress_arg,
123 struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg);
125 const struct got_error *
126 got_pack_load_tree_entries(struct got_object_id_queue *ids, int want_meta,
127 struct got_object_idset *idset, struct got_object_idset *idset_exclude,
128 struct got_tree_object *tree,
129 const char *dpath, time_t mtime, uint32_t seed, struct got_repository *repo,
130 int loose_obj_only, int *ncolored, int *nfound, int *ntrees,
131 got_pack_progress_cb progress_cb, void *progress_arg,
132 struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg);
134 const struct got_error *
135 got_pack_load_tree(int want_meta, struct got_object_idset *idset,
136 struct got_object_idset *idset_exclude,
137 struct got_object_id *tree_id, const char *dpath, time_t mtime,
138 uint32_t seed, struct got_repository *repo, int loose_obj_only,
139 int *ncolored, int *nfound, int *ntrees,
140 got_pack_progress_cb progress_cb, void *progress_arg,
141 struct got_ratelimit *rl, got_cancel_cb cancel_cb, void *cancel_arg);
143 const struct got_error *
144 got_pack_add_object(int want_meta, struct got_object_idset *idset,
145 struct got_object_id *id, const char *path, int obj_type,
146 time_t mtime, uint32_t seed, int loose_obj_only,
147 struct got_repository *repo, int *ncolored, int *nfound, int *ntrees,
148 got_pack_progress_cb progress_cb, void *progress_arg,
149 struct got_ratelimit *rl);