diff --git a/radicle-cli/examples/git/git-fetch.md b/radicle-cli/examples/git/git-fetch.md index 1a0cb81e..652254b7 100644 --- a/radicle-cli/examples/git/git-fetch.md +++ b/radicle-cli/examples/git/git-fetch.md @@ -13,7 +13,6 @@ f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 refs/heads/master ``` (stderr) $ git fetch alice@z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi -✓ Synced with 1 peer(s) From rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi * [new branch] alice/1 -> alice@z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi/alice/1 ``` diff --git a/radicle-cli/examples/rad-patch-checkout-force.md b/radicle-cli/examples/rad-patch-checkout-force.md index 2775e3ba..3f69abf6 100644 --- a/radicle-cli/examples/rad-patch-checkout-force.md +++ b/radicle-cli/examples/rad-patch-checkout-force.md @@ -55,7 +55,6 @@ Bob fetches these new changes and can see their branch is now behind: ``` ~bob (stderr) $ git fetch rad -✓ Synced with 1 peer(s) From rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji 3e674d1..27857ec patches/6ff4f09c1b5a81347981f59b02ef43a31a07cdae -> rad/patches/6ff4f09c1b5a81347981f59b02ef43a31a07cdae ``` diff --git a/radicle-cli/examples/rad-push-and-pull-patches.md b/radicle-cli/examples/rad-push-and-pull-patches.md index baba06f6..8228f375 100644 --- a/radicle-cli/examples/rad-push-and-pull-patches.md +++ b/radicle-cli/examples/rad-push-and-pull-patches.md @@ -50,7 +50,6 @@ $ git push ``` ~alice (stderr) $ git checkout master -q $ git pull -✓ Synced with 1 peer(s) From rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji + c2aaf1c...8d5f1ba patches/0fd67a0364af1f79ed8770a35ed09d85571d4c21 -> rad/patches/0fd67a0364af1f79ed8770a35ed09d85571d4c21 (forced update) $ git checkout - -q @@ -71,7 +70,6 @@ f2de534b5e81d7c6e2dcaf58c3dd91573c0a0354 branch 'master' of rad://z42hL2jL4XNk6 ``` ~bob (stderr) $ git checkout master -q $ git pull -✓ Synced with 1 peer(s) From rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji + c2aaf1c...8d5f1ba patches/0fd67a0364af1f79ed8770a35ed09d85571d4c21 -> rad/patches/0fd67a0364af1f79ed8770a35ed09d85571d4c21 (forced update) ``` diff --git a/radicle-cli/examples/workflow/5-patching-maintainer.md b/radicle-cli/examples/workflow/5-patching-maintainer.md index ec2c332f..c6a85cda 100644 --- a/radicle-cli/examples/workflow/5-patching-maintainer.md +++ b/radicle-cli/examples/workflow/5-patching-maintainer.md @@ -15,11 +15,13 @@ peer. Upcoming versions of radicle will not require this step. $ rad remote add z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk --name bob ✓ Remote bob added ✓ Remote-tracking branch bob/master created for z6Mkt67…v4N1tRk +$ rad sync -f +✓ Fetching rad:z42hL2jL4XNk6K8oHQaSWfMgCL7ji from z6Mkt67…v4N1tRk.. +✓ Fetched repository from 1 seed(s) ``` ``` (stderr) $ git fetch bob -✓ Synced with 1 peer(s) From rad://z42hL2jL4XNk6K8oHQaSWfMgCL7ji/z6Mkt67GdsW7715MEfRuP4pSZxJRJh6kj6Y48WRqVv4N1tRk * [new branch] patches/3581e83ad18f5cdd806ab50fa11cfd5dd4e8ae1c -> bob/patches/3581e83ad18f5cdd806ab50fa11cfd5dd4e8ae1c ``` diff --git a/radicle-remote-helper/src/lib.rs b/radicle-remote-helper/src/lib.rs index bfd3244f..3721dfe6 100644 --- a/radicle-remote-helper/src/lib.rs +++ b/radicle-remote-helper/src/lib.rs @@ -7,19 +7,14 @@ mod fetch; mod list; mod push; -use std::io::IsTerminal as _; use std::path::PathBuf; use std::str::FromStr; -use std::time; use std::{env, io}; use radicle_cli::git::Rev; use thiserror::Error; use radicle::git; -use radicle::node::FetchResults; -use radicle::node::Handle as _; -use radicle::prelude::Id; use radicle::storage::git::transport::local::{Url, UrlError}; use radicle::storage::{ReadRepository, WriteStorage}; use radicle_cli::terminal as cli; @@ -119,7 +114,6 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> { let stdin = io::stdin(); let mut line = String::new(); let mut opts = Options::default(); - let mut sync = SyncState::new(url.repo); loop { let tokens = read_line(&stdin, &mut line)?; @@ -155,8 +149,6 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> { let oid = git::Oid::from_str(oid)?; let refstr = git::RefString::try_from(*refstr)?; - sync.run(&opts, &profile).ok(); - return fetch::run(vec![(oid, refstr)], &working, url, stored, &stdin) .map_err(Error::from); } @@ -173,8 +165,6 @@ pub fn run(profile: radicle::Profile) -> Result<(), Error> { .map_err(Error::from); } ["list"] => { - sync.run(&opts, &profile).ok(); - list::for_fetch(&url, &stored)?; } ["list", "for-push"] => { @@ -237,77 +227,3 @@ pub(crate) fn read_line<'a>(stdin: &io::Stdin, line: &'a mut String) -> io::Resu Ok(tokens) } - -/// Keeps track of sync state. -struct SyncState { - /// Whether we tried to fetch already. - fetched: bool, - /// The repo id. - rid: Id, -} - -impl SyncState { - fn new(rid: Id) -> Self { - Self { - fetched: false, - rid, - } - } - - /// Connect to local node and try to fetch refs from the network. - /// If our node is not running, or the "no-sync" option is enabled, - /// we simply do nothing. - fn run( - &mut self, - opts: &Options, - profile: &radicle::Profile, - ) -> Result<(), radicle::node::Error> { - if opts.no_sync || self.fetched { - return Ok(()); - } - let mut node = radicle::Node::new(profile.socket()); - if !node.is_running() { - return Ok(()); - } - - let target = 3; - let timeout = time::Duration::from_secs(6); - let seeds = node.seeds(self.rid)?; - let connected = seeds.connected().map(|s| s.nid).collect::>(); - - if connected.is_empty() { - return Ok(()); - } - let message = format!("Syncing with {} node(s)..", connected.len().min(target)); - let mut spinner = if io::stderr().is_terminal() { - cli::spinner_to(message, io::stderr(), io::stderr()) - } else { - cli::spinner_to(message, io::stderr(), io::sink()) - }; - - // Fetch from connected seeds. - let mut results = FetchResults::default(); - for seed in connected.into_iter() { - spinner.message(format!("Syncing with {seed}..")); - - let result = node.fetch(self.rid, seed, timeout)?; - results.push(seed, result); - - if results.success().count() >= target { - break; - } - } - - let success = results.success().count(); - if success > 0 { - spinner.message(format!("Synced with {success} peer(s)")); - spinner.finish(); - } else { - spinner.failed(); - } - // Make sure we don't try to fetch again while this program is running. - self.fetched = true; - - Ok(()) - } -}