mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-11-29 14:10:27 +08:00
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:
@@ -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>;
|
||||
}
|
||||
Reference in New Issue
Block a user