From 53aeb8a1a4f7fcb3ba2768f359529af3d56ce2f6 Mon Sep 17 00:00:00 2001 From: Josh Junon Date: Fri, 1 Mar 2024 18:39:11 +0100 Subject: [PATCH] remove build warnings --- gitbutler-app/src/deltas.rs | 3 +- gitbutler-app/src/deltas/writer.rs | 5 +- gitbutler-app/src/gb_repository/repository.rs | 1 + .../src/gb_repository/repository_tests.rs | 18 ++--- .../src/project_repository/repository.rs | 2 + gitbutler-app/src/projects.rs | 5 +- gitbutler-app/src/watcher/handlers.rs | 1 - .../handlers/calculate_deltas_handler.rs | 23 +++--- .../watcher/handlers/fetch_project_data.rs | 73 ------------------- 9 files changed, 32 insertions(+), 99 deletions(-) delete mode 100644 gitbutler-app/src/watcher/handlers/fetch_project_data.rs diff --git a/gitbutler-app/src/deltas.rs b/gitbutler-app/src/deltas.rs index d8ae97dd5..009f83036 100644 --- a/gitbutler-app/src/deltas.rs +++ b/gitbutler-app/src/deltas.rs @@ -2,16 +2,15 @@ mod controller; mod database; mod delta; mod document; -mod operations; mod reader; mod writer; pub mod commands; +pub mod operations; pub use controller::Controller; pub use database::Database; pub use delta::Delta; pub use document::Document; -pub use operations::Operation; pub use reader::DeltasReader as Reader; pub use writer::DeltasWriter as Writer; diff --git a/gitbutler-app/src/deltas/writer.rs b/gitbutler-app/src/deltas/writer.rs index 2c67602a2..69bf428b8 100644 --- a/gitbutler-app/src/deltas/writer.rs +++ b/gitbutler-app/src/deltas/writer.rs @@ -81,6 +81,7 @@ mod tests { }; use super::*; + use deltas::operations::Operation; #[test] fn write_no_vbranches() -> Result<()> { @@ -95,11 +96,11 @@ mod tests { let path = "test.txt"; let deltas = vec![ deltas::Delta { - operations: vec![deltas::Operation::Insert((0, "hello".to_string()))], + operations: vec![Operation::Insert((0, "hello".to_string()))], timestamp_ms: 0, }, deltas::Delta { - operations: vec![deltas::Operation::Insert((5, " world".to_string()))], + operations: vec![Operation::Insert((5, " world".to_string()))], timestamp_ms: 0, }, ]; diff --git a/gitbutler-app/src/gb_repository/repository.rs b/gitbutler-app/src/gb_repository/repository.rs index d85b4a52b..55f89ceab 100644 --- a/gitbutler-app/src/gb_repository/repository.rs +++ b/gitbutler-app/src/gb_repository/repository.rs @@ -417,6 +417,7 @@ impl Repository { } } + #[cfg(test)] pub fn flush( &self, project_repository: &project_repository::Repository, diff --git a/gitbutler-app/src/gb_repository/repository_tests.rs b/gitbutler-app/src/gb_repository/repository_tests.rs index 13cf667af..6990756d6 100644 --- a/gitbutler-app/src/gb_repository/repository_tests.rs +++ b/gitbutler-app/src/gb_repository/repository_tests.rs @@ -4,8 +4,8 @@ use anyhow::Result; use pretty_assertions::assert_eq; use crate::{ - deltas, - projects::{self, ProjectId}, + deltas::{self, operations::Operation}, + projects::{self, ApiProject, ProjectId}, reader, sessions::{self, SessionId}, tests::{Case, Suite}, @@ -100,7 +100,7 @@ fn test_list_deltas_from_current_session() -> Result<()> { writer.write( "test.txt", &vec![deltas::Delta { - operations: vec![deltas::Operation::Insert((0, "Hello World".to_string()))], + operations: vec![Operation::Insert((0, "Hello World".to_string()))], timestamp_ms: 0, }], )?; @@ -116,7 +116,7 @@ fn test_list_deltas_from_current_session() -> Result<()> { ); assert_eq!( deltas[&path::PathBuf::from("test.txt")][0].operations[0], - deltas::Operation::Insert((0, "Hello World".to_string())) + Operation::Insert((0, "Hello World".to_string())) ); Ok(()) @@ -134,7 +134,7 @@ fn test_list_deltas_from_flushed_session() -> Result<()> { writer.write( "test.txt", &vec![deltas::Delta { - operations: vec![deltas::Operation::Insert((0, "Hello World".to_string()))], + operations: vec![Operation::Insert((0, "Hello World".to_string()))], timestamp_ms: 0, }], )?; @@ -151,7 +151,7 @@ fn test_list_deltas_from_flushed_session() -> Result<()> { ); assert_eq!( deltas[&path::PathBuf::from("test.txt")][0].operations[0], - deltas::Operation::Insert((0, "Hello World".to_string())) + Operation::Insert((0, "Hello World".to_string())) ); Ok(()) @@ -206,7 +206,7 @@ fn test_list_files_from_flushed_session() -> Result<()> { async fn test_remote_syncronization() -> Result<()> { // first, crate a remote, pretending it's a cloud let cloud = test_remote_repository()?; - let api_project = projects::ApiProject { + let api_project = ApiProject { name: "test-sync".to_string(), description: None, repository_id: "123".to_string(), @@ -239,7 +239,7 @@ async fn test_remote_syncronization() -> Result<()> { writer.write( "test.txt", &vec![deltas::Delta { - operations: vec![deltas::Operation::Insert((0, "Hello World".to_string()))], + operations: vec![Operation::Insert((0, "Hello World".to_string()))], timestamp_ms: 0, }], )?; @@ -285,7 +285,7 @@ async fn test_remote_syncronization() -> Result<()> { assert_eq!( deltas[&path::PathBuf::from("test.txt")], vec![deltas::Delta { - operations: vec![deltas::Operation::Insert((0, "Hello World".to_string()))], + operations: vec![Operation::Insert((0, "Hello World".to_string()))], timestamp_ms: 0, }] ); diff --git a/gitbutler-app/src/project_repository/repository.rs b/gitbutler-app/src/project_repository/repository.rs index 930b7c093..6eb33147a 100644 --- a/gitbutler-app/src/project_repository/repository.rs +++ b/gitbutler-app/src/project_repository/repository.rs @@ -208,6 +208,7 @@ impl Repository { } Ok(oids) } + #[cfg(test)] LogUntil::End => { let mut revwalk = self .git_repository @@ -484,5 +485,6 @@ pub enum LogUntil { Commit(git::Oid), Take(usize), When(Box), + #[cfg(test)] End, } diff --git a/gitbutler-app/src/projects.rs b/gitbutler-app/src/projects.rs index 659e263c8..953d1fadd 100644 --- a/gitbutler-app/src/projects.rs +++ b/gitbutler-app/src/projects.rs @@ -4,5 +4,8 @@ mod project; mod storage; pub use controller::*; -pub use project::{ApiProject, AuthKey, CodePushState, FetchResult, Project, ProjectId}; +pub use project::{AuthKey, CodePushState, FetchResult, Project, ProjectId}; pub use storage::UpdateRequest; + +#[cfg(test)] +pub use project::ApiProject; diff --git a/gitbutler-app/src/watcher/handlers.rs b/gitbutler-app/src/watcher/handlers.rs index 4e12b826e..d166a868b 100644 --- a/gitbutler-app/src/watcher/handlers.rs +++ b/gitbutler-app/src/watcher/handlers.rs @@ -2,7 +2,6 @@ mod analytics_handler; mod calculate_deltas_handler; mod caltulate_virtual_branches_handler; mod fetch_gitbutler_data; -mod fetch_project_data; mod filter_ignored_files; mod flush_session; mod git_file_change; diff --git a/gitbutler-app/src/watcher/handlers/calculate_deltas_handler.rs b/gitbutler-app/src/watcher/handlers/calculate_deltas_handler.rs index 979f50ee4..840321bcf 100644 --- a/gitbutler-app/src/watcher/handlers/calculate_deltas_handler.rs +++ b/gitbutler-app/src/watcher/handlers/calculate_deltas_handler.rs @@ -200,7 +200,8 @@ mod test { use once_cell::sync::Lazy; use crate::{ - deltas, sessions, + deltas::{self, operations::Operation}, + sessions, tests::{self, Case, Suite}, virtual_branches::{self, branch}, }; @@ -290,7 +291,7 @@ mod test { assert_eq!(deltas[0].operations.len(), 1); assert_eq!( deltas[0].operations[0], - deltas::Operation::Insert((4, "2".to_string())), + Operation::Insert((4, "2".to_string())), ); assert_eq!( std::fs::read_to_string(gb_repository.session_wd_path().join("test.txt"))?, @@ -423,7 +424,7 @@ mod test { assert_eq!(deltas[0].operations.len(), 1); assert_eq!( deltas[0].operations[0], - deltas::Operation::Insert((0, "test".to_string())), + Operation::Insert((0, "test".to_string())), ); assert_eq!( std::fs::read_to_string(gb_repository.session_wd_path().join("test.txt"))?, @@ -483,7 +484,7 @@ mod test { assert_eq!(deltas[0].operations.len(), 1); assert_eq!( deltas[0].operations[0], - deltas::Operation::Insert((0, "test".to_string())), + Operation::Insert((0, "test".to_string())), ); assert_eq!( std::fs::read_to_string(gb_repository.session_wd_path().join("test.txt"))?, @@ -498,12 +499,12 @@ mod test { assert_eq!(deltas[0].operations.len(), 1); assert_eq!( deltas[0].operations[0], - deltas::Operation::Insert((0, "test".to_string())), + Operation::Insert((0, "test".to_string())), ); assert_eq!(deltas[1].operations.len(), 1); assert_eq!( deltas[1].operations[0], - deltas::Operation::Insert((4, "2".to_string())), + Operation::Insert((4, "2".to_string())), ); assert_eq!( std::fs::read_to_string(gb_repository.session_wd_path().join("test.txt"))?, @@ -540,7 +541,7 @@ mod test { assert_eq!(deltas[0].operations.len(), 1); assert_eq!( deltas[0].operations[0], - deltas::Operation::Insert((0, "test".to_string())), + Operation::Insert((0, "test".to_string())), ); assert_eq!( std::fs::read_to_string(gb_repository.session_wd_path().join("test.txt"))?, @@ -576,7 +577,7 @@ mod test { let deltas = deltas_reader.read_file("test.txt")?.unwrap(); assert_eq!(deltas.len(), 1); assert_eq!(deltas[0].operations.len(), 1); - assert_eq!(deltas[0].operations[0], deltas::Operation::Delete((0, 4)),); + assert_eq!(deltas[0].operations[0], Operation::Delete((0, 4)),); } gb_repository.flush(&project_repository, None)?; @@ -640,7 +641,7 @@ mod test { let sessions_slice = &mut sessions[i..]; // collect all operations from sessions in the reverse order - let mut operations: Vec = vec![]; + let mut operations: Vec = vec![]; for session in &mut *sessions_slice { let session_reader = sessions::Reader::open(&gb_repository, session).unwrap(); let deltas_reader = deltas::Reader::new(&session_reader); @@ -726,7 +727,7 @@ mod test { let sessions_slice = &mut sessions[i..]; // collect all operations from sessions in the reverse order - let mut operations: Vec = vec![]; + let mut operations: Vec = vec![]; for session in &mut *sessions_slice { let session_reader = sessions::Reader::open(&gb_repository, session).unwrap(); let deltas_reader = deltas::Reader::new(&session_reader); @@ -789,7 +790,7 @@ mod test { } // collect all operations from sessions in the reverse order - let mut operations: Vec = vec![]; + let mut operations: Vec = vec![]; let session = gb_repository.get_current_session()?.unwrap(); let session_reader = sessions::Reader::open(&gb_repository, &session).unwrap(); let deltas_reader = deltas::Reader::new(&session_reader); diff --git a/gitbutler-app/src/watcher/handlers/fetch_project_data.rs b/gitbutler-app/src/watcher/handlers/fetch_project_data.rs deleted file mode 100644 index 993747c4c..000000000 --- a/gitbutler-app/src/watcher/handlers/fetch_project_data.rs +++ /dev/null @@ -1,73 +0,0 @@ -use std::sync::Arc; - -use anyhow::{Context, Result}; -use tauri::{AppHandle, Manager}; -use tokio::sync::Mutex; - -use crate::{ - events as app_events, project_repository::RemoteError, projects::ProjectId, virtual_branches, -}; - -use super::events; - -#[derive(Clone)] -pub struct Handler { - inner: Arc>, -} - -impl TryFrom<&AppHandle> for Handler { - type Error = anyhow::Error; - - fn try_from(value: &AppHandle) -> std::result::Result { - if let Some(handler) = value.try_state::() { - Ok(handler.inner().clone()) - } else { - let vbranches = virtual_branches::Controller::try_from(value)?; - let inner = HandlerInner::new(vbranches); - let handler = Handler::new(inner); - value.manage(handler.clone()); - Ok(handler) - } - } -} - -impl Handler { - fn new(inner: HandlerInner) -> Handler { - Handler { - inner: Arc::new(Mutex::new(inner)), - } - } - - pub async fn handle(&self, project_id: &ProjectId) -> Result> { - if let Ok(inner) = self.inner.try_lock() { - inner.handle(project_id).await - } else { - Ok(vec![]) - } - } -} - -struct HandlerInner { - vbranches: virtual_branches::Controller, -} - -impl HandlerInner { - fn new(vbranches: virtual_branches::Controller) -> HandlerInner { - HandlerInner { vbranches } - } - - pub async fn handle(&self, project_id: &ProjectId) -> Result> { - match self.vbranches.fetch_from_target(project_id).await { - Ok(_) - | Err(virtual_branches::controller::ControllerError::VerifyError(_)) - | Err(virtual_branches::controller::ControllerError::Action( - virtual_branches::errors::FetchFromTargetError::DefaultTargetNotSet(_) - | virtual_branches::errors::FetchFromTargetError::Remote(RemoteError::Network) - | virtual_branches::errors::FetchFromTargetError::Remote(RemoteError::Auth), - )) => Ok(vec![events::Event::Emit(app_events::Event::git_fetch( - project_id, - ))]), - Err(error) => Err(error).context("failed to fetch project"), - } - } -}