Blob


1 /*
2 * Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
3 *
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.
7 *
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.
15 */
17 /* A callback function which gets invoked with progress information to print. */
18 typedef const struct got_error *(*got_pack_progress_cb)(void *arg,
19 int ncolored, int nfound, int ntrees, off_t packfile_size, int ncommits,
20 int nobj_total, int obj_deltify, int nobj_written);
22 /*
23 * Attempt to pack objects reachable via 'include_refs' into a new packfile.
24 * If 'excluded_refs' is not an empty list, do not pack any objects
25 * reachable from the listed references.
26 * If loose_obj_only is zero, pack reachable objects even if they are
27 * already packed in another packfile. Otherwise, add only loose
28 * objects to the new pack file.
29 * Return an open file handle for the generated pack file.
30 * Return the SHA1 digest of the resulting pack file in pack_hash which
31 * must freed by the caller when done.
32 */
33 const struct got_error *
34 got_repo_pack_objects(FILE **packfile, struct got_object_id **pack_hash,
35 struct got_reflist_head *include_refs,
36 struct got_reflist_head *exclude_refs, struct got_repository *repo,
37 int loose_obj_only, int force_refdelta,
38 got_pack_progress_cb progress_cb, void *progress_arg,
39 got_cancel_cb cancel_cb, void *cancel_arg);
41 /*
42 * Attempt to open a pack file at the specified path. Return an open
43 * file handle and the expected hash of pack file contents.
44 */
45 const struct got_error *
46 got_repo_find_pack(FILE **packfile, struct got_object_id **pack_hash,
47 struct got_repository *repo, const char *packfile_path);
49 /* A callback function which gets invoked with progress information to print. */
50 typedef const struct got_error *(*got_pack_index_progress_cb)(void *arg,
51 off_t packfile_size, int nobj_total, int nobj_indexed,
52 int nobj_loose, int nobj_resolved);
54 /* (Re-)Index the pack file identified by the given hash. */
55 const struct got_error *
56 got_repo_index_pack(FILE *packfile, struct got_object_id *pack_hash,
57 struct got_repository *repo,
58 got_pack_index_progress_cb progress_cb, void *progress_arg,
59 got_cancel_cb cancel_cb, void *cancel_arg);
61 typedef const struct got_error *(*got_pack_list_cb)(void *arg,
62 struct got_object_id *id, int type, off_t offset, off_t size,
63 off_t base_offset, struct got_object_id *base_id);
65 /* List the pack file identified by the given hash. */
66 const struct got_error *
67 got_repo_list_pack(FILE *packfile, struct got_object_id *pack_hash,
68 struct got_repository *repo, got_pack_list_cb list_cb, void *list_arg,
69 got_cancel_cb cancel_cb, void *cancel_arg);
71 /* A callback function which gets invoked with cleanup information to print. */
72 typedef const struct got_error *(*got_cleanup_progress_cb)(void *arg,
73 int nloose, int ncommits, int npurged);
75 /*
76 * Walk objects reachable via references to determine whether any loose
77 * objects can be removed from disk. Do remove such objects from disk
78 * unless the dry_run parameter is set.
79 * Do not remove objects with a modification timestamp above an
80 * implementation-defined timestamp threshold, unless ignore_mtime is set.
81 * Return the disk space size occupied by loose objects before and after
82 * the operation.
83 * Return the number of loose objects which are also stored in a pack file.
84 */
85 const struct got_error *
86 got_repo_purge_unreferenced_loose_objects(struct got_repository *repo,
87 off_t *size_before, off_t *size_after, int *npacked, int dry_run,
88 int ignore_mtime, got_cleanup_progress_cb progress_cb, void *progress_arg,
89 got_cancel_cb cancel_cb, void *cancel_arg);
91 /* A callback function which gets invoked with cleanup information to print. */
92 typedef const struct got_error *(*got_lonely_packidx_progress_cb)(void *arg,
93 const char *path);
95 /* Remove pack index files which do not have a corresponding pack file. */
96 const struct got_error *
97 got_repo_remove_lonely_packidx(struct got_repository *repo, int dry_run,
98 got_lonely_packidx_progress_cb progress_cb, void *progress_arg,
99 got_cancel_cb cancel_cb, void *cancel_arg);