diff --git a/bobbin/crates/edge-index/src/invites.rs b/bobbin/crates/edge-index/src/invites.rs index f2fe38b54..c288335b1 100644 --- a/bobbin/crates/edge-index/src/invites.rs +++ b/bobbin/crates/edge-index/src/invites.rs @@ -90,9 +90,10 @@ impl InviteIndex { .flatten() .map(|(scope, offer)| (scope.clone(), offer.clone())) .sorted_by(|(left_scope, left), (right_scope, right)| { - right.offered_at.cmp(&left.offered_at).then_with(|| { - left_scope.repo.as_ref().cmp(right_scope.repo.as_ref()) - }) + right + .offered_at + .cmp(&left.offered_at) + .then_with(|| left_scope.repo.as_ref().cmp(right_scope.repo.as_ref())) }) .collect() } diff --git a/bobbin/crates/knot-ingest/src/registry.rs b/bobbin/crates/knot-ingest/src/registry.rs index c37d856b3..7b6543a46 100644 --- a/bobbin/crates/knot-ingest/src/registry.rs +++ b/bobbin/crates/knot-ingest/src/registry.rs @@ -63,7 +63,6 @@ impl KnotRegistry { pub fn host_of_repo(&self, repo: &Did) -> Option { self.inner.lock().unwrap().repo_host.get(repo).cloned() } - } #[cfg(test)] @@ -127,5 +126,4 @@ mod tests { ); assert_eq!(registry.host_of_repo(&did("did:plc:limpet")), None); } - } diff --git a/bobbin/crates/knot-ingest/src/stream.rs b/bobbin/crates/knot-ingest/src/stream.rs index 66b1a85c2..f6731bc7c 100644 --- a/bobbin/crates/knot-ingest/src/stream.rs +++ b/bobbin/crates/knot-ingest/src/stream.rs @@ -347,8 +347,8 @@ mod tests { use parking_lot::Mutex; use super::*; - use crate::firehose::testcbor::*; use crate::firehose::OpAction; + use crate::firehose::testcbor::*; #[derive(Clone, Debug, PartialEq)] enum Entry { diff --git a/bobbin/crates/resolver/src/legacy_upgrade.rs b/bobbin/crates/resolver/src/legacy_upgrade.rs index 2834a7949..2ce8c7e86 100644 --- a/bobbin/crates/resolver/src/legacy_upgrade.rs +++ b/bobbin/crates/resolver/src/legacy_upgrade.rs @@ -3,8 +3,8 @@ use bobbin_types::com_atproto::repo::strong_ref::StrongRef; use bobbin_types::edges::{ExtractError, Record}; use bobbin_types::legacy::{ LEGACY_COMMENT_SENTINEL_CID, LegacyCollaborator, LegacyIssue, LegacyIssueComment, - LegacyPublicKey, LegacyPull, LegacyPullComment, LegacyRecord, LegacyRepo, - LegacySource, LegacyStar, LegacyTarget, + LegacyPublicKey, LegacyPull, LegacyPullComment, LegacyRecord, LegacyRepo, LegacySource, + LegacyStar, LegacyTarget, }; use bobbin_types::sh_tangled::feed::comment::Comment as FeedComment; use bobbin_types::sh_tangled::feed::star::{Repo as StarRepo, Star, StarString, StarSubject}; diff --git a/bobbin/crates/xrpc/tests/coverage.rs b/bobbin/crates/xrpc/tests/coverage.rs index e860d5d17..11ccfd4dc 100644 --- a/bobbin/crates/xrpc/tests/coverage.rs +++ b/bobbin/crates/xrpc/tests/coverage.rs @@ -333,10 +333,7 @@ async fn any_origin_allows_preflight_and_get() { } fn ready_request(path: &str) -> Request { - Request::builder() - .uri(path) - .body(Body::empty()) - .unwrap() + Request::builder().uri(path).body(Body::empty()).unwrap() } #[tokio::test] diff --git a/gitmirror/crates/gitmirror-xrpc/src/last_commit.rs b/gitmirror/crates/gitmirror-xrpc/src/last_commit.rs index c7c19ad45..ca5de29d9 100644 --- a/gitmirror/crates/gitmirror-xrpc/src/last_commit.rs +++ b/gitmirror/crates/gitmirror-xrpc/src/last_commit.rs @@ -103,7 +103,11 @@ pub(crate) async fn store( } fn commit_tree(repo: &gix::Repository, commit: ObjectId) -> Option { - repo.find_commit(commit).ok()?.tree_id().ok().map(|id| id.detach()) + repo.find_commit(commit) + .ok()? + .tree_id() + .ok() + .map(|id| id.detach()) } fn subtree_of( @@ -139,7 +143,10 @@ fn ensure_entries( let mut entries = HashMap::new(); if let Ok(tree) = repo.find_tree(subtree) { for entry in tree.iter().flatten() { - entries.insert(entry.filename().to_str_lossy().into_owned(), entry.object_id()); + entries.insert( + entry.filename().to_str_lossy().into_owned(), + entry.object_id(), + ); } } memo.insert(subtree, entries); diff --git a/gitmirror/crates/gitmirror-xrpc/src/routes/git.rs b/gitmirror/crates/gitmirror-xrpc/src/routes/git.rs index 14dd2ad68..945db701e 100644 --- a/gitmirror/crates/gitmirror-xrpc/src/routes/git.rs +++ b/gitmirror/crates/gitmirror-xrpc/src/routes/git.rs @@ -614,9 +614,8 @@ fn commit_log_walk<'repo>( } } } else { - let peel = |id| -> anyhow::Result { - Ok(repo.find_object(id)?.peel_to_commit()?.id) - }; + let peel = + |id| -> anyhow::Result { Ok(repo.find_object(id)?.peel_to_commit()?.id) }; for range in ranges { let revspec = repo.rev_parse(range.as_bstr())?; let spec = revspec.detach(); diff --git a/gitmirror/crates/gitmirror-xrpc/src/routes/reads.rs b/gitmirror/crates/gitmirror-xrpc/src/routes/reads.rs index 4c4ccbcc6..c7d5f3d45 100644 --- a/gitmirror/crates/gitmirror-xrpc/src/routes/reads.rs +++ b/gitmirror/crates/gitmirror-xrpc/src/routes/reads.rs @@ -36,7 +36,11 @@ const DEFAULT_REFS_LIMIT: i64 = 50; const MAX_REFS_LIMIT: i64 = 100; fn cache_control(refs: &[&str]) -> &'static str { - if !refs.is_empty() && refs.iter().all(|r| ObjectId::from_hex(r.as_bytes()).is_ok()) { + if !refs.is_empty() + && refs + .iter() + .all(|r| ObjectId::from_hex(r.as_bytes()).is_ok()) + { IMMUTABLE } else { MUTABLE @@ -48,9 +52,12 @@ fn cache_header(value: &'static str) -> [(header::HeaderName, &'static str); 1] } fn open(state: &AppState, repo: &Did) -> Result { - state.layout.open(repo).map_err(|e| XrpcError::RepoNotFound { - detail: e.to_string(), - }) + state + .layout + .open(repo) + .map_err(|e| XrpcError::RepoNotFound { + detail: e.to_string(), + }) } fn open_capped(state: &AppState, repo: &Did, limit: u64) -> Result { @@ -190,10 +197,12 @@ pub(crate) async fn get_merge_base( let head = resolve_commit(&repo, &head_spec)?; match repo.merge_base(head, base) { Ok(id) => Ok(id.detach().to_smolstr()), - Err(gix::repository::merge_base::Error::NotFound { .. }) => Err(XrpcError::NoMergeBase { - base: base_spec, - head: head_spec, - }), + Err(gix::repository::merge_base::Error::NotFound { .. }) => { + Err(XrpcError::NoMergeBase { + base: base_spec, + head: head_spec, + }) + } Err(error) => Err(XrpcError::Internal(error.to_string())), } }) @@ -350,46 +359,51 @@ pub(crate) async fn get_tree( let repo = open(&state, &args.repo)?; let refspec = args.r#ref.as_deref().unwrap_or("HEAD").to_owned(); let cache = cache_control(&[&refspec]); - let tree_path = args.path.as_deref().unwrap_or("").trim_matches('/').to_owned(); + let tree_path = args + .path + .as_deref() + .unwrap_or("") + .trim_matches('/') + .to_owned(); let path = tree_path.clone(); let (repo, head, mut entries) = crate::metrics::blocking(BlockingKind::Git, move || { let head = resolve_commit(&repo, &refspec)?; let entries = { - let root = repo - .find_commit(head) - .map_err(|e| XrpcError::Internal(e.to_string()))? - .tree() - .map_err(|e| XrpcError::Internal(e.to_string()))?; - let subtree = if path.is_empty() { - root - } else { - let entry = root - .lookup_entry_by_path(&path) + let root = repo + .find_commit(head) .map_err(|e| XrpcError::Internal(e.to_string()))? - .filter(|entry| entry.mode().is_tree()) - .ok_or_else(|| XrpcError::PathNotFound { path: path.clone() })?; - repo.find_tree(entry.object_id()) - .map_err(|_| XrpcError::PathNotFound { path: path.clone() })? - }; - - let mut entries: Vec = Vec::new(); - for entry in subtree.iter() { - let entry = entry.map_err(|e| XrpcError::Internal(e.to_string()))?; - let kind = entry.mode().kind(); - let size = match kind { - EntryKind::Tree | EntryKind::Commit => 0, - _ => blob_size(&repo, entry.object_id())? as i64, + .tree() + .map_err(|e| XrpcError::Internal(e.to_string()))?; + let subtree = if path.is_empty() { + root + } else { + let entry = root + .lookup_entry_by_path(&path) + .map_err(|e| XrpcError::Internal(e.to_string()))? + .filter(|entry| entry.mode().is_tree()) + .ok_or_else(|| XrpcError::PathNotFound { path: path.clone() })?; + repo.find_tree(entry.object_id()) + .map_err(|_| XrpcError::PathNotFound { path: path.clone() })? }; - entries.push(get_tree::TreeEntry { - name: entry.filename().to_str_lossy().as_ref().into(), - mode: mode_of(kind).as_str().into(), - size, - last_commit: None, - extra_data: Default::default(), - }); - } - entries + + let mut entries: Vec = Vec::new(); + for entry in subtree.iter() { + let entry = entry.map_err(|e| XrpcError::Internal(e.to_string()))?; + let kind = entry.mode().kind(); + let size = match kind { + EntryKind::Tree | EntryKind::Commit => 0, + _ => blob_size(&repo, entry.object_id())? as i64, + }; + entries.push(get_tree::TreeEntry { + name: entry.filename().to_str_lossy().as_ref().into(), + mode: mode_of(kind).as_str().into(), + size, + last_commit: None, + extra_data: Default::default(), + }); + } + entries }; Ok::<_, XrpcError>((repo, head, entries)) }) diff --git a/knot2/crates/knot-atproto/src/lib.rs b/knot2/crates/knot-atproto/src/lib.rs index 281a250e7..2b2f1e7bd 100644 --- a/knot2/crates/knot-atproto/src/lib.rs +++ b/knot2/crates/knot-atproto/src/lib.rs @@ -66,8 +66,8 @@ use knot_runtime::{ UnixMicros, }; use knot_types::{ - AccountDid, Collection, Handle, HttpStatus, KnotId, Nsid, OfferedKey, RecordRkey, - RepoDid, RepoRkey, Rkey, UnixSeconds, + AccountDid, Collection, Handle, HttpStatus, KnotId, Nsid, OfferedKey, RecordRkey, RepoDid, + RepoRkey, Rkey, UnixSeconds, }; use pubkeys::Cursor; use serde::{Deserialize, Serialize}; @@ -260,10 +260,7 @@ impl Atproto { identities: MokaFuture::by_count(EntryCount::new(MAX_IDENTITY_CACHE as u64)), handles: MokaFuture::by_count(EntryCount::new(MAX_IDENTITY_CACHE as u64)), claimed: MokaFuture::by_weight(Weight::new(MAX_PUBKEY_CACHE_BYTES), claimed_weight), - defs: MokaFuture::by_weight( - Weight::new(MAX_DEF_CACHE_BYTES), - def_weight, - ), + defs: MokaFuture::by_weight(Weight::new(MAX_DEF_CACHE_BYTES), def_weight), seen_jti: Expiring::new(Quotas { per_group: GroupQuota::new(MAX_JTI_PER_ISSUER), total: TotalQuota::new(MAX_SEEN_JTI), @@ -592,10 +589,7 @@ impl Atproto { } } - pub async fn remote_def( - &self, - wanted: &knot_record::label::DefRef, - ) -> RemoteDef { + pub async fn remote_def(&self, wanted: &knot_record::label::DefRef) -> RemoteDef { let now = self.clock.now_unix_micros(); let filled = self .defs @@ -620,13 +614,11 @@ impl Atproto { expires_at: expires(now, DEF_TTL), }, Err(reason) => Cached { - resolution: RemoteDef::Unread(Arc::new( - AtprotoError::MalformedDef { - owner: AccountDid::from(wanted.repo().clone()), - rkey: wanted.rkey().clone(), - reason: reason.to_string(), - }, - )), + resolution: RemoteDef::Unread(Arc::new(AtprotoError::MalformedDef { + owner: AccountDid::from(wanted.repo().clone()), + rkey: wanted.rkey().clone(), + reason: reason.to_string(), + })), expires_at: expires(now, NEGATIVE_TTL), }, }, @@ -1617,9 +1609,7 @@ mod tests { "several operands on one def share a single getRecord" ); - atproto - .clock - .advance(DEF_TTL + Duration::from_micros(1)); + atproto.clock.advance(DEF_TTL + Duration::from_micros(1)); let refreshed = atproto.remote_def(&wontfix).await; assert!(matches!(&refreshed, RemoteDef::Read { .. })); assert_eq!(reads.load(Ordering::SeqCst), 2); diff --git a/knot2/crates/knot-cobs/src/grant.rs b/knot2/crates/knot-cobs/src/grant.rs index 4c7a10f9d..014898b7a 100644 --- a/knot2/crates/knot-cobs/src/grant.rs +++ b/knot2/crates/knot-cobs/src/grant.rs @@ -343,7 +343,10 @@ mod tests { .clone() .apply_change(&change(b'a', "nel", "olaren", 7)); assert_eq!( - (accepted, invited.would_change(&change(b'a', "nel", "olaren", 7))), + ( + accepted, + invited.would_change(&change(b'a', "nel", "olaren", 7)) + ), (invited.clone(), false), "an acceptance left over from the consent model must fold to nothing, and never \ append a change of its own" diff --git a/knot2/crates/knot-cobs/src/label.rs b/knot2/crates/knot-cobs/src/label.rs index 7d34d7d53..7fd0b70e8 100644 --- a/knot2/crates/knot-cobs/src/label.rs +++ b/knot2/crates/knot-cobs/src/label.rs @@ -39,9 +39,7 @@ impl LabelOp { key: operand.key().clone(), value: operand.value().clone(), verb, - multiple: defs - .get(operand.key()) - .is_some_and(|def| def.multiple()), + multiple: defs.get(operand.key()).is_some_and(|def| def.multiple()), }; Ok(Self { operands: record @@ -172,8 +170,7 @@ mod tests { ], vec![operand("wontfix", "null")], ); - let defs: BTreeMap<_, _> = - [defined("wontfix", false), defined("assignee", true)].into(); + let defs: BTreeMap<_, _> = [defined("wontfix", false), defined("assignee", true)].into(); let change = SocialChange::Open { creation: seeded( RecordAddress::new( diff --git a/knot2/crates/knot-cobs/tests/invariants.rs b/knot2/crates/knot-cobs/tests/invariants.rs index 5b97f1174..8ebe32b4d 100644 --- a/knot2/crates/knot-cobs/tests/invariants.rs +++ b/knot2/crates/knot-cobs/tests/invariants.rs @@ -6,9 +6,9 @@ use common::{ }; use knot_cob::{ChangePayload, CobError, CobHome, CobId, CobStore, Evaluate}; use knot_cobs::{ - Accept, CollaboratorsChange, ImportError, Invite, MembersChange, MembersCob, - RegistryChange, RegistryError, Removal, RepoRef, RepoRegistryCob, deregister_repo, - register_repo, verify_cob_ref, + Accept, CollaboratorsChange, ImportError, Invite, MembersChange, MembersCob, RegistryChange, + RegistryError, Removal, RepoRef, RepoRegistryCob, deregister_repo, register_repo, + verify_cob_ref, }; use knot_git::RefUpdate; use knot_runtime::Signer; diff --git a/knot2/crates/knot-git/src/repo.rs b/knot2/crates/knot-git/src/repo.rs index 7ee8f2a30..28c4e9c42 100644 --- a/knot2/crates/knot-git/src/repo.rs +++ b/knot2/crates/knot-git/src/repo.rs @@ -714,7 +714,10 @@ impl Repo { Ok(self.find_ref(&branch)?.is_some()) } - pub fn ensure_valid_head<'a>(&self, updates: &'a [RefUpdate]) -> Result, GitError> { + pub fn ensure_valid_head<'a>( + &self, + updates: &'a [RefUpdate], + ) -> Result, GitError> { if self.has_valid_head()? { return Ok(None); } diff --git a/knot2/crates/knot-index/src/lib.rs b/knot2/crates/knot-index/src/lib.rs index f804052d3..2ea8212ad 100644 --- a/knot2/crates/knot-index/src/lib.rs +++ b/knot2/crates/knot-index/src/lib.rs @@ -14,11 +14,11 @@ use std::sync::atomic::{AtomicU64, Ordering}; use std::time::Duration; use knot_cob::{ChangePayload, CobId, CobStore}; +pub use knot_cobs::Entry; use knot_cobs::{ BlocklistChange, BlocklistCob, CollaboratorsChange, CollaboratorsCob, MembersChange, MembersCob, RegistryChange, RepoRef, RepoRegistryCob, }; -pub use knot_cobs::Entry; use knot_git::{Layout, Repo}; use knot_resource::StructureBytes; use knot_types::{ @@ -28,9 +28,7 @@ use knot_types::{ use tokio::sync::watch; use intern::{Interner, RepoKey}; -use projections::{ - CollaboratorsProjection, GrantSetProjection, KeyProjection, RegistryProjection, -}; +use projections::{CollaboratorsProjection, GrantSetProjection, KeyProjection, RegistryProjection}; pub struct Answer<'a, S> { scope: S, @@ -787,13 +785,13 @@ impl Index { .filter(|repo| matches!(repo, Folded::Pending)) .count(), ); - let grants = folded - .into_iter() - .filter_map(Folded::into_seats) - .fold(Vec::new(), |mut grants, seats| { + let grants = folded.into_iter().filter_map(Folded::into_seats).fold( + Vec::new(), + |mut grants, seats| { grants.extend(seats); grants - }); + }, + ); Resolved::Ready(Granted { subjects: sorted(grants), hosted, diff --git a/knot2/crates/knot-record/src/chain.rs b/knot2/crates/knot-record/src/chain.rs index e01d20de6..85560a709 100644 --- a/knot2/crates/knot-record/src/chain.rs +++ b/knot2/crates/knot-record/src/chain.rs @@ -1357,10 +1357,7 @@ mod tests { let signer = key(); let mut records = records(2); let mut chunks = enable(&repo, &records, &signer).await.unwrap(); - records.insert( - MstKey::new(format!("{COLLECTION}/late")).unwrap(), - body(7), - ); + records.insert(MstKey::new(format!("{COLLECTION}/late")).unwrap(), body(7)); chunks.extend( sync( &repo, diff --git a/knot2/crates/knot-record/src/label.rs b/knot2/crates/knot-record/src/label.rs index dece51e00..ec785e687 100644 --- a/knot2/crates/knot-record/src/label.rs +++ b/knot2/crates/knot-record/src/label.rs @@ -112,13 +112,9 @@ pub enum LabelError { FormatOnNonString(&'static str), #[error("A def doesn't decode: {0}")] Decode(String), - #[error( - "A def's $type is {spelled}, and this collection is {LABEL_DEF_COLLECTION}" - )] + #[error("A def's $type is {spelled}, and this collection is {LABEL_DEF_COLLECTION}")] Kind { spelled: String }, - #[error( - "An operand cites a label def by at-uri, and {at_uri} doesn't parse: {reason}" - )] + #[error("An operand cites a label def by at-uri, and {at_uri} doesn't parse: {reason}")] DefUri { at_uri: String, reason: String }, #[error("An operand cites a label def by at-uri, and {at_uri} cites {collection}")] NotADef { at_uri: String, collection: String }, @@ -425,11 +421,9 @@ impl Def { serde_json::from_value::(value) .map_err(|error| LabelError::Decode(error.to_string())) .and_then(|draft| match draft.kind.as_ref() { - Some(kind) if kind.as_str() != LABEL_DEF_COLLECTION => { - Err(LabelError::Kind { - spelled: kind.to_string(), - }) - } + Some(kind) if kind.as_str() != LABEL_DEF_COLLECTION => Err(LabelError::Kind { + spelled: kind.to_string(), + }), _ => draft_def(draft), }) } @@ -508,11 +502,7 @@ pub struct LabelDefRecord { } impl LabelDefRecord { - pub fn new( - def: Def, - created_at: UnixSeconds, - editor: AccountDid, - ) -> Result { + pub fn new(def: Def, created_at: UnixSeconds, editor: AccountDid) -> Result { Ok(Self { def, created_at: CreatedAt::at(created_at)?, @@ -649,10 +639,7 @@ impl LabelOpRecord { } } - pub fn vetted_against( - &self, - defs: &BTreeMap, - ) -> Result<(), LabelError> { + pub fn vetted_against(&self, defs: &BTreeMap) -> Result<(), LabelError> { let subject = self.subject.at_uri(&self.repo).as_str().to_owned(); self.adds .iter() @@ -664,8 +651,7 @@ impl LabelOpRecord { def: operand.key().to_string(), }); }; - def - .scopes(self.subject.collection()) + def.scopes(self.subject.collection()) .and_then(|()| def.value().check(operand.value())) .map_err(|reason| LabelError::OperandRefused { subject: subject.clone(), @@ -772,8 +758,7 @@ mod tests { #[test] fn def_record_bytes_frozen() { - let record = - LabelDefRecord::new(null_def(), UnixSeconds::new(1), editor()).unwrap(); + let record = LabelDefRecord::new(null_def(), UnixSeconds::new(1), editor()).unwrap(); assert_eq!( record.body().unwrap().as_bytes(), frozen(DEF).as_slice(), @@ -837,11 +822,8 @@ mod tests { #[test] fn value_check_takes_what_each_type_declares() { - let refused = |value: &str, def: &LabelValue| { - def - .check(&OperandValue::new(value).unwrap()) - .is_err() - }; + let refused = + |value: &str, def: &LabelValue| def.check(&OperandValue::new(value).unwrap()).is_err(); let null = LabelValue::Null; assert!(!refused("null", &null)); assert!(refused("kelp", &null)); @@ -878,15 +860,10 @@ mod tests { .unwrap(); assert!(def.scopes(&crate::issue::issue_collection()).is_ok()); assert!( - def - .scopes(&knot_types::RecordCollection::new("sh.tangled.repo.pull").unwrap()) + def.scopes(&knot_types::RecordCollection::new("sh.tangled.repo.pull").unwrap()) .is_ok() ); - assert!( - def - .scopes(&crate::comment::comment_collection()) - .is_err() - ); + assert!(def.scopes(&crate::comment::comment_collection()).is_err()); } #[test] @@ -1071,10 +1048,7 @@ mod tests { #[test] fn def_ref_takes_whatever_rkey_the_remote_writes() { use std::str::FromStr; - assert!( - DefRef::from_str("at://did:plc:squid/sh.tangled.label.definition/wontfix") - .is_ok() - ); + assert!(DefRef::from_str("at://did:plc:squid/sh.tangled.label.definition/wontfix").is_ok()); assert!( DefRef::from_str("at://did:plc:squid/sh.tangled.label.definition/3lubrptx57d22") .is_ok(), diff --git a/knot2/crates/knot-record/src/lib.rs b/knot2/crates/knot-record/src/lib.rs index 20da7701c..daff0eb1a 100644 --- a/knot2/crates/knot-record/src/lib.rs +++ b/knot2/crates/knot-record/src/lib.rs @@ -30,7 +30,6 @@ pub enum RecordError { pub type Result = std::result::Result; #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] - #[serde(transparent)] pub struct CreatedAt(String); @@ -261,4 +260,3 @@ impl jacquard_repo::commit::SigningKey for CommitSigner<'_> { self.0.public_key().as_bytes().to_vec() } } -