diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-29 00:16:56 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-29 00:23:32 +0900 |
| commit | 7f83e785a77fbdbcada9c6714703d4e5801af82a (patch) | |
| tree | ef7debc5cbc91d521db4dc5a563807c486dafd22 /crates/shirabe/src/repository | |
| parent | 7715c98aaf3e3962cabbcf740e93fa817a2f8027 (diff) | |
| download | php-shirabe-7f83e785a77fbdbcada9c6714703d4e5801af82a.tar.gz php-shirabe-7f83e785a77fbdbcada9c6714703d4e5801af82a.tar.zst php-shirabe-7f83e785a77fbdbcada9c6714703d4e5801af82a.zip | |
refactor(io): unify IOInterface params to Rc<RefCell<dyn _>>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'crates/shirabe/src/repository')
10 files changed, 47 insertions, 18 deletions
diff --git a/crates/shirabe/src/repository/composer_repository.rs b/crates/shirabe/src/repository/composer_repository.rs index 9931a73..d39fd82 100644 --- a/crates/shirabe/src/repository/composer_repository.rs +++ b/crates/shirabe/src/repository/composer_repository.rs @@ -264,11 +264,12 @@ impl ComposerRepository { let base_url = base_url_trimmed.trim_end_matches('/').to_string(); assert!(!base_url.is_empty()); - // TODO(phase-b): Cache::new expects std::rc::Rc<std::cell::RefCell<dyn IOInterface>> but io is also stored in self.io; - // need shared ownership (Rc) for IOInterface. Using todo!() placeholder. - let cache: Cache = todo!( - "Cache::new requires std::rc::Rc<std::cell::RefCell<dyn IOInterface>> but io is also moved into self.io" + let cache_dir = format!( + "{}/{}", + config.get("cache-repo-dir").as_string().unwrap_or(""), + Preg::replace(r"{[^a-z0-9.]}i", "-", &Url::sanitize(url.clone()))?, ); + let cache = Cache::new(io.clone(), &cache_dir, Some("a-z0-9.$~"), None, false); let version_parser = VersionParser::new(); let loader = ArrayLoader::new(Some(version_parser.clone()), true); @@ -2963,7 +2964,7 @@ impl ComposerRepository { .as_array() .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) .unwrap_or_default(); - HttpDownloader::output_warnings(&*self.io.borrow(), &self.url, &data_local); + HttpDownloader::output_warnings(self.io.clone(), &self.url, &data_local); if let Some(ck) = cache_key_owned.as_ref() { if !ck.is_empty() && !self.cache.is_read_only() { @@ -3160,7 +3161,7 @@ impl ComposerRepository { .as_array() .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) .unwrap_or_default(); - HttpDownloader::output_warnings(&*self.io.borrow(), &self.url, &data); + HttpDownloader::output_warnings(self.io.clone(), &self.url, &data); let last_modified_date = response.get_header("last-modified"); response.collect(); @@ -3338,7 +3339,7 @@ impl ComposerRepository { .as_array() .map(|a| a.iter().map(|(k, v)| (k.clone(), (**v).clone())).collect()) .unwrap_or_default(); - HttpDownloader::output_warnings(&*self.io.borrow(), &self.url, &data); + HttpDownloader::output_warnings(self.io.clone(), &self.url, &data); let last_modified_date = response.get_header("last-modified"); response.collect(); diff --git a/crates/shirabe/src/repository/repository_factory.rs b/crates/shirabe/src/repository/repository_factory.rs index 1159da1..89334a1 100644 --- a/crates/shirabe/src/repository/repository_factory.rs +++ b/crates/shirabe/src/repository/repository_factory.rs @@ -10,6 +10,7 @@ use crate::config::Config; use crate::event_dispatcher::EventDispatcher; use crate::factory::Factory; use crate::io::IOInterface; +use crate::io::IOInterfaceMutable; use crate::json::JsonFile; use crate::repository::FilesystemRepository; use crate::repository::RepositoryInterfaceHandle; @@ -150,9 +151,9 @@ impl RepositoryFactory { Some(c) => c, None => std::rc::Rc::new(std::cell::RefCell::new(Factory::create_config(None, None)?)), }; - if let Some(_io) = &io { - // TODO(phase-b): IOInterface::load_configuration requires &mut self, but this - // function takes &dyn IOInterface. Wider refactor needed; skip for now. + if let Some(io) = &io { + io.borrow_mut() + .load_configuration(&mut *config.borrow_mut())?; } let mut owned_rm; diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs index ccd0c16..d5c4a89 100644 --- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs +++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs @@ -487,7 +487,12 @@ impl ForgejoDriver { } } - pub fn supports(io: &dyn IOInterface, config: &Config, url: &str, _deep: bool) -> bool { + pub fn supports( + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + config: &Config, + url: &str, + _deep: bool, + ) -> bool { let forgejo_url = ForgejoUrl::try_from(Some(url)); if forgejo_url.is_none() { return false; diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs index 207a138..1e34f21 100644 --- a/crates/shirabe/src/repository/vcs/fossil_driver.rs +++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs @@ -32,7 +32,7 @@ impl FossilDriver { // Ensure we are allowed to use this URL by config. self.inner.config.borrow_mut().prohibit_url_by_config( &self.inner.url, - Some(&*self.inner.io.borrow()), + Some(self.inner.io.clone()), &indexmap::IndexMap::new(), )?; diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs index 53e49fc..8a0dffd 100644 --- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs @@ -857,7 +857,12 @@ impl GitBitbucketDriver { } /// @inheritDoc - pub fn supports(io: &dyn IOInterface, _config: &Config, url: &str, _deep: bool) -> bool { + pub fn supports( + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + _config: &Config, + url: &str, + _deep: bool, + ) -> bool { if !Preg::is_match( r"#^https?://bitbucket\.org/([^/]+)/([^/]+?)(\.git|/?)?$#i", url, diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs index 665e2fb..01aa759 100644 --- a/crates/shirabe/src/repository/vcs/git_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_driver.rs @@ -536,7 +536,12 @@ impl crate::repository::vcs::VcsDriverInterface for GitDriver { Ok(()) } - fn supports(_io: &dyn IOInterface, _config: &Config, _url: &str, _deep: bool) -> bool { + fn supports( + _io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + _config: &Config, + _url: &str, + _deep: bool, + ) -> bool { todo!() } } diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index 5f8266c..0b9066b 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -934,7 +934,12 @@ impl GitHubDriver { Ok(self.branches.clone().unwrap_or_default()) } - pub fn supports(io: &dyn IOInterface, config: &Config, url: &str, _deep: bool) -> bool { + pub fn supports( + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + config: &Config, + url: &str, + _deep: bool, + ) -> bool { let mut matches: IndexMap<CaptureKey, String> = IndexMap::new(); if !Preg::is_match_strict_groups3( r"#^((?:https?|git)://([^/]+)/|git@([^:]+):/?)([^/]+)/([^/]+?)(?:\.git|/)?$#", diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index e31eb67..e8701bf 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -979,7 +979,12 @@ impl GitLabDriver { /// Uses the config `gitlab-domains` to see if the driver supports the url for the /// repository given. - pub fn supports(io: &dyn IOInterface, config: &Config, url: &str, _deep: bool) -> bool { + pub fn supports( + io: std::rc::Rc<std::cell::RefCell<dyn IOInterface>>, + config: &Config, + url: &str, + _deep: bool, + ) -> bool { let mut match_: IndexMap<CaptureKey, String> = IndexMap::new(); if !Preg::is_match_strict_groups3(Self::URL_REGEX, url, Some(&mut match_)).unwrap_or(false) { diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs index ab3bd0c..9079d71 100644 --- a/crates/shirabe/src/repository/vcs/hg_driver.rs +++ b/crates/shirabe/src/repository/vcs/hg_driver.rs @@ -62,7 +62,7 @@ impl HgDriver { self.inner.config.borrow_mut().prohibit_url_by_config( &self.inner.url, - Some(&*self.inner.io.borrow()), + Some(self.inner.io.clone()), &indexmap::IndexMap::new(), )?; diff --git a/crates/shirabe/src/repository/vcs/vcs_driver_interface.rs b/crates/shirabe/src/repository/vcs/vcs_driver_interface.rs index 7ace36a..c002dc5 100644 --- a/crates/shirabe/src/repository/vcs/vcs_driver_interface.rs +++ b/crates/shirabe/src/repository/vcs/vcs_driver_interface.rs @@ -5,6 +5,8 @@ use crate::io::IOInterface; use chrono::{DateTime, Utc}; use indexmap::IndexMap; use shirabe_php_shim::PhpMixed; +use std::cell::RefCell; +use std::rc::Rc; pub trait VcsDriverInterface: std::fmt::Debug { fn initialize(&mut self) -> anyhow::Result<()>; @@ -34,7 +36,7 @@ pub trait VcsDriverInterface: std::fmt::Debug { fn cleanup(&mut self) -> anyhow::Result<()>; - fn supports(io: &dyn IOInterface, config: &Config, url: &str, deep: bool) -> bool + fn supports(io: Rc<RefCell<dyn IOInterface>>, config: &Config, url: &str, deep: bool) -> bool where Self: Sized; } |
