Update `radicle-git` to `79a94721366490053e2d8ac1c1afa14fb0c25f09`

Signed-off-by: xphoniex <dj.2dixx@gmail.com>
This commit is contained in:
xphoniex 2022-12-21 15:24:22 +00:00 committed by Alexis Sellier
parent 9017c59110
commit 1f55d7a327
No known key found for this signature in database
5 changed files with 96 additions and 179 deletions

150
Cargo.lock generated
View File

@ -84,12 +84,6 @@ version = "1.0.66"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6"
[[package]]
name = "arrayvec"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "23b62fc65de8e4e7f52534fb52b0f3ed04746ae267519eef2a83941e8085068b"
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
version = "0.7.2" version = "0.7.2"
@ -252,28 +246,16 @@ version = "1.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
[[package]]
name = "bitvec"
version = "0.19.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "55f93d0ef3363c364d5976646a38f04cf67cfe1d4c8d160cdea02cab2c116b33"
dependencies = [
"funty 1.1.0",
"radium 0.5.3",
"tap",
"wyz 0.2.0",
]
[[package]] [[package]]
name = "bitvec" name = "bitvec"
version = "1.0.1" version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c" checksum = "1bc2832c24239b0141d5674bb9174f9d68a8b5b3f2753311927c172ca46f7e9c"
dependencies = [ dependencies = [
"funty 2.0.0", "funty",
"radium 0.7.0", "radium",
"tap", "tap",
"wyz 0.5.1", "wyz",
] ]
[[package]] [[package]]
@ -761,12 +743,6 @@ dependencies = [
"zeroize", "zeroize",
] ]
[[package]]
name = "either"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797"
[[package]] [[package]]
name = "elliptic-curve" name = "elliptic-curve"
version = "0.12.3" version = "0.12.3"
@ -867,7 +843,7 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ade3e9c97727343984e1ceada4fdab11142d2ee3472d2c67027d56b1251d4f15" checksum = "ade3e9c97727343984e1ceada4fdab11142d2ee3472d2c67027d56b1251d4f15"
dependencies = [ dependencies = [
"arrayvec 0.7.2", "arrayvec",
"bytes", "bytes",
"chrono", "chrono",
"elliptic-curve", "elliptic-curve",
@ -961,12 +937,6 @@ dependencies = [
"percent-encoding", "percent-encoding",
] ]
[[package]]
name = "funty"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7"
[[package]] [[package]]
name = "funty" name = "funty"
version = "2.0.0" version = "2.0.0"
@ -1058,34 +1028,16 @@ dependencies = [
[[package]] [[package]]
name = "git-ref-format" name = "git-ref-format"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/radicle-dev/radicle-git?rev=39ce2f934915a563f9420ac9c85480df8a591481#39ce2f934915a563f9420ac9c85480df8a591481" source = "git+https://github.com/radicle-dev/radicle-git?rev=79a94721366490053e2d8ac1c1afa14fb0c25f09#79a94721366490053e2d8ac1c1afa14fb0c25f09"
dependencies = [ dependencies = [
"git-ref-format-core 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=39ce2f934915a563f9420ac9c85480df8a591481)", "git-ref-format-core",
"git-ref-format-macro 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=39ce2f934915a563f9420ac9c85480df8a591481)", "git-ref-format-macro",
]
[[package]]
name = "git-ref-format"
version = "0.1.0"
source = "git+https://github.com/radicle-dev/radicle-git?rev=d3115a22158c8395705babefdc89049f7510d32d#d3115a22158c8395705babefdc89049f7510d32d"
dependencies = [
"git-ref-format-core 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=d3115a22158c8395705babefdc89049f7510d32d)",
"git-ref-format-macro 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=d3115a22158c8395705babefdc89049f7510d32d)",
] ]
[[package]] [[package]]
name = "git-ref-format-core" name = "git-ref-format-core"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/radicle-dev/radicle-git?rev=39ce2f934915a563f9420ac9c85480df8a591481#39ce2f934915a563f9420ac9c85480df8a591481" source = "git+https://github.com/radicle-dev/radicle-git?rev=79a94721366490053e2d8ac1c1afa14fb0c25f09#79a94721366490053e2d8ac1c1afa14fb0c25f09"
dependencies = [
"serde",
"thiserror",
]
[[package]]
name = "git-ref-format-core"
version = "0.1.0"
source = "git+https://github.com/radicle-dev/radicle-git?rev=d3115a22158c8395705babefdc89049f7510d32d#d3115a22158c8395705babefdc89049f7510d32d"
dependencies = [ dependencies = [
"serde", "serde",
"thiserror", "thiserror",
@ -1094,20 +1046,9 @@ dependencies = [
[[package]] [[package]]
name = "git-ref-format-macro" name = "git-ref-format-macro"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/radicle-dev/radicle-git?rev=39ce2f934915a563f9420ac9c85480df8a591481#39ce2f934915a563f9420ac9c85480df8a591481" source = "git+https://github.com/radicle-dev/radicle-git?rev=79a94721366490053e2d8ac1c1afa14fb0c25f09#79a94721366490053e2d8ac1c1afa14fb0c25f09"
dependencies = [ dependencies = [
"git-ref-format-core 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=39ce2f934915a563f9420ac9c85480df8a591481)", "git-ref-format-core",
"proc-macro-error",
"quote",
"syn",
]
[[package]]
name = "git-ref-format-macro"
version = "0.1.0"
source = "git+https://github.com/radicle-dev/radicle-git?rev=d3115a22158c8395705babefdc89049f7510d32d#d3115a22158c8395705babefdc89049f7510d32d"
dependencies = [
"git-ref-format-core 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=d3115a22158c8395705babefdc89049f7510d32d)",
"proc-macro-error", "proc-macro-error",
"quote", "quote",
"syn", "syn",
@ -1119,7 +1060,7 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e0934f57135449b88bea0e28efd80aab0c1b53692f8207c7e232086db824c7a8" checksum = "e0934f57135449b88bea0e28efd80aab0c1b53692f8207c7e232086db824c7a8"
dependencies = [ dependencies = [
"nom 7.1.1", "nom",
"thiserror", "thiserror",
] ]
@ -1520,19 +1461,6 @@ dependencies = [
"spin", "spin",
] ]
[[package]]
name = "lexical-core"
version = "0.7.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6607c62aa161d23d17a9072cc5da0be67cdfc89d3afb1e8d9c842bebc2525ffe"
dependencies = [
"arrayvec 0.5.2",
"bitflags",
"cfg-if",
"ryu",
"static_assertions",
]
[[package]] [[package]]
name = "lexopt" name = "lexopt"
version = "0.2.1" version = "0.2.1"
@ -1693,19 +1621,6 @@ dependencies = [
"socket2", "socket2",
] ]
[[package]]
name = "nom"
version = "6.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7413f999671bd4745a7b624bd370a569fb6bc574b23c83a3c5ed2e453f3d5e2"
dependencies = [
"bitvec 0.19.6",
"funty 1.1.0",
"lexical-core",
"memchr",
"version_check",
]
[[package]] [[package]]
name = "nom" name = "nom"
version = "7.1.1" version = "7.1.1"
@ -1840,7 +1755,7 @@ version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "786393f80485445794f6043fd3138854dd109cc6c4bd1a6383db304c9ce9b9ce" checksum = "786393f80485445794f6043fd3138854dd109cc6c4bd1a6383db304c9ce9b9ce"
dependencies = [ dependencies = [
"arrayvec 0.7.2", "arrayvec",
"auto_impl", "auto_impl",
"bytes", "bytes",
"ethereum-types", "ethereum-types",
@ -1902,8 +1817,8 @@ version = "3.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "366e44391a8af4cfd6002ef6ba072bae071a96aafca98d7d448a34c5dca38b6a" checksum = "366e44391a8af4cfd6002ef6ba072bae071a96aafca98d7d448a34c5dca38b6a"
dependencies = [ dependencies = [
"arrayvec 0.7.2", "arrayvec",
"bitvec 1.0.1", "bitvec",
"byte-slice-cast", "byte-slice-cast",
"impl-trait-for-tuples", "impl-trait-for-tuples",
"parity-scale-codec-derive", "parity-scale-codec-derive",
@ -2151,7 +2066,7 @@ dependencies = [
"cyphernet", "cyphernet",
"ed25519-compact", "ed25519-compact",
"fastrand", "fastrand",
"git-ref-format 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=39ce2f934915a563f9420ac9c85480df8a591481)", "git-ref-format",
"git2", "git2",
"log", "log",
"multibase", "multibase",
@ -2210,7 +2125,7 @@ dependencies = [
"ed25519-compact", "ed25519-compact",
"fastrand", "fastrand",
"git-commit", "git-commit",
"git-ref-format 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=39ce2f934915a563f9420ac9c85480df8a591481)", "git-ref-format",
"git-trailers", "git-trailers",
"git2", "git2",
"log", "log",
@ -2248,7 +2163,7 @@ dependencies = [
"cyphernet", "cyphernet",
"ed25519-compact", "ed25519-compact",
"fastrand", "fastrand",
"git-ref-format 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=39ce2f934915a563f9420ac9c85480df8a591481)", "git-ref-format",
"multibase", "multibase",
"qcheck", "qcheck",
"qcheck-macros", "qcheck-macros",
@ -2265,9 +2180,9 @@ dependencies = [
[[package]] [[package]]
name = "radicle-git-ext" name = "radicle-git-ext"
version = "0.2.0" version = "0.2.0"
source = "git+https://github.com/radicle-dev/radicle-git?rev=d3115a22158c8395705babefdc89049f7510d32d#d3115a22158c8395705babefdc89049f7510d32d" source = "git+https://github.com/radicle-dev/radicle-git?rev=79a94721366490053e2d8ac1c1afa14fb0c25f09#79a94721366490053e2d8ac1c1afa14fb0c25f09"
dependencies = [ dependencies = [
"git-ref-format 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=d3115a22158c8395705babefdc89049f7510d32d)", "git-ref-format",
"git2", "git2",
"percent-encoding", "percent-encoding",
"radicle-std-ext", "radicle-std-ext",
@ -2315,7 +2230,7 @@ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"cyphernet", "cyphernet",
"fastrand", "fastrand",
"git-ref-format 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=39ce2f934915a563f9420ac9c85480df8a591481)", "git-ref-format",
"lexopt", "lexopt",
"log", "log",
"nakamoto-net", "nakamoto-net",
@ -2357,23 +2272,22 @@ dependencies = [
[[package]] [[package]]
name = "radicle-std-ext" name = "radicle-std-ext"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/radicle-dev/radicle-git?rev=d3115a22158c8395705babefdc89049f7510d32d#d3115a22158c8395705babefdc89049f7510d32d" source = "git+https://github.com/radicle-dev/radicle-git?rev=79a94721366490053e2d8ac1c1afa14fb0c25f09#79a94721366490053e2d8ac1c1afa14fb0c25f09"
[[package]] [[package]]
name = "radicle-surf" name = "radicle-surf"
version = "0.8.0" version = "0.8.0"
source = "git+https://github.com/radicle-dev/radicle-git?rev=d3115a22158c8395705babefdc89049f7510d32d#d3115a22158c8395705babefdc89049f7510d32d" source = "git+https://github.com/radicle-dev/radicle-git?rev=79a94721366490053e2d8ac1c1afa14fb0c25f09#79a94721366490053e2d8ac1c1afa14fb0c25f09"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64", "base64",
"either",
"flate2", "flate2",
"git-ref-format 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=d3115a22158c8395705babefdc89049f7510d32d)", "git-ref-format",
"git2", "git2",
"nom 6.1.2", "log",
"nonempty 0.5.0", "nonempty 0.5.0",
"radicle-git-ext", "radicle-git-ext",
"regex", "radicle-std-ext",
"serde", "serde",
"tar", "tar",
"thiserror", "thiserror",
@ -2384,16 +2298,10 @@ name = "radicle-tools"
version = "0.2.0" version = "0.2.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"git-ref-format 0.1.0 (git+https://github.com/radicle-dev/radicle-git?rev=39ce2f934915a563f9420ac9c85480df8a591481)", "git-ref-format",
"radicle", "radicle",
] ]
[[package]]
name = "radium"
version = "0.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "941ba9d78d8e2f7ce474c015eea4d9c6d25b6a3327f9832ee29a4de27f91bbb8"
[[package]] [[package]]
name = "radium" name = "radium"
version = "0.7.0" version = "0.7.0"
@ -3640,12 +3548,6 @@ version = "0.42.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5" checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
[[package]]
name = "wyz"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214"
[[package]] [[package]]
name = "wyz" name = "wyz"
version = "0.5.1" version = "0.5.1"

View File

@ -46,8 +46,8 @@ version = "0.1.0"
[patch.crates-io.radicle-git-ext] [patch.crates-io.radicle-git-ext]
git = "https://github.com/radicle-dev/radicle-git" git = "https://github.com/radicle-dev/radicle-git"
rev = "d3115a22158c8395705babefdc89049f7510d32d" rev = "79a94721366490053e2d8ac1c1afa14fb0c25f09"
[patch.crates-io.git-ref-format] [patch.crates-io.git-ref-format]
git = "https://github.com/radicle-dev/radicle-git" git = "https://github.com/radicle-dev/radicle-git"
rev = "39ce2f934915a563f9420ac9c85480df8a591481" rev = "79a94721366490053e2d8ac1c1afa14fb0c25f09"

View File

@ -41,5 +41,5 @@ version = "0.2.0"
[dependencies.radicle-surf] [dependencies.radicle-surf]
git = "https://github.com/radicle-dev/radicle-git" git = "https://github.com/radicle-dev/radicle-git"
features = ["serialize"] features = ["serde"]
rev = "d3115a22158c8395705babefdc89049f7510d32d" rev = "79a94721366490053e2d8ac1c1afa14fb0c25f09"

View File

@ -18,22 +18,6 @@ pub enum Error {
#[error(transparent)] #[error(transparent)]
Env(#[from] std::env::VarError), Env(#[from] std::env::VarError),
/// I/O error.
#[error("i/o error: {0}")]
Io(#[from] std::io::Error),
/// Invalid identifier.
#[error("invalid radicle identifier: {0}")]
Id(#[from] radicle::identity::IdError),
/// HeaderName error.
#[error(transparent)]
InvalidHeaderName(#[from] axum::http::header::InvalidHeaderName),
/// HeaderValue error.
#[error(transparent)]
InvalidHeaderValue(#[from] axum::http::header::InvalidHeaderValue),
/// An error occurred while verifying the siwe message. /// An error occurred while verifying the siwe message.
#[error(transparent)] #[error(transparent)]
SiweVerification(#[from] siwe::VerificationError), SiweVerification(#[from] siwe::VerificationError),
@ -56,11 +40,11 @@ pub enum Error {
/// Surf commit error. /// Surf commit error.
#[error(transparent)] #[error(transparent)]
SurfCommit(#[from] radicle_surf::commit::Error), SurfCommit(#[from] radicle_surf::source::commit::Error),
/// Surf object error. /// Surf object error.
#[error(transparent)] #[error(transparent)]
SurfObject(#[from] radicle_surf::object::Error), SurfObject(#[from] radicle_surf::source::object::Error),
/// Surf git error. /// Surf git error.
#[error(transparent)] #[error(transparent)]

View File

@ -1,4 +1,4 @@
use std::collections::HashSet; use std::collections::{BTreeMap, HashSet};
use axum::handler::Handler; use axum::handler::Handler;
use axum::http::{header, HeaderValue}; use axum::http::{header, HeaderValue};
@ -13,12 +13,15 @@ use tower_http::set_header::SetResponseHeaderLayer;
use radicle::cob::issue::Issues; use radicle::cob::issue::Issues;
use radicle::cob::thread::{self, CommentId}; use radicle::cob::thread::{self, CommentId};
use radicle::cob::Timestamp; use radicle::cob::Timestamp;
use radicle::git::raw::BranchType; use radicle::git::Oid;
use radicle::identity::{Id, PublicKey}; use radicle::identity::{Id, PublicKey};
use radicle::node::NodeId; use radicle::node::NodeId;
use radicle::storage::{Oid, ReadRepository, WriteRepository, WriteStorage}; use radicle::storage::git::paths;
use radicle_surf::git::History; use radicle::storage::{ReadRepository, WriteStorage};
use radicle_surf::Revision::Sha; use radicle_surf::git::{Glob, History, Repository};
use radicle_surf::source;
use radicle_surf::source::object::blob::Blob;
use radicle_surf::source::object::tree::Tree;
use crate::api::axum_extra::{Path, Query}; use crate::api::axum_extra::{Path, Query};
use crate::api::error::Error; use crate::api::error::Error;
@ -133,7 +136,7 @@ async fn history_handler(
}; };
let storage = &ctx.profile.storage; let storage = &ctx.profile.storage;
let repo = storage.repository(project)?; let repo = Repository::open(paths::repository(storage, &project))?;
// If a pagination is defined, we do not want to paginate the commits, and we return all of them on the first page. // If a pagination is defined, we do not want to paginate the commits, and we return all of them on the first page.
let page = page.unwrap_or(0); let page = page.unwrap_or(0);
@ -143,7 +146,8 @@ async fn history_handler(
per_page.unwrap_or(30) per_page.unwrap_or(30)
}; };
let headers = History::new(repo.raw().into(), sha.as_str())? let headers = repo
.history(sha)?
.filter(|q| { .filter(|q| {
if let Ok(q) = q { if let Ok(q) = q {
if let (Some(since), Some(until)) = (since, until) { if let (Some(since), Some(until)) = (since, until) {
@ -164,7 +168,7 @@ async fn history_handler(
.take(per_page) .take(per_page)
.filter_map(|commit| { .filter_map(|commit| {
if let Ok(commit) = commit { if let Ok(commit) = commit {
radicle_surf::commit(&repo.raw().into(), commit.id).ok() source::commit(&repo, commit.id).ok()
} else { } else {
None None
} }
@ -173,7 +177,7 @@ async fn history_handler(
let response = json!({ let response = json!({
"headers": headers, "headers": headers,
"stats": stats(&repo)?, "stats": repo.stats()?,
}); });
if fallback_to_head { if fallback_to_head {
@ -190,8 +194,8 @@ async fn commit_handler(
Path((project, sha)): Path<(Id, Oid)>, Path((project, sha)): Path<(Id, Oid)>,
) -> impl IntoResponse { ) -> impl IntoResponse {
let storage = &ctx.profile.storage; let storage = &ctx.profile.storage;
let repo = storage.repository(project)?; let repo = Repository::open(paths::repository(storage, &project))?;
let commit = radicle_surf::commit(&repo.raw().into(), sha)?; let commit = source::commit(&repo, sha)?;
Ok::<_, Error>(Json(commit)) Ok::<_, Error>(Json(commit))
} }
@ -205,9 +209,10 @@ async fn activity_handler(
let current_date = chrono::Utc::now().timestamp(); let current_date = chrono::Utc::now().timestamp();
let one_year_ago = chrono::Duration::weeks(52); let one_year_ago = chrono::Duration::weeks(52);
let storage = &ctx.profile.storage; let storage = &ctx.profile.storage;
let repo = storage.repository(project)?; let repo = Repository::open(paths::repository(storage, &project))?;
let (_, head) = repo.head()?; let head = repo.head()?;
let timestamps = History::new(repo.raw().into(), head)? let timestamps = repo
.history(head)?
.filter_map(|a| { .filter_map(|a| {
if let Ok(a) = a { if let Ok(a) = a {
let seconds = a.committer.time.seconds(); let seconds = a.committer.time.seconds();
@ -230,14 +235,11 @@ async fn tree_handler(
) -> impl IntoResponse { ) -> impl IntoResponse {
let path = path.strip_prefix('/').ok_or(Error::NotFound)?.to_string(); let path = path.strip_prefix('/').ok_or(Error::NotFound)?.to_string();
let storage = &ctx.profile.storage; let storage = &ctx.profile.storage;
let repo = storage.repository(project)?; let repo = Repository::open(paths::repository(storage, &project))?;
let tree = radicle_surf::object::tree(&repo.raw().into(), Some(Sha { sha }), Some(path))?; let path = if path.is_empty() { None } else { Some(&path) };
let response = json!({ let tree = Tree::new(&repo, &sha, path)?;
"path": &tree.path, let mut response = json!(tree);
"entries": &tree.entries, response["stats"] = json!(stats(&repo, sha)?);
"info": &tree.info,
"stats": stats(&repo)?,
});
Ok::<_, Error>(Json(response)) Ok::<_, Error>(Json(response))
} }
@ -253,6 +255,23 @@ async fn remotes_handler(
let remotes = repo let remotes = repo
.remotes()? .remotes()?
.filter_map(|r| r.map(|r| r.1).ok()) .filter_map(|r| r.map(|r| r.1).ok())
.map(|remote| {
let refs = remote
.refs
.iter()
.filter_map(|(r, oid)| {
r.as_str()
.strip_prefix("refs/heads/")
.map(|head| (head.to_string(), oid))
})
.collect::<BTreeMap<String, &Oid>>();
json!({
"id": remote.id,
"heads": refs,
"delegate": remote.delegate,
})
})
.collect::<Vec<_>>(); .collect::<Vec<_>>();
Ok::<_, Error>(Json(remotes)) Ok::<_, Error>(Json(remotes))
@ -267,6 +286,20 @@ async fn remote_handler(
let storage = &ctx.profile.storage; let storage = &ctx.profile.storage;
let repo = storage.repository(project)?; let repo = storage.repository(project)?;
let remote = repo.remote(&node_id)?; let remote = repo.remote(&node_id)?;
let refs = remote
.refs
.iter()
.filter_map(|(r, oid)| {
r.as_str()
.strip_prefix("refs/heads/")
.map(|head| (head.to_string(), oid))
})
.collect::<BTreeMap<String, &Oid>>();
let remote = json!({
"id": remote.id,
"heads": refs,
"delegate": remote.delegate,
});
Ok::<_, Error>(Json(remote)) Ok::<_, Error>(Json(remote))
} }
@ -279,8 +312,8 @@ async fn blob_handler(
) -> impl IntoResponse { ) -> impl IntoResponse {
let path = path.strip_prefix('/').ok_or(Error::NotFound)?; let path = path.strip_prefix('/').ok_or(Error::NotFound)?;
let storage = &ctx.profile.storage; let storage = &ctx.profile.storage;
let repo = storage.repository(project)?; let repo = Repository::open(paths::repository(storage, &project))?;
let blob = radicle_surf::blob::blob(&repo.raw().into(), Some(Sha { sha }), path)?; let blob = Blob::new(&repo, &sha, &path)?;
Ok::<_, Error>(Json(blob)) Ok::<_, Error>(Json(blob))
} }
@ -292,7 +325,7 @@ async fn readme_handler(
Path((project, sha)): Path<(Id, Oid)>, Path((project, sha)): Path<(Id, Oid)>,
) -> impl IntoResponse { ) -> impl IntoResponse {
let storage = &ctx.profile.storage; let storage = &ctx.profile.storage;
let repo = storage.repository(project)?; let repo = Repository::open(paths::repository(storage, &project))?;
let paths = &[ let paths = &[
"README", "README",
"README.md", "README.md",
@ -303,14 +336,12 @@ async fn readme_handler(
]; ];
for path in paths { for path in paths {
if let Ok(blob) = radicle_surf::blob::blob(&repo.raw().into(), Some(Sha { sha }), path) { if let Ok(blob) = Blob::new(&repo, &sha, &path) {
return Ok::<_, Error>(Json(blob)); return Ok::<_, Error>(Json(blob));
} }
} }
Err(radicle_surf::object::Error::PathNotFound( Err(Error::NotFound)
radicle_surf::file_system::Path::try_from("README").unwrap(),
))?
} }
/// Get project issues list. /// Get project issues list.
@ -413,11 +444,11 @@ struct Stats {
contributors: usize, contributors: usize,
} }
fn stats<R: WriteRepository>(repo: &R) -> Result<Stats, Error> { fn stats(repo: &Repository, head: Oid) -> Result<Stats, Error> {
let branches = repo.raw().branches(Some(BranchType::Local))?.count(); let branches = repo.branches(Glob::all_heads())?.count();
let (_, head) = repo.head()?;
let mut commits = 0; let mut commits = 0;
let contributors = History::new(repo.raw().into(), head)? let contributors = History::new(repo, head)?
.filter_map(|commit| { .filter_map(|commit| {
commits += 1; commits += 1;
if let Ok(commit) = commit { if let Ok(commit) = commit {