mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-11-21 02:20:44 +08:00
radicle-git init
Port over all git relevant parts of the radicle-link repository[0]. The packages that are kept are: * git-ext * git-ref-format * git-trailers * link-git * macros * std-ext * test -- only the portions that test the above The development and testing scripts are also added for local and CI testing. [0]: https://github.com/radicle-dev/radicle-link/ Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
This commit is contained in:
@@ -0,0 +1,51 @@
|
||||
// Copyright © 2021 The Radicle Link Contributors
|
||||
//
|
||||
// This file is part of radicle-link, distributed under the GPLv3 with Radicle
|
||||
// Linking Exception. For full terms see the included LICENSE file.
|
||||
|
||||
use git_hash::oid;
|
||||
use thiserror::Error;
|
||||
|
||||
pub mod backend;
|
||||
pub mod index;
|
||||
pub mod pack;
|
||||
pub mod window;
|
||||
|
||||
pub use git_pack::{cache, data::Object};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
#[error(transparent)]
|
||||
Packed(#[from] index::error::Lookup<pack::error::Data>),
|
||||
|
||||
#[error(transparent)]
|
||||
Loose(#[from] git_odb::loose::find::Error),
|
||||
}
|
||||
|
||||
pub struct Odb<I, D> {
|
||||
pub loose: backend::Loose,
|
||||
pub packed: backend::Packed<I, D>,
|
||||
}
|
||||
|
||||
impl<I, D> Odb<I, D>
|
||||
where
|
||||
I: index::Index,
|
||||
D: window::Cache,
|
||||
{
|
||||
pub fn contains(&self, id: impl AsRef<oid>) -> bool {
|
||||
self.packed.contains(id.as_ref()) || self.loose.contains(id)
|
||||
}
|
||||
|
||||
pub fn find<'a>(
|
||||
&self,
|
||||
id: impl AsRef<oid>,
|
||||
buf: &'a mut Vec<u8>,
|
||||
cache: &mut impl cache::DecodeEntry,
|
||||
) -> Result<Option<Object<'a>>, Error> {
|
||||
let id = id.as_ref();
|
||||
if self.packed.contains(id) {
|
||||
return self.packed.find(id, buf, cache).map_err(Into::into);
|
||||
}
|
||||
self.loose.try_find(id, buf).map_err(Into::into)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user