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/gitlab_driver.rs | 92 ++++++++++++++++++++-- 1 file changed, 85 insertions(+), 7 deletions(-) (limited to 'crates/shirabe/src/repository/vcs/gitlab_driver.rs') diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index 3e2cd38..84a569f 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -972,14 +972,14 @@ impl GitLabDriver { /// repository given. pub fn supports( io: std::rc::Rc>, - config: &Config, + config: std::rc::Rc>, url: &str, _deep: bool, - ) -> bool { + ) -> anyhow::Result { let mut match_: IndexMap = IndexMap::new(); if !Preg::is_match_strict_groups3(Self::URL_REGEX, url, Some(&mut match_)).unwrap_or(false) { - return false; + return Ok(false); } let scheme = match_ @@ -1005,14 +1005,14 @@ impl GitLabDriver { ); if Self::determine_origin( - &config.get("gitlab-domains"), + &config.borrow().get("gitlab-domains"), guessed_domain, &mut url_parts, match_.get(&CaptureKey::ByName("port".to_string())).cloned(), ) .is_none() { - return false; + return Ok(false); } if scheme == "https" && !extension_loaded("openssl") { @@ -1025,10 +1025,10 @@ impl GitLabDriver { io_interface::VERBOSE, ); - return false; + return Ok(false); } - true + Ok(true) } /// Gives back the loaded /projects// result @@ -1122,3 +1122,81 @@ impl GitLabDriver { None } } + +impl crate::repository::vcs::VcsDriverInterface for GitLabDriver { + fn initialize(&mut self) -> anyhow::Result<()> { + GitLabDriver::initialize(self) + } + + fn get_composer_information( + &mut self, + identifier: &str, + ) -> anyhow::Result>> { + GitLabDriver::get_composer_information(self, identifier) + } + + fn get_file_content(&mut self, file: &str, identifier: &str) -> anyhow::Result> { + GitLabDriver::get_file_content(self, file, identifier) + } + + fn get_change_date(&mut self, identifier: &str) -> anyhow::Result>> { + GitLabDriver::get_change_date(self, identifier) + } + + fn get_root_identifier(&mut self) -> anyhow::Result { + GitLabDriver::get_root_identifier(self) + } + + fn get_branches(&mut self) -> anyhow::Result> { + GitLabDriver::get_branches(self) + } + + fn get_tags(&mut self) -> anyhow::Result> { + GitLabDriver::get_tags(self) + } + + fn get_dist(&self, identifier: &str) -> anyhow::Result>> { + Ok(GitLabDriver::get_dist(self, identifier).map(|m| { + m.into_iter() + .map(|(k, v)| (k, v.as_string().unwrap_or("").to_string())) + .collect() + })) + } + + fn get_source(&self, identifier: &str) -> anyhow::Result> { + Ok(GitLabDriver::get_source(self, identifier) + .into_iter() + .map(|(k, v)| (k, v.as_string().unwrap_or("").to_string())) + .collect()) + } + + fn get_url(&self) -> String { + GitLabDriver::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 { + GitLabDriver::supports(io, config, url, deep) + } +} -- cgit v1.3.1