radicle: accept Scope as track_repo argument
The method `track_repo` only accepted the RID as the argument for tracking. Instead, allow passing Scope as an argument for tracking a repository. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
546b402467
commit
3b015a9325
|
|
@ -48,9 +48,9 @@ repository that was already created:
|
|||
|
||||
```
|
||||
$ rad node tracking
|
||||
RID Scope Policy
|
||||
--- ----- ------
|
||||
rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji all track
|
||||
RID Scope Policy
|
||||
--- ----- ------
|
||||
rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji trusted track
|
||||
```
|
||||
|
||||
This is the same as using the `--repos` flag, but if we wish to see
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ use radicle::git::raw;
|
|||
use radicle::identity::doc::{DocError, Id};
|
||||
use radicle::identity::{doc, IdentityError};
|
||||
use radicle::node;
|
||||
use radicle::node::tracking::Scope;
|
||||
use radicle::node::{Handle as _, Node};
|
||||
use radicle::prelude::*;
|
||||
use radicle::rad;
|
||||
|
|
@ -169,7 +170,7 @@ pub fn clone<G: Signer>(
|
|||
let me = *signer.public_key();
|
||||
|
||||
// Track.
|
||||
if node.track_repo(id)? {
|
||||
if node.track_repo(id, Scope::default())? {
|
||||
term::success!(
|
||||
"Tracking relationship established for {}",
|
||||
term::format::tertiary(id)
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use anyhow::{anyhow, bail, Context as _};
|
|||
|
||||
use radicle::crypto::ssh;
|
||||
use radicle::git::RefString;
|
||||
use radicle::node::tracking::Scope;
|
||||
use radicle::node::{Handle, NodeId};
|
||||
|
||||
use crate::git;
|
||||
|
|
@ -220,7 +221,7 @@ pub fn init(options: Options, profile: &profile::Profile) -> anyhow::Result<()>
|
|||
if options.track && node.is_running() {
|
||||
// It's important to track our own repositories to make sure that our node signals
|
||||
// interest for them. This ensures that messages relating to them are relayed to us.
|
||||
node.track_repo(id)?;
|
||||
node.track_repo(id, Scope::default())?;
|
||||
}
|
||||
|
||||
spinner.message(format!(
|
||||
|
|
|
|||
|
|
@ -108,9 +108,9 @@ fn command<H: Handle<Error = runtime::HandleError>>(
|
|||
json::to_writer(writer, &seeds)?;
|
||||
}
|
||||
CommandName::TrackRepo => {
|
||||
let rid: Id = parse::arg(cmd)?;
|
||||
let (rid, scope) = parse::args(cmd)?;
|
||||
|
||||
match handle.track_repo(rid) {
|
||||
match handle.track_repo(rid, scope) {
|
||||
Ok(updated) => {
|
||||
CommandResult::Okay { updated }.to_writer(writer)?;
|
||||
}
|
||||
|
|
@ -294,6 +294,7 @@ mod tests {
|
|||
use crate::identity::Id;
|
||||
use crate::node::Handle;
|
||||
use crate::node::{Node, NodeId};
|
||||
use crate::service::tracking::Scope;
|
||||
use crate::test;
|
||||
|
||||
#[test]
|
||||
|
|
@ -352,8 +353,8 @@ mod tests {
|
|||
// Wait for node to be online.
|
||||
while !handle.is_running() {}
|
||||
|
||||
assert!(handle.track_repo(proj).unwrap());
|
||||
assert!(!handle.track_repo(proj).unwrap());
|
||||
assert!(handle.track_repo(proj, Scope::default()).unwrap());
|
||||
assert!(!handle.track_repo(proj, Scope::default()).unwrap());
|
||||
assert!(handle.untrack_repo(proj).unwrap());
|
||||
assert!(!handle.untrack_repo(proj).unwrap());
|
||||
|
||||
|
|
|
|||
|
|
@ -182,9 +182,9 @@ impl<G: Signer + Ecdh + 'static> radicle::node::Handle for Handle<G> {
|
|||
receiver.recv().map_err(Error::from)
|
||||
}
|
||||
|
||||
fn track_repo(&mut self, id: Id) -> Result<bool, Error> {
|
||||
fn track_repo(&mut self, id: Id, scope: tracking::Scope) -> Result<bool, Error> {
|
||||
let (sender, receiver) = chan::bounded(1);
|
||||
self.command(service::Command::TrackRepo(id, sender))?;
|
||||
self.command(service::Command::TrackRepo(id, scope, sender))?;
|
||||
receiver.recv().map_err(Error::from)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -116,7 +116,7 @@ pub enum Command {
|
|||
/// Fetch the given repository from the network.
|
||||
Fetch(Id, NodeId, chan::Sender<FetchResult>),
|
||||
/// Track the given repository.
|
||||
TrackRepo(Id, chan::Sender<bool>),
|
||||
TrackRepo(Id, tracking::Scope, chan::Sender<bool>),
|
||||
/// Untrack the given repository.
|
||||
UntrackRepo(Id, chan::Sender<bool>),
|
||||
/// Track the given node.
|
||||
|
|
@ -136,7 +136,7 @@ impl fmt::Debug for Command {
|
|||
Self::Connect(id, addr) => write!(f, "Connect({id}, {addr})"),
|
||||
Self::Seeds(id, _) => write!(f, "Seeds({id})"),
|
||||
Self::Fetch(id, node, _) => write!(f, "Fetch({id}, {node})"),
|
||||
Self::TrackRepo(id, _) => write!(f, "TrackRepo({id})"),
|
||||
Self::TrackRepo(id, scope, _) => write!(f, "TrackRepo({id}, {scope})"),
|
||||
Self::UntrackRepo(id, _) => write!(f, "UntrackRepo({id})"),
|
||||
Self::TrackNode(id, _, _) => write!(f, "TrackNode({id})"),
|
||||
Self::UntrackNode(id, _) => write!(f, "UntrackNode({id})"),
|
||||
|
|
@ -491,9 +491,9 @@ where
|
|||
self.fetch_reqs.insert(rid, resp);
|
||||
self.fetch(rid, &seed);
|
||||
}
|
||||
Command::TrackRepo(rid, resp) => {
|
||||
Command::TrackRepo(rid, scope, resp) => {
|
||||
let tracked = self
|
||||
.track_repo(&rid, tracking::Scope::All)
|
||||
.track_repo(&rid, scope)
|
||||
.expect("Service::command: error tracking repository");
|
||||
// TODO: Try to fetch project if we weren't tracking it before.
|
||||
resp.send(tracked).ok();
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ impl radicle::node::Handle for Handle {
|
|||
.collect())
|
||||
}
|
||||
|
||||
fn track_repo(&mut self, id: Id) -> Result<bool, Self::Error> {
|
||||
fn track_repo(&mut self, id: Id, _scope: tracking::Scope) -> Result<bool, Self::Error> {
|
||||
Ok(self.tracking_repos.insert(id))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -345,7 +345,11 @@ fn test_tracking() {
|
|||
let proj_id: identity::Id = test::arbitrary::gen(1);
|
||||
|
||||
let (sender, receiver) = chan::bounded(1);
|
||||
alice.command(Command::TrackRepo(proj_id, sender));
|
||||
alice.command(Command::TrackRepo(
|
||||
proj_id,
|
||||
tracking::Scope::default(),
|
||||
sender,
|
||||
));
|
||||
let policy_change = receiver.recv().map_err(runtime::HandleError::from).unwrap();
|
||||
assert!(policy_change);
|
||||
assert!(alice.tracking().is_repo_tracked(&proj_id).unwrap());
|
||||
|
|
@ -927,7 +931,7 @@ fn test_track_repo_subscribe() {
|
|||
let (send, recv) = chan::bounded(1);
|
||||
|
||||
alice.connect_to(&bob);
|
||||
alice.command(Command::TrackRepo(rid, send));
|
||||
alice.command(Command::TrackRepo(rid, tracking::Scope::default(), send));
|
||||
assert!(recv.recv().unwrap());
|
||||
|
||||
assert_matches!(
|
||||
|
|
@ -981,11 +985,19 @@ fn test_push_and_pull() {
|
|||
|
||||
// Bob tracks Alice's project.
|
||||
let (sender, _) = chan::bounded(1);
|
||||
bob.command(service::Command::TrackRepo(proj_id, sender));
|
||||
bob.command(service::Command::TrackRepo(
|
||||
proj_id,
|
||||
tracking::Scope::default(),
|
||||
sender,
|
||||
));
|
||||
|
||||
// Eve tracks Alice's project.
|
||||
let (sender, _) = chan::bounded(1);
|
||||
eve.command(service::Command::TrackRepo(proj_id, sender));
|
||||
eve.command(service::Command::TrackRepo(
|
||||
proj_id,
|
||||
tracking::Scope::default(),
|
||||
sender,
|
||||
));
|
||||
|
||||
let mut sim = Simulation::new(
|
||||
LocalTime::now(),
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use radicle::storage::{ReadRepository, ReadStorage};
|
|||
use radicle::{assert_matches, rad};
|
||||
|
||||
use crate::service;
|
||||
use crate::service::tracking::Scope;
|
||||
use crate::storage::git::transport;
|
||||
use crate::test::environment::{converge, Node};
|
||||
use crate::test::logger;
|
||||
|
|
@ -155,7 +156,7 @@ fn test_replication() {
|
|||
let inventory = alice.handle.inventory().unwrap();
|
||||
assert!(inventory.try_iter().next().is_none());
|
||||
|
||||
let tracked = alice.handle.track_repo(acme).unwrap();
|
||||
let tracked = alice.handle.track_repo(acme, Scope::All).unwrap();
|
||||
assert!(tracked);
|
||||
|
||||
let seeds = alice.handle.seeds(acme).unwrap();
|
||||
|
|
@ -211,7 +212,7 @@ fn test_clone() {
|
|||
|
||||
transport::local::register(alice.storage.clone());
|
||||
|
||||
let _ = alice.handle.track_repo(acme).unwrap();
|
||||
let _ = alice.handle.track_repo(acme, Scope::All).unwrap();
|
||||
let seeds = alice.handle.seeds(acme).unwrap();
|
||||
assert!(seeds.is_connected(&bob.id));
|
||||
|
||||
|
|
@ -261,7 +262,7 @@ fn test_fetch_up_to_date() {
|
|||
|
||||
transport::local::register(alice.storage.clone());
|
||||
|
||||
let _ = alice.handle.track_repo(acme).unwrap();
|
||||
let _ = alice.handle.track_repo(acme, Scope::All).unwrap();
|
||||
let result = alice.handle.fetch(acme, bob.id).unwrap();
|
||||
assert!(result.is_success());
|
||||
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ pub trait Handle {
|
|||
fn fetch(&mut self, id: Id, from: NodeId) -> Result<FetchResult, Self::Error>;
|
||||
/// Start tracking the given project. Doesn't do anything if the project is already
|
||||
/// tracked.
|
||||
fn track_repo(&mut self, id: Id) -> Result<bool, Self::Error>;
|
||||
fn track_repo(&mut self, id: Id, scope: tracking::Scope) -> Result<bool, Self::Error>;
|
||||
/// Start tracking the given node.
|
||||
fn track_node(&mut self, id: NodeId, alias: Option<String>) -> Result<bool, Self::Error>;
|
||||
/// Untrack the given project and delete it from storage.
|
||||
|
|
@ -544,8 +544,8 @@ impl Handle for Node {
|
|||
response.into()
|
||||
}
|
||||
|
||||
fn track_repo(&mut self, id: Id) -> Result<bool, Error> {
|
||||
let mut line = self.call(CommandName::TrackRepo, [id.urn()])?;
|
||||
fn track_repo(&mut self, id: Id, scope: tracking::Scope) -> Result<bool, Error> {
|
||||
let mut line = self.call(CommandName::TrackRepo, [id.urn(), scope.to_string()])?;
|
||||
let response: CommandResult = line.next().ok_or(Error::EmptyResponse {
|
||||
cmd: CommandName::TrackRepo,
|
||||
})??;
|
||||
|
|
|
|||
Loading…
Reference in New Issue