From 6d0c571ea9998dd98bf10cc191848029f5210d8a Mon Sep 17 00:00:00 2001 From: Sebastian Martinez Date: Thu, 6 Nov 2025 09:52:14 +0100 Subject: [PATCH] radicle: Return individual results for repo in `repositories_by_id` Change `repositories_by_id` to return `impl Iterator>` instead of `Result, RepositoryError>`. This allows callers to handle failures on a per-repository basis rather than having the entire operation fail if a single repository lookup fails. Previously, the method would stop processing and return an error as soon as any repository failed to load. Now it processes all repositories and returns individual results, making the API more resilient and giving callers more control over error handling. --- crates/radicle/CHANGELOG.md | 5 +++++ crates/radicle/src/storage/git.rs | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/crates/radicle/CHANGELOG.md b/crates/radicle/CHANGELOG.md index 7e1b130f..cf7590e6 100644 --- a/crates/radicle/CHANGELOG.md +++ b/crates/radicle/CHANGELOG.md @@ -18,6 +18,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed +- `radicle::storage::git::Storage::repositories_by_id` returns + `impl Iterator>` instead of + `Result, RepositoryError>`. Allowing callers to handle + failures on a per-repository basis rather than having the entire operation + fail if a single repository lookup fails. - Re-exports from `git2` at `radicle::git::raw` were limited, using the heartwood workspace as a filter. Dependents that require members that are not exported anymore will have to depend on `git2` directly. diff --git a/crates/radicle/src/storage/git.rs b/crates/radicle/src/storage/git.rs index f2592805..d36c33ca 100644 --- a/crates/radicle/src/storage/git.rs +++ b/crates/radicle/src/storage/git.rs @@ -236,11 +236,14 @@ impl Storage { self.path.as_path() } - pub fn repositories_by_id<'a>( + pub fn repositories_by_id<'a, I>( &self, - mut rids: impl Iterator, - ) -> Result, RepositoryError> { - rids.try_fold(Vec::new(), |mut infos, rid| { + rids: I, + ) -> impl Iterator> + use<'_, 'a, I> + where + I: Iterator, + { + rids.map(|rid| { let repo = self.repository(*rid)?; let (_, head) = repo.head()?; let refs = refs::SignedRefsAt::load(self.info.key, &repo)?; @@ -248,15 +251,14 @@ impl Storage { .as_ref() .map(|r| SyncedAt::new(r.at, &repo)) .transpose()?; - let info = RepositoryInfo { + + Ok(RepositoryInfo { rid: *rid, head, doc: repo.identity_doc()?.into(), refs, synced_at, - }; - infos.push(info); - Ok(infos) + }) }) }