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 struct got_lockfile;
19 /* A callback function which gets invoked with progress information to print. */
20 typedef const struct got_error *(*got_pack_progress_cb)(void *arg,
21 int ncolored, int nfound, int ntrees, off_t packfile_size, int ncommits,
22 int nobj_total, int obj_deltify, int nobj_written);
24 /*
25 * Attempt to pack objects reachable via 'include_refs' into a new packfile.
26 * If 'excluded_refs' is not an empty list, do not pack any objects
27 * reachable from the listed references.
28 * If loose_obj_only is zero, pack reachable objects even if they are
29 * already packed in another packfile. Otherwise, add only loose
30 * objects to the new pack file.
31 * Return an open file handle for the generated pack file.
32 * Return the SHA1 digest of the resulting pack file in pack_hash which
33 * must freed by the caller when done.
34 */
35 const struct got_error *
36 got_repo_pack_objects(FILE **packfile, struct got_object_id **pack_hash,
37 struct got_reflist_head *include_refs,
38 struct got_reflist_head *exclude_refs, struct got_repository *repo,
39 int loose_obj_only, int force_refdelta,
40 got_pack_progress_cb progress_cb, void *progress_arg,
41 got_cancel_cb cancel_cb, void *cancel_arg);
43 /*
44 * Attempt to open a pack file at the specified path. Return an open
45 * file handle and the expected hash of pack file contents.
46 */
47 const struct got_error *
48 got_repo_find_pack(FILE **packfile, struct got_object_id **pack_hash,
49 struct got_repository *repo, const char *packfile_path);
51 /* A callback function which gets invoked with progress information to print. */
52 typedef const struct got_error *(*got_pack_index_progress_cb)(void *arg,
53 off_t packfile_size, int nobj_total, int nobj_indexed,
54 int nobj_loose, int nobj_resolved);
56 /* (Re-)Index the pack file identified by the given hash. */
57 const struct got_error *
58 got_repo_index_pack(FILE *packfile, struct got_object_id *pack_hash,
59 struct got_repository *repo,
60 got_pack_index_progress_cb progress_cb, void *progress_arg,
61 got_cancel_cb cancel_cb, void *cancel_arg);
63 typedef const struct got_error *(*got_pack_list_cb)(void *arg,
64 struct got_object_id *id, int type, off_t offset, off_t size,
65 off_t base_offset, struct got_object_id *base_id);
67 /* List the pack file identified by the given hash. */
68 const struct got_error *
69 got_repo_list_pack(FILE *packfile, struct got_object_id *pack_hash,
70 struct got_repository *repo, got_pack_list_cb list_cb, void *list_arg,
71 got_cancel_cb cancel_cb, void *cancel_arg);
73 /*
74 * Prepare for removing loose objects or redundant packfiles.
75 *
76 * These functions do the necessary locking in order to avoid
77 * concurrent operation to irremediably damage the repository.
78 */
79 const struct got_error *
80 got_repo_cleanup_prepare(struct got_repository *, struct got_lockfile **);
82 const struct got_error *
83 got_repo_cleanup_complete(struct got_repository *, struct got_lockfile *);
85 /* A callback function which gets invoked with cleanup information to print. */
86 typedef const struct got_error *(*got_cleanup_progress_cb)(void *arg,
87 int nloose, int ncommits, int npurged, int nredundant);
89 /*
90 * Walk objects reachable via references to determine whether any loose
91 * objects can be removed from disk. Do remove such objects from disk
92 * unless the dry_run parameter is set.
93 * Do not remove objects with a modification timestamp above an
94 * implementation-defined timestamp threshold, unless ignore_mtime is set.
95 * Return the disk space size occupied by loose objects before and after
96 * the operation.
97 * Return the number of loose objects which are also stored in a pack file.
98 */
99 const struct got_error *
100 got_repo_purge_unreferenced_loose_objects(struct got_repository *repo,
101 off_t *size_before, off_t *size_after, int *npacked, int dry_run,
102 int ignore_mtime, got_cleanup_progress_cb progress_cb, void *progress_arg,
103 got_cancel_cb cancel_cb, void *cancel_arg);
105 const struct got_error *
106 got_repo_purge_redundant_packfiles(struct got_repository *repo,
107 off_t *before, off_t *size_after, int dry_run,
108 got_cleanup_progress_cb progress_cb, void *progress_arg,
109 got_cancel_cb cancel_cb, void *cancel_arg);
111 /* A callback function which gets invoked with cleanup information to print. */
112 typedef const struct got_error *(*got_lonely_packidx_progress_cb)(void *arg,
113 const char *path);
115 /* Remove pack index files which do not have a corresponding pack file. */
116 const struct got_error *
117 got_repo_remove_lonely_packidx(struct got_repository *repo, int dry_run,
118 got_lonely_packidx_progress_cb progress_cb, void *progress_arg,
119 got_cancel_cb cancel_cb, void *cancel_arg);