summary refs log tree commit diff
path: root/src/diff_thread/mod.rs
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2021-08-17 19:22:05 +0000
committerAlyssa Ross <hi@alyssa.is>2021-08-17 19:22:05 +0000
commit94a23a6839f3d4632c5abed1cb8846e4d295383e (patch)
treefbebc5db3366f3fdc70238ca08fbd769838fd063 /src/diff_thread/mod.rs
parent256ac9c8eb8775acd1f812ee4345e13926181f0e (diff)
downloadgit-girf-94a23a6839f3d4632c5abed1cb8846e4d295383e.tar
git-girf-94a23a6839f3d4632c5abed1cb8846e4d295383e.tar.gz
git-girf-94a23a6839f3d4632c5abed1cb8846e4d295383e.tar.bz2
git-girf-94a23a6839f3d4632c5abed1cb8846e4d295383e.tar.lz
git-girf-94a23a6839f3d4632c5abed1cb8846e4d295383e.tar.xz
git-girf-94a23a6839f3d4632c5abed1cb8846e4d295383e.tar.zst
git-girf-94a23a6839f3d4632c5abed1cb8846e4d295383e.zip
Proof of concept
Diffstat (limited to 'src/diff_thread/mod.rs')
-rw-r--r--src/diff_thread/mod.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/diff_thread/mod.rs b/src/diff_thread/mod.rs
new file mode 100644
index 0000000..9416509
--- /dev/null
+++ b/src/diff_thread/mod.rs
@@ -0,0 +1,28 @@
+// SPDX-License-Identifier: EUPL-1.2
+// SPDX-FileCopyrightText: 2021 Alyssa Ross <hi@alyssa.is>
+
+//! libgit2's diffing API gives us a callback whenever a file diff is ready, but
+//! that's not very convenient for Rust code, because it can't be used as an
+//! iterator.  So we run the diff in a thread, and send the diff information we need
+//! to the main thread over a channel.  When the main thread is processing diff
+//! information too slowly, we block the diff thread until the main thread catches
+//! up.
+
+mod server;
+mod client;
+
+pub use client::DiffThread;
+
+use std::path::PathBuf;
+
+use git2::{Repository, Diff, Delta};
+
+pub trait MakeDiff: Send + 'static {
+    fn make_diff(self, _: &Repository) -> Result<Diff, git2::Error>;
+}
+
+/// `new_path` isn't included because it's not currently used in git-girf.
+pub struct FileDiff {
+    pub status: Delta,
+    pub old_path: Option<PathBuf>,
+}