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 --- .../shirabe/src/downloader/perforce_downloader.rs | 44 ++++++++++++++++------ 1 file changed, 32 insertions(+), 12 deletions(-) (limited to 'crates/shirabe/src/downloader/perforce_downloader.rs') diff --git a/crates/shirabe/src/downloader/perforce_downloader.rs b/crates/shirabe/src/downloader/perforce_downloader.rs index fcea57c..e33b159 100644 --- a/crates/shirabe/src/downloader/perforce_downloader.rs +++ b/crates/shirabe/src/downloader/perforce_downloader.rs @@ -1,7 +1,9 @@ //! ref: composer/src/Composer/Downloader/PerforceDownloader.php 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; @@ -124,18 +126,6 @@ impl PerforceDownloader { self.do_install(target, path, url).await } - pub fn get_local_changes( - &self, - _package: PackageInterfaceHandle, - _path: String, - ) -> Option { - self.inner - .io - .write_error("Perforce driver does not check for local changes before overriding"); - - None - } - pub(crate) fn get_commit_logs( &mut self, from_reference: String, @@ -159,11 +149,41 @@ impl PerforceDownloader { } } +impl ChangeReportInterface for PerforceDownloader { + fn get_local_changes( + &self, + _package: PackageInterfaceHandle, + _path: &str, + ) -> Result> { + self.inner + .io + .write_error("Perforce driver does not check for local changes before overriding"); + + Ok(None) + } +} + +impl VcsCapableDownloaderInterface for PerforceDownloader { + 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. PerforceDownloader extends VcsDownloader // which implements DownloaderInterface in PHP. Delegating each trait method to todo!() until the // inner VcsDownloaderBase exposes the matching impl surface. #[async_trait::async_trait(?Send)] impl DownloaderInterface for PerforceDownloader { + 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) + } + fn get_installation_source(&self) -> String { todo!() } -- cgit v1.3.1