mirror of
https://seed.radicle.dev/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5.git
synced 2026-11-29 05:50:31 +08:00
node: Change storage layout
Projects now have their own repos. Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
@@ -26,6 +26,7 @@ impl quickcheck::Arbitrary for storage::Remote<storage::Unverified> {
|
||||
let mut refs: HashMap<storage::BranchName, storage::Oid> = HashMap::with_hasher(rng.into());
|
||||
let mut bytes: [u8; 20] = [0; 20];
|
||||
let names = &["master", "dev", "feature/1", "feature/2", "feature/3"];
|
||||
let id = UserId::arbitrary(g);
|
||||
|
||||
for _ in 0..g.size().min(2) {
|
||||
if let Some(name) = g.choose(names) {
|
||||
@@ -36,7 +37,7 @@ impl quickcheck::Arbitrary for storage::Remote<storage::Unverified> {
|
||||
refs.insert(name.to_string(), oid);
|
||||
}
|
||||
}
|
||||
storage::Remote::new(refs)
|
||||
storage::Remote::new(id, refs)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,8 @@ use std::str::FromStr;
|
||||
use once_cell::sync::Lazy;
|
||||
|
||||
use crate::identity::{ProjId, UserId};
|
||||
use crate::storage::{Storage, WriteStorage};
|
||||
use crate::storage::git::Storage;
|
||||
use crate::storage::{WriteRepository, WriteStorage};
|
||||
|
||||
pub static USER_IDS: Lazy<[UserId; 16]> = Lazy::new(|| {
|
||||
[
|
||||
@@ -48,16 +49,23 @@ pub static PROJ_IDS: Lazy<[ProjId; 16]> = Lazy::new(|| {
|
||||
]
|
||||
});
|
||||
|
||||
pub fn storage(path: &Path) -> Storage {
|
||||
let mut storage = Storage::open(path).unwrap();
|
||||
pub fn storage<P: AsRef<Path>>(path: P) -> Storage {
|
||||
let path = path.as_ref();
|
||||
let storage = Storage::new(path);
|
||||
|
||||
for proj in PROJ_IDS.iter().take(3) {
|
||||
log::debug!("creating {}...", proj);
|
||||
let mut repo = storage.repository(proj).unwrap();
|
||||
|
||||
for user in USER_IDS.iter().take(3) {
|
||||
let repo = storage.namespace(proj, user).unwrap();
|
||||
let repo = repo.namespace(user).unwrap();
|
||||
let head_oid = initial_commit(repo).unwrap();
|
||||
let head = repo.find_commit(head_oid).unwrap();
|
||||
|
||||
log::debug!("creating {}...", repo.namespace().unwrap());
|
||||
log::debug!("{}: creating {}...", proj, repo.namespace().unwrap());
|
||||
|
||||
repo.reference("refs/rad/root", head_oid, false, "test")
|
||||
.unwrap();
|
||||
|
||||
// TODO: Different commits.
|
||||
repo.branch("master", &head, false).unwrap();
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
use crate::identity::ProjId;
|
||||
use crate::storage::{Error, Inventory, ReadStorage, Remotes, Unverified, WriteStorage};
|
||||
use crate::storage::{
|
||||
Error, Inventory, ReadStorage, Remotes, Unverified, WriteRepository, WriteStorage,
|
||||
};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct MockStorage {
|
||||
@@ -38,13 +40,22 @@ impl ReadStorage for MockStorage {
|
||||
}
|
||||
|
||||
impl WriteStorage for MockStorage {
|
||||
fn repository(&mut self) -> &mut git2::Repository {
|
||||
type Repository = MockRepository;
|
||||
|
||||
fn repository(&self, _proj: &ProjId) -> Result<Self::Repository, Error> {
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct MockRepository {}
|
||||
|
||||
impl WriteRepository for MockRepository {
|
||||
fn fetch(&mut self, _url: &str) -> Result<(), git2::Error> {
|
||||
todo!()
|
||||
}
|
||||
|
||||
fn namespace(
|
||||
&mut self,
|
||||
_proj: &ProjId,
|
||||
_user: &crate::identity::UserId,
|
||||
) -> Result<&mut git2::Repository, git2::Error> {
|
||||
todo!()
|
||||
|
||||
Reference in New Issue
Block a user