From 918dd3fa3747700c05c1afc22ba16f89efac10a1 Mon Sep 17 00:00:00 2001 From: "Alexis (Poliorcetics) Bourget" Date: Sat, 27 Apr 2024 14:36:44 +0200 Subject: [PATCH] cleanup: remove dummy diff provider, it's the exact same as not having one --- helix-vcs/src/git/test.rs | 2 +- helix-vcs/src/lib.rs | 45 ++++++--------------------------------- 2 files changed, 7 insertions(+), 40 deletions(-) diff --git a/helix-vcs/src/git/test.rs b/helix-vcs/src/git/test.rs index 0f928204a..cb3397323 100644 --- a/helix-vcs/src/git/test.rs +++ b/helix-vcs/src/git/test.rs @@ -2,7 +2,7 @@ use std::{fs::File, io::Write, path::Path, process::Command}; use tempfile::TempDir; -use crate::Git; +use crate::git::Git; fn exec_git_cmd(args: &str, git_dir: &Path) { let res = Command::new("git") diff --git a/helix-vcs/src/lib.rs b/helix-vcs/src/lib.rs index 7225c38eb..6382928d4 100644 --- a/helix-vcs/src/lib.rs +++ b/helix-vcs/src/lib.rs @@ -1,15 +1,10 @@ -use anyhow::{anyhow, bail, Result}; +use anyhow::{anyhow, Result}; use arc_swap::ArcSwap; use std::{ path::{Path, PathBuf}, sync::Arc, }; -#[cfg(feature = "git")] -pub use git::Git; -#[cfg(not(feature = "git"))] -pub use Dummy as Git; - #[cfg(feature = "git")] mod git; @@ -21,33 +16,6 @@ mod status; pub use status::FileChange; -#[doc(hidden)] -#[derive(Clone, Copy)] -pub struct Dummy; -impl Dummy { - fn get_diff_base(&self, _file: &Path) -> Result> { - bail!("helix was compiled without git support") - } - - fn get_current_head_name(&self, _file: &Path) -> Result>>> { - bail!("helix was compiled without git support") - } - - fn for_each_changed_file( - &self, - _cwd: &Path, - _f: impl Fn(Result) -> bool, - ) -> Result<()> { - bail!("helix was compiled without git support") - } -} - -impl From for DiffProvider { - fn from(value: Dummy) -> Self { - DiffProvider::Dummy(value) - } -} - #[derive(Clone)] pub struct DiffProviderRegistry { providers: Vec, @@ -104,7 +72,10 @@ impl Default for DiffProviderRegistry { fn default() -> Self { // currently only git is supported // TODO make this configurable when more providers are added - let providers = vec![Git.into()]; + let providers = vec![ + #[cfg(feature = "git")] + git::Git.into(), + ]; DiffProviderRegistry { providers } } } @@ -113,15 +84,13 @@ impl Default for DiffProviderRegistry { /// cloning [DiffProviderRegistry] as `Clone` cannot be used in trait objects. #[derive(Clone)] pub enum DiffProvider { - Dummy(Dummy), #[cfg(feature = "git")] - Git(Git), + Git(git::Git), } impl DiffProvider { fn get_diff_base(&self, file: &Path) -> Result> { match self { - Self::Dummy(inner) => inner.get_diff_base(file), #[cfg(feature = "git")] Self::Git(inner) => inner.get_diff_base(file), } @@ -129,7 +98,6 @@ impl DiffProvider { fn get_current_head_name(&self, file: &Path) -> Result>>> { match self { - Self::Dummy(inner) => inner.get_current_head_name(file), #[cfg(feature = "git")] Self::Git(inner) => inner.get_current_head_name(file), } @@ -141,7 +109,6 @@ impl DiffProvider { f: impl Fn(Result) -> bool, ) -> Result<()> { match self { - Self::Dummy(inner) => inner.for_each_changed_file(cwd, f), #[cfg(feature = "git")] Self::Git(inner) => inner.for_each_changed_file(cwd, f), }