aboutsummaryrefslogtreecommitdiffhomepage
path: root/crates/shirabe/src/repository
diff options
context:
space:
mode:
Diffstat (limited to 'crates/shirabe/src/repository')
-rw-r--r--crates/shirabe/src/repository/vcs/forgejo_driver.rs6
-rw-r--r--crates/shirabe/src/repository/vcs/fossil_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/git_bitbucket_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/git_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/github_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/gitlab_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/hg_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/perforce_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/svn_driver.rs4
-rw-r--r--crates/shirabe/src/repository/vcs/vcs_driver.rs61
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 74f1e11..c03f217 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 6e99f5f..f1e6a89 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 dc3b5f3..0e16ced 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 0f8f841..48aa4c1 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 bd2e2ad..233e3ea 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 cb0d0a2..583f221 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 6b32a0a..a8fc70a 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 cd3b32b..ee09dee 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 7c32e4a..0a05d84 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 3195822..162792e 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 {