mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-02 07:53:55 +03:00
move deltas inside app
This commit is contained in:
parent
7b637ee527
commit
014a4e0575
@ -3,7 +3,7 @@ use std::{collections::HashMap, sync};
|
||||
use anyhow::{Context, Result};
|
||||
use crossbeam_channel::{bounded, Sender};
|
||||
|
||||
use crate::{deltas, events, git::activity, projects, pty, search, storage, users};
|
||||
use crate::{app, events, git::activity, projects, pty, search, storage, users};
|
||||
|
||||
use super::{gb_repository, project_repository, watcher, sessions};
|
||||
|
||||
@ -308,7 +308,7 @@ impl App {
|
||||
project_id: &str,
|
||||
session_id: &str,
|
||||
paths: Option<Vec<&str>>,
|
||||
) -> Result<HashMap<String, Vec<deltas::Delta>>> {
|
||||
) -> Result<HashMap<String, Vec<app::Delta>>> {
|
||||
let gb_repository = gb_repository::Repository::open(
|
||||
self.local_data_dir.clone(),
|
||||
project_id.to_string(),
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::deltas::operations::{get_delta_operations, Operation};
|
||||
use super::{get_delta_operations, Operation};
|
||||
|
||||
#[test]
|
||||
fn test_get_delta_operations_insert_end() {
|
@ -1,4 +1,4 @@
|
||||
use crate::deltas::{operations::Operation, text_document::TextDocument, Delta};
|
||||
use super::{Operation, TextDocument, Delta};
|
||||
|
||||
#[test]
|
||||
fn test_new() {
|
@ -1,7 +1,10 @@
|
||||
use anyhow::Result;
|
||||
use tempfile::tempdir;
|
||||
|
||||
use crate::{app::gb_repository, deltas, projects, storage, users};
|
||||
use crate::{
|
||||
app::{self, gb_repository},
|
||||
projects, storage, users,
|
||||
};
|
||||
|
||||
fn test_repository() -> Result<git2::Repository> {
|
||||
let path = tempdir()?.path().to_str().unwrap().to_string();
|
||||
@ -224,8 +227,8 @@ fn test_list_deltas_from_current_session() -> Result<()> {
|
||||
let writer = gb_repo.get_session_writer(¤t_session)?;
|
||||
writer.write_deltas(
|
||||
"test.txt",
|
||||
&vec![deltas::Delta {
|
||||
operations: vec![deltas::Operation::Insert((0, "Hello World".to_string()))],
|
||||
&vec![app::Delta {
|
||||
operations: vec![app::Operation::Insert((0, "Hello World".to_string()))],
|
||||
timestamp_ms: 0,
|
||||
}],
|
||||
)?;
|
||||
@ -237,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],
|
||||
deltas::Operation::Insert((0, "Hello World".to_string()))
|
||||
app::Operation::Insert((0, "Hello World".to_string()))
|
||||
);
|
||||
|
||||
Ok(())
|
||||
@ -263,8 +266,8 @@ fn test_list_deltas_from_flushed_session() -> Result<()> {
|
||||
let writer = gb_repo.get_session_writer(¤t_session)?;
|
||||
writer.write_deltas(
|
||||
"test.txt",
|
||||
&vec![deltas::Delta {
|
||||
operations: vec![deltas::Operation::Insert((0, "Hello World".to_string()))],
|
||||
&vec![app::Delta {
|
||||
operations: vec![app::Operation::Insert((0, "Hello World".to_string()))],
|
||||
timestamp_ms: 0,
|
||||
}],
|
||||
)?;
|
||||
@ -277,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],
|
||||
deltas::Operation::Insert((0, "Hello World".to_string()))
|
||||
app::Operation::Insert((0, "Hello World".to_string()))
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
@ -1,4 +1,5 @@
|
||||
mod app;
|
||||
mod deltas;
|
||||
pub mod gb_repository;
|
||||
pub mod project_repository;
|
||||
pub mod reader;
|
||||
@ -12,5 +13,6 @@ 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};
|
||||
|
@ -2,12 +2,9 @@ use std::collections::HashMap;
|
||||
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
|
||||
use crate::{
|
||||
app::{
|
||||
gb_repository,
|
||||
reader::{self, CommitReader, Reader},
|
||||
},
|
||||
deltas,
|
||||
use crate::app::{
|
||||
self, gb_repository,
|
||||
reader::{self, CommitReader, Reader},
|
||||
};
|
||||
|
||||
use super::Session;
|
||||
@ -120,7 +117,7 @@ impl<'reader> SessionReader<'reader> {
|
||||
pub fn file_deltas<P: AsRef<std::path::Path>>(
|
||||
&self,
|
||||
path: P,
|
||||
) -> Result<Option<Vec<deltas::Delta>>> {
|
||||
) -> Result<Option<Vec<app::Delta>>> {
|
||||
let path = path.as_ref();
|
||||
let file_deltas_path = std::path::Path::new("session/deltas").join(path);
|
||||
match self
|
||||
@ -140,7 +137,7 @@ impl<'reader> SessionReader<'reader> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deltas(&self, paths: Option<Vec<&str>>) -> Result<HashMap<String, Vec<deltas::Delta>>> {
|
||||
pub fn deltas(&self, paths: Option<Vec<&str>>) -> Result<HashMap<String, Vec<app::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();
|
||||
|
@ -4,11 +4,11 @@ use anyhow::{anyhow, Context, Result};
|
||||
|
||||
use crate::{
|
||||
app::{
|
||||
gb_repository,
|
||||
self, gb_repository,
|
||||
reader::{self, Reader},
|
||||
writer::{self, Writer},
|
||||
},
|
||||
deltas, pty,
|
||||
pty,
|
||||
};
|
||||
|
||||
use super::Session;
|
||||
@ -188,7 +188,7 @@ impl<'writer> SessionWriter<'writer> {
|
||||
pub fn write_deltas<P: AsRef<std::path::Path>>(
|
||||
&self,
|
||||
path: P,
|
||||
deltas: &Vec<deltas::Delta>,
|
||||
deltas: &Vec<app::Delta>,
|
||||
) -> Result<()> {
|
||||
self.repository.lock()?;
|
||||
defer! {
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::{path, time};
|
||||
|
||||
use crate::{app, deltas, projects};
|
||||
use crate::{app, projects};
|
||||
|
||||
pub enum Event {
|
||||
Tick(time::SystemTime),
|
||||
@ -21,7 +21,7 @@ pub enum Event {
|
||||
projects::Project,
|
||||
app::Session,
|
||||
path::PathBuf,
|
||||
Vec<deltas::Delta>,
|
||||
Vec<app::Delta>,
|
||||
),
|
||||
),
|
||||
}
|
||||
|
@ -4,10 +4,10 @@ use anyhow::{Context, Result};
|
||||
|
||||
use crate::{
|
||||
app::{
|
||||
gb_repository, project_repository,
|
||||
self, gb_repository, project_repository,
|
||||
reader::{self, Reader},
|
||||
},
|
||||
deltas, projects,
|
||||
projects,
|
||||
};
|
||||
|
||||
use super::events;
|
||||
@ -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<deltas::Delta>>> {
|
||||
fn get_current_deltas(&self, path: &std::path::Path) -> Result<Option<Vec<app::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)) => {
|
||||
deltas::TextDocument::new(Some(&latest_contents), deltas)?
|
||||
app::TextDocument::new(Some(&latest_contents), deltas)?
|
||||
}
|
||||
(Some(latest_contents), None) => {
|
||||
deltas::TextDocument::new(Some(&latest_contents), vec![])?
|
||||
app::TextDocument::new(Some(&latest_contents), vec![])?
|
||||
}
|
||||
(None, Some(deltas)) => deltas::TextDocument::new(None, deltas)?,
|
||||
(None, None) => deltas::TextDocument::new(None, vec![])?,
|
||||
(None, Some(deltas)) => app::TextDocument::new(None, deltas)?,
|
||||
(None, None) => app::TextDocument::new(None, vec![])?,
|
||||
};
|
||||
|
||||
if !text_doc
|
||||
|
@ -3,7 +3,7 @@ use tempfile::tempdir;
|
||||
|
||||
use crate::{
|
||||
app::{self, gb_repository, project_repository},
|
||||
deltas, projects, storage, users,
|
||||
projects, storage, users,
|
||||
};
|
||||
|
||||
use super::project_file_change::Handler;
|
||||
@ -88,7 +88,7 @@ fn test_register_existing_commited_file() -> Result<()> {
|
||||
assert_eq!(deltas[0].operations.len(), 1);
|
||||
assert_eq!(
|
||||
deltas[0].operations[0],
|
||||
deltas::Operation::Insert((4, "2".to_string())),
|
||||
app::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],
|
||||
deltas::Operation::Insert((0, "test".to_string())),
|
||||
app::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],
|
||||
deltas::Operation::Insert((0, "test".to_string())),
|
||||
app::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],
|
||||
deltas::Operation::Insert((0, "test".to_string())),
|
||||
app::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())),
|
||||
app::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],
|
||||
deltas::Operation::Insert((0, "test".to_string())),
|
||||
app::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],
|
||||
deltas::Operation::Insert((0, "test".to_string())),
|
||||
app::Operation::Insert((0, "test".to_string())),
|
||||
);
|
||||
assert_eq!(deltas[1].operations.len(), 1);
|
||||
assert_eq!(deltas[1].operations[0], deltas::Operation::Delete((0, 4)),);
|
||||
assert_eq!(deltas[1].operations[0], app::Operation::Delete((0, 4)),);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@ -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<deltas::Operation> = vec![];
|
||||
let mut operations: Vec<app::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();
|
||||
@ -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<deltas::Operation> = vec![];
|
||||
let mut operations: Vec<app::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<deltas::Operation> = vec![];
|
||||
let mut operations: Vec<app::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();
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::{app, deltas, projects};
|
||||
use crate::{app, projects};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Event {
|
||||
@ -42,7 +42,7 @@ impl Event {
|
||||
pub fn detlas(
|
||||
project: &projects::Project,
|
||||
session: &app::Session,
|
||||
deltas: &Vec<deltas::Delta>,
|
||||
deltas: &Vec<app::Delta>,
|
||||
relative_file_path: &std::path::Path,
|
||||
) -> Self {
|
||||
let event_name = format!("project://{}/sessions/{}/deltas", project.id, session.id);
|
||||
|
@ -4,7 +4,6 @@ extern crate scopeguard;
|
||||
extern crate lazy_static;
|
||||
|
||||
mod app;
|
||||
mod deltas;
|
||||
mod events;
|
||||
mod fs;
|
||||
mod git;
|
||||
@ -18,7 +17,6 @@ mod users;
|
||||
extern crate log;
|
||||
|
||||
use anyhow::{Context, Result};
|
||||
use deltas::Delta;
|
||||
use git::activity;
|
||||
use serde::{ser::SerializeMap, Serialize};
|
||||
use std::{collections::HashMap, ops::Range};
|
||||
@ -286,7 +284,7 @@ async fn list_deltas(
|
||||
project_id: &str,
|
||||
session_id: &str,
|
||||
paths: Option<Vec<&str>>,
|
||||
) -> Result<HashMap<String, Vec<Delta>>, Error> {
|
||||
) -> Result<HashMap<String, Vec<app::Delta>>, Error> {
|
||||
let app = handle.state::<app::App>();
|
||||
let deltas = app
|
||||
.list_session_deltas(project_id, session_id, paths)
|
||||
|
@ -11,7 +11,7 @@ use serde::Serialize;
|
||||
use similar::{ChangeTag, TextDiff};
|
||||
use tantivy::{collector, directory::MmapDirectory, schema, IndexWriter};
|
||||
|
||||
use crate::{app, deltas, storage};
|
||||
use crate::{app, storage};
|
||||
|
||||
const CURRENT_VERSION: u64 = 4; // should not decrease
|
||||
|
||||
@ -238,7 +238,7 @@ fn index_delta(
|
||||
file_text: &mut Vec<char>,
|
||||
file_path: &str,
|
||||
i: usize,
|
||||
delta: &deltas::Delta,
|
||||
delta: &app::Delta,
|
||||
) -> Result<()> {
|
||||
let mut doc = tantivy::Document::default();
|
||||
doc.add_u64(
|
||||
|
@ -4,11 +4,7 @@ use std::path::Path;
|
||||
use anyhow::Result;
|
||||
use tempfile::tempdir;
|
||||
|
||||
use crate::{
|
||||
app,
|
||||
deltas::{self, Operation},
|
||||
projects, storage, users,
|
||||
};
|
||||
use crate::{app, projects, storage, users};
|
||||
|
||||
fn test_repository() -> Result<git2::Repository> {
|
||||
let path = tempdir()?.path().to_str().unwrap().to_string();
|
||||
@ -63,16 +59,16 @@ fn test_filter_by_timestamp() -> Result<()> {
|
||||
writer.write_deltas(
|
||||
Path::new("test.txt"),
|
||||
&vec![
|
||||
deltas::Delta {
|
||||
operations: vec![Operation::Insert((0, "Hello".to_string()))],
|
||||
app::Delta {
|
||||
operations: vec![app::Operation::Insert((0, "Hello".to_string()))],
|
||||
timestamp_ms: 0,
|
||||
},
|
||||
deltas::Delta {
|
||||
operations: vec![Operation::Insert((5, "World".to_string()))],
|
||||
app::Delta {
|
||||
operations: vec![app::Operation::Insert((5, "World".to_string()))],
|
||||
timestamp_ms: 1,
|
||||
},
|
||||
deltas::Delta {
|
||||
operations: vec![Operation::Insert((5, " ".to_string()))],
|
||||
app::Delta {
|
||||
operations: vec![app::Operation::Insert((5, " ".to_string()))],
|
||||
timestamp_ms: 2,
|
||||
},
|
||||
],
|
||||
@ -139,12 +135,12 @@ fn test_sorted_by_timestamp() -> Result<()> {
|
||||
writer.write_deltas(
|
||||
Path::new("test.txt"),
|
||||
&vec![
|
||||
deltas::Delta {
|
||||
operations: vec![Operation::Insert((0, "Hello".to_string()))],
|
||||
app::Delta {
|
||||
operations: vec![app::Operation::Insert((0, "Hello".to_string()))],
|
||||
timestamp_ms: 0,
|
||||
},
|
||||
deltas::Delta {
|
||||
operations: vec![Operation::Insert((5, " World".to_string()))],
|
||||
app::Delta {
|
||||
operations: vec![app::Operation::Insert((5, " World".to_string()))],
|
||||
timestamp_ms: 1,
|
||||
},
|
||||
],
|
||||
@ -196,12 +192,12 @@ fn test_simple() -> Result<()> {
|
||||
writer.write_deltas(
|
||||
Path::new("test.txt"),
|
||||
&vec![
|
||||
deltas::Delta {
|
||||
operations: vec![Operation::Insert((0, "Hello".to_string()))],
|
||||
app::Delta {
|
||||
operations: vec![app::Operation::Insert((0, "Hello".to_string()))],
|
||||
timestamp_ms: 0,
|
||||
},
|
||||
deltas::Delta {
|
||||
operations: vec![Operation::Insert((5, " World".to_string()))],
|
||||
app::Delta {
|
||||
operations: vec![app::Operation::Insert((5, " World".to_string()))],
|
||||
timestamp_ms: 0,
|
||||
},
|
||||
],
|
||||
|
Loading…
Reference in New Issue
Block a user