diff options
| author | nsfisis <nsfisis@gmail.com> | 2026-05-10 20:31:00 +0900 |
|---|---|---|
| committer | nsfisis <nsfisis@gmail.com> | 2026-05-10 20:31:00 +0900 |
| commit | 59bab6efee41a196b0d9d392167c536abbe068ba (patch) | |
| tree | f36ca1c8534cf703b357d3f9090ba85efd9a9b74 /crates/mozart-core/src/downloader/hg_downloader.rs | |
| parent | 24bb31c109332ae982b7091ffcd5183442ce6f6f (diff) | |
| download | php-mozart-59bab6efee41a196b0d9d392167c536abbe068ba.tar.gz php-mozart-59bab6efee41a196b0d9d392167c536abbe068ba.tar.zst php-mozart-59bab6efee41a196b0d9d392167c536abbe068ba.zip | |
refactor(downloader): introduce top-level downloader module
Move VCS downloaders and DownloadManager out of vcs/repository into a
new top-level downloader module mirroring Composer\Downloader, and add
stub types for the remaining Composer downloader hierarchy (file,
archive variants, path, perforce, fossil, exceptions, interfaces) so
future ports have a home.
Diffstat (limited to 'crates/mozart-core/src/downloader/hg_downloader.rs')
| -rw-r--r-- | crates/mozart-core/src/downloader/hg_downloader.rs | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/crates/mozart-core/src/downloader/hg_downloader.rs b/crates/mozart-core/src/downloader/hg_downloader.rs new file mode 100644 index 0000000..9fb918e --- /dev/null +++ b/crates/mozart-core/src/downloader/hg_downloader.rs @@ -0,0 +1,84 @@ +use anyhow::Result; +use std::path::Path; + +use crate::{downloader::VcsDownloader, vcs::util::hg::HgUtil}; + +/// Mercurial downloader using clone/pull/update. +pub struct HgDownloader { + hg_util: HgUtil, +} + +impl HgDownloader { + pub fn new(hg_util: HgUtil) -> Self { + Self { hg_util } + } +} + +impl VcsDownloader for HgDownloader { + fn download(&self, _url: &str, _reference: &str, _target: &Path) -> Result<()> { + Ok(()) + } + + fn install(&self, url: &str, reference: &str, target: &Path) -> Result<()> { + let target_str = target.to_string_lossy().to_string(); + self.hg_util + .execute(&["clone", "--", url, &target_str], None)?; + self.hg_util + .execute(&["update", "-r", reference], Some(target))?; + Ok(()) + } + + fn update(&self, url: &str, _old_ref: &str, new_ref: &str, target: &Path) -> Result<()> { + self.hg_util.execute(&["pull", url], Some(target))?; + self.hg_util + .execute(&["update", "-r", new_ref], Some(target))?; + Ok(()) + } + + fn remove(&self, target: &Path) -> Result<()> { + if target.exists() { + std::fs::remove_dir_all(target)?; + } + Ok(()) + } + + fn get_local_changes(&self, target: &Path) -> Result<Option<String>> { + if !target.join(".hg").is_dir() { + return Ok(None); + } + let output = self.hg_util.execute(&["st"], Some(target))?; + let trimmed = output.stdout.trim(); + if trimmed.is_empty() { + Ok(None) + } else { + Ok(Some(trimmed.to_string())) + } + } + + fn commit_logs(&self, from: &str, to: &str, target: &Path) -> Result<String> { + let range = format!("{from}:{to}"); + let output = self.hg_util.execute( + &[ + "log", + "-r", + &range, + "--template", + "{rev}:{node|short} {desc|firstline}\\n", + ], + Some(target), + )?; + Ok(output.stdout) + } + + fn is_change_report(&self) -> bool { + true + } + + fn is_vcs_capable_downloader(&self) -> bool { + true + } + + fn is_dvcs_downloader(&self) -> bool { + false + } +} |
