Blame


1 05118f5a 2021-06-22 stsp /*
2 05118f5a 2021-06-22 stsp * Copyright (c) 2021 Stefan Sperling <stsp@openbsd.org>
3 05118f5a 2021-06-22 stsp *
4 05118f5a 2021-06-22 stsp * Permission to use, copy, modify, and distribute this software for any
5 05118f5a 2021-06-22 stsp * purpose with or without fee is hereby granted, provided that the above
6 05118f5a 2021-06-22 stsp * copyright notice and this permission notice appear in all copies.
7 05118f5a 2021-06-22 stsp *
8 05118f5a 2021-06-22 stsp * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 05118f5a 2021-06-22 stsp * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 05118f5a 2021-06-22 stsp * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 05118f5a 2021-06-22 stsp * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 05118f5a 2021-06-22 stsp * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 05118f5a 2021-06-22 stsp * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 05118f5a 2021-06-22 stsp * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 05118f5a 2021-06-22 stsp */
16 05118f5a 2021-06-22 stsp
17 3bf0e21f 2023-06-19 op struct got_lockfile;
18 3bf0e21f 2023-06-19 op
19 05118f5a 2021-06-22 stsp /* A callback function which gets invoked with progress information to print. */
20 05118f5a 2021-06-22 stsp typedef const struct got_error *(*got_pack_progress_cb)(void *arg,
21 b8af7c06 2022-03-15 stsp int ncolored, int nfound, int ntrees, off_t packfile_size, int ncommits,
22 b8af7c06 2022-03-15 stsp int nobj_total, int obj_deltify, int nobj_written);
23 05118f5a 2021-06-22 stsp
24 05118f5a 2021-06-22 stsp /*
25 05118f5a 2021-06-22 stsp * Attempt to pack objects reachable via 'include_refs' into a new packfile.
26 05118f5a 2021-06-22 stsp * If 'excluded_refs' is not an empty list, do not pack any objects
27 05118f5a 2021-06-22 stsp * reachable from the listed references.
28 05118f5a 2021-06-22 stsp * If loose_obj_only is zero, pack reachable objects even if they are
29 05118f5a 2021-06-22 stsp * already packed in another packfile. Otherwise, add only loose
30 05118f5a 2021-06-22 stsp * objects to the new pack file.
31 05118f5a 2021-06-22 stsp * Return an open file handle for the generated pack file.
32 05118f5a 2021-06-22 stsp * Return the SHA1 digest of the resulting pack file in pack_hash which
33 05118f5a 2021-06-22 stsp * must freed by the caller when done.
34 05118f5a 2021-06-22 stsp */
35 05118f5a 2021-06-22 stsp const struct got_error *
36 05118f5a 2021-06-22 stsp got_repo_pack_objects(FILE **packfile, struct got_object_id **pack_hash,
37 05118f5a 2021-06-22 stsp struct got_reflist_head *include_refs,
38 05118f5a 2021-06-22 stsp struct got_reflist_head *exclude_refs, struct got_repository *repo,
39 c7a4fcc8 2023-02-17 op int loose_obj_only, int force_refdelta,
40 05118f5a 2021-06-22 stsp got_pack_progress_cb progress_cb, void *progress_arg,
41 05118f5a 2021-06-22 stsp got_cancel_cb cancel_cb, void *cancel_arg);
42 05118f5a 2021-06-22 stsp
43 05118f5a 2021-06-22 stsp /*
44 05118f5a 2021-06-22 stsp * Attempt to open a pack file at the specified path. Return an open
45 05118f5a 2021-06-22 stsp * file handle and the expected hash of pack file contents.
46 05118f5a 2021-06-22 stsp */
47 05118f5a 2021-06-22 stsp const struct got_error *
48 05118f5a 2021-06-22 stsp got_repo_find_pack(FILE **packfile, struct got_object_id **pack_hash,
49 05118f5a 2021-06-22 stsp struct got_repository *repo, const char *packfile_path);
50 05118f5a 2021-06-22 stsp
51 05118f5a 2021-06-22 stsp /* A callback function which gets invoked with progress information to print. */
52 05118f5a 2021-06-22 stsp typedef const struct got_error *(*got_pack_index_progress_cb)(void *arg,
53 05118f5a 2021-06-22 stsp off_t packfile_size, int nobj_total, int nobj_indexed,
54 05118f5a 2021-06-22 stsp int nobj_loose, int nobj_resolved);
55 05118f5a 2021-06-22 stsp
56 05118f5a 2021-06-22 stsp /* (Re-)Index the pack file identified by the given hash. */
57 05118f5a 2021-06-22 stsp const struct got_error *
58 05118f5a 2021-06-22 stsp got_repo_index_pack(FILE *packfile, struct got_object_id *pack_hash,
59 05118f5a 2021-06-22 stsp struct got_repository *repo,
60 05118f5a 2021-06-22 stsp got_pack_index_progress_cb progress_cb, void *progress_arg,
61 05118f5a 2021-06-22 stsp got_cancel_cb cancel_cb, void *cancel_arg);
62 05118f5a 2021-06-22 stsp
63 05118f5a 2021-06-22 stsp typedef const struct got_error *(*got_pack_list_cb)(void *arg,
64 05118f5a 2021-06-22 stsp struct got_object_id *id, int type, off_t offset, off_t size,
65 05118f5a 2021-06-22 stsp off_t base_offset, struct got_object_id *base_id);
66 05118f5a 2021-06-22 stsp
67 05118f5a 2021-06-22 stsp /* List the pack file identified by the given hash. */
68 05118f5a 2021-06-22 stsp const struct got_error *
69 05118f5a 2021-06-22 stsp got_repo_list_pack(FILE *packfile, struct got_object_id *pack_hash,
70 05118f5a 2021-06-22 stsp struct got_repository *repo, got_pack_list_cb list_cb, void *list_arg,
71 05118f5a 2021-06-22 stsp got_cancel_cb cancel_cb, void *cancel_arg);
72 b3d68e7f 2021-07-03 stsp
73 3bf0e21f 2023-06-19 op /*
74 3bf0e21f 2023-06-19 op * Prepare for removing loose objects or redundant packfiles.
75 3bf0e21f 2023-06-19 op *
76 3bf0e21f 2023-06-19 op * These functions do the necessary locking in order to avoid
77 3bf0e21f 2023-06-19 op * concurrent operation to irremediably damage the repository.
78 3bf0e21f 2023-06-19 op */
79 3bf0e21f 2023-06-19 op const struct got_error *
80 3bf0e21f 2023-06-19 op got_repo_cleanup_prepare(struct got_repository *, struct got_lockfile **);
81 3bf0e21f 2023-06-19 op
82 3bf0e21f 2023-06-19 op const struct got_error *
83 3bf0e21f 2023-06-19 op got_repo_cleanup_complete(struct got_repository *, struct got_lockfile *);
84 3bf0e21f 2023-06-19 op
85 b3d68e7f 2021-07-03 stsp /* A callback function which gets invoked with cleanup information to print. */
86 b3d68e7f 2021-07-03 stsp typedef const struct got_error *(*got_cleanup_progress_cb)(void *arg,
87 9a7c12cf 2023-06-18 op int nloose, int ncommits, int npurged, int nredundant);
88 b3d68e7f 2021-07-03 stsp
89 b3d68e7f 2021-07-03 stsp /*
90 b3d68e7f 2021-07-03 stsp * Walk objects reachable via references to determine whether any loose
91 b3d68e7f 2021-07-03 stsp * objects can be removed from disk. Do remove such objects from disk
92 b3d68e7f 2021-07-03 stsp * unless the dry_run parameter is set.
93 ef8ec606 2021-07-27 stsp * Do not remove objects with a modification timestamp above an
94 ef8ec606 2021-07-27 stsp * implementation-defined timestamp threshold, unless ignore_mtime is set.
95 b3d68e7f 2021-07-03 stsp * Return the disk space size occupied by loose objects before and after
96 b3d68e7f 2021-07-03 stsp * the operation.
97 b3d68e7f 2021-07-03 stsp * Return the number of loose objects which are also stored in a pack file.
98 b3d68e7f 2021-07-03 stsp */
99 b3d68e7f 2021-07-03 stsp const struct got_error *
100 b3d68e7f 2021-07-03 stsp got_repo_purge_unreferenced_loose_objects(struct got_repository *repo,
101 b3d68e7f 2021-07-03 stsp off_t *size_before, off_t *size_after, int *npacked, int dry_run,
102 ef8ec606 2021-07-27 stsp int ignore_mtime, got_cleanup_progress_cb progress_cb, void *progress_arg,
103 b3d68e7f 2021-07-03 stsp got_cancel_cb cancel_cb, void *cancel_arg);
104 1124fe40 2021-07-07 stsp
105 9a7c12cf 2023-06-18 op const struct got_error *
106 9a7c12cf 2023-06-18 op got_repo_purge_redundant_packfiles(struct got_repository *repo,
107 9a7c12cf 2023-06-18 op off_t *before, off_t *size_after, int dry_run,
108 9a7c12cf 2023-06-18 op got_cleanup_progress_cb progress_cb, void *progress_arg,
109 9a7c12cf 2023-06-18 op got_cancel_cb cancel_cb, void *cancel_arg);
110 9a7c12cf 2023-06-18 op
111 1124fe40 2021-07-07 stsp /* A callback function which gets invoked with cleanup information to print. */
112 1124fe40 2021-07-07 stsp typedef const struct got_error *(*got_lonely_packidx_progress_cb)(void *arg,
113 1124fe40 2021-07-07 stsp const char *path);
114 1124fe40 2021-07-07 stsp
115 1124fe40 2021-07-07 stsp /* Remove pack index files which do not have a corresponding pack file. */
116 1124fe40 2021-07-07 stsp const struct got_error *
117 1124fe40 2021-07-07 stsp got_repo_remove_lonely_packidx(struct got_repository *repo, int dry_run,
118 1124fe40 2021-07-07 stsp got_lonely_packidx_progress_cb progress_cb, void *progress_arg,
119 1124fe40 2021-07-07 stsp got_cancel_cb cancel_cb, void *cancel_arg);