use std::path::PathBuf;
use git_hash::ObjectId;
use git_object::bstr::{BStr, BString};
use memmap2::Mmap;
use crate::{file, transaction::RefEdit, FullNameRef};
#[derive(Debug)]
enum Backing {
InMemory(Vec<u8>),
Mapped(Mmap),
}
#[derive(Debug)]
pub struct Buffer {
data: Backing,
offset: usize,
path: PathBuf,
}
struct Edit {
inner: RefEdit,
peeled: Option<ObjectId>,
}
pub(crate) struct Transaction {
buffer: Option<file::packed::SharedBufferSnapshot>,
edits: Option<Vec<Edit>>,
lock: Option<git_lock::File>,
#[allow(dead_code)] closed_lock: Option<git_lock::Marker>,
}
#[derive(Debug, PartialEq, Eq)]
pub struct Reference<'a> {
pub name: &'a FullNameRef,
pub target: &'a BStr,
pub object: Option<&'a BStr>,
}
impl<'a> Reference<'a> {
pub fn target(&self) -> ObjectId {
git_hash::ObjectId::from_hex(self.target).expect("parser validation")
}
pub fn object(&self) -> ObjectId {
self.object.map_or_else(
|| self.target(),
|id| ObjectId::from_hex(id).expect("parser validation"),
)
}
}
pub struct Iter<'a> {
cursor: &'a [u8],
current_line: usize,
prefix: Option<BString>,
}
mod decode;
pub mod iter;
pub mod buffer;
pub mod find;
pub mod transaction;