Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
cli: add caching commands for patch and issue
Browse files Browse the repository at this point in the history
In order to bootstrap the COB cache, and also in case of issues,
supply a command for caching a set of patches/issues, or a single
patch/issue.

This is necessary since reads are not read-thru, it may appear that
COBs are missing when in fact they haven't been cached when first
moving over to the cache.

Signed-off-by: Fintan Halpenny <[email protected]>
X-Clacks-Overhead: GNU Terry Pratchett
  • Loading branch information
FintanH authored and cloudhead committed Feb 23, 2024
1 parent 985b0af commit 9e745b6
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 1 deletion.
14 changes: 14 additions & 0 deletions radicle-cli/src/commands/issue.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#[path = "issue/cache.rs"]
mod cache;

use std::collections::BTreeSet;
use std::ffi::OsString;
use std::str::FromStr;
Expand Down Expand Up @@ -44,6 +47,7 @@ Usage
rad issue comment <issue-id> [--message <message>] [--reply-to <comment-id>] [<option>...]
rad issue show <issue-id> [<option>...]
rad issue state <issue-id> [--closed | --open | --solved] [<option>...]
rad issue cache [<issue-id>] [<option>...]
Assign options
Expand Down Expand Up @@ -85,6 +89,7 @@ pub enum OperationName {
React,
Show,
State,
Cache,
}

/// Command line Peer argument.
Expand Down Expand Up @@ -142,6 +147,9 @@ pub enum Operation {
assigned: Option<Assigned>,
state: Option<State>,
},
Cache {
id: Option<Rev>,
},
}

#[derive(Debug, Default, PartialEq, Eq)]
Expand Down Expand Up @@ -341,6 +349,7 @@ impl Args for Options {
"s" | "state" => op = Some(OperationName::State),
"assign" => op = Some(OperationName::Assign),
"label" => op = Some(OperationName::Label),
"cache" => op = Some(OperationName::Cache),

unknown => anyhow::bail!("unknown operation '{}'", unknown),
},
Expand Down Expand Up @@ -397,6 +406,7 @@ impl Args for Options {
opts: label_opts,
},
OperationName::List => Operation::List { assigned, state },
OperationName::Cache => Operation::Cache { id },
};

Ok((
Expand Down Expand Up @@ -553,6 +563,10 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {
let id = id.resolve(&repo.backend)?;
issues.remove(&id, &signer)?;
}
Operation::Cache { id } => {
let id = id.map(|id| id.resolve(&repo.backend)).transpose()?;
cache::run(id, &repo, &profile)?;
}
}

if announce {
Expand Down
28 changes: 28 additions & 0 deletions radicle-cli/src/commands/issue/cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::ops::ControlFlow;

use radicle::issue::IssueId;
use radicle::storage::git::Repository;
use radicle::Profile;

use crate::terminal as term;

pub fn run(id: Option<IssueId>, repository: &Repository, profile: &Profile) -> anyhow::Result<()> {
let mut issues = profile.issues_mut(repository)?;

match id {
Some(id) => {
issues.write(&id)?;
term::success!("Successfully cached issue `{id}`");
}
None => issues.write_all(|result, progress| {
match result {
Ok((id, _)) => term::success!("Successfully cached issue `{id}`"),
Err(e) => term::warning(format!("Failed to retrieve issue: {e}")),
};
term::info!("Cached {} of {}", progress.seen(), progress.total());
ControlFlow::Continue(())
})?,
}

Ok(())
}
19 changes: 18 additions & 1 deletion radicle-cli/src/commands/patch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
mod archive;
#[path = "patch/assign.rs"]
mod assign;
#[path = "patch/cache.rs"]
mod cache;
#[path = "patch/checkout.rs"]
mod checkout;
#[path = "patch/comment.rs"]
Expand Down Expand Up @@ -67,6 +69,7 @@ Usage
rad patch edit <patch-id> [<option>...]
rad patch set <patch-id> [<option>...]
rad patch comment <patch-id | revision-id> [<option>...]
rad patch cache [<patch-id>] [<option>...]
Show options
Expand Down Expand Up @@ -166,6 +169,7 @@ pub enum OperationName {
Edit,
Redact,
Set,
Cache,
}

#[derive(Debug, Default, PartialEq, Eq)]
Expand Down Expand Up @@ -243,6 +247,9 @@ pub enum Operation {
Set {
patch_id: Rev,
},
Cache {
patch_id: Option<Rev>,
},
}

impl Operation {
Expand All @@ -262,7 +269,8 @@ impl Operation {
Operation::Show { .. }
| Operation::Diff { .. }
| Operation::Checkout { .. }
| Operation::List { .. } => false,
| Operation::List { .. }
| Operation::Cache { .. } => false,
}
}
}
Expand Down Expand Up @@ -518,6 +526,7 @@ impl Args for Options {
"comment" => op = Some(OperationName::Comment),
"review" => op = Some(OperationName::Review),
"set" => op = Some(OperationName::Set),
"cache" => op = Some(OperationName::Cache),
unknown => anyhow::bail!("unknown operation '{}'", unknown),
},
Value(val) if op == Some(OperationName::Redact) => {
Expand All @@ -540,6 +549,7 @@ impl Args for Options {
Some(OperationName::Set),
Some(OperationName::Assign),
Some(OperationName::Label),
Some(OperationName::Cache),
]
.contains(&op) =>
{
Expand Down Expand Up @@ -615,6 +625,7 @@ impl Args for Options {
OperationName::Set => Operation::Set {
patch_id: patch_id.ok_or_else(|| anyhow!("a patch must be provided"))?,
},
OperationName::Cache => Operation::Cache { patch_id },
};

Ok((
Expand Down Expand Up @@ -790,6 +801,12 @@ pub fn run(options: Options, ctx: impl term::Context) -> anyhow::Result<()> {

radicle::rad::setup_patch_upstream(&patch_id, *patch.head(), &workdir, true)?;
}
Operation::Cache { patch_id } => {
let patch_id = patch_id
.map(|id| id.resolve(&repository.backend))
.transpose()?;
cache::run(patch_id, &repository, &profile)?;
}
}

if announce {
Expand Down
28 changes: 28 additions & 0 deletions radicle-cli/src/commands/patch/cache.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
use std::ops::ControlFlow;

use radicle::patch::PatchId;
use radicle::storage::git::Repository;
use radicle::Profile;

use crate::terminal as term;

pub fn run(id: Option<PatchId>, repository: &Repository, profile: &Profile) -> anyhow::Result<()> {
let mut patches = profile.patches_mut(repository)?;

match id {
Some(id) => {
patches.write(&id)?;
term::success!("Successfully cached patch `{id}`");
}
None => patches.write_all(|result, progress| {
match result {
Ok((id, _)) => term::success!("Successfully cached patch `{id}`"),
Err(e) => term::warning(format!("Failed to retrieve patch: {e}")),
};
term::info!("Cached {} of {}", progress.seen(), progress.total());
ControlFlow::Continue(())
})?,
}

Ok(())
}

0 comments on commit 9e745b6

Please sign in to comment.