diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-17 13:56:15 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-17 13:59:31 +0900 |
| commit | a9bb49c7d685dd82feaf4050f756fdf590315200 (patch) | |
| tree | 0242a737e8280fe9e25c38bb7a6f844d2eff623c /crates/shirabe/src/repository | |
| parent | 15b1be89eb168a30e96459c6a5307afcb7323bbc (diff) | |
| download | php-shirabe-a9bb49c7d685dd82feaf4050f756fdf590315200.tar.gz php-shirabe-a9bb49c7d685dd82feaf4050f756fdf590315200.tar.zst php-shirabe-a9bb49c7d685dd82feaf4050f756fdf590315200.zip | |
fix(compile): implement abstract class traits across all types
Implement BaseCommand trait and other abstract class traits across
all command, downloader, io, package, and VCS driver types. Also
fix trait method signatures for composer_mut and io_mut to return
mutable references to Option rather than Option of mutable references.
Diffstat (limited to 'crates/shirabe/src/repository')
10 files changed, 80 insertions, 19 deletions
diff --git a/crates/shirabe/src/repository/vcs/forgejo_driver.rs b/crates/shirabe/src/repository/vcs/forgejo_driver.rs index 74f1e119..c03f2177 100644 --- a/crates/shirabe/src/repository/vcs/forgejo_driver.rs +++ b/crates/shirabe/src/repository/vcs/forgejo_driver.rs @@ -13,7 +13,7 @@ use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::forgejo::Forgejo; use crate::util::forgejo_repository_data::ForgejoRepositoryData; use crate::util::forgejo_url::ForgejoUrl; @@ -21,7 +21,7 @@ use crate::util::http::response::Response; #[derive(Debug)] pub struct ForgejoDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) forgejo_url: Option<ForgejoUrl>, pub(crate) repository_data: Option<ForgejoRepositoryData>, pub(crate) git_driver: Option<GitDriver>, @@ -500,7 +500,7 @@ impl ForgejoDriver { fn setup_git_driver(&mut self, url: &str) -> Result<()> { let mut git_driver = GitDriver { - inner: VcsDriver::new( + inner: VcsDriverBase::new( { let mut m = IndexMap::new(); m.insert("url".to_string(), PhpMixed::String(url.to_string())); diff --git a/crates/shirabe/src/repository/vcs/fossil_driver.rs b/crates/shirabe/src/repository/vcs/fossil_driver.rs index 6e99f5f1..f1e6a89a 100644 --- a/crates/shirabe/src/repository/vcs/fossil_driver.rs +++ b/crates/shirabe/src/repository/vcs/fossil_driver.rs @@ -8,13 +8,13 @@ use shirabe_php_shim::{PhpMixed, RuntimeException, dirname, is_dir, is_file, is_ use crate::cache::Cache; use crate::config::Config; use crate::io::io_interface::IOInterface; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::filesystem::Filesystem; use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct FossilDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) tags: Option<IndexMap<String, String>>, pub(crate) branches: Option<IndexMap<String, String>>, pub(crate) root_identifier: Option<String>, diff --git a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs index dc3b5f3c..0e16ced9 100644 --- a/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs @@ -16,14 +16,14 @@ use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::repository::vcs::vcs_driver_interface::VcsDriverInterface; use crate::util::bitbucket::Bitbucket; use crate::util::http::response::Response; #[derive(Debug)] pub struct GitBitbucketDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, /// @var string pub(crate) owner: String, /// @var string diff --git a/crates/shirabe/src/repository/vcs/git_driver.rs b/crates/shirabe/src/repository/vcs/git_driver.rs index 0f8f841e..48aa4c17 100644 --- a/crates/shirabe/src/repository/vcs/git_driver.rs +++ b/crates/shirabe/src/repository/vcs/git_driver.rs @@ -12,7 +12,7 @@ use shirabe_php_shim::{ use crate::cache::Cache; use crate::config::Config; use crate::io::io_interface::IOInterface; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::filesystem::Filesystem; use crate::util::git::Git as GitUtil; use crate::util::process_executor::ProcessExecutor; @@ -20,7 +20,7 @@ use crate::util::url::Url; #[derive(Debug)] pub struct GitDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) tags: Option<IndexMap<String, String>>, pub(crate) branches: Option<IndexMap<String, String>>, pub(crate) root_identifier: Option<String>, diff --git a/crates/shirabe/src/repository/vcs/github_driver.rs b/crates/shirabe/src/repository/vcs/github_driver.rs index bd2e2ade..233e3ea5 100644 --- a/crates/shirabe/src/repository/vcs/github_driver.rs +++ b/crates/shirabe/src/repository/vcs/github_driver.rs @@ -16,13 +16,13 @@ use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::github::GitHub; use crate::util::http::response::Response; #[derive(Debug)] pub struct GitHubDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) owner: String, pub(crate) repository: String, /// @var array<int|string, string> Map of tag name to identifier diff --git a/crates/shirabe/src/repository/vcs/gitlab_driver.rs b/crates/shirabe/src/repository/vcs/gitlab_driver.rs index cb0d0a2d..583f2218 100644 --- a/crates/shirabe/src/repository/vcs/gitlab_driver.rs +++ b/crates/shirabe/src/repository/vcs/gitlab_driver.rs @@ -16,7 +16,7 @@ use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; use crate::repository::vcs::git_driver::GitDriver; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::gitlab::GitLab; use crate::util::http::response::Response; use crate::util::http_downloader::HttpDownloader; @@ -24,7 +24,7 @@ use crate::util::http_downloader::HttpDownloader; /// Driver for GitLab API, use the Git driver for local checkouts. #[derive(Debug)] pub struct GitLabDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, /// @phpstan-var 'https'|'http' scheme: String, namespace: String, diff --git a/crates/shirabe/src/repository/vcs/hg_driver.rs b/crates/shirabe/src/repository/vcs/hg_driver.rs index 6b32a0ac..a8fc70af 100644 --- a/crates/shirabe/src/repository/vcs/hg_driver.rs +++ b/crates/shirabe/src/repository/vcs/hg_driver.rs @@ -3,7 +3,7 @@ use crate::cache::Cache; use crate::config::Config; use crate::io::io_interface::IOInterface; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::filesystem::Filesystem; use crate::util::hg::Hg as HgUtils; use crate::util::url::Url; @@ -14,7 +14,7 @@ use shirabe_php_shim::{RuntimeException, dirname, is_dir, is_writable}; #[derive(Debug)] pub struct HgDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, pub(crate) tags: Option<IndexMap<String, String>>, pub(crate) branches: Option<IndexMap<String, String>>, pub(crate) root_identifier: Option<String>, diff --git a/crates/shirabe/src/repository/vcs/perforce_driver.rs b/crates/shirabe/src/repository/vcs/perforce_driver.rs index cd3b32b5..ee09deed 100644 --- a/crates/shirabe/src/repository/vcs/perforce_driver.rs +++ b/crates/shirabe/src/repository/vcs/perforce_driver.rs @@ -7,14 +7,14 @@ use shirabe_php_shim::{BadMethodCallException, PhpMixed, RuntimeException}; use crate::cache::Cache; use crate::config::Config; use crate::io::io_interface::IOInterface; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::http::response::Response; use crate::util::perforce::Perforce; use crate::util::process_executor::ProcessExecutor; #[derive(Debug)] pub struct PerforceDriver { - inner: VcsDriver, + inner: VcsDriverBase, pub(crate) depot: String, pub(crate) branch: String, pub(crate) perforce: Option<Perforce>, diff --git a/crates/shirabe/src/repository/vcs/svn_driver.rs b/crates/shirabe/src/repository/vcs/svn_driver.rs index 7c32e4ab..0a05d844 100644 --- a/crates/shirabe/src/repository/vcs/svn_driver.rs +++ b/crates/shirabe/src/repository/vcs/svn_driver.rs @@ -14,7 +14,7 @@ use crate::config::Config; use crate::downloader::transport_exception::TransportException; use crate::io::io_interface::IOInterface; use crate::json::json_file::JsonFile; -use crate::repository::vcs::vcs_driver::VcsDriver; +use crate::repository::vcs::vcs_driver::VcsDriverBase; use crate::util::filesystem::Filesystem; use crate::util::process_executor::ProcessExecutor; use crate::util::svn::Svn as SvnUtil; @@ -22,7 +22,7 @@ use crate::util::url::Url; #[derive(Debug)] pub struct SvnDriver { - pub(crate) inner: VcsDriver, + pub(crate) inner: VcsDriverBase, /// @var string pub(crate) base_url: String, /// @var array<int|string, string> Map of tag name to identifier diff --git a/crates/shirabe/src/repository/vcs/vcs_driver.rs b/crates/shirabe/src/repository/vcs/vcs_driver.rs index 3195822d..162792e7 100644 --- a/crates/shirabe/src/repository/vcs/vcs_driver.rs +++ b/crates/shirabe/src/repository/vcs/vcs_driver.rs @@ -17,6 +17,67 @@ use crate::util::http::response::Response; use crate::util::http_downloader::HttpDownloader; use crate::util::process_executor::ProcessExecutor; +#[derive(Debug)] +pub struct VcsDriverBase { + pub url: String, + pub origin_url: String, + pub repo_config: IndexMap<String, PhpMixed>, + pub io: Box<dyn IOInterface>, + pub config: Config, + pub process: ProcessExecutor, + pub http_downloader: HttpDownloader, + pub info_cache: IndexMap<String, Option<IndexMap<String, PhpMixed>>>, + pub cache: Option<Cache>, +} + +impl VcsDriverBase { + pub fn new( + repo_config: IndexMap<String, PhpMixed>, + io: Box<dyn IOInterface>, + config: Config, + http_downloader: HttpDownloader, + process: ProcessExecutor, + ) -> Self { + let url = repo_config + .get("url") + .and_then(|v| v.as_string()) + .unwrap_or("") + .to_string(); + let origin_url = url.clone(); + Self { + url, + origin_url, + repo_config, + io, + config, + process, + http_downloader, + info_cache: IndexMap::new(), + cache: None, + } + } + + pub fn should_cache(&self, identifier: &str) -> bool { + self.cache.is_some() && Preg::is_match("{^[a-f0-9]{40}$}iD", identifier).unwrap_or(false) + } + + pub fn get_scheme(&self) -> &str { + if extension_loaded("openssl") { + return "https"; + } + "http" + } + + pub fn get_contents(&self, url: &str) -> anyhow::Result<Response, TransportException> { + let options = self + .repo_config + .get("options") + .cloned() + .unwrap_or(PhpMixed::Array(IndexMap::new())); + self.http_downloader.get(url, &options) + } +} + // TODO(phase-b): the constructor is `final` in PHP; concrete implementations must replicate the // initialization logic (local-path normalization etc.) from the original new() body. pub trait VcsDriver: VcsDriverInterface { |
