use git_hash::ObjectId;
use git_object::bstr::BString;
use crate::{
store::{file, file::Transaction},
transaction::RefEdit,
};
pub type FindObjectFn =
dyn FnMut(
git_hash::ObjectId,
&mut Vec<u8>,
) -> Result<Option<git_object::Kind>, Box<dyn std::error::Error + Send + Sync + 'static>>;
pub enum PackedRefs {
DeletionsOnly,
DeletionsAndNonSymbolicUpdates(Box<FindObjectFn>),
DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference(Box<FindObjectFn>),
}
impl Default for PackedRefs {
fn default() -> Self {
PackedRefs::DeletionsOnly
}
}
#[derive(Debug)]
pub(in crate::store::file) struct Edit {
update: RefEdit,
lock: Option<git_lock::Marker>,
parent_index: Option<usize>,
leaf_referent_previous_oid: Option<ObjectId>,
}
impl Edit {
fn name(&self) -> BString {
self.update.name.0.clone()
}
}
impl std::borrow::Borrow<RefEdit> for Edit {
fn borrow(&self) -> &RefEdit {
&self.update
}
}
impl std::borrow::BorrowMut<RefEdit> for Edit {
fn borrow_mut(&mut self) -> &mut RefEdit {
&mut self.update
}
}
impl file::Store {
pub fn transaction(&self) -> Transaction<'_> {
Transaction {
store: self,
packed_transaction: None,
updates: None,
packed_refs: PackedRefs::default(),
}
}
}
impl<'s> Transaction<'s> {
pub fn packed_refs(mut self, packed_refs: PackedRefs) -> Self {
self.packed_refs = packed_refs;
self
}
}
pub mod prepare;
pub mod commit;