Rename Id to RepoId

Rename the type to make it clearer and consistent with `NodeId`.
This commit is contained in:
cloudhead
2024-01-22 15:51:44 +01:00
parent 60efd13ff3
commit 9a36d11ccf
8 changed files with 47 additions and 44 deletions
+5 -5
View File
@@ -16,7 +16,7 @@ use tower_http::cors::{self, CorsLayer};
use radicle::cob::issue;
use radicle::cob::patch;
use radicle::identity::{DocAt, Id};
use radicle::identity::{DocAt, RepoId};
use radicle::node::policy::Scope;
use radicle::node::routing::Store;
use radicle::node::{Handle, NodeId};
@@ -52,7 +52,7 @@ impl Context {
}
}
pub fn project_info(&self, id: Id) -> Result<project::Info, error::Error> {
pub fn project_info(&self, id: RepoId) -> Result<project::Info, error::Error> {
let storage = &self.profile.storage;
let repo = storage.repository(id)?;
let (_, head) = repo.head()?;
@@ -196,7 +196,7 @@ mod project {
use radicle::cob;
use radicle::git::Oid;
use radicle::identity::project::Project;
use radicle::identity::{Id, Visibility};
use radicle::identity::{RepoId, Visibility};
use radicle::prelude::Did;
/// Project info.
@@ -211,13 +211,13 @@ mod project {
pub head: Oid,
pub patches: cob::patch::PatchCounts,
pub issues: cob::issue::IssueCounts,
pub id: Id,
pub id: RepoId,
pub seeding: usize,
}
}
/// Announce refs to the network for the given RID.
pub fn announce_refs(mut node: Node, rid: Id) -> Result<(), Error> {
pub fn announce_refs(mut node: Node, rid: RepoId) -> Result<(), Error> {
match node.announce_refs(rid) {
Ok(_) => Ok(()),
Err(e) if e.is_connection_err() => Ok(()),
+3 -3
View File
@@ -6,7 +6,7 @@ use axum_auth::AuthBearer;
use hyper::StatusCode;
use serde_json::json;
use radicle::identity::Id;
use radicle::identity::RepoId;
use radicle::node::{policy, Handle, DEFAULT_TIMEOUT};
use radicle::Node;
@@ -74,7 +74,7 @@ async fn node_policies_repos_handler(State(ctx): State<Context>) -> impl IntoRes
async fn node_policies_seed_handler(
State(ctx): State<Context>,
AuthBearer(token): AuthBearer,
Path(project): Path<Id>,
Path(project): Path<RepoId>,
Query(qs): Query<PoliciesQuery>,
) -> impl IntoResponse {
api::auth::validate(&ctx, &token).await?;
@@ -96,7 +96,7 @@ async fn node_policies_seed_handler(
async fn node_policies_unseed_handler(
State(ctx): State<Context>,
AuthBearer(token): AuthBearer,
Path(project): Path<Id>,
Path(project): Path<RepoId>,
) -> impl IntoResponse {
api::auth::validate(&ctx, &token).await?;
let mut node = Node::new(ctx.profile.socket());
+23 -20
View File
@@ -15,7 +15,7 @@ use serde_json::json;
use tower_http::set_header::SetResponseHeaderLayer;
use radicle::cob::{issue, patch, resolve_embed, Embed, Label, Uri};
use radicle::identity::{Did, Id, Visibility};
use radicle::identity::{Did, RepoId, Visibility};
use radicle::node::routing::Store;
use radicle::node::{AliasStore, Node, NodeId};
use radicle::storage::git::paths;
@@ -141,7 +141,7 @@ async fn project_root_handler(
/// Get project metadata.
/// `GET /projects/:project`
async fn project_handler(State(ctx): State<Context>, Path(id): Path<Id>) -> impl IntoResponse {
async fn project_handler(State(ctx): State<Context>, Path(id): Path<RepoId>) -> impl IntoResponse {
let info = ctx.project_info(id)?;
Ok::<_, Error>(Json(info))
@@ -161,7 +161,7 @@ pub struct CommitsQueryString {
/// `GET /projects/:project/commits?since=<sha>`
async fn history_handler(
State(ctx): State<Context>,
Path(project): Path<Id>,
Path(project): Path<RepoId>,
Query(qs): Query<CommitsQueryString>,
) -> impl IntoResponse {
let CommitsQueryString {
@@ -242,7 +242,7 @@ async fn history_handler(
/// `GET /projects/:project/commits/:sha`
async fn commit_handler(
State(ctx): State<Context>,
Path((project, sha)): Path<(Id, Oid)>,
Path((project, sha)): Path<(RepoId, Oid)>,
) -> impl IntoResponse {
let storage = &ctx.profile.storage;
let repo = Repository::open(paths::repository(storage, &project))?;
@@ -308,7 +308,7 @@ async fn commit_handler(
/// `GET /projects/:project/diff/:base/:oid`
async fn diff_handler(
State(ctx): State<Context>,
Path((project, base, oid)): Path<(Id, Oid, Oid)>,
Path((project, base, oid)): Path<(RepoId, Oid, Oid)>,
) -> impl IntoResponse {
let storage = &ctx.profile.storage;
let repo = Repository::open(paths::repository(storage, &project))?;
@@ -375,7 +375,7 @@ async fn diff_handler(
/// `GET /projects/:project/activity`
async fn activity_handler(
State(ctx): State<Context>,
Path(project): Path<Id>,
Path(project): Path<RepoId>,
) -> impl IntoResponse {
let current_date = chrono::Utc::now().timestamp();
let one_year_ago = chrono::Duration::weeks(52);
@@ -402,7 +402,7 @@ async fn activity_handler(
/// `GET /projects/:project/tree/:sha/`
async fn tree_handler_root(
State(ctx): State<Context>,
Path((project, sha)): Path<(Id, Oid)>,
Path((project, sha)): Path<(RepoId, Oid)>,
) -> impl IntoResponse {
tree_handler(State(ctx), Path((project, sha, String::new()))).await
}
@@ -411,7 +411,7 @@ async fn tree_handler_root(
/// `GET /projects/:project/tree/:sha/*path`
async fn tree_handler(
State(ctx): State<Context>,
Path((project, sha, path)): Path<(Id, Oid, String)>,
Path((project, sha, path)): Path<(RepoId, Oid, String)>,
) -> impl IntoResponse {
if let Some(ref cache) = ctx.cache {
let cache = &mut cache.tree.lock().await;
@@ -436,7 +436,10 @@ async fn tree_handler(
/// Get all project remotes.
/// `GET /projects/:project/remotes`
async fn remotes_handler(State(ctx): State<Context>, Path(project): Path<Id>) -> impl IntoResponse {
async fn remotes_handler(
State(ctx): State<Context>,
Path(project): Path<RepoId>,
) -> impl IntoResponse {
let storage = &ctx.profile.storage;
let repo = storage.repository(project)?;
let delegates = repo.delegates()?;
@@ -478,7 +481,7 @@ async fn remotes_handler(State(ctx): State<Context>, Path(project): Path<Id>) ->
/// `GET /projects/:project/remotes/:peer`
async fn remote_handler(
State(ctx): State<Context>,
Path((project, node_id)): Path<(Id, NodeId)>,
Path((project, node_id)): Path<(RepoId, NodeId)>,
) -> impl IntoResponse {
let storage = &ctx.profile.storage;
let repo = storage.repository(project)?;
@@ -506,7 +509,7 @@ async fn remote_handler(
/// `GET /projects/:project/blob/:sha/*path`
async fn blob_handler(
State(ctx): State<Context>,
Path((project, sha, path)): Path<(Id, Oid, String)>,
Path((project, sha, path)): Path<(RepoId, Oid, String)>,
) -> impl IntoResponse {
let storage = &ctx.profile.storage;
let repo = Repository::open(paths::repository(storage, &project))?;
@@ -520,7 +523,7 @@ async fn blob_handler(
/// `GET /projects/:project/readme/:sha`
async fn readme_handler(
State(ctx): State<Context>,
Path((project, sha)): Path<(Id, Oid)>,
Path((project, sha)): Path<(RepoId, Oid)>,
) -> impl IntoResponse {
let storage = &ctx.profile.storage;
let repo = Repository::open(paths::repository(storage, &project))?;
@@ -551,7 +554,7 @@ async fn readme_handler(
/// `GET /projects/:project/issues`
async fn issues_handler(
State(ctx): State<Context>,
Path(project): Path<Id>,
Path(project): Path<RepoId>,
Query(qs): Query<CobsQuery<api::IssueState>>,
) -> impl IntoResponse {
let CobsQuery {
@@ -599,7 +602,7 @@ pub struct IssueCreate {
async fn issue_create_handler(
State(ctx): State<Context>,
AuthBearer(token): AuthBearer,
Path(project): Path<Id>,
Path(project): Path<RepoId>,
Json(issue): Json<IssueCreate>,
) -> impl IntoResponse {
api::auth::validate(&ctx, &token).await?;
@@ -641,7 +644,7 @@ async fn issue_create_handler(
async fn issue_update_handler(
State(ctx): State<Context>,
AuthBearer(token): AuthBearer,
Path((project, issue_id)): Path<(Id, Oid)>,
Path((project, issue_id)): Path<(RepoId, Oid)>,
Json(action): Json<issue::Action>,
) -> impl IntoResponse {
api::auth::validate(&ctx, &token).await?;
@@ -696,7 +699,7 @@ async fn issue_update_handler(
/// `GET /projects/:project/issues/:id`
async fn issue_handler(
State(ctx): State<Context>,
Path((project, issue_id)): Path<(Id, Oid)>,
Path((project, issue_id)): Path<(RepoId, Oid)>,
) -> impl IntoResponse {
let storage = &ctx.profile.storage;
let repo = storage.repository(project)?;
@@ -722,7 +725,7 @@ pub struct PatchCreate {
async fn patch_create_handler(
State(ctx): State<Context>,
AuthBearer(token): AuthBearer,
Path(project): Path<Id>,
Path(project): Path<RepoId>,
Json(patch): Json<PatchCreate>,
) -> impl IntoResponse {
api::auth::validate(&ctx, &token).await?;
@@ -761,7 +764,7 @@ async fn patch_create_handler(
async fn patch_update_handler(
State(ctx): State<Context>,
AuthBearer(token): AuthBearer,
Path((project, patch_id)): Path<(Id, Oid)>,
Path((project, patch_id)): Path<(RepoId, Oid)>,
Json(action): Json<patch::Action>,
) -> impl IntoResponse {
api::auth::validate(&ctx, &token).await?;
@@ -901,7 +904,7 @@ async fn patch_update_handler(
/// `GET /projects/:project/patches`
async fn patches_handler(
State(ctx): State<Context>,
Path(project): Path<Id>,
Path(project): Path<RepoId>,
Query(qs): Query<CobsQuery<api::PatchState>>,
) -> impl IntoResponse {
let CobsQuery {
@@ -938,7 +941,7 @@ async fn patches_handler(
/// `GET /projects/:project/patches/:id`
async fn patch_handler(
State(ctx): State<Context>,
Path((project, patch_id)): Path<(Id, Oid)>,
Path((project, patch_id)): Path<(RepoId, Oid)>,
) -> impl IntoResponse {
let storage = &ctx.profile.storage;
let repo = storage.repository(project)?;
+2 -2
View File
@@ -4,12 +4,12 @@ use std::sync::Arc;
use lru::LruCache;
use tokio::sync::Mutex;
use radicle::prelude::Id;
use radicle::prelude::RepoId;
use radicle_surf::Oid;
#[derive(Clone)]
pub struct Cache {
pub tree: Arc<Mutex<LruCache<(Id, Oid, String), serde_json::Value>>>,
pub tree: Arc<Mutex<LruCache<(RepoId, Oid, String), serde_json::Value>>>,
}
impl Cache {
+7 -7
View File
@@ -16,19 +16,19 @@ use axum::Router;
use flate2::write::GzDecoder;
use hyper::body::Buf as _;
use radicle::identity::Id;
use radicle::identity::RepoId;
use radicle::profile::Profile;
use crate::error::GitError as Error;
pub fn router(profile: Arc<Profile>, aliases: HashMap<String, Id>) -> Router {
pub fn router(profile: Arc<Profile>, aliases: HashMap<String, RepoId>) -> Router {
Router::new()
.route("/:project/*request", any(git_handler))
.with_state((profile, aliases))
}
async fn git_handler(
State((profile, aliases)): State<(Arc<Profile>, HashMap<String, Id>)>,
State((profile, aliases)): State<(Arc<Profile>, HashMap<String, RepoId>)>,
AxumPath((project, request)): AxumPath<(String, String)>,
method: Method,
headers: HeaderMap,
@@ -38,7 +38,7 @@ async fn git_handler(
) -> impl IntoResponse {
let query = query.0.unwrap_or_default();
let name = project.strip_suffix(".git").unwrap_or(&project);
let rid: Id = match name.parse() {
let rid: RepoId = match name.parse() {
Ok(rid) => rid,
Err(_) => {
let Some(rid) = aliases.get(name) else {
@@ -70,7 +70,7 @@ async fn git_http_backend(
headers: HeaderMap,
mut body: Bytes,
remote: net::SocketAddr,
id: Id,
id: RepoId,
path: &str,
query: String,
) -> Result<(StatusCode, HashMap<String, Vec<String>>, Vec<u8>), Error> {
@@ -210,7 +210,7 @@ mod routes {
use axum::extract::connect_info::MockConnectInfo;
use axum::http::StatusCode;
use radicle::identity::Id;
use radicle::identity::RepoId;
use crate::test::{self, get, RID};
@@ -232,7 +232,7 @@ mod routes {
let ctx = test::seed(tmp.path());
let app = super::router(
ctx.profile().to_owned(),
HashMap::from_iter([(String::from("heartwood"), Id::from_str(RID).unwrap())]),
HashMap::from_iter([(String::from("heartwood"), RepoId::from_str(RID).unwrap())]),
)
.layer(MockConnectInfo(SocketAddr::from(([0, 0, 0, 0], 8080))));
+2 -2
View File
@@ -21,7 +21,7 @@ use tokio::net::TcpListener;
use tower_http::trace::TraceLayer;
use tracing::Span;
use radicle::identity::Id;
use radicle::identity::RepoId;
use radicle::Profile;
use tracing_extra::{tracing_middleware, ColoredStatus, Paint, RequestId, TracingInfo};
@@ -40,7 +40,7 @@ pub const DEFAULT_CACHE_SIZE: NonZeroUsize = unsafe { NonZeroUsize::new_unchecke
#[derive(Debug, Clone)]
pub struct Options {
pub aliases: HashMap<String, Id>,
pub aliases: HashMap<String, RepoId>,
pub listen: SocketAddr,
pub cache: Option<NonZeroUsize>,
}
+2 -2
View File
@@ -1,7 +1,7 @@
use std::num::NonZeroUsize;
use std::{collections::HashMap, process};
use radicle::prelude::Id;
use radicle::prelude::RepoId;
use radicle_httpd as httpd;
#[tokio::main]
@@ -39,7 +39,7 @@ fn parse_options() -> Result<httpd::Options, lexopt::Error> {
}
Long("alias") | Short('a') => {
let alias: String = parser.value()?.parse()?;
let id: Id = parser.value()?.parse()?;
let id: RepoId = parser.value()?.parse()?;
aliases.insert(alias, id);
}
+3 -3
View File
@@ -9,7 +9,7 @@ use axum::Router;
use hyper::HeaderMap;
use tower_http::cors;
use radicle::prelude::Id;
use radicle::prelude::RepoId;
use radicle::profile::Profile;
use radicle::storage::{ReadRepository, ReadStorage};
use radicle_surf::{Oid, Repository};
@@ -107,7 +107,7 @@ pub fn router(profile: Arc<Profile>) -> Router {
}
async fn file_by_path_handler(
Path((project, sha, path)): Path<(Id, Oid, String)>,
Path((project, sha, path)): Path<(RepoId, Oid, String)>,
State(profile): State<Arc<Profile>>,
) -> impl IntoResponse {
let storage = &profile.storage;
@@ -134,7 +134,7 @@ async fn file_by_path_handler(
}
async fn file_by_oid_handler(
Path((project, oid)): Path<(Id, Oid)>,
Path((project, oid)): Path<(RepoId, Oid)>,
State(profile): State<Arc<Profile>>,
Query(qs): Query<RawQuery>,
) -> impl IntoResponse {