use crate::error::Result;
use crate::fsck::{FsckOptions, FsckReport};
use crate::gc::PruneStats;
use crate::objects::ObjectId;
use crate::progress::{CancelToken, ProgressSink};
use crate::repo::Repository;
use super::{
AutoGcOutcome, AutoGcReason, CommitGraphBuild, CommitGraphOptions, CommitGraphWriteReport,
DropPromisedBlobsOptions, DropPromisedBlobsReport, GcLock, GcLockAttempt, GcLockHolder,
GcOptions, GcStats, MidxOptions, MidxWriteReport, OffloadOptions, OffloadReport,
PackRefsOptions, PackRefsReport, PruneOptions, RepackOptions, RepackReport, RepackStats,
};
#[derive(Debug, Copy, Clone)]
pub struct Maintenance<'repo> {
repo: &'repo Repository,
}
impl<'repo> Maintenance<'repo> {
#[inline]
#[must_use]
pub fn new(repo: &'repo Repository) -> Self {
Self { repo }
}
#[inline]
#[must_use]
pub fn repository(&self) -> &'repo Repository {
self.repo
}
pub fn gc(
&self,
opts: &GcOptions,
progress: &mut dyn ProgressSink,
cancel: &CancelToken,
) -> Result<GcStats> {
super::gc(self.repo, opts, progress, cancel)
}
pub fn gc_auto(
&self,
opts: &GcOptions,
progress: &mut dyn ProgressSink,
cancel: &CancelToken,
) -> Result<AutoGcOutcome> {
super::gc_auto(self.repo, opts, progress, cancel)
}
pub fn auto_gc_needed(&self) -> Result<Option<AutoGcReason>> {
super::auto_gc_needed(self.repo)
}
pub fn repack(
&self,
opts: &RepackOptions,
progress: &mut dyn ProgressSink,
cancel: &CancelToken,
) -> Result<RepackReport> {
super::repack(self.repo, opts, progress, cancel)
}
pub fn repack_all(
&self,
opts: &RepackOptions,
progress: &mut dyn ProgressSink,
cancel: &CancelToken,
) -> Result<RepackStats> {
super::repack_all(self.repo, opts, progress, cancel)
}
pub fn prune_loose_objects(&self, opts: &PruneOptions) -> Result<PruneStats> {
super::prune_loose_objects(self.repo, opts)
}
pub fn build_commit_graph(&self, opts: &CommitGraphOptions) -> Result<CommitGraphBuild> {
super::build_commit_graph(self.repo, opts)
}
pub fn write_commit_graph(&self, opts: &CommitGraphOptions) -> Result<CommitGraphWriteReport> {
super::write_commit_graph(self.repo, opts)
}
pub fn write_midx(&self, opts: &MidxOptions) -> Result<MidxWriteReport> {
super::write_midx(self.repo, opts)
}
pub fn pack_refs(&self, opts: &PackRefsOptions) -> Result<PackRefsReport> {
super::pack_refs(self.repo, opts)
}
pub fn offload_blobs(&self, opts: &OffloadOptions) -> Result<OffloadReport> {
crate::offload::offload_blobs(self.repo, opts)
}
pub fn drop_promised_blobs(
&self,
opts: &DropPromisedBlobsOptions,
) -> Result<DropPromisedBlobsReport> {
super::drop_blobs::drop_promised_blobs(self.repo, opts)
}
pub fn reachability_roots(&self) -> Result<Vec<ObjectId>> {
crate::fsck::reachability_roots(self.repo)
}
pub fn fsck(
&self,
opts: &FsckOptions,
progress: &mut dyn ProgressSink,
cancel: &CancelToken,
) -> Result<FsckReport> {
crate::fsck::fsck(self.repo, opts, progress, cancel)
}
pub fn try_lock(&self, now_unix: i64) -> Result<GcLockAttempt> {
GcLock::try_acquire(self.repo, now_unix)
}
#[must_use]
pub fn lock_holder(&self, now_unix: i64) -> Option<GcLockHolder> {
GcLock::current_holder(self.repo, now_unix)
}
}