Local workflow, smart-HTTP clone/fetch/push and public HTTPS clone/fetch match native git in stdout and exit codes. Only WASI imports (wasi:http, exit-with-code).
53 lines
1.7 KiB
Rust
53 lines
1.7 KiB
Rust
use crate::find::Entry;
|
|
use gix_error::Result;
|
|
|
|
/// An in-memory object database without pack locations.
|
|
#[derive(Clone)]
|
|
pub struct Memory {
|
|
objects: std::sync::Arc<gix_hashtable::HashMap<gix_hash::ObjectId, (gix_object::Kind, Vec<u8>)>>,
|
|
}
|
|
|
|
impl Memory {
|
|
/// Create a database containing all `objects`.
|
|
///
|
|
/// Each item is `(id, (kind, data))`, where `data` is the uncompressed object body without a
|
|
/// loose-object header. IDs are trusted rather than recomputed. If an ID occurs more than once,
|
|
/// the last item wins.
|
|
pub fn new(objects: impl IntoIterator<Item = (gix_hash::ObjectId, (gix_object::Kind, Vec<u8>))>) -> Self {
|
|
Self {
|
|
objects: std::sync::Arc::new(objects.into_iter().collect()),
|
|
}
|
|
}
|
|
}
|
|
|
|
impl crate::Find for Memory {
|
|
fn contains(&self, id: &gix_hash::oid) -> bool {
|
|
self.objects.contains_key(id)
|
|
}
|
|
|
|
fn try_find_cached<'a>(
|
|
&self,
|
|
id: &gix_hash::oid,
|
|
buffer: &'a mut Vec<u8>,
|
|
_pack_cache: &mut dyn crate::cache::DecodeEntry,
|
|
) -> Result<Option<(gix_object::Data<'a>, Option<crate::data::entry::Location>)>> {
|
|
Ok(self.objects.get(id).map(|(kind, data)| {
|
|
buffer.clear();
|
|
buffer.extend_from_slice(data);
|
|
(gix_object::Data::new(buffer, *kind, id.kind()), None)
|
|
}))
|
|
}
|
|
|
|
fn location_by_oid(&self, _id: &gix_hash::oid, _buf: &mut Vec<u8>) -> Result<Option<crate::data::entry::Location>> {
|
|
Ok(None)
|
|
}
|
|
|
|
fn pack_offsets_and_oid(&self, _pack_id: u32) -> Result<Option<Vec<(crate::data::Offset, gix_hash::ObjectId)>>> {
|
|
Ok(None)
|
|
}
|
|
|
|
fn entry_by_location(&self, _location: &crate::data::entry::Location) -> Option<Entry> {
|
|
None
|
|
}
|
|
}
|