use std::path::Path;
use crate::error::Result;
use crate::index::Index;
use crate::repo::Repository;
use crate::split_index::WriteSplitIndexRequest;
#[derive(Debug, Copy, Clone)]
pub struct IndexHandle<'repo> {
repo: &'repo Repository,
}
impl<'repo> IndexHandle<'repo> {
#[inline]
#[must_use]
pub fn new(repo: &'repo Repository) -> Self {
Self { repo }
}
#[inline]
#[must_use]
pub fn repository(&self) -> &'repo Repository {
self.repo
}
#[inline]
#[must_use]
pub fn path(&self) -> std::path::PathBuf {
self.repo.index_path()
}
#[inline]
pub fn path_for_env(&self) -> Result<std::path::PathBuf> {
self.repo.index_path_for_env()
}
#[inline]
pub fn load(&self) -> Result<Index> {
self.repo.load_index()
}
#[inline]
pub fn load_at(&self, path: &Path) -> Result<Index> {
self.repo.load_index_at(path)
}
#[inline]
pub fn write(&self, index: &mut Index) -> Result<()> {
self.repo.write_index(index)
}
#[inline]
pub fn write_at(&self, path: &Path, index: &mut Index) -> Result<()> {
self.repo.write_index_at(path, index)
}
#[inline]
pub fn write_at_with_split(
&self,
path: &Path,
index: &mut Index,
split: WriteSplitIndexRequest,
) -> Result<()> {
self.repo.write_index_at_with_split(path, index, split)
}
#[must_use]
#[inline]
pub fn split_would_force_write(&self, index: &Index) -> bool {
self.repo.split_index_would_force_write(index)
}
#[inline]
pub fn begin_update(&self) -> Result<crate::index::IndexLock> {
self.repo.begin_index_update()
}
#[inline]
pub fn commit_update(
&self,
lock: &mut crate::index::IndexLock,
index: &mut Index,
updated_workdir: bool,
) -> Result<()> {
self.repo.commit_index_update(lock, index, updated_workdir)
}
#[inline]
pub fn flush_update(
&self,
lock: &mut crate::index::IndexLock,
index: &mut Index,
) -> Result<()> {
self.repo.flush_index_update(lock, index)
}
#[inline]
pub fn finish_update(
&self,
lock: &mut crate::index::IndexLock,
updated_workdir: bool,
) -> Result<()> {
self.repo.finish_index_update(lock, updated_workdir)
}
#[inline]
pub fn try_write(&self, index: &mut Index) -> Result<bool> {
self.repo.try_write_index(index)
}
}