mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-09-11 12:25:42 +03:00
share repo for deltas storage
This commit is contained in:
parent
3009958218
commit
e79d377e3e
@ -1,4 +1,4 @@
|
||||
use crate::{deltas, projects, sessions};
|
||||
use crate::{deltas, sessions};
|
||||
use anyhow::Result;
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
@ -13,11 +13,11 @@ pub struct Store {
|
||||
}
|
||||
|
||||
impl Store {
|
||||
pub fn new(project: projects::Project) -> Result<Self> {
|
||||
Ok(Self {
|
||||
git_repository: Arc::new(Mutex::new(git2::Repository::open(&project.path)?)),
|
||||
pub fn new(git_repository: Arc<Mutex<git2::Repository>>) -> Self {
|
||||
Self {
|
||||
git_repository,
|
||||
cache: Arc::new(Mutex::new(HashMap::new())),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn list_all(&self, session: &sessions::Session) -> Result<HashMap<String, Vec<deltas::Delta>>> {
|
||||
|
@ -1,6 +1,11 @@
|
||||
use crate::{deltas, projects, sessions};
|
||||
use anyhow::{anyhow, Context, Result};
|
||||
use std::{collections::HashMap, path::Path, time};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
path::Path,
|
||||
sync::{Arc, Mutex},
|
||||
time,
|
||||
};
|
||||
|
||||
use super::{current, persistent};
|
||||
|
||||
@ -12,12 +17,16 @@ pub struct Store {
|
||||
}
|
||||
|
||||
impl Store {
|
||||
pub fn new(project: projects::Project, sessions_store: sessions::Store) -> Result<Self> {
|
||||
Ok(Self {
|
||||
pub fn new(
|
||||
git_repository: Arc<Mutex<git2::Repository>>,
|
||||
project: projects::Project,
|
||||
sessions_store: sessions::Store,
|
||||
) -> Self {
|
||||
Self {
|
||||
current: current::Store::new(project.clone()),
|
||||
persistent: persistent::Store::new(project)?,
|
||||
persistent: persistent::Store::new(git_repository),
|
||||
sessions_store,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn read<P: AsRef<Path>>(&self, file_path: P) -> Result<Option<Vec<deltas::Delta>>> {
|
||||
|
@ -1,6 +1,9 @@
|
||||
use crate::{deltas::Delta, deltas::Operation, projects, sessions};
|
||||
use anyhow::Result;
|
||||
use std::path::Path;
|
||||
use std::{
|
||||
path::Path,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
|
||||
fn test_project() -> Result<(git2::Repository, projects::Project)> {
|
||||
@ -26,7 +29,7 @@ fn test_project() -> Result<(git2::Repository, projects::Project)> {
|
||||
fn test_read_none() {
|
||||
let (repo, project) = test_project().unwrap();
|
||||
let sessions_store = sessions::Store::new(clone_repo(&repo), project.clone()).unwrap();
|
||||
let store = super::Store::new(project, sessions_store).unwrap();
|
||||
let store = super::Store::new(Arc::new(Mutex::new(repo)), project, sessions_store);
|
||||
let file_path = Path::new("test.txt");
|
||||
let deltas = store.read(file_path);
|
||||
assert!(deltas.is_ok());
|
||||
@ -37,7 +40,7 @@ fn test_read_none() {
|
||||
fn test_read_invalid() {
|
||||
let (repo, project) = test_project().unwrap();
|
||||
let sessions_store = sessions::Store::new(clone_repo(&repo), project.clone()).unwrap();
|
||||
let store = super::Store::new(project.clone(), sessions_store).unwrap();
|
||||
let store = super::Store::new(Arc::new(Mutex::new(repo)), project.clone(), sessions_store);
|
||||
let file_path = Path::new("test.txt");
|
||||
let full_file_path = project.deltas_path().join(file_path);
|
||||
|
||||
@ -52,7 +55,7 @@ fn test_read_invalid() {
|
||||
fn test_write_read() {
|
||||
let (repo, project) = test_project().unwrap();
|
||||
let sessions_store = sessions::Store::new(clone_repo(&repo), project.clone()).unwrap();
|
||||
let store = super::Store::new(project, sessions_store).unwrap();
|
||||
let store = super::Store::new(Arc::new(Mutex::new(repo)), project, sessions_store);
|
||||
let file_path = Path::new("test.txt");
|
||||
|
||||
let deltas = vec![Delta {
|
||||
@ -71,7 +74,7 @@ fn test_write_read() {
|
||||
fn test_write_must_create_session() {
|
||||
let (repo, project) = test_project().unwrap();
|
||||
let sessions_store = sessions::Store::new(clone_repo(&repo), project.clone()).unwrap();
|
||||
let store = super::Store::new(project.clone(), sessions_store.clone()).unwrap();
|
||||
let store = super::Store::new(Arc::new(Mutex::new(repo)), project, sessions_store.clone());
|
||||
let file_path = Path::new("test.txt");
|
||||
|
||||
let deltas = vec![Delta {
|
||||
@ -96,7 +99,7 @@ fn clone_repo(repo: &git2::Repository) -> git2::Repository {
|
||||
fn test_write_must_not_override_session() {
|
||||
let (repo, project) = test_project().unwrap();
|
||||
let sessions_store = sessions::Store::new(clone_repo(&repo), project.clone()).unwrap();
|
||||
let store = super::Store::new(project.clone(), sessions_store.clone()).unwrap();
|
||||
let store = super::Store::new(Arc::new(Mutex::new(repo)), project, sessions_store.clone());
|
||||
let file_path = Path::new("test.txt");
|
||||
|
||||
let session_before_write = sessions_store.create_current();
|
||||
|
@ -1,7 +1,12 @@
|
||||
use crate::{deltas, fs, projects, sessions, users};
|
||||
use anyhow::{Context, Result};
|
||||
use git2::{BranchType, Cred, DiffOptions, Signature};
|
||||
use std::{collections::HashMap, env, path::Path};
|
||||
use std::{
|
||||
collections::HashMap,
|
||||
env,
|
||||
path::Path,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use tauri::regex::Regex;
|
||||
use walkdir::WalkDir;
|
||||
|
||||
@ -33,7 +38,11 @@ impl Repository {
|
||||
Ok(Repository {
|
||||
project: project.clone(),
|
||||
git_repository,
|
||||
deltas_storage: deltas::Store::new(project, sessions_storage.clone())?,
|
||||
deltas_storage: deltas::Store::new(
|
||||
Arc::new(Mutex::new(git2::Repository::open(&project.path)?)),
|
||||
project,
|
||||
sessions_storage.clone(),
|
||||
),
|
||||
sessions_storage,
|
||||
})
|
||||
}
|
||||
|
@ -4,7 +4,10 @@ use crate::{
|
||||
};
|
||||
use anyhow::Result;
|
||||
use core::ops::Range;
|
||||
use std::path::Path;
|
||||
use std::{
|
||||
path::Path,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
use tempfile::tempdir;
|
||||
|
||||
fn test_project() -> Result<(git2::Repository, projects::Project)> {
|
||||
@ -36,7 +39,11 @@ fn test_filter_by_timestamp() {
|
||||
let index_path = tempdir().unwrap().path().to_str().unwrap().to_string();
|
||||
|
||||
let sessions_storage = sessions::Store::new(clone_repo(&repo), project.clone()).unwrap();
|
||||
let deltas_storage = deltas::Store::new(project.clone(), sessions_storage.clone()).unwrap();
|
||||
let deltas_storage = deltas::Store::new(
|
||||
Arc::new(Mutex::new(repo)),
|
||||
project.clone(),
|
||||
sessions_storage.clone(),
|
||||
);
|
||||
let mut session = sessions_storage.create_current().unwrap();
|
||||
deltas_storage
|
||||
.write(
|
||||
@ -108,7 +115,11 @@ fn test_sorted_by_timestamp() {
|
||||
let index_path = tempdir().unwrap().path().to_str().unwrap().to_string();
|
||||
|
||||
let sessions_storage = sessions::Store::new(clone_repo(&repo), project.clone()).unwrap();
|
||||
let deltas_storage = deltas::Store::new(project.clone(), sessions_storage.clone()).unwrap();
|
||||
let deltas_storage = deltas::Store::new(
|
||||
Arc::new(Mutex::new(repo)),
|
||||
project.clone(),
|
||||
sessions_storage.clone(),
|
||||
);
|
||||
let mut session = sessions_storage.create_current().unwrap();
|
||||
deltas_storage
|
||||
.write(
|
||||
@ -154,7 +165,11 @@ fn test_simple() {
|
||||
let index_path = tempdir().unwrap().path().to_str().unwrap().to_string();
|
||||
|
||||
let sessions_storage = sessions::Store::new(clone_repo(&repo), project.clone()).unwrap();
|
||||
let deltas_storage = deltas::Store::new(project.clone(), sessions_storage.clone()).unwrap();
|
||||
let deltas_storage = deltas::Store::new(
|
||||
Arc::new(Mutex::new(repo)),
|
||||
project.clone(),
|
||||
sessions_storage.clone(),
|
||||
);
|
||||
let mut session = sessions_storage.create_current().unwrap();
|
||||
deltas_storage
|
||||
.write(
|
||||
|
@ -1,4 +1,7 @@
|
||||
use std::path::Path;
|
||||
use std::{
|
||||
path::Path,
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use crate::{deltas, projects, sessions};
|
||||
use anyhow::Result;
|
||||
@ -35,8 +38,11 @@ fn test_register_file_change_must_create_session() {
|
||||
std::fs::write(Path::new(&project.path).join(relative_file_path), "test").unwrap();
|
||||
|
||||
let sessions_storage = sessions::Store::new(clone_repo(&repo), project.clone()).unwrap();
|
||||
let deltas_storage =
|
||||
deltas::Store::new(project.clone(), sessions_storage).unwrap();
|
||||
let deltas_storage = deltas::Store::new(
|
||||
Arc::new(Mutex::new(clone_repo(&repo))),
|
||||
project.clone(),
|
||||
sessions_storage,
|
||||
);
|
||||
let result =
|
||||
super::delta::register_file_change(&project, &repo, &deltas_storage, &relative_file_path);
|
||||
println!("{:?}", result);
|
||||
@ -56,8 +62,11 @@ fn test_register_file_change_must_not_change_session() {
|
||||
std::fs::write(Path::new(&project.path).join(relative_file_path), "test").unwrap();
|
||||
|
||||
let sessions_storage = sessions::Store::new(clone_repo(&repo), project.clone()).unwrap();
|
||||
let deltas_storage =
|
||||
deltas::Store::new(project.clone(), sessions_storage).unwrap();
|
||||
let deltas_storage = deltas::Store::new(
|
||||
Arc::new(Mutex::new(clone_repo(&repo))),
|
||||
project.clone(),
|
||||
sessions_storage,
|
||||
);
|
||||
let result =
|
||||
super::delta::register_file_change(&project, &repo, &deltas_storage, &relative_file_path);
|
||||
assert!(result.is_ok());
|
||||
|
Loading…
Reference in New Issue
Block a user