Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
node: Cleanup a few things
Alexis Sellier committed 3 years ago
commit 3e173a18abcf0cfc2223d0a4afca887ec322a7b1
parent 64cec32ac6119d3740fdbb182f4174a36a38e96f
3 files changed +10 -31
modified node/src/identity.rs
@@ -1,6 +1,8 @@
+
use std::path::Path;
use std::{ffi::OsString, fmt, io, str::FromStr};

use nonempty::NonEmpty;
+
use once_cell::sync::Lazy;
use radicle_git_ext::Oid;
use serde::{Deserialize, Serialize};
use thiserror::Error;
@@ -8,6 +10,8 @@ use thiserror::Error;
use crate::crypto;
use crate::hash;

+
pub static IDENTITY_PATH: Lazy<&Path> = Lazy::new(|| Path::new("Radicle.toml"));
+

/// A user's identifier is simply their public key.
pub type UserId = crypto::PublicKey;

modified node/src/rad.rs
@@ -1,11 +1,10 @@
-
use std::path::Path;
use std::{fs, io};

use nonempty::NonEmpty;
use thiserror::Error;

-
use crate::identity;
use crate::identity::{ProjId, UserId};
+
use crate::{identity, storage};

#[derive(Error, Debug)]
pub enum InitError {
@@ -55,9 +54,8 @@ pub fn init(
        .signature()
        .or_else(|_| git2::Signature::now("anonymous", "anonymous@anonymous.xyz"))?;

-
    let base = repo.workdir().ok_or(InitError::BareRepo)?;
-
    let filename = Path::new("Project.toml");
-
    let path = base.join(filename);
+
    let filename = *identity::IDENTITY_PATH;
+
    let path = repo.workdir().ok_or(InitError::BareRepo)?.join(filename);
    let file = fs::OpenOptions::new()
        .create_new(true)
        .write(true)
@@ -70,7 +68,7 @@ pub fn init(
    let tree_id = index.write_tree()?;
    let tree = repo.find_tree(tree_id)?;
    let _oid = repo.commit(
-
        Some("refs/heads/rad/id"),
+
        Some(storage::git::RAD_ID_REF.as_str()),
        &sig,
        &sig,
        "Initialize Radicle",
modified node/src/storage/git.rs
@@ -10,7 +10,6 @@ pub use radicle_git_ext::Oid;

use crate::collections::HashMap;
use crate::git;
-
use crate::identity;
use crate::identity::{ProjId, UserId};

use super::{
@@ -18,11 +17,10 @@ use super::{
    WriteStorage,
};

-
pub static RAD_ROOT_GLOB: Lazy<refspec::PatternString> =
-
    Lazy::new(|| refspec::pattern!("refs/namespaces/*/refs/rad/root"));
+
pub static RAD_ID_REF: Lazy<refspec::PatternString> =
+
    Lazy::new(|| refspec::pattern!("refs/heads/rad/id"));
pub static NAMESPACES_GLOB: Lazy<refspec::PatternString> =
    Lazy::new(|| refspec::pattern!("refs/namespaces/*"));
-
pub static IDENTITY_PATH: Lazy<&Path> = Lazy::new(|| Path::new(".rad/identity.toml"));

pub struct Storage {
    path: PathBuf,
@@ -94,27 +92,6 @@ impl Storage {
        }
        Ok(projects)
    }
-

-
    pub fn create(
-
        &self,
-
        repo: &git2::Repository,
-
        identity: impl Into<identity::Doc>,
-
    ) -> Result<(ProjId, Oid), Error> {
-
        let doc = identity.into();
-
        let file = fs::OpenOptions::new()
-
            .create_new(true)
-
            .write(true)
-
            .open(*IDENTITY_PATH)?;
-
        let id = doc.write(file)?;
-
        let ref_name = RAD_ROOT_GLOB.replace('*', &id.encode());
-
        let oid = repo.head()?.target().ok_or(Error::InvalidHead)?;
-
        let repository = self.repository(&id)?;
-
        let _reference = repository.backend.reference(&ref_name, oid, false, "")?;
-

-
        // TODO: Push project to monorepo.
-

-
        Ok((id, oid.into()))
-
    }
}

pub struct Repository {