move debouncer code into its own crate

That way the public API that isn't used doesn't have to be `dead_code`.

Also adjust CI to run the tests we have in the debouncer crate.
Previously, it might not have run them though.
This commit is contained in:
Sebastian Thiel 2024-06-02 15:14:47 +02:00
parent 3723cd279c
commit 184f557897
No known key found for this signature in database
GPG Key ID: 9CB5EE7895E8268B
47 changed files with 63 additions and 42 deletions

View File

@ -54,7 +54,7 @@ jobs:
- 'crates/gitbutler-cli/**'
gitbutler-watcher:
- *rust
- 'crates/gitbutler-cli/**'
- 'crates/gitbutler-watcher/**'
lint-node:
needs: changes
@ -228,7 +228,7 @@ jobs:
- uses: ./.github/actions/init-env-rust
- uses: ./.github/actions/check-crate
with:
crate: gitbutler-watcher
crate: gitbutler-notify-debouncer
features: ${{ toJson(matrix.features) }}
action: ${{ matrix.action }}

31
Cargo.lock generated
View File

@ -2177,6 +2177,24 @@ dependencies = [
"windows-named-pipe",
]
[[package]]
name = "gitbutler-notify-debouncer"
version = "0.0.0"
dependencies = [
"crossbeam-channel",
"deser-hjson",
"file-id",
"gitbutler-notify-debouncer",
"mock_instant",
"notify",
"parking_lot 0.12.3",
"pretty_assertions",
"rstest",
"serde",
"tracing",
"walkdir",
]
[[package]]
name = "gitbutler-tauri"
version = "0.0.0"
@ -2232,26 +2250,15 @@ version = "0.0.0"
dependencies = [
"anyhow",
"backoff",
"crossbeam-channel",
"deser-hjson",
"file-id",
"futures",
"gitbutler-core",
"gitbutler-watcher",
"gitbutler-notify-debouncer",
"gix",
"itertools 0.13.0",
"mock_instant",
"notify",
"parking_lot 0.12.3",
"pretty_assertions",
"rand 0.8.5",
"rstest",
"serde",
"thiserror",
"tokio",
"tokio-util",
"tracing",
"walkdir",
]
[[package]]

View File

@ -4,6 +4,7 @@ members = [
"crates/gitbutler-tauri",
"crates/gitbutler-git",
"crates/gitbutler-watcher",
"crates/gitbutler-watcher/vendor/debouncer",
"crates/gitbutler-testsupport",
"crates/gitbutler-cli",
]

View File

@ -5,11 +5,9 @@ edition = "2021"
publish = false
[lib]
test = false
doctest = false
[features]
mock_instant = ["dep:mock_instant"]
[dependencies]
gitbutler-core.workspace = true
thiserror.workspace = true
@ -22,21 +20,7 @@ gix = { workspace = true, features = ["excludes"] }
backoff = "0.4.0"
notify = { version = "6.0.1" }
parking_lot = "0.12.3"
file-id = "0.2.1"
walkdir = "2.2.2"
crossbeam-channel = "0.5.13"
itertools = "0.13"
mock_instant = { version = "0.3.2", optional = true }
[dev-dependencies]
gitbutler-watcher = { path = ".", features = ["mock_instant"] }
pretty_assertions = "1.3.0"
rstest = "0.20"
serde = { version = "1.0.203", features = ["derive"] }
deser-hjson = "1.1.1"
rand = "0.8.5"
gitbutler-notify-debouncer.path = "vendor/debouncer"
[lints.clippy]
all = "deny"

View File

@ -2,12 +2,11 @@ use std::collections::HashSet;
use std::path::Path;
use std::time::Duration;
use crate::debouncer::Debouncer;
use crate::debouncer::FileIdMap;
use crate::{debouncer::new_debouncer, events::InternalEvent};
use crate::events::InternalEvent;
use anyhow::{anyhow, Context, Result};
use gitbutler_core::ops::OPLOG_FILE_NAME;
use gitbutler_core::projects::ProjectId;
use gitbutler_notify_debouncer::{new_debouncer, Debouncer, FileIdMap};
use notify::RecommendedWatcher;
use notify::Watcher;
use tokio::task;

View File

@ -18,7 +18,6 @@ use tokio::{
};
use tokio_util::sync::CancellationToken;
mod debouncer;
mod file_monitor;
mod handler;

View File

@ -0,0 +1,34 @@
[package]
name = "gitbutler-notify-debouncer"
version = "0.0.0"
edition = "2021"
publish = false
[lib]
doctest = false
[features]
mock_instant = ["dep:mock_instant"]
[dependencies]
tracing = "0.1.40"
notify = { version = "6.0.1" }
parking_lot = "0.12.3"
file-id = "0.2.1"
walkdir = "2.2.2"
crossbeam-channel = "0.5.13"
mock_instant = { version = "0.3.2", optional = true }
[dev-dependencies]
gitbutler-notify-debouncer = { path = ".", features = ["mock_instant"] }
pretty_assertions = "1.4.0"
rstest = "0.20"
serde = { version = "1.0.203", features = ["derive"] }
deser-hjson = "1.1.1"
[lints.clippy]
all = "deny"
perf = "deny"
correctness = "deny"

View File

@ -94,7 +94,6 @@ impl FileIdMap {
/// Remove a path form the cache.
///
/// If the path was added with `Recursive` mode, all children will also be removed from the cache.
#[allow(dead_code)]
pub fn remove_root(&mut self, path: impl AsRef<Path>) {
self.roots.retain(|(root, _)| !root.starts_with(&path));

View File

@ -495,7 +495,6 @@ pub struct Debouncer<T: Watcher, C: FileIdCache> {
impl<T: Watcher, C: FileIdCache> Debouncer<T, C> {
/// Stop the debouncer, waits for the event thread to finish.
/// May block for the duration of one tick_rate.
#[allow(dead_code)]
pub fn stop(mut self) {
self.set_stop();
if let Some(t) = self.debouncer_thread.take() {
@ -504,7 +503,6 @@ impl<T: Watcher, C: FileIdCache> Debouncer<T, C> {
}
/// Stop the debouncer, does not wait for the event thread to finish.
#[allow(dead_code)]
pub fn stop_nonblocking(self) {
self.set_stop();
}

View File

@ -166,7 +166,7 @@ fn state(
mod schema;
mod utils {
use crate::debouncer::FileIdCache;
use crate::FileIdCache;
use file_id::FileId;
use std::collections::HashMap;

View File

@ -27,7 +27,7 @@
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
// IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
use crate::debouncer::{DebounceDataInner, DebouncedEvent};
use crate::{DebounceDataInner, DebouncedEvent};
use file_id::FileId;
use mock_instant::Instant;
use notify::event::{
@ -241,7 +241,7 @@ impl State {
.queues
.into_iter()
.map(|(path, queue)| {
let queue = crate::debouncer::Queue {
let queue = crate::Queue {
events: queue
.events
.into_iter()