radicle_protocol/worker/
fetch.rs1pub mod error;
2
3use std::collections::{BTreeMap, HashSet};
4
5use radicle::crypto::PublicKey;
6use radicle::git;
7use radicle::{identity::DocAt, storage::RefUpdate};
8
9#[derive(Debug, Clone)]
10pub struct FetchResult {
11 pub updated: Vec<RefUpdate>,
13 pub canonical: UpdatedCanonicalRefs,
15 pub namespaces: HashSet<PublicKey>,
17 pub clone: bool,
19 pub doc: DocAt,
21}
22
23impl FetchResult {
24 pub fn new(doc: DocAt) -> Self {
25 Self {
26 updated: vec![],
27 canonical: UpdatedCanonicalRefs::default(),
28 namespaces: HashSet::new(),
29 clone: false,
30 doc,
31 }
32 }
33}
34
35#[derive(Clone, Default, Debug)]
38pub struct UpdatedCanonicalRefs {
39 inner: BTreeMap<git::Qualified<'static>, git::Oid>,
40}
41
42impl IntoIterator for UpdatedCanonicalRefs {
43 type Item = (git::Qualified<'static>, git::Oid);
44 type IntoIter = std::collections::btree_map::IntoIter<git::Qualified<'static>, git::Oid>;
45
46 fn into_iter(self) -> Self::IntoIter {
47 self.inner.into_iter()
48 }
49}
50
51impl UpdatedCanonicalRefs {
52 pub fn updated(&mut self, refname: git::Qualified<'static>, target: git::Oid) {
55 self.inner.insert(refname, target);
56 }
57
58 pub fn iter(&self) -> impl Iterator<Item = (&git::Qualified<'static>, &git::Oid)> {
60 self.inner.iter()
61 }
62}
63
64#[cfg(any(test, feature = "test"))]
65impl qcheck::Arbitrary for FetchResult {
66 fn arbitrary(g: &mut qcheck::Gen) -> Self {
67 FetchResult {
68 updated: vec![],
69 canonical: UpdatedCanonicalRefs::default(),
70 namespaces: HashSet::arbitrary(g),
71 clone: bool::arbitrary(g),
72 doc: DocAt::arbitrary(g),
73 }
74 }
75}