|
|
@ -1,15 +1,10 @@
|
|
|
|
use anyhow::{anyhow, bail, Result};
|
|
|
|
use anyhow::{anyhow, Result};
|
|
|
|
use arc_swap::ArcSwap;
|
|
|
|
use arc_swap::ArcSwap;
|
|
|
|
use std::{
|
|
|
|
use std::{
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
path::{Path, PathBuf},
|
|
|
|
sync::Arc,
|
|
|
|
sync::Arc,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "git")]
|
|
|
|
|
|
|
|
pub use git::Git;
|
|
|
|
|
|
|
|
#[cfg(not(feature = "git"))]
|
|
|
|
|
|
|
|
pub use Dummy as Git;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(feature = "git")]
|
|
|
|
#[cfg(feature = "git")]
|
|
|
|
mod git;
|
|
|
|
mod git;
|
|
|
|
|
|
|
|
|
|
|
@ -21,33 +16,6 @@ mod status;
|
|
|
|
|
|
|
|
|
|
|
|
pub use status::FileChange;
|
|
|
|
pub use status::FileChange;
|
|
|
|
|
|
|
|
|
|
|
|
#[doc(hidden)]
|
|
|
|
|
|
|
|
#[derive(Clone, Copy)]
|
|
|
|
|
|
|
|
pub struct Dummy;
|
|
|
|
|
|
|
|
impl Dummy {
|
|
|
|
|
|
|
|
fn get_diff_base(&self, _file: &Path) -> Result<Vec<u8>> {
|
|
|
|
|
|
|
|
bail!("helix was compiled without git support")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn get_current_head_name(&self, _file: &Path) -> Result<Arc<ArcSwap<Box<str>>>> {
|
|
|
|
|
|
|
|
bail!("helix was compiled without git support")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn for_each_changed_file(
|
|
|
|
|
|
|
|
&self,
|
|
|
|
|
|
|
|
_cwd: &Path,
|
|
|
|
|
|
|
|
_f: impl Fn(Result<FileChange>) -> bool,
|
|
|
|
|
|
|
|
) -> Result<()> {
|
|
|
|
|
|
|
|
bail!("helix was compiled without git support")
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl From<Dummy> for DiffProvider {
|
|
|
|
|
|
|
|
fn from(value: Dummy) -> Self {
|
|
|
|
|
|
|
|
DiffProvider::Dummy(value)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub struct DiffProviderRegistry {
|
|
|
|
pub struct DiffProviderRegistry {
|
|
|
|
providers: Vec<DiffProvider>,
|
|
|
|
providers: Vec<DiffProvider>,
|
|
|
@ -104,7 +72,10 @@ impl Default for DiffProviderRegistry {
|
|
|
|
fn default() -> Self {
|
|
|
|
fn default() -> Self {
|
|
|
|
// currently only git is supported
|
|
|
|
// currently only git is supported
|
|
|
|
// TODO make this configurable when more providers are added
|
|
|
|
// 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 }
|
|
|
|
DiffProviderRegistry { providers }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -113,15 +84,13 @@ impl Default for DiffProviderRegistry {
|
|
|
|
/// cloning [DiffProviderRegistry] as `Clone` cannot be used in trait objects.
|
|
|
|
/// cloning [DiffProviderRegistry] as `Clone` cannot be used in trait objects.
|
|
|
|
#[derive(Clone)]
|
|
|
|
#[derive(Clone)]
|
|
|
|
pub enum DiffProvider {
|
|
|
|
pub enum DiffProvider {
|
|
|
|
Dummy(Dummy),
|
|
|
|
|
|
|
|
#[cfg(feature = "git")]
|
|
|
|
#[cfg(feature = "git")]
|
|
|
|
Git(Git),
|
|
|
|
Git(git::Git),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl DiffProvider {
|
|
|
|
impl DiffProvider {
|
|
|
|
fn get_diff_base(&self, file: &Path) -> Result<Vec<u8>> {
|
|
|
|
fn get_diff_base(&self, file: &Path) -> Result<Vec<u8>> {
|
|
|
|
match self {
|
|
|
|
match self {
|
|
|
|
Self::Dummy(inner) => inner.get_diff_base(file),
|
|
|
|
|
|
|
|
#[cfg(feature = "git")]
|
|
|
|
#[cfg(feature = "git")]
|
|
|
|
Self::Git(inner) => inner.get_diff_base(file),
|
|
|
|
Self::Git(inner) => inner.get_diff_base(file),
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -129,7 +98,6 @@ impl DiffProvider {
|
|
|
|
|
|
|
|
|
|
|
|
fn get_current_head_name(&self, file: &Path) -> Result<Arc<ArcSwap<Box<str>>>> {
|
|
|
|
fn get_current_head_name(&self, file: &Path) -> Result<Arc<ArcSwap<Box<str>>>> {
|
|
|
|
match self {
|
|
|
|
match self {
|
|
|
|
Self::Dummy(inner) => inner.get_current_head_name(file),
|
|
|
|
|
|
|
|
#[cfg(feature = "git")]
|
|
|
|
#[cfg(feature = "git")]
|
|
|
|
Self::Git(inner) => inner.get_current_head_name(file),
|
|
|
|
Self::Git(inner) => inner.get_current_head_name(file),
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -141,7 +109,6 @@ impl DiffProvider {
|
|
|
|
f: impl Fn(Result<FileChange>) -> bool,
|
|
|
|
f: impl Fn(Result<FileChange>) -> bool,
|
|
|
|
) -> Result<()> {
|
|
|
|
) -> Result<()> {
|
|
|
|
match self {
|
|
|
|
match self {
|
|
|
|
Self::Dummy(inner) => inner.for_each_changed_file(cwd, f),
|
|
|
|
|
|
|
|
#[cfg(feature = "git")]
|
|
|
|
#[cfg(feature = "git")]
|
|
|
|
Self::Git(inner) => inner.for_each_changed_file(cwd, f),
|
|
|
|
Self::Git(inner) => inner.for_each_changed_file(cwd, f),
|
|
|
|
}
|
|
|
|
}
|
|
|
|