remove build warnings

This commit is contained in:
Josh Junon 2024-03-01 18:39:11 +01:00
parent 37e316e0c7
commit 53aeb8a1a4
9 changed files with 32 additions and 99 deletions

View File

@ -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;

View File

@ -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,
},
];

View File

@ -417,6 +417,7 @@ impl Repository {
}
}
#[cfg(test)]
pub fn flush(
&self,
project_repository: &project_repository::Repository,

View File

@ -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,
}]
);

View File

@ -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<OidFilter>),
#[cfg(test)]
End,
}

View File

@ -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;

View File

@ -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;

View File

@ -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<deltas::Operation> = vec![];
let mut operations: Vec<Operation> = 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<deltas::Operation> = vec![];
let mut operations: Vec<Operation> = 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<deltas::Operation> = vec![];
let mut operations: Vec<Operation> = 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);

View File

@ -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<Mutex<HandlerInner>>,
}
impl TryFrom<&AppHandle> for Handler {
type Error = anyhow::Error;
fn try_from(value: &AppHandle) -> std::result::Result<Self, Self::Error> {
if let Some(handler) = value.try_state::<Handler>() {
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<Vec<events::Event>> {
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<Vec<events::Event>> {
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"),
}
}
}