use std::fmt::Formatter;
use git_hash::ObjectId;
use git_object::bstr::BString;
use crate::{
store_impl::{file, file::Transaction},
transaction::RefEdit,
};
pub type FindObjectFn<'a> = dyn FnMut(
git_hash::ObjectId,
&mut Vec<u8>,
) -> Result<Option<git_object::Kind>, Box<dyn std::error::Error + Send + Sync + 'static>>
+ 'a;
pub enum PackedRefs<'a> {
DeletionsOnly,
DeletionsAndNonSymbolicUpdates(Box<FindObjectFn<'a>>),
DeletionsAndNonSymbolicUpdatesRemoveLooseSourceReference(Box<FindObjectFn<'a>>),
}
impl Default for PackedRefs<'_> {
fn default() -> Self {
PackedRefs::DeletionsOnly
}
}
#[derive(Debug)]
pub(in crate::store_impl::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, 'p> Transaction<'s, 'p> {
pub fn packed_refs(mut self, packed_refs: PackedRefs<'p>) -> Self {
self.packed_refs = packed_refs;
self
}
}
impl std::fmt::Debug for Transaction<'_, '_> {
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
f.debug_struct("Transaction")
.field("store", self.store)
.field("edits", &self.updates.as_ref().map(|u| u.len()))
.finish_non_exhaustive()
}
}
pub mod prepare;
pub mod commit;