From 98c94de5e3db8acb55433ffd95f137396cde6fe4 Mon Sep 17 00:00:00 2001 From: cloudhead Date: Fri, 2 Feb 2024 16:46:20 +0100 Subject: [PATCH] Various small improvements across crates Most of these changes should be self-explanatory. * Atomic fetch was no longer used * The default policy when initializing should be 'all', as it is with `rad init`. --- radicle-crypto/src/lib.rs | 5 ++++ radicle-node/src/runtime.rs | 8 ------- radicle-node/src/test/environment.rs | 5 +--- radicle/src/cob/issue.rs | 7 +++++- radicle/src/cob/patch.rs | 2 +- radicle/src/node.rs | 2 +- radicle/src/storage.rs | 36 ++++++++++++++++++++++------ 7 files changed, 43 insertions(+), 22 deletions(-) diff --git a/radicle-crypto/src/lib.rs b/radicle-crypto/src/lib.rs index 0d1278d9..550ce479 100644 --- a/radicle-crypto/src/lib.rs +++ b/radicle-crypto/src/lib.rs @@ -354,6 +354,11 @@ impl PublicKey { refname!("refs/namespaces").join(Component::from(self)) } + #[cfg(feature = "radicle-git-ext")] + pub fn to_component(&self) -> radicle_git_ext::ref_format::Component { + radicle_git_ext::ref_format::Component::from(self) + } + #[cfg(feature = "radicle-git-ext")] pub fn from_namespaced( refstr: &radicle_git_ext::ref_format::Namespaced, diff --git a/radicle-node/src/runtime.rs b/radicle-node/src/runtime.rs index 613ec14d..49895872 100644 --- a/radicle-node/src/runtime.rs +++ b/radicle-node/src/runtime.rs @@ -240,14 +240,6 @@ impl Runtime { } let reactor = Reactor::named(wire, popol::Poller::new(), thread::name(&id, "service"))?; let handle = Handle::new(home.clone(), reactor.controller(), emitter); - let atomic = git::version()? >= git::VERSION_REQUIRED; - - if !atomic { - log::warn!( - target: "node", - "Disabling atomic fetches; git version >= {} required", git::VERSION_REQUIRED - ); - } let nid = *signer.public_key(); let fetch = worker::FetchConfig { diff --git a/radicle-node/src/test/environment.rs b/radicle-node/src/test/environment.rs index c7048077..d2439685 100644 --- a/radicle-node/src/test/environment.rs +++ b/radicle-node/src/test/environment.rs @@ -476,10 +476,7 @@ impl + Signer + Clone> Node { .map(|(id, _, _)| id) .unwrap(); - assert!(self - .policies - .seed(&id, node::policy::Scope::Followed) - .unwrap()); + assert!(self.policies.seed(&id, node::policy::Scope::All).unwrap()); log::debug!( target: "test", diff --git a/radicle/src/cob/issue.rs b/radicle/src/cob/issue.rs index e9b8d04b..5c5a1861 100644 --- a/radicle/src/cob/issue.rs +++ b/radicle/src/cob/issue.rs @@ -688,7 +688,7 @@ impl IssueCounts { } } -impl<'a, R: WriteRepository> Issues<'a, R> +impl<'a, R> Issues<'a, R> where R: ReadRepository + cob::Store, { @@ -699,7 +699,12 @@ where Ok(Self { raw }) } +} +impl<'a, R> Issues<'a, R> +where + R: WriteRepository + cob::Store, +{ /// Get an issue. pub fn get(&self, id: &ObjectId) -> Result, store::Error> { self.raw.get(id) diff --git a/radicle/src/cob/patch.rs b/radicle/src/cob/patch.rs index 5263f4f9..13d6f498 100644 --- a/radicle/src/cob/patch.rs +++ b/radicle/src/cob/patch.rs @@ -2241,7 +2241,7 @@ impl<'a, R> Deref for Patches<'a, R> { impl<'a, R> Patches<'a, R> where - R: ReadRepository + cob::Store + 'static, + R: ReadRepository + cob::Store, { /// Open a patches store. pub fn open(repository: &'a R) -> Result { diff --git a/radicle/src/node.rs b/radicle/src/node.rs index dfc7d6d4..99d6394b 100644 --- a/radicle/src/node.rs +++ b/radicle/src/node.rs @@ -659,7 +659,7 @@ impl FetchResult { } } - pub fn find_updated(&self, name: &git::RefString) -> Option { + pub fn find_updated(&self, name: &git::RefStr) -> Option { let updated = match self { Self::Success { updated, .. } => Some(updated), _ => None, diff --git a/radicle/src/storage.rs b/radicle/src/storage.rs index 4fdf88df..a0ba8090 100644 --- a/radicle/src/storage.rs +++ b/radicle/src/storage.rs @@ -17,7 +17,7 @@ pub use radicle_git_ext::Oid; use crate::cob; use crate::collections::RandomMap; use crate::git::ext as git_ext; -use crate::git::{refspec::Refspec, PatternString, Qualified, RefError, RefString}; +use crate::git::{refspec::Refspec, PatternString, Qualified, RefError, RefStr, RefString}; use crate::identity::{Did, PayloadError}; use crate::identity::{Doc, DocAt, DocError}; use crate::identity::{Identity, RepoId}; @@ -186,12 +186,34 @@ impl RefUpdate { } } - pub fn name(&self) -> &RefString { - match &self { - RefUpdate::Updated { name, .. } => name, - RefUpdate::Created { name, .. } => name, - RefUpdate::Deleted { name, .. } => name, - RefUpdate::Skipped { name, .. } => name, + /// Get the old OID, if any. + pub fn old(&self) -> Option { + match self { + RefUpdate::Updated { old, .. } => Some(*old), + RefUpdate::Created { .. } => None, + RefUpdate::Deleted { oid, .. } => Some(*oid), + RefUpdate::Skipped { oid, .. } => Some(*oid), + } + } + + /// Get the new OID, if any. + #[allow(clippy::new_ret_no_self)] + pub fn new(&self) -> Option { + match self { + RefUpdate::Updated { new, .. } => Some(*new), + RefUpdate::Created { oid, .. } => Some(*oid), + RefUpdate::Deleted { .. } => None, + RefUpdate::Skipped { .. } => None, + } + } + + /// Get the ref name. + pub fn name(&self) -> &RefStr { + match self { + RefUpdate::Updated { name, .. } => name.as_refstr(), + RefUpdate::Created { name, .. } => name.as_refstr(), + RefUpdate::Deleted { name, .. } => name.as_refstr(), + RefUpdate::Skipped { name, .. } => name.as_refstr(), } } }