git-storage: port storage from librad

This provides a port of the librad::git::storage[0] API, with a focus
on being more generic and decomposing writing and reading
operations. It also takes heavy inspiration from
link_replication::io::refdb[1] for its implementation of the
transactional writes.

[0]: https://github.com/radicle-dev/radicle-link/blob/master/librad/src/git/storage.rs
[1]: https://github.com/radicle-dev/radicle-link/blob/master/link-replication/src/io/refdb.rs

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
This commit is contained in:
Fintan Halpenny
2022-09-27 12:32:20 +01:00
parent 69e815c124
commit e6f36318cd
19 changed files with 2131 additions and 0 deletions
+43
View File
@@ -0,0 +1,43 @@
// Copyright © 2022 The Radicle Link Contributors
// SPDX-License-Identifier: GPL-3.0-or-later
use std::error::Error;
use git_ext::Oid;
use git_ref_format::{refspec, RefStr};
use super::Reference;
/// Read-only access to a git refdb.
///
/// See [`crate::Read`] for an implementation of this trait.
pub trait Read {
/// The error type for finding a reference in the refdb.
type FindRef: Error + Send + Sync + 'static;
/// The error type for finding references in the refdb.
type FindRefs: Error + Send + Sync + 'static;
/// The error type for finding reference Oid in the refdb.
type FindRefOid: Error + Send + Sync + 'static;
/// Iterator for references returned by `find_references`.
type References: Iterator<Item = Result<Reference, Self::FindRefs>>;
/// Find the reference that corresponds to `name`. If the reference does not
/// exist, then `None` is returned.
fn find_reference<Ref>(&self, name: Ref) -> Result<Option<Reference>, Self::FindRef>
where
Ref: AsRef<RefStr>;
/// Find the references that match `pattern`.
fn find_references<Pat>(&self, pattern: Pat) -> Result<Self::References, Self::FindRefs>
where
Pat: AsRef<refspec::PatternStr>;
/// Find the [`Oid`] for the reference that corresponds to `name`. If the
/// reference does not exist, then `None` is returned.
fn find_reference_oid<Ref>(&self, name: Ref) -> Result<Option<Oid>, Self::FindRefOid>
where
Ref: AsRef<RefStr>;
}