From 6cbca9401f693018f88e8202c48bd304cf0d4dc9 Mon Sep 17 00:00:00 2001 From: Erik Kundt Date: Mon, 26 Feb 2024 15:00:09 +0100 Subject: [PATCH] lib: Move to cob cache --- Cargo.lock | 12 ++++++------ Cargo.toml | 4 ++-- bin/commands/issue/flux/select.rs | 2 +- bin/commands/patch/flux/select.rs | 2 +- src/common/cob/issue.rs | 31 ++++++++++++++++++------------- src/common/cob/patch.rs | 28 ++++++++++++++++------------ src/common/context.rs | 8 ++++---- 7 files changed, 48 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 935e891b..aa946731 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1473,7 +1473,7 @@ dependencies = [ [[package]] name = "radicle" version = "0.2.0" -source = "git+https://github.com/radicle-dev/heartwood?rev=eff4016#eff40166c9ac8ad9776ecb6160d245220bfb1f87" +source = "git+https://github.com/radicle-dev/heartwood#09f2befa58dc6057e052904b6947bdd17d3b0553" dependencies = [ "amplify", "base64 0.21.7", @@ -1503,7 +1503,7 @@ dependencies = [ [[package]] name = "radicle-cob" version = "0.2.0" -source = "git+https://github.com/radicle-dev/heartwood?rev=eff4016#eff40166c9ac8ad9776ecb6160d245220bfb1f87" +source = "git+https://github.com/radicle-dev/heartwood#09f2befa58dc6057e052904b6947bdd17d3b0553" dependencies = [ "fastrand", "git2", @@ -1521,7 +1521,7 @@ dependencies = [ [[package]] name = "radicle-crypto" version = "0.2.0" -source = "git+https://github.com/radicle-dev/heartwood?rev=eff4016#eff40166c9ac8ad9776ecb6160d245220bfb1f87" +source = "git+https://github.com/radicle-dev/heartwood#09f2befa58dc6057e052904b6947bdd17d3b0553" dependencies = [ "amplify", "cyphernet", @@ -1539,7 +1539,7 @@ dependencies = [ [[package]] name = "radicle-dag" version = "0.2.0" -source = "git+https://github.com/radicle-dev/heartwood?rev=eff4016#eff40166c9ac8ad9776ecb6160d245220bfb1f87" +source = "git+https://github.com/radicle-dev/heartwood#09f2befa58dc6057e052904b6947bdd17d3b0553" dependencies = [ "fastrand", ] @@ -1561,7 +1561,7 @@ dependencies = [ [[package]] name = "radicle-ssh" version = "0.2.0" -source = "git+https://github.com/radicle-dev/heartwood?rev=eff4016#eff40166c9ac8ad9776ecb6160d245220bfb1f87" +source = "git+https://github.com/radicle-dev/heartwood#09f2befa58dc6057e052904b6947bdd17d3b0553" dependencies = [ "byteorder", "log", @@ -1596,7 +1596,7 @@ dependencies = [ [[package]] name = "radicle-term" version = "0.1.0" -source = "git+https://github.com/radicle-dev/heartwood?rev=eff4016#eff40166c9ac8ad9776ecb6160d245220bfb1f87" +source = "git+https://github.com/radicle-dev/heartwood#09f2befa58dc6057e052904b6947bdd17d3b0553" dependencies = [ "anstyle-query", "anyhow", diff --git a/Cargo.toml b/Cargo.toml index ac137325..071372c7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,8 +21,8 @@ inquire = { version = "0.6.2", default-features = false, features = ["termion", lexopt = { version = "0.3.0" } libc = { version = "^0.2" } log = { version = "0.4.19" } -radicle = { git = "https://github.com/radicle-dev/heartwood", rev = "eff4016" } -radicle-term = { git = "https://github.com/radicle-dev/heartwood", package = "radicle-term", rev = "eff4016" } +radicle = { git = "https://github.com/radicle-dev/heartwood" } +radicle-term = { git = "https://github.com/radicle-dev/heartwood", package = "radicle-term" } radicle-surf = { version = "0.18.0" } ratatui = { git = "https://github.com/erak/ratatui", branch = "termion-cursor", default-features = false, features = ["all-widgets", "termion"] } simple-logging = { version = "2.0.2" } diff --git a/bin/commands/issue/flux/select.rs b/bin/commands/issue/flux/select.rs index bec74ff8..903495ab 100644 --- a/bin/commands/issue/flux/select.rs +++ b/bin/commands/issue/flux/select.rs @@ -45,7 +45,7 @@ impl TryFrom<&Context> for IssuesState { type Error = anyhow::Error; fn try_from(context: &Context) -> Result { - let issues = issue::all(&context.repository)?; + let issues = issue::all(&context.profile, &context.repository)?; let issues = issues .iter() .filter(|(_, issue)| context.filter.matches(&context.profile, issue)); diff --git a/bin/commands/patch/flux/select.rs b/bin/commands/patch/flux/select.rs index 612e39ee..4981b352 100644 --- a/bin/commands/patch/flux/select.rs +++ b/bin/commands/patch/flux/select.rs @@ -45,7 +45,7 @@ impl TryFrom<&Context> for PatchesState { type Error = anyhow::Error; fn try_from(context: &Context) -> Result { - let patches = patch::all(&context.repository)?; + let patches = patch::all(&context.profile, &context.repository)?; let patches = patches .iter() .filter(|(_, patch)| context.filter.matches(&context.profile, patch)); diff --git a/src/common/cob/issue.rs b/src/common/cob/issue.rs index a64ae0f2..659addae 100644 --- a/src/common/cob/issue.rs +++ b/src/common/cob/issue.rs @@ -1,8 +1,9 @@ use std::fmt::Display; use anyhow::Result; -use radicle::cob::issue::{Issue, IssueId, Issues}; +use radicle::cob::issue::{Issue, IssueId}; use radicle::cob::Label; +use radicle::issue::cache::Issues; use radicle::issue::CloseReason; use radicle::prelude::{Did, Signer}; use radicle::storage::git::Repository; @@ -118,23 +119,27 @@ impl ToString for Filter { } } -pub fn all(repository: &Repository) -> Result> { - let patches = Issues::open(repository)? - .all() - .map(|iter| iter.flatten().collect::>())?; +pub fn all(profile: &Profile, repository: &Repository) -> Result> { + let cache = profile.issues(repository)?; + let issues = cache.list()?; + + let mut all = vec![]; + for issue in issues { + if let Ok((id, issue)) = issue { + all.push((id, issue)) + } + } - Ok(patches - .into_iter() - .map(|(id, issue)| (id, issue)) - .collect::>()) + Ok(all) } -pub fn find(repository: &Repository, id: &IssueId) -> Result> { - let issues = Issues::open(repository)?; - Ok(issues.get(id)?) +pub fn find(profile: &Profile, repository: &Repository, id: &IssueId) -> Result> { + let cache = profile.issues(repository)?; + Ok(cache.get(id)?) } pub fn create( + profile: &Profile, repository: &Repository, signer: &G, title: String, @@ -142,7 +147,7 @@ pub fn create( labels: &[Label], assignees: &[Did], ) -> Result { - let mut issues = Issues::open(repository)?; + let mut issues = profile.issues_mut(repository)?; let issue = issues.create(title, description.trim(), labels, assignees, [], signer)?; Ok(*issue.id()) diff --git a/src/common/cob/patch.rs b/src/common/cob/patch.rs index 11b48791..f17e8454 100644 --- a/src/common/cob/patch.rs +++ b/src/common/cob/patch.rs @@ -2,8 +2,9 @@ use std::fmt::Display; use anyhow::Result; -use radicle::cob::patch::{Patch, PatchId, Patches}; +use radicle::cob::patch::{Patch, PatchId}; use radicle::identity::Did; +use radicle::patch::cache::Patches; use radicle::storage::git::Repository; use radicle::{patch, Profile}; @@ -110,18 +111,21 @@ impl ToString for Filter { } } -pub fn all(repository: &Repository) -> Result> { - let patches = Patches::open(repository)? - .all() - .map(|iter| iter.flatten().collect::>())?; +pub fn all(profile: &Profile, repository: &Repository) -> Result> { + let cache = profile.patches(repository)?; + let patches = cache.list()?; - Ok(patches - .into_iter() - .map(|(id, patch)| (id, patch)) - .collect::>()) + let mut all = vec![]; + for patch in patches { + if let Ok((id, patch)) = patch { + all.push((id, patch)) + } + } + + Ok(all) } -pub fn find(repository: &Repository, id: &PatchId) -> Result> { - let patches = Patches::open(repository)?; - Ok(patches.get(id)?) +pub fn find(profile: &Profile, repository: &Repository, id: &PatchId) -> Result> { + let cache = profile.patches(repository)?; + Ok(cache.get(id)?) } diff --git a/src/common/context.rs b/src/common/context.rs index d3f61346..5a542b4f 100644 --- a/src/common/context.rs +++ b/src/common/context.rs @@ -71,13 +71,13 @@ impl Context { pub fn with_issues(mut self) -> Self { use super::cob::issue; - self.issues = Some(issue::all(&self.repository).unwrap_or_default()); + self.issues = Some(issue::all(&self.profile, &self.repository).unwrap_or_default()); self } pub fn with_patches(mut self) -> Self { use super::cob::patch; - self.patches = Some(patch::all(&self.repository).unwrap_or_default()); + self.patches = Some(patch::all(&self.profile, &self.repository).unwrap_or_default()); self } @@ -121,12 +121,12 @@ impl Context { pub fn reload_patches(&mut self) { use super::cob::patch; - self.patches = Some(patch::all(&self.repository).unwrap_or_default()); + self.patches = Some(patch::all(&self.profile, &self.repository).unwrap_or_default()); } pub fn reload_issues(&mut self) { use super::cob::issue; - self.issues = Some(issue::all(&self.repository).unwrap_or_default()); + self.issues = Some(issue::all(&self.profile, &self.repository).unwrap_or_default()); } }