mirror of
https://seed.radicle.dev/rad:z6cFWeWpnZNHh9rUW8phgA3b5yGt.git
synced 2026-10-25 14:20:31 +08:00
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>
50 lines
1.3 KiB
Rust
50 lines
1.3 KiB
Rust
// Copyright © 2022 The Radicle Link Contributors
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
//! Iterator adaptors over [`git2::References`].
|
|
|
|
use std::fmt::Debug;
|
|
|
|
use crate::glob;
|
|
|
|
use super::{error, Reference};
|
|
|
|
/// Iterator for [`Reference`]s where the inner [`glob::Pattern`] supplied
|
|
/// filters out any non-matching reference names.
|
|
pub struct References<'a> {
|
|
pub(crate) inner: ReferencesGlob<'a, glob::RefspecMatcher>,
|
|
}
|
|
|
|
impl<'a> Iterator for References<'a> {
|
|
type Item = Result<Reference, error::Iter>;
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
self.inner.next()
|
|
}
|
|
}
|
|
|
|
pub struct ReferencesGlob<'a, G: glob::Pattern + Debug> {
|
|
pub(crate) iter: git2::References<'a>,
|
|
pub(crate) glob: G,
|
|
}
|
|
|
|
impl<'a, G: glob::Pattern + Debug> Iterator for ReferencesGlob<'a, G> {
|
|
type Item = Result<Reference, error::Iter>;
|
|
|
|
fn next(&mut self) -> Option<Self::Item> {
|
|
for reference in &mut self.iter {
|
|
match reference {
|
|
Ok(reference) => match reference.name() {
|
|
Some(name) if self.glob.matches(name) => {
|
|
return Some(Reference::try_from(reference).map_err(error::Iter::from))
|
|
},
|
|
_ => continue,
|
|
},
|
|
|
|
Err(e) => return Some(Err(e.into())),
|
|
}
|
|
}
|
|
None
|
|
}
|
|
}
|