node: Use stronger types for refs

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier
2022-09-13 10:16:05 +02:00
parent a4d2232578
commit e4e4d9dcaa
6 changed files with 41 additions and 33 deletions
+5 -2
View File
@@ -7,6 +7,7 @@ use quickcheck::Arbitrary;
use crate::collections::HashMap;
use crate::crypto::{self, Signer};
use crate::crypto::{PublicKey, SecretKey};
use crate::git;
use crate::hash;
use crate::identity::ProjId;
use crate::storage;
@@ -50,7 +51,7 @@ impl Arbitrary for MockStorage {
impl Arbitrary for Refs {
fn arbitrary(g: &mut quickcheck::Gen) -> Self {
let mut refs: BTreeMap<storage::RefName, storage::Oid> = BTreeMap::new();
let mut refs: BTreeMap<git::RefString, storage::Oid> = BTreeMap::new();
let mut bytes: [u8; 20] = [0; 20];
let names = &[
"heads/master",
@@ -69,7 +70,9 @@ impl Arbitrary for Refs {
*byte = u8::arbitrary(g);
}
let oid = storage::Oid::try_from(&bytes[..]).unwrap();
refs.insert(name.to_string(), oid);
let name = git::RefString::try_from(*name).unwrap();
refs.insert(name, oid);
}
}
Self::from(refs)
+3 -2
View File
@@ -1,6 +1,7 @@
use git_url::Url;
use crate::crypto::Verified;
use crate::git;
use crate::identity::{ProjId, UserId};
use crate::storage::refs;
use crate::storage::{
@@ -96,7 +97,7 @@ impl ReadRepository for MockRepository {
fn reference(
&self,
_user: &UserId,
_reference: &str,
_reference: &git::RefStr,
) -> Result<Option<git2::Reference>, git2::Error> {
todo!()
}
@@ -104,7 +105,7 @@ impl ReadRepository for MockRepository {
fn reference_oid(
&self,
_user: &UserId,
_reference: &str,
_reference: &git::RefStr,
) -> Result<Option<radicle_git_ext::Oid>, git2::Error> {
todo!()
}