node: Cleanup a few things

Signed-off-by: Alexis Sellier <self@cloudhead.io>
This commit is contained in:
Alexis Sellier 2022-08-31 22:44:33 +02:00
parent 64cec32ac6
commit 3e173a18ab
No known key found for this signature in database
3 changed files with 10 additions and 31 deletions

View File

@ -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;

View File

@ -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",

View File

@ -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 {