reexport deltas

This commit is contained in:
Nikita Galaiko 2023-05-07 17:10:42 +02:00
parent 77bdd0650b
commit 39b3cc0698
17 changed files with 122 additions and 118 deletions

View File

@ -3,9 +3,9 @@ use std::{collections::HashMap, sync};
use anyhow::{Context, Result};
use crossbeam_channel::{bounded, Sender};
use crate::{app, events, git::activity, projects, pty, search, storage, users};
use crate::{events, git::activity, projects, pty, search, storage, users};
use super::{gb_repository, project_repository, watcher, sessions};
use super::{gb_repository, project_repository, watcher, sessions, deltas};
#[derive(Clone)]
pub struct App {
@ -308,7 +308,7 @@ impl App {
project_id: &str,
session_id: &str,
paths: Option<Vec<&str>>,
) -> Result<HashMap<String, Vec<app::Delta>>> {
) -> Result<HashMap<String, Vec<deltas::Delta>>> {
let gb_repository = gb_repository::Repository::open(
self.local_data_dir.clone(),
project_id.to_string(),

View File

@ -16,10 +16,7 @@ use crate::{fs, projects, users};
use super::{
project_repository,
reader::{self, Reader},
sessions::{
get_hash_mapping, SessionReader, SessionWriter, SessionsIdsIterator, SessionsIterator,
},
Meta, Session, SessionError,
sessions,
};
pub struct Repository {
@ -120,7 +117,7 @@ impl Repository {
fn create_current_session(
&self,
project_repository: &project_repository::Repository,
) -> Result<Session> {
) -> Result<sessions::Session> {
log::info!("{}: creating new session", self.project_id);
let now_ms = time::SystemTime::now()
@ -129,13 +126,13 @@ impl Repository {
.as_millis();
let meta = match project_repository.get_head() {
Result::Ok(head) => Meta {
Result::Ok(head) => sessions::Meta {
start_timestamp_ms: now_ms,
last_timestamp_ms: now_ms,
branch: head.name().map(|name| name.to_string()),
commit: Some(head.peel_to_commit()?.id().to_string()),
},
Err(_) => Meta {
Err(_) => sessions::Meta {
start_timestamp_ms: now_ms,
last_timestamp_ms: now_ms,
branch: None,
@ -143,7 +140,7 @@ impl Repository {
},
};
let session = Session {
let session = sessions::Session {
id: Uuid::new_v4().to_string(),
hash: None,
meta,
@ -156,9 +153,9 @@ impl Repository {
pub fn get_session_writer<'repository>(
&'repository self,
session: &Session,
) -> Result<SessionWriter<'repository>> {
SessionWriter::open(&self, &session)
session: &sessions::Session,
) -> Result<sessions::SessionWriter<'repository>> {
sessions::SessionWriter::open(&self, &session)
}
pub(crate) fn lock(&self) -> Result<()> {
@ -179,7 +176,7 @@ impl Repository {
Ok(())
}
pub fn get_or_create_current_session(&self) -> Result<Session> {
pub fn get_or_create_current_session(&self) -> Result<sessions::Session> {
match self
.get_current_session()
.context("failed to get current session")?
@ -201,7 +198,7 @@ impl Repository {
}
}
pub fn flush(&self) -> Result<Option<Session>> {
pub fn flush(&self) -> Result<Option<sessions::Session>> {
let current_session = self
.get_current_session()
.context("failed to get current session")?;
@ -229,8 +226,8 @@ impl Repository {
pub fn flush_session(
&self,
project_repository: &project_repository::Repository,
session: &Session,
) -> Result<Session> {
session: &sessions::Session,
) -> Result<sessions::Session> {
if session.hash.is_some() {
return Ok(session.clone());
}
@ -287,7 +284,7 @@ impl Repository {
log::error!("{}: failed to push to remote: {:#}", self.project_id, e);
}
let session = Session {
let session = sessions::Session {
hash: Some(commit_oid.to_string()),
..session.clone()
};
@ -297,22 +294,22 @@ impl Repository {
pub fn get_session_reader<'repository>(
&'repository self,
session: &Session,
) -> Result<SessionReader<'repository>> {
SessionReader::open(&self, &session)
session: &sessions::Session,
) -> Result<sessions::SessionReader<'repository>> {
sessions::SessionReader::open(&self, &session)
}
pub fn get_sessions_iterator<'repository>(
&'repository self,
) -> Result<SessionsIterator<'repository>> {
Ok(SessionsIterator::new(&self.git_repository)?)
) -> Result<sessions::SessionsIterator<'repository>> {
Ok(sessions::SessionsIterator::new(&self.git_repository)?)
}
pub fn get_session(&self, session_id: &str) -> Result<Session> {
if let Some(oid) = get_hash_mapping(session_id) {
pub fn get_session(&self, session_id: &str) -> Result<sessions::Session> {
if let Some(oid) = sessions::get_hash_mapping(session_id) {
let commit = self.git_repository.find_commit(oid)?;
let reader = reader::CommitReader::from_commit(&self.git_repository, commit)?;
return Ok(Session::try_from(reader)?);
return Ok(sessions::Session::try_from(reader)?);
}
if let Some(session) = self.get_current_session()? {
@ -321,7 +318,7 @@ impl Repository {
}
}
let mut session_ids_iterator = SessionsIdsIterator::new(&self.git_repository)?;
let mut session_ids_iterator = sessions::SessionsIdsIterator::new(&self.git_repository)?;
while let Some(ids) = session_ids_iterator.next() {
match ids {
Result::Ok((oid, sid)) => {
@ -329,7 +326,7 @@ impl Repository {
let commit = self.git_repository.find_commit(oid)?;
let reader =
reader::CommitReader::from_commit(&self.git_repository, commit)?;
return Ok(Session::try_from(reader)?);
return Ok(sessions::Session::try_from(reader)?);
}
}
Err(e) => return Err(e),
@ -338,12 +335,12 @@ impl Repository {
Err(anyhow!("session not found"))
}
pub fn get_current_session(&self) -> Result<Option<Session>> {
pub fn get_current_session(&self) -> Result<Option<sessions::Session>> {
let reader = reader::DirReader::open(self.root());
match Session::try_from(reader) {
match sessions::Session::try_from(reader) {
Result::Ok(session) => Ok(Some(session)),
Err(SessionError::NoSession) => Ok(None),
Err(SessionError::Err(err)) => Err(err),
Err(sessions::SessionError::NoSession) => Ok(None),
Err(sessions::SessionError::Err(err)) => Err(err),
}
}

View File

@ -2,7 +2,7 @@ use anyhow::Result;
use tempfile::tempdir;
use crate::{
app::{self, gb_repository},
app::{deltas, gb_repository},
projects, storage, users,
};
@ -227,8 +227,8 @@ fn test_list_deltas_from_current_session() -> Result<()> {
let writer = gb_repo.get_session_writer(&current_session)?;
writer.write_deltas(
"test.txt",
&vec![app::Delta {
operations: vec![app::Operation::Insert((0, "Hello World".to_string()))],
&vec![deltas::Delta {
operations: vec![deltas::Operation::Insert((0, "Hello World".to_string()))],
timestamp_ms: 0,
}],
)?;
@ -240,7 +240,7 @@ fn test_list_deltas_from_current_session() -> Result<()> {
assert_eq!(deltas.get("test.txt").unwrap()[0].operations.len(), 1);
assert_eq!(
deltas.get("test.txt").unwrap()[0].operations[0],
app::Operation::Insert((0, "Hello World".to_string()))
deltas::Operation::Insert((0, "Hello World".to_string()))
);
Ok(())
@ -266,8 +266,8 @@ fn test_list_deltas_from_flushed_session() -> Result<()> {
let writer = gb_repo.get_session_writer(&current_session)?;
writer.write_deltas(
"test.txt",
&vec![app::Delta {
operations: vec![app::Operation::Insert((0, "Hello World".to_string()))],
&vec![deltas::Delta {
operations: vec![deltas::Operation::Insert((0, "Hello World".to_string()))],
timestamp_ms: 0,
}],
)?;
@ -280,7 +280,7 @@ fn test_list_deltas_from_flushed_session() -> Result<()> {
assert_eq!(deltas.get("test.txt").unwrap()[0].operations.len(), 1);
assert_eq!(
deltas.get("test.txt").unwrap()[0].operations[0],
app::Operation::Insert((0, "Hello World".to_string()))
deltas::Operation::Insert((0, "Hello World".to_string()))
);
Ok(())

View File

@ -1,10 +1,10 @@
mod app;
mod deltas;
pub mod deltas;
pub mod gb_repository;
pub mod project_repository;
pub mod projects;
pub mod reader;
mod sessions;
pub mod sessions;
pub mod watcher;
mod writer;
@ -14,6 +14,4 @@ mod gb_repository_tests;
mod reader_tests;
pub use app::{AddProjectError, App};
pub use deltas::{Delta, Operation, TextDocument};
pub use project_repository::FileStatus;
pub use sessions::{Meta, Session, SessionError};

View File

@ -3,7 +3,7 @@ use std::collections::HashMap;
use anyhow::{anyhow, Context, Result};
use crate::app::{
self, gb_repository,
deltas, gb_repository,
reader::{self, CommitReader, Reader},
};
@ -117,7 +117,7 @@ impl<'reader> SessionReader<'reader> {
pub fn file_deltas<P: AsRef<std::path::Path>>(
&self,
path: P,
) -> Result<Option<Vec<app::Delta>>> {
) -> Result<Option<Vec<deltas::Delta>>> {
let path = path.as_ref();
let file_deltas_path = std::path::Path::new("session/deltas").join(path);
match self
@ -137,7 +137,7 @@ impl<'reader> SessionReader<'reader> {
}
}
pub fn deltas(&self, paths: Option<Vec<&str>>) -> Result<HashMap<String, Vec<app::Delta>>> {
pub fn deltas(&self, paths: Option<Vec<&str>>) -> Result<HashMap<String, Vec<deltas::Delta>>> {
let deltas_dir = std::path::Path::new("session/deltas");
let files = self.reader.list_files(deltas_dir.to_str().unwrap())?;
let mut result = HashMap::new();

View File

@ -2,7 +2,7 @@ use anyhow::Result;
use tempfile::tempdir;
use crate::{
app::{gb_repository, Meta, Session},
app::{gb_repository, sessions},
projects, storage, users,
};
@ -54,10 +54,10 @@ fn test_should_not_write_session_with_hash() -> Result<()> {
user_store,
)?;
let session = Session {
let session = sessions::Session {
id: "session_id".to_string(),
hash: Some("hash".to_string()),
meta: Meta {
meta: sessions::Meta {
start_timestamp_ms: 0,
last_timestamp_ms: 1,
branch: Some("branch".to_string()),
@ -86,10 +86,10 @@ fn test_should_write_full_session() -> Result<()> {
user_store,
)?;
let session = Session {
let session = sessions::Session {
id: "session_id".to_string(),
hash: None,
meta: Meta {
meta: sessions::Meta {
start_timestamp_ms: 0,
last_timestamp_ms: 1,
branch: Some("branch".to_string()),
@ -139,10 +139,10 @@ fn test_should_write_partial_session() -> Result<()> {
user_store,
)?;
let session = Session {
let session = sessions::Session {
id: "session_id".to_string(),
hash: None,
meta: Meta {
meta: sessions::Meta {
start_timestamp_ms: 0,
last_timestamp_ms: 1,
branch: None,

View File

@ -4,7 +4,7 @@ use anyhow::{anyhow, Context, Result};
use crate::{
app::{
self, gb_repository,
deltas, gb_repository,
reader::{self, Reader},
writer::{self, Writer},
},
@ -188,7 +188,7 @@ impl<'writer> SessionWriter<'writer> {
pub fn write_deltas<P: AsRef<std::path::Path>>(
&self,
path: P,
deltas: &Vec<app::Delta>,
deltas: &Vec<deltas::Delta>,
) -> Result<()> {
self.repository.lock()?;
defer! {

View File

@ -1,11 +1,14 @@
use std::{path, time};
use crate::{app, projects};
use crate::{
app::{deltas, sessions},
projects,
};
pub enum Event {
Tick(time::SystemTime),
FlushSession(app::Session),
SessionFlushed(app::Session),
FlushSession(sessions::Session),
SessionFlushed(sessions::Session),
FileChange(path::PathBuf),
GitFileChange(path::PathBuf),
@ -15,13 +18,13 @@ pub enum Event {
ProjectFileChange(path::PathBuf),
Session((projects::Project, app::Session)),
Session((projects::Project, sessions::Session)),
Deltas(
(
projects::Project,
app::Session,
sessions::Session,
path::PathBuf,
Vec<app::Delta>,
Vec<deltas::Delta>,
),
),
}

View File

@ -2,7 +2,7 @@ use std::{sync, time};
use anyhow::{Context, Result};
use crate::{app::gb_repository, app};
use crate::app::{gb_repository, sessions};
use super::events;
@ -37,13 +37,13 @@ impl<'handler> Handler<'handler> {
}
}
pub(super) fn should_flush(now: time::SystemTime, session: &app::Session) -> bool {
pub(super) fn should_flush(now: time::SystemTime, session: &sessions::Session) -> bool {
!is_session_active(now, session) || is_session_too_old(now, session)
}
const ONE_HOUR: time::Duration = time::Duration::new(60 * 60, 0);
fn is_session_too_old(now: time::SystemTime, session: &app::Session) -> bool {
fn is_session_too_old(now: time::SystemTime, session: &sessions::Session) -> bool {
let session_start = time::UNIX_EPOCH
+ time::Duration::from_millis(session.meta.start_timestamp_ms.try_into().unwrap());
session_start + ONE_HOUR < now
@ -51,7 +51,7 @@ fn is_session_too_old(now: time::SystemTime, session: &app::Session) -> bool {
const FIVE_MINUTES: time::Duration = time::Duration::new(5 * 60, 0);
fn is_session_active(now: time::SystemTime, session: &app::Session) -> bool {
fn is_session_active(now: time::SystemTime, session: &sessions::Session) -> bool {
let session_last_update = time::UNIX_EPOCH
+ time::Duration::from_millis(session.meta.last_timestamp_ms.try_into().unwrap());
session_last_update + FIVE_MINUTES > now

View File

@ -2,7 +2,7 @@ use std::time;
use anyhow::Result;
use crate::app;
use crate::app::sessions;
use super::check_current_session::should_flush;
@ -15,10 +15,10 @@ fn test_should_flush() -> Result<()> {
let start = now;
let last = now;
let session = app::Session {
let session = sessions::Session {
id: "session-id".to_string(),
hash: None,
meta: app::Meta {
meta: sessions::Meta {
start_timestamp_ms: start.duration_since(time::UNIX_EPOCH)?.as_millis(),
last_timestamp_ms: last.duration_since(time::UNIX_EPOCH)?.as_millis(),
branch: None,

View File

@ -1,7 +1,7 @@
use anyhow::{anyhow, Context, Result};
use crate::{
app::{self, gb_repository, project_repository},
app::{gb_repository, project_repository, sessions},
projects,
};
@ -26,7 +26,7 @@ impl<'listener> Handler<'listener> {
}
}
pub fn handle(&self, session: &app::Session) -> Result<Vec<events::Event>> {
pub fn handle(&self, session: &sessions::Session) -> Result<Vec<events::Event>> {
let project = self
.project_store
.get_project(&self.project_id)

View File

@ -4,7 +4,7 @@ use anyhow::{Context, Result};
use crate::{
app::{
self, gb_repository, project_repository,
deltas, gb_repository, project_repository,
reader::{self, Reader},
},
projects,
@ -135,7 +135,7 @@ impl<'listener> Handler<'listener> {
}
// returns deltas for the file that are already part of the current session (if any)
fn get_current_deltas(&self, path: &std::path::Path) -> Result<Option<Vec<app::Delta>>> {
fn get_current_deltas(&self, path: &std::path::Path) -> Result<Option<Vec<deltas::Delta>>> {
let current_session = self.gb_repository.get_current_session()?;
if current_session.is_none() {
return Ok(None);
@ -197,13 +197,13 @@ impl<'listener> Handler<'listener> {
let mut text_doc = match (latest_file_content, current_deltas) {
(Some(latest_contents), Some(deltas)) => {
app::TextDocument::new(Some(&latest_contents), deltas)?
deltas::TextDocument::new(Some(&latest_contents), deltas)?
}
(Some(latest_contents), None) => {
app::TextDocument::new(Some(&latest_contents), vec![])?
deltas::TextDocument::new(Some(&latest_contents), vec![])?
}
(None, Some(deltas)) => app::TextDocument::new(None, deltas)?,
(None, None) => app::TextDocument::new(None, vec![])?,
(None, Some(deltas)) => deltas::TextDocument::new(None, deltas)?,
(None, None) => deltas::TextDocument::new(None, vec![])?,
};
if !text_doc

View File

@ -2,7 +2,7 @@ use anyhow::Result;
use tempfile::tempdir;
use crate::{
app::{self, gb_repository, project_repository},
app::{deltas, gb_repository, project_repository, sessions},
projects, storage, users,
};
@ -88,7 +88,7 @@ fn test_register_existing_commited_file() -> Result<()> {
assert_eq!(deltas[0].operations.len(), 1);
assert_eq!(
deltas[0].operations[0],
app::Operation::Insert((4, "2".to_string())),
deltas::Operation::Insert((4, "2".to_string())),
);
assert_eq!(
std::fs::read_to_string(gb_repo.session_wd_path().join(file_path))?,
@ -189,7 +189,7 @@ fn test_register_new_file() -> Result<()> {
assert_eq!(deltas[0].operations.len(), 1);
assert_eq!(
deltas[0].operations[0],
app::Operation::Insert((0, "test".to_string())),
deltas::Operation::Insert((0, "test".to_string())),
);
assert_eq!(
std::fs::read_to_string(gb_repo.session_wd_path().join(file_path))?,
@ -228,7 +228,7 @@ fn test_register_new_file_twice() -> Result<()> {
assert_eq!(deltas[0].operations.len(), 1);
assert_eq!(
deltas[0].operations[0],
app::Operation::Insert((0, "test".to_string())),
deltas::Operation::Insert((0, "test".to_string())),
);
assert_eq!(
std::fs::read_to_string(gb_repo.session_wd_path().join(file_path))?,
@ -243,12 +243,12 @@ fn test_register_new_file_twice() -> Result<()> {
assert_eq!(deltas[0].operations.len(), 1);
assert_eq!(
deltas[0].operations[0],
app::Operation::Insert((0, "test".to_string())),
deltas::Operation::Insert((0, "test".to_string())),
);
assert_eq!(deltas[1].operations.len(), 1);
assert_eq!(
deltas[1].operations[0],
app::Operation::Insert((4, "2".to_string())),
deltas::Operation::Insert((4, "2".to_string())),
);
assert_eq!(
std::fs::read_to_string(gb_repo.session_wd_path().join(file_path))?,
@ -287,7 +287,7 @@ fn test_register_file_delted() -> Result<()> {
assert_eq!(deltas[0].operations.len(), 1);
assert_eq!(
deltas[0].operations[0],
app::Operation::Insert((0, "test".to_string())),
deltas::Operation::Insert((0, "test".to_string())),
);
assert_eq!(
std::fs::read_to_string(gb_repo.session_wd_path().join(file_path))?,
@ -302,10 +302,10 @@ fn test_register_file_delted() -> Result<()> {
assert_eq!(deltas[0].operations.len(), 1);
assert_eq!(
deltas[0].operations[0],
app::Operation::Insert((0, "test".to_string())),
deltas::Operation::Insert((0, "test".to_string())),
);
assert_eq!(deltas[1].operations.len(), 1);
assert_eq!(deltas[1].operations[0], app::Operation::Delete((0, 4)),);
assert_eq!(deltas[1].operations[0], deltas::Operation::Delete((0, 4)),);
Ok(())
}
@ -343,7 +343,7 @@ fn test_flow_with_commits() -> Result<()> {
}
// get all the created sessions
let mut sessions: Vec<app::Session> = gb_repo
let mut sessions: Vec<sessions::Session> = gb_repo
.get_sessions_iterator()?
.map(|s| s.unwrap())
.collect();
@ -364,7 +364,7 @@ fn test_flow_with_commits() -> Result<()> {
let sessions_slice = &mut sessions[i..];
// collect all operations from sessions in the reverse order
let mut operations: Vec<app::Operation> = vec![];
let mut operations: Vec<deltas::Operation> = vec![];
sessions_slice.iter().for_each(|session| {
let reader = gb_repo.get_session_reader(&session).unwrap();
let deltas_by_filepath = reader.deltas(None).unwrap();
@ -435,7 +435,7 @@ fn test_flow_no_commits() -> Result<()> {
}
// get all the created sessions
let mut sessions: Vec<app::Session> = gb_repo
let mut sessions: Vec<sessions::Session> = gb_repo
.get_sessions_iterator()?
.map(|s| s.unwrap())
.collect();
@ -456,7 +456,7 @@ fn test_flow_no_commits() -> Result<()> {
let sessions_slice = &mut sessions[i..];
// collect all operations from sessions in the reverse order
let mut operations: Vec<app::Operation> = vec![];
let mut operations: Vec<deltas::Operation> = vec![];
sessions_slice.iter().for_each(|session| {
let reader = gb_repo.get_session_reader(&session).unwrap();
let deltas_by_filepath = reader.deltas(None).unwrap();
@ -526,7 +526,7 @@ fn test_flow_signle_session() -> Result<()> {
}
// collect all operations from sessions in the reverse order
let mut operations: Vec<app::Operation> = vec![];
let mut operations: Vec<deltas::Operation> = vec![];
let session = gb_repo.get_current_session()?.unwrap();
let reader = gb_repo.get_session_reader(&session).unwrap();
let deltas_by_filepath = reader.deltas(None).unwrap();

View File

@ -1,4 +1,7 @@
use crate::{app, projects};
use crate::{
app::{deltas, sessions},
projects,
};
#[derive(Debug)]
pub struct Event {
@ -7,7 +10,7 @@ pub struct Event {
}
impl Event {
pub fn session(project: &projects::Project, session: &app::Session) -> Self {
pub fn session(project: &projects::Project, session: &sessions::Session) -> Self {
let event_name = format!("project://{}/sessions", project.id);
Event {
name: event_name,
@ -41,8 +44,8 @@ impl Event {
pub fn detlas(
project: &projects::Project,
session: &app::Session,
deltas: &Vec<app::Delta>,
session: &sessions::Session,
deltas: &Vec<deltas::Delta>,
relative_file_path: &std::path::Path,
) -> Self {
let event_name = format!("project://{}/sessions/{}/deltas", project.id, session.id);

View File

@ -27,7 +27,7 @@ use tauri_plugin_log::{
use thiserror::Error;
use timed::timed;
use crate::app::projects;
use crate::app::{projects, deltas, sessions};
#[derive(Debug, Error)]
pub enum Error {
@ -149,7 +149,7 @@ async fn list_sessions(
handle: tauri::AppHandle,
project_id: &str,
earliest_timestamp_ms: Option<u128>,
) -> Result<Vec<app::Session>, Error> {
) -> Result<Vec<sessions::Session>, Error> {
let app = handle.state::<app::App>();
let sessions = app
.list_sessions(project_id, earliest_timestamp_ms)
@ -285,7 +285,7 @@ async fn list_deltas(
project_id: &str,
session_id: &str,
paths: Option<Vec<&str>>,
) -> Result<HashMap<String, Vec<app::Delta>>, Error> {
) -> Result<HashMap<String, Vec<deltas::Delta>>, Error> {
let app = handle.state::<app::App>();
let deltas = app
.list_session_deltas(project_id, session_id, paths)

View File

@ -11,7 +11,10 @@ use serde::Serialize;
use similar::{ChangeTag, TextDiff};
use tantivy::{collector, directory::MmapDirectory, schema, IndexWriter};
use crate::{app, storage};
use crate::{
app::{self, deltas, sessions},
storage,
};
const CURRENT_VERSION: u64 = 4; // should not decrease
@ -130,7 +133,7 @@ impl Deltas {
pub fn index_session(
&self,
repository: &app::gb_repository::Repository,
session: &app::Session,
session: &sessions::Session,
) -> Result<()> {
index_session(
&self.index,
@ -187,7 +190,7 @@ pub struct SearchResults {
fn index_session(
index: &tantivy::Index,
writer: &mut IndexWriter,
session: &app::Session,
session: &sessions::Session,
repository: &app::gb_repository::Repository,
) -> Result<()> {
let reader = repository
@ -233,12 +236,12 @@ fn index_session(
fn index_delta(
index: &tantivy::Index,
writer: &mut IndexWriter,
session: &app::Session,
session: &sessions::Session,
project_id: &str,
file_text: &mut Vec<char>,
file_path: &str,
i: usize,
delta: &app::Delta,
delta: &deltas::Delta,
) -> Result<()> {
let mut doc = tantivy::Document::default();
doc.add_u64(

View File

@ -4,7 +4,7 @@ use std::path::Path;
use anyhow::Result;
use tempfile::tempdir;
use crate::{app, projects, storage, users};
use crate::{app::{self, deltas}, projects, storage, users};
fn test_repository() -> Result<git2::Repository> {
let path = tempdir()?.path().to_str().unwrap().to_string();
@ -59,16 +59,16 @@ fn test_filter_by_timestamp() -> Result<()> {
writer.write_deltas(
Path::new("test.txt"),
&vec![
app::Delta {
operations: vec![app::Operation::Insert((0, "Hello".to_string()))],
deltas::Delta {
operations: vec![deltas::Operation::Insert((0, "Hello".to_string()))],
timestamp_ms: 0,
},
app::Delta {
operations: vec![app::Operation::Insert((5, "World".to_string()))],
deltas::Delta {
operations: vec![deltas::Operation::Insert((5, "World".to_string()))],
timestamp_ms: 1,
},
app::Delta {
operations: vec![app::Operation::Insert((5, " ".to_string()))],
deltas::Delta {
operations: vec![deltas::Operation::Insert((5, " ".to_string()))],
timestamp_ms: 2,
},
],
@ -135,12 +135,12 @@ fn test_sorted_by_timestamp() -> Result<()> {
writer.write_deltas(
Path::new("test.txt"),
&vec![
app::Delta {
operations: vec![app::Operation::Insert((0, "Hello".to_string()))],
deltas::Delta {
operations: vec![deltas::Operation::Insert((0, "Hello".to_string()))],
timestamp_ms: 0,
},
app::Delta {
operations: vec![app::Operation::Insert((5, " World".to_string()))],
deltas::Delta {
operations: vec![deltas::Operation::Insert((5, " World".to_string()))],
timestamp_ms: 1,
},
],
@ -192,12 +192,12 @@ fn test_simple() -> Result<()> {
writer.write_deltas(
Path::new("test.txt"),
&vec![
app::Delta {
operations: vec![app::Operation::Insert((0, "Hello".to_string()))],
deltas::Delta {
operations: vec![deltas::Operation::Insert((0, "Hello".to_string()))],
timestamp_ms: 0,
},
app::Delta {
operations: vec![app::Operation::Insert((5, " World".to_string()))],
deltas::Delta {
operations: vec![deltas::Operation::Insert((5, " World".to_string()))],
timestamp_ms: 0,
},
],