From d8ecb21a7931ec6f1d7b447d0c15f53de32bfc45 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Mon, 23 Feb 2026 12:10:44 +0900 Subject: refactor(vcs): convert VcsDriver trait to native async Replace manual tokio::runtime::Handle::current().block_on() calls with native async/await throughout all VCS drivers. Introduce AnyVcsDriver enum for static dispatch to avoid dyn trait with async methods. Co-Authored-By: Claude Opus 4.6 --- crates/mozart-vcs/src/driver/hg.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'crates/mozart-vcs/src/driver/hg.rs') diff --git a/crates/mozart-vcs/src/driver/hg.rs b/crates/mozart-vcs/src/driver/hg.rs index 7bfb07e..f884c50 100644 --- a/crates/mozart-vcs/src/driver/hg.rs +++ b/crates/mozart-vcs/src/driver/hg.rs @@ -49,7 +49,7 @@ impl HgDriver { } impl VcsDriver for HgDriver { - fn initialize(&mut self) -> Result<()> { + async fn initialize(&mut self) -> Result<()> { let cache_dir = self.config.cache_dir.join("hg"); std::fs::create_dir_all(&cache_dir)?; let repo_dir = cache_dir.join(crate::util::git::GitUtil::sanitize_url(&self.url)); @@ -83,7 +83,7 @@ impl VcsDriver for HgDriver { self.root_identifier.as_deref().unwrap_or("default") } - fn branches(&mut self) -> Result<&BTreeMap> { + async fn branches(&mut self) -> Result<&BTreeMap> { if self.branches.is_none() { let repo_dir = self.get_repo_dir()?.clone(); let mut branches = BTreeMap::new(); @@ -121,7 +121,7 @@ impl VcsDriver for HgDriver { Ok(self.branches.as_ref().unwrap()) } - fn tags(&mut self) -> Result<&BTreeMap> { + async fn tags(&mut self) -> Result<&BTreeMap> { if self.tags.is_none() { let repo_dir = self.get_repo_dir()?.clone(); let output = self.hg_util.execute(&["tags", "-q"], Some(&repo_dir))?; @@ -142,18 +142,21 @@ impl VcsDriver for HgDriver { Ok(self.tags.as_ref().unwrap()) } - fn composer_information(&mut self, identifier: &str) -> Result> { + async fn composer_information( + &mut self, + identifier: &str, + ) -> Result> { if let Some(cached) = self.info_cache.get(identifier) { return Ok(cached.clone()); } - let content = self.file_content("composer.json", identifier)?; + let content = self.file_content("composer.json", identifier).await?; let value = content.and_then(|c| serde_json::from_str(&c).ok()); self.info_cache .insert(identifier.to_string(), value.clone()); Ok(value) } - fn file_content(&self, file: &str, identifier: &str) -> Result> { + async fn file_content(&self, file: &str, identifier: &str) -> Result> { let repo_dir = self.get_repo_dir()?; let output = self .hg_util @@ -165,7 +168,7 @@ impl VcsDriver for HgDriver { } } - fn change_date(&self, identifier: &str) -> Result> { + async fn change_date(&self, identifier: &str) -> Result> { let repo_dir = self.get_repo_dir()?; let output = self.hg_util.execute( &["log", "-r", identifier, "--template", "{date|isodatesec}"], @@ -179,7 +182,7 @@ impl VcsDriver for HgDriver { } } - fn dist(&self, _identifier: &str) -> Result> { + async fn dist(&self, _identifier: &str) -> Result> { Ok(None) } @@ -195,7 +198,7 @@ impl VcsDriver for HgDriver { &self.url } - fn cleanup(&mut self) -> Result<()> { + async fn cleanup(&mut self) -> Result<()> { Ok(()) } } -- cgit v1.3.1