aboutsummaryrefslogtreecommitdiff
path: root/helix-vcs/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'helix-vcs/src/lib.rs')
-rw-r--r--helix-vcs/src/lib.rs51
1 files changed, 51 insertions, 0 deletions
diff --git a/helix-vcs/src/lib.rs b/helix-vcs/src/lib.rs
new file mode 100644
index 00000000..97320d32
--- /dev/null
+++ b/helix-vcs/src/lib.rs
@@ -0,0 +1,51 @@
+use std::path::Path;
+
+#[cfg(feature = "git")]
+pub use git::Git;
+#[cfg(not(feature = "git"))]
+pub use Dummy as Git;
+
+#[cfg(feature = "git")]
+mod git;
+
+mod diff;
+
+pub use diff::{DiffHandle, Hunk};
+
+pub trait DiffProvider {
+ /// Returns the data that a diff should be computed against
+ /// if this provider is used.
+ /// The data is returned as raw byte without any decoding or encoding performed
+ /// to ensure all file encodings are handled correctly.
+ fn get_diff_base(&self, file: &Path) -> Option<Vec<u8>>;
+}
+
+#[doc(hidden)]
+pub struct Dummy;
+impl DiffProvider for Dummy {
+ fn get_diff_base(&self, _file: &Path) -> Option<Vec<u8>> {
+ None
+ }
+}
+
+pub struct DiffProviderRegistry {
+ providers: Vec<Box<dyn DiffProvider>>,
+}
+
+impl DiffProviderRegistry {
+ pub fn get_diff_base(&self, file: &Path) -> Option<Vec<u8>> {
+ self.providers
+ .iter()
+ .find_map(|provider| provider.get_diff_base(file))
+ }
+}
+
+impl Default for DiffProviderRegistry {
+ fn default() -> Self {
+ // currently only git is supported
+ // TODO make this configurable when more providers are added
+ let git: Box<dyn DiffProvider> = Box::new(Git);
+ let providers = vec![git];
+ DiffProviderRegistry { providers }
+ }
+}