Skip to content

Commit

Permalink
move debouncer code into its own crate
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Byron committed Jun 16, 2024
1 parent 3723cd2 commit 184f557
Show file tree
Hide file tree
Showing 47 changed files with 63 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/push.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs:
- 'crates/gitbutler-cli/**'
gitbutler-watcher:
- *rust
- 'crates/gitbutler-cli/**'
- 'crates/gitbutler-watcher/**'
lint-node:
needs: changes
Expand Down Expand Up @@ -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 }}

Expand Down
31 changes: 19 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
Expand Down
20 changes: 2 additions & 18 deletions crates/gitbutler-watcher/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand Down
5 changes: 2 additions & 3 deletions crates/gitbutler-watcher/src/file_monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion crates/gitbutler-watcher/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use tokio::{
};
use tokio_util::sync::CancellationToken;

mod debouncer;
mod file_monitor;
mod handler;

Expand Down
34 changes: 34 additions & 0 deletions crates/gitbutler-watcher/vendor/debouncer/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 184f557

Please sign in to comment.