From c028a9d5c737de5d2b259638a0a76b999364a262 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 6 Jun 2026 22:40:30 +0900 Subject: feat(vcs): implement VcsDriverInterface for all VCS drivers Reconcile the VcsDriverInterface trait with the concrete drivers so every driver implements it as in PHP, where each driver extends VcsDriver. - Make cache-mutating getters take &mut self in the trait, matching the inherent methods' lazy-cache semantics; update vcs_repository consumers. - Change supports() to take Rc> and return Result, completing GitDriver::supports deep ls-remote and its config wiring. - Add base get_composer_information to Git/Hg/Fossil/Perforce and an impl VcsDriverInterface block to every driver, delegating to inherent methods and absorbing type differences in the impl. Co-Authored-By: Claude Opus 4.8 (1M context) --- crates/shirabe/src/repository/vcs/fossil_driver.rs | 103 +++++++++++++++++++-- 1 file changed, 96 insertions(+), 7 deletions(-) (limited to 'crates/shirabe/src/repository/vcs/fossil_driver.rs') diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs index 1e34f21..5b7ccc1 100644 --- a/crates/shirabe/src/repository/vcs/fossil_driver.rs +++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs @@ -8,6 +8,7 @@ use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_file, is_ use crate::cache::Cache; use crate::config::Config; +use crate::downloader::TransportException; use crate::io::IOInterface; use crate::io::IOInterfaceImmutable; use crate::repository::vcs::VcsDriverBase; @@ -292,28 +293,28 @@ impl FossilDriver { pub fn supports( io: std::rc::Rc>, - config: &Config, + _config: std::rc::Rc>, url: &str, deep: bool, - ) -> bool { + ) -> anyhow::Result { if Preg::is_match( r"#(^(?:https?|ssh)://(?:[^@]@)?(?:chiselapp\.com|fossil\.))#i", url, ) .unwrap_or(false) { - return true; + return Ok(true); } if Preg::is_match(r"!/fossil/|\.fossil!", url).unwrap_or(false) { - return true; + return Ok(true); } // local filesystem if Filesystem::is_local_path(url) { let url = Filesystem::get_platform_path(url); if !is_dir(&url) { - return false; + return Ok(false); } let mut process = ProcessExecutor::new(Some(io)); @@ -324,10 +325,98 @@ impl FossilDriver { Some(url), ) == 0 { - return true; + return Ok(true); } } - false + Ok(false) + } + + pub fn get_composer_information( + &mut self, + identifier: &str, + ) -> anyhow::Result>> { + if let Some(cached) = self.inner.read_cached_composer(identifier)? { + return Ok(cached); + } + + let file_content = self.get_file_content("composer.json", identifier)?; + let composer = + VcsDriverBase::finish_base_composer_information(identifier, file_content, || { + self.get_change_date(identifier) + })?; + + self.inner.write_cached_composer(identifier, composer) + } +} + +impl crate::repository::vcs::VcsDriverInterface for FossilDriver { + fn initialize(&mut self) -> anyhow::Result<()> { + FossilDriver::initialize(self) + } + + fn get_composer_information( + &mut self, + identifier: &str, + ) -> anyhow::Result>> { + FossilDriver::get_composer_information(self, identifier) + } + + fn get_file_content(&mut self, file: &str, identifier: &str) -> anyhow::Result> { + FossilDriver::get_file_content(self, file, identifier) + } + + fn get_change_date(&mut self, identifier: &str) -> anyhow::Result>> { + FossilDriver::get_change_date(self, identifier) + } + + fn get_root_identifier(&mut self) -> anyhow::Result { + Ok(FossilDriver::get_root_identifier(self)) + } + + fn get_branches(&mut self) -> anyhow::Result> { + FossilDriver::get_branches(self) + } + + fn get_tags(&mut self) -> anyhow::Result> { + FossilDriver::get_tags(self) + } + + fn get_dist(&self, identifier: &str) -> anyhow::Result>> { + Ok(FossilDriver::get_dist(self, identifier)) + } + + fn get_source(&self, identifier: &str) -> anyhow::Result> { + Ok(FossilDriver::get_source(self, identifier)) + } + + fn get_url(&self) -> String { + FossilDriver::get_url(self) + } + + fn has_composer_file(&mut self, identifier: &str) -> anyhow::Result { + match self.get_composer_information(identifier) { + Ok(info) => Ok(info.is_some()), + Err(e) => { + if e.downcast_ref::().is_some() { + Ok(false) + } else { + Err(e) + } + } + } + } + + fn cleanup(&mut self) -> anyhow::Result<()> { + Ok(()) + } + + fn supports( + io: std::rc::Rc>, + config: std::rc::Rc>, + url: &str, + deep: bool, + ) -> anyhow::Result { + FossilDriver::supports(io, config, url, deep) } } -- cgit v1.3.1