From 3e173a18abcf0cfc2223d0a4afca887ec322a7b1 Mon Sep 17 00:00:00 2001 From: Alexis Sellier Date: Wed, 31 Aug 2022 22:44:33 +0200 Subject: [PATCH] node: Cleanup a few things Signed-off-by: Alexis Sellier --- node/src/identity.rs | 4 ++++ node/src/rad.rs | 10 ++++------ node/src/storage/git.rs | 27 ++------------------------- 3 files changed, 10 insertions(+), 31 deletions(-) diff --git a/node/src/identity.rs b/node/src/identity.rs index adadd44c..9f1ecd7c 100644 --- a/node/src/identity.rs +++ b/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; diff --git a/node/src/rad.rs b/node/src/rad.rs index fc2ccf1b..04774894 100644 --- a/node/src/rad.rs +++ b/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", diff --git a/node/src/storage/git.rs b/node/src/storage/git.rs index fc7da8b7..fc481d7d 100644 --- a/node/src/storage/git.rs +++ b/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 = - Lazy::new(|| refspec::pattern!("refs/namespaces/*/refs/rad/root")); +pub static RAD_ID_REF: Lazy = + Lazy::new(|| refspec::pattern!("refs/heads/rad/id")); pub static NAMESPACES_GLOB: Lazy = 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, - ) -> 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 {