From dd19bda86582e9f6a4ba1879112d9ab3ba8432f6 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Wed, 3 Jun 2026 23:24:52 +0900 Subject: feat(downloader): implement ChangeReport/VcsCapable for VCS downloaders Git/Svn/Hg/Fossil/Perforce now implement ChangeReportInterface and VcsCapableDownloaderInterface and override the as_* downcasts, so PHP-style instanceof checks on a DownloaderInterface resolve to these sub-interfaces. get_local_changes lives directly in the ChangeReportInterface impl (returning anyhow::Result; GitDownloader now surfaces a RuntimeException instead of panicking on a failed git status). get_vcs_reference is shared via a new VcsDownloaderBase helper that each downloader delegates to. Co-Authored-By: Claude Opus 4.8 --- crates/shirabe/src/downloader/svn_downloader.rs | 70 +++++++++++++++++-------- 1 file changed, 48 insertions(+), 22 deletions(-) (limited to 'crates/shirabe/src/downloader/svn_downloader.rs') diff --git a/crates/shirabe/src/downloader/svn_downloader.rs b/crates/shirabe/src/downloader/svn_downloader.rs index 98456a4..8ac3e99 100644 --- a/crates/shirabe/src/downloader/svn_downloader.rs +++ b/crates/shirabe/src/downloader/svn_downloader.rs @@ -6,7 +6,9 @@ use shirabe_external_packages::composer::pcre::{CaptureKey, Preg}; use shirabe_php_shim::{PhpMixed, RuntimeException, is_dir, version_compare}; use crate::config::Config; +use crate::downloader::ChangeReportInterface; use crate::downloader::DownloaderInterface; +use crate::downloader::VcsCapableDownloaderInterface; use crate::downloader::VcsDownloaderBase; use crate::io::IOInterface; use crate::io::IOInterfaceImmutable; @@ -158,27 +160,6 @@ impl SvnDownloader { Ok(None) } - pub fn get_local_changes(&self, package: PackageInterfaceHandle, path: &str) -> Option { - if !self.has_metadata_repository(path) { - return None; - } - - let mut output = String::new(); - self.inner.process.borrow_mut().execute_args( - &["svn", "status", "--ignore-externals"] - .map(|s| s.to_string()) - .to_vec(), - &mut output, - Some(path.to_string()), - ); - - if Preg::is_match("{^ *[^X ] +}m", &output).unwrap_or(false) { - Some(output) - } else { - None - } - } - pub(crate) fn execute( &self, package: PackageInterfaceHandle, @@ -211,7 +192,7 @@ impl SvnDownloader { path: &str, update: bool, ) -> anyhow::Result> { - let changes = self.get_local_changes(package.clone(), path); + let changes = self.get_local_changes(package.clone(), path)?; if changes.is_none() { return Ok(None); } @@ -432,6 +413,41 @@ impl SvnDownloader { } } +impl ChangeReportInterface for SvnDownloader { + fn get_local_changes( + &self, + _package: PackageInterfaceHandle, + path: &str, + ) -> anyhow::Result> { + if !self.has_metadata_repository(path) { + return Ok(None); + } + + let mut output = String::new(); + self.inner.process.borrow_mut().execute_args( + &["svn", "status", "--ignore-externals"] + .map(|s| s.to_string()) + .to_vec(), + &mut output, + Some(path.to_string()), + ); + + Ok( + if Preg::is_match("{^ *[^X ] +}m", &output).unwrap_or(false) { + Some(output) + } else { + None + }, + ) + } +} + +impl VcsCapableDownloaderInterface for SvnDownloader { + fn get_vcs_reference(&self, package: PackageInterfaceHandle, path: String) -> Option { + self.inner.get_vcs_reference(package, &path) + } +} + // TODO(phase-b): wire up VcsDownloader trait properly. SvnDownloader extends VcsDownloader which // implements DownloaderInterface in PHP. Delegating each trait method to todo!() until the inner // VcsDownloaderBase exposes the matching impl surface. @@ -441,6 +457,16 @@ impl DownloaderInterface for SvnDownloader { todo!() } + fn as_change_report_interface(&self) -> Option<&dyn crate::downloader::ChangeReportInterface> { + Some(self) + } + + fn as_vcs_capable_downloader_interface( + &self, + ) -> Option<&dyn crate::downloader::VcsCapableDownloaderInterface> { + Some(self) + } + async fn download( &self, _package: PackageInterfaceHandle, -- cgit v1.3.1