From 5ba4a9a6b413dd6deccfc12b3a7049d04fc1eda2 Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Wed, 4 Oct 2023 15:53:00 +0200 Subject: [PATCH 1/2] drop gb_project's dependency on project_storage --- packages/tauri/src/app.rs | 46 +++++----- packages/tauri/src/bookmarks/writer.rs | 2 +- packages/tauri/src/deltas/writer.rs | 4 +- .../tauri/src/gb_repository/repository.rs | 85 ++++++------------- .../src/gb_repository/repository_tests.rs | 12 ++- packages/tauri/src/sessions/writer.rs | 2 +- packages/tauri/src/test_utils.rs | 29 +++++-- .../tauri/src/virtual_branches/controller.rs | 40 ++++----- packages/tauri/src/virtual_branches/tests.rs | 2 + .../watcher/handlers/fetch_gitbutler_data.rs | 22 ++--- .../watcher/handlers/fetch_project_data.rs | 15 ++-- .../src/watcher/handlers/flush_session.rs | 10 +-- .../src/watcher/handlers/index_handler.rs | 28 +++--- .../watcher/handlers/project_file_change.rs | 10 +-- .../watcher/handlers/push_gitbutler_data.rs | 14 +-- .../src/watcher/handlers/tick_handler.rs | 12 +-- 16 files changed, 147 insertions(+), 186 deletions(-) diff --git a/packages/tauri/src/app.rs b/packages/tauri/src/app.rs index 9b8203914..9f9c6656e 100644 --- a/packages/tauri/src/app.rs +++ b/packages/tauri/src/app.rs @@ -86,20 +86,6 @@ impl App { Ok(()) } - fn gb_repository( - &self, - project_id: &str, - user: Option<&users::User>, - ) -> Result { - gb_repository::Repository::open( - self.local_data_dir.clone(), - project_id, - self.projects_storage.clone(), - user, - ) - .context("failed to open repository") - } - fn gb_project(&self, project_id: &str) -> Result { self.projects_storage .get_project(project_id) @@ -179,8 +165,7 @@ impl App { Some(project) => { let gb_repository = match gb_repository::Repository::open( self.local_data_dir.clone(), - id, - self.projects_storage.clone(), + &project, self.users_storage.get()?.as_ref(), ) { Ok(repo) => Ok(Some(repo)), @@ -242,9 +227,15 @@ impl App { .context("failed to get session")? .context("session not found")?; let user = self.users_storage.get()?; - let gb_repo = self - .gb_repository(project_id, user.as_ref()) - .context("failed to open repository")?; + let project = self + .projects_storage + .get_project(project_id) + .context("failed to get project")? + .ok_or_else(|| anyhow::anyhow!("project {} not found", project_id))?; + + let gb_repo = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open gb repository")?; let session_reader = sessions::Reader::open(&gb_repo, &session).context("failed to open session reader")?; session_reader @@ -265,7 +256,9 @@ impl App { let project = self.gb_project(project_id)?; let project_repository = project_repository::Repository::open(&project)?; let user = self.users_storage.get()?; - let gb_repo = self.gb_repository(project_id, user.as_ref())?; + let gb_repo = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open gb repository")?; let current_session = gb_repo.get_or_create_current_session()?; let current_session_reader = sessions::Reader::open(&gb_repo, ¤t_session)?; let target_reader = target::Reader::new(¤t_session_reader); @@ -299,7 +292,9 @@ impl App { pub fn upsert_bookmark(&self, bookmark: &bookmarks::Bookmark) -> Result<()> { let user = self.users_storage.get()?; - let gb_repository = self.gb_repository(&bookmark.project_id, user.as_ref())?; + let project = self.gb_project(&bookmark.project_id)?; + let gb_repository = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref())?; let writer = bookmarks::Writer::new(&gb_repository).context("failed to open writer")?; writer.write(bookmark).context("failed to write bookmark")?; @@ -411,8 +406,10 @@ impl App { project_id: &str, ) -> Result> { let user = self.users_storage.get()?; - let gb_repository = self.gb_repository(project_id, user.as_ref())?; let project = self.gb_project(project_id)?; + let gb_repository = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open gb repo")?; let project_repository = project_repository::Repository::open(&project) .context("failed to open project repository")?; virtual_branches::list_remote_branches(&gb_repository, &project_repository) @@ -449,7 +446,10 @@ impl App { pub fn git_gb_push(&self, project_id: &str) -> Result<()> { let user = self.users_storage.get()?; - let gb_repository = self.gb_repository(project_id, user.as_ref())?; + let project = self.gb_project(project_id)?; + let gb_repository = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open gb repo")?; gb_repository.push(user.as_ref()) } diff --git a/packages/tauri/src/bookmarks/writer.rs b/packages/tauri/src/bookmarks/writer.rs index 1e4416211..e6de8ba65 100644 --- a/packages/tauri/src/bookmarks/writer.rs +++ b/packages/tauri/src/bookmarks/writer.rs @@ -25,7 +25,7 @@ impl<'writer> BookmarksWriter<'writer> { )?; tracing::debug!( - project_id = self.repository.project_id, + project_id = self.repository.project.id, timestamp_ms = bookmark.timestamp_ms, "wrote bookmark", ); diff --git a/packages/tauri/src/deltas/writer.rs b/packages/tauri/src/deltas/writer.rs index 74d2ce25b..4e2a63cb6 100644 --- a/packages/tauri/src/deltas/writer.rs +++ b/packages/tauri/src/deltas/writer.rs @@ -32,7 +32,7 @@ impl<'writer> DeltasWriter<'writer> { .write_string(&format!("session/deltas/{}", path.display()), &raw_deltas)?; tracing::debug!( - project_id = self.repository.project_id, + project_id = self.repository.project.id, path = %path.display(), "wrote deltas" ); @@ -52,7 +52,7 @@ impl<'writer> DeltasWriter<'writer> { .write_string(&format!("session/wd/{}", path.display()), contents)?; tracing::debug!( - project_id = self.repository.project_id, + project_id = self.repository.project.id, path = %path.display(), "wrote session wd file" ); diff --git a/packages/tauri/src/gb_repository/repository.rs b/packages/tauri/src/gb_repository/repository.rs index b211b1504..701903cef 100644 --- a/packages/tauri/src/gb_repository/repository.rs +++ b/packages/tauri/src/gb_repository/repository.rs @@ -23,8 +23,7 @@ use crate::{ }; pub struct Repository { - pub project_id: String, - project_store: projects::Storage, + pub project: projects::Project, pub git_repository: git::Repository, lock_file: std::fs::File, } @@ -44,29 +43,19 @@ pub enum Error { impl Repository { pub fn open>( root: P, - project_id: &str, - project_store: projects::Storage, + project: &projects::Project, user: Option<&users::User>, ) -> Result { - let project = project_store - .get_project(project_id) - .context("failed to get project") - .map_err(Error::Other)?; - if project.is_none() { - return Err(Error::ProjectNotFound); - } - let project = project.unwrap(); - let project_objects_path = std::path::Path::new(&project.path).join(".git/objects"); if !project_objects_path.exists() { return Err(Error::ProjectPathNotFound(project_objects_path)); } - let path = root.as_ref().join("projects").join(project_id.clone()); + let path = root.as_ref().join("projects").join(&project.id); let lock_path = root .as_ref() .join("projects") - .join(format!("{}.lock", project_id)); + .join(format!("{}.lock", project.id)); if path.exists() { let git_repository = git::Repository::open(path.clone()) .with_context(|| format!("{}: failed to open git repository", path.display()))?; @@ -76,9 +65,8 @@ impl Repository { .map_err(Error::Git)?; Result::Ok(Self { - project_id: project_id.to_string(), + project: project.clone(), git_repository, - project_store, lock_file: File::create(lock_path).context("failed to create lock file")?, }) } else { @@ -96,9 +84,8 @@ impl Repository { .context("failed to add disk alternate")?; let gb_repository = Self { - project_id: project_id.to_string(), + project: project.clone(), git_repository, - project_store, lock_file: File::create(lock_path).context("failed to create lock file")?, }; @@ -106,7 +93,7 @@ impl Repository { .migrate(&project) .context("failed to migrate")? { - tracing::info!(project_id = gb_repository.project_id, "repository migrated"); + tracing::info!(project_id = gb_repository.project.id, "repository migrated"); return Result::Ok(gb_repository); } @@ -128,17 +115,10 @@ impl Repository { } pub fn get_project_id(&self) -> &str { - &self.project_id + &self.project.id } fn remote(&self, user: Option<&users::User>) -> Result> { - let project = self - .project_store - .get_project(&self.project_id) - .context("failed to get project")? - .ok_or(anyhow!("project not found"))?; - let project = project.as_ref(); - // only push if logged in let access_token = match user { Some(user) => user.access_token.clone(), @@ -146,7 +126,7 @@ impl Repository { }; // only push if project is connected - let remote_url = match project.api { + let remote_url = match self.project.api { Some(ref api) => api.git_url.clone(), None => return Ok(None), }; @@ -173,7 +153,7 @@ impl Repository { let mut callbacks = git2::RemoteCallbacks::new(); callbacks.push_update_reference(move |refname, message| { tracing::debug!( - project_id = self.project_id, + project_id = self.project.id, refname, message, "pulling reference" @@ -182,7 +162,7 @@ impl Repository { }); callbacks.push_transfer_progress(move |one, two, three| { tracing::debug!( - project_id = self.project_id, + project_id = self.project.id, "transferred {}/{}/{} objects", one, two, @@ -204,7 +184,7 @@ impl Repository { ))?; tracing::info!( - project_id = self.project_id, + project_id = self.project.id, remote = %remote.url()?.unwrap(), "gb repo fetched", ); @@ -222,7 +202,7 @@ impl Repository { let mut callbacks = git2::RemoteCallbacks::new(); callbacks.push_update_reference(move |refname, message| { tracing::debug!( - project_id = self.project_id, + project_id = self.project.id, refname, message, "pushing reference" @@ -231,7 +211,7 @@ impl Repository { }); callbacks.push_transfer_progress(move |one, two, three| { tracing::debug!( - project_id = self.project_id, + project_id = self.project.id, "transferred {}/{}/{} objects", one, two, @@ -245,7 +225,7 @@ impl Repository { let headers = &[auth_header.as_str()]; push_options.custom_headers(headers); - let remote_refspec = format!("refs/heads/current:refs/heads/{}", self.project_id); + let remote_refspec = format!("refs/heads/current:refs/heads/{}", self.project.id); // Push to the remote remote @@ -255,7 +235,7 @@ impl Repository { remote.url()?.unwrap() ))?; - tracing::info!(project_id = self.project_id, remote = %remote.url()?.unwrap(), "gb repository pushed"); + tracing::info!(project_id = self.project.id, remote = %remote.url()?.unwrap(), "gb repository pushed"); Ok(()) } @@ -362,7 +342,7 @@ impl Repository { .context("failed to write session")?; tracing::info!( - project_id = self.project_id, + project_id = self.project.id, session_id = session.id, "created new session" ); @@ -381,15 +361,7 @@ impl Repository { match sessions::Session::try_from(reader) { Result::Ok(session) => Ok(session), Err(sessions::SessionError::NoSession) => { - let project = self - .project_store - .get_project(&self.project_id) - .context("failed to get project")?; - if project.is_none() { - return Err(anyhow!("project does not exist")); - } - let project = project.unwrap(); - let project_repository = project_repository::Repository::open(&project) + let project_repository = project_repository::Repository::open(&self.project) .context("failed to open project repository")?; let session = self .create_current_session(&project_repository) @@ -410,18 +382,9 @@ impl Repository { return Ok(None); } - let project = self - .project_store - .get_project(&self.project_id) - .context("failed to get project")?; - if project.is_none() { - return Err(anyhow!("project not found")); - } - let project = project.unwrap(); - let current_session = current_session.unwrap(); let current_session = self.flush_session( - &project_repository::Repository::open(&project)?, + &project_repository::Repository::open(&self.project)?, ¤t_session, user, )?; @@ -476,7 +439,7 @@ impl Repository { write_gb_commit(tree_id, self, user).context("failed to write gb commit")?; tracing::info!( - project_id = self.project_id, + project_id = self.project.id, session_id = session.id, %commit_oid, "flushed session" @@ -653,7 +616,7 @@ fn build_wd_tree( Result::Ok(reader::Content::UTF8(content)) => content, Result::Ok(reader::Content::Large) => { tracing::error!( - project_id = gb_repository.project_id, + project_id = gb_repository.project.id, path = %abs_path.display(), "large file in session working directory" ); @@ -661,7 +624,7 @@ fn build_wd_tree( } Result::Ok(reader::Content::Binary) => { tracing::error!( - project_id = gb_repository.project_id, + project_id = gb_repository.project.id, path = %abs_path.display(), "binary file in session working directory" ); @@ -669,7 +632,7 @@ fn build_wd_tree( } Err(error) => { tracing::error!( - project_id = gb_repository.project_id, + project_id = gb_repository.project.id, path = %abs_path.display(), ?error, "failed to read file" @@ -838,7 +801,7 @@ fn add_wd_path( // TODO: size limit should be configurable let blob = if metadata.len() > 100_000_000 { tracing::warn!( - project_id = gb_repository.project_id, + project_id = gb_repository.project.id, path = %file_path.display(), "file too big" ); diff --git a/packages/tauri/src/gb_repository/repository_tests.rs b/packages/tauri/src/gb_repository/repository_tests.rs index b24b3bc05..cc21d42da 100644 --- a/packages/tauri/src/gb_repository/repository_tests.rs +++ b/packages/tauri/src/gb_repository/repository_tests.rs @@ -201,7 +201,7 @@ fn test_remote_syncronization() -> Result<()> { let user = suite.sign_in(); // create first local project, add files, deltas and flush a session - let case_one = suite.new_case_with_files(HashMap::from([( + let mut case_one = suite.new_case_with_files(HashMap::from([( path::PathBuf::from("test.txt"), "Hello World", )])); @@ -212,6 +212,7 @@ fn test_remote_syncronization() -> Result<()> { api: Some(api_project.clone()), ..Default::default() })?; + case_one.refresh(); let writer = deltas::Writer::new(&case_one.gb_repository); writer.write( @@ -225,7 +226,7 @@ fn test_remote_syncronization() -> Result<()> { case_one.gb_repository.push(Some(&user)).unwrap(); // create second local project, fetch it and make sure session is there - let case_two = suite.new_case(); + let mut case_two = suite.new_case(); suite .projects_storage .update_project(&projects::UpdateRequest { @@ -233,6 +234,7 @@ fn test_remote_syncronization() -> Result<()> { api: Some(api_project.clone()), ..Default::default() })?; + case_two.refresh(); case_two.gb_repository.fetch(Some(&user))?; @@ -282,7 +284,7 @@ fn test_remote_sync_order() -> Result<()> { let suite = Suite::default(); - let case_one = suite.new_case(); + let mut case_one = suite.new_case(); suite .projects_storage .update_project(&projects::UpdateRequest { @@ -290,8 +292,9 @@ fn test_remote_sync_order() -> Result<()> { api: Some(api_project.clone()), ..Default::default() })?; + case_one.refresh(); - let case_two = suite.new_case(); + let mut case_two = suite.new_case(); suite .projects_storage .update_project(&projects::UpdateRequest { @@ -299,6 +302,7 @@ fn test_remote_sync_order() -> Result<()> { api: Some(api_project.clone()), ..Default::default() })?; + case_two.refresh(); let user = suite.sign_in(); diff --git a/packages/tauri/src/sessions/writer.rs b/packages/tauri/src/sessions/writer.rs index 974dd5f15..cf3ed2e83 100644 --- a/packages/tauri/src/sessions/writer.rs +++ b/packages/tauri/src/sessions/writer.rs @@ -39,7 +39,7 @@ impl<'writer> SessionWriter<'writer> { if current_session_id.is_some() && current_session_id.as_ref() != Some(&session.id) { return Err(anyhow!( "{}: can not open writer for {} because a writer for {} is still open", - self.repository.project_id, + self.repository.project.id, session.id, current_session_id.unwrap() )); diff --git a/packages/tauri/src/test_utils.rs b/packages/tauri/src/test_utils.rs index fa9052b90..18c7f6de3 100644 --- a/packages/tauri/src/test_utils.rs +++ b/packages/tauri/src/test_utils.rs @@ -66,14 +66,10 @@ impl Suite { .expect("failed to add project"); let project_repository = project_repository::Repository::try_from(&project) .expect("failed to create project repository"); - let gb_repository = gb_repository::Repository::open( - &self.local_app_data, - &project.id, - self.projects_storage.clone(), - None, - ) - .expect("failed to open gb repository"); + let gb_repository = gb_repository::Repository::open(&self.local_app_data, &project, None) + .expect("failed to open gb repository"); Case { + suite: self, project_repository, project, gb_repository, @@ -81,12 +77,29 @@ impl Suite { } } -pub struct Case { +pub struct Case<'a> { + suite: &'a Suite, pub project_repository: project_repository::Repository, pub gb_repository: gb_repository::Repository, pub project: projects::Project, } +impl Case<'_> { + pub fn refresh(&mut self) { + self.project = self + .suite + .projects_storage + .get_project(&self.project.id) + .expect("failed to get project") + .expect("project not found"); + self.project_repository = project_repository::Repository::try_from(&self.project) + .expect("failed to create project repository"); + self.gb_repository = + gb_repository::Repository::open(&self.suite.local_app_data, &self.project, None) + .expect("failed to open gb repository"); + } +} + pub fn test_database() -> database::Database { let path = temp_dir().join("test.db"); database::Database::try_from(&path).unwrap() diff --git a/packages/tauri/src/virtual_branches/controller.rs b/packages/tauri/src/virtual_branches/controller.rs index 87288c864..a2987c40d 100644 --- a/packages/tauri/src/virtual_branches/controller.rs +++ b/packages/tauri/src/virtual_branches/controller.rs @@ -115,7 +115,10 @@ impl Controller { .try_into() .context("failed to open project repository")?; let user = self.users_storage.get().context("failed to get user")?; - let gb_repository = self.open_gb_repository(project_id, user.as_ref())?; + let gb_repository = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open gitbutler repository") + .map_err(Error::Other)?; super::is_remote_branch_mergeable(&gb_repository, &project_repository, branch_name) .map_err(Error::Other) } @@ -135,7 +138,10 @@ impl Controller { .try_into() .context("failed to open project repository")?; let user = self.users_storage.get().context("failed to get user")?; - let gb_repository = self.open_gb_repository(project_id, user.as_ref())?; + let gb_repository = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open gitbutler repository") + .map_err(Error::Other)?; super::is_virtual_branch_mergeable(&gb_repository, &project_repository, branch_id) .map_err(Error::Other) } @@ -229,7 +235,10 @@ impl Controller { .try_into() .context("failed to open project repository")?; let user = self.users_storage.get().context("failed to get user")?; - let gb_repository = self.open_gb_repository(project_id, user.as_ref())?; + let gb_repository = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open gitbutler repository") + .map_err(Error::Other)?; let base_branch = super::get_base_branch_data(&gb_repository, &project_repository)?; if let Some(branch) = base_branch { Ok(Some(self.proxy_base_branch(branch).await)) @@ -277,7 +286,10 @@ impl Controller { let user = self.users_storage.get().context("failed to get user")?; - let gb_repository = self.open_gb_repository(project_id, user.as_ref())?; + let gb_repository = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open gitbutler repository") + .map_err(Error::Other)?; let target = super::set_base_branch( &gb_repository, &project_repository, @@ -484,7 +496,10 @@ impl Controller { .try_into() .context("failed to open project repository")?; let user = self.users_storage.get().context("failed to get user")?; - let gb_repository = self.open_gb_repository(project_id, user.as_ref())?; + let gb_repository = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open gitbutler repository") + .map_err(Error::Other)?; super::integration::verify_branch(&gb_repository, &project_repository).map_err( |e| match e { super::integration::VerifyError::DetachedHead => Error::DetachedHead, @@ -505,21 +520,6 @@ impl Controller { action() } - fn open_gb_repository( - &self, - project_id: &str, - user: Option<&users::User>, - ) -> Result { - gb_repository::Repository::open( - self.local_data_dir.clone(), - project_id, - self.projects_storage.clone(), - user, - ) - .context("failed to open repository") - .map_err(Error::Other) - } - async fn proxy_base_branch(&self, target: super::BaseBranch) -> super::BaseBranch { super::BaseBranch { recent_commits: join_all( diff --git a/packages/tauri/src/virtual_branches/tests.rs b/packages/tauri/src/virtual_branches/tests.rs index ee91636de..2a3ed2287 100644 --- a/packages/tauri/src/virtual_branches/tests.rs +++ b/packages/tauri/src/virtual_branches/tests.rs @@ -1570,6 +1570,7 @@ fn test_update_target_with_conflicts_in_vbranches() -> Result<()> { project_repository, gb_repository, project, + .. } = Suite::default().new_case(); let current_session = gb_repository.get_or_create_current_session()?; @@ -1972,6 +1973,7 @@ fn test_unapply_ownership_full_file() -> Result<()> { project_repository, gb_repository, project, + .. } = Suite::default().new_case(); set_test_target(&gb_repository, &project_repository)?; diff --git a/packages/tauri/src/watcher/handlers/fetch_gitbutler_data.rs b/packages/tauri/src/watcher/handlers/fetch_gitbutler_data.rs index 875775a4f..87411c245 100644 --- a/packages/tauri/src/watcher/handlers/fetch_gitbutler_data.rs +++ b/packages/tauri/src/watcher/handlers/fetch_gitbutler_data.rs @@ -68,19 +68,6 @@ impl HandlerInner { let user = self.user_storage.get()?; - let gb_repo = gb_repository::Repository::open( - self.local_data_dir.clone(), - project_id, - self.project_storage.clone(), - user.as_ref(), - ) - .context("failed to open repository")?; - - let sessions_before_fetch = gb_repo - .get_sessions_iterator()? - .filter_map(|s| s.ok()) - .collect::>(); - // mark fetching self.project_storage .update_project(&projects::UpdateRequest { @@ -98,6 +85,15 @@ impl HandlerInner { .context("failed to get project")? .ok_or_else(|| anyhow::anyhow!("project not found"))?; + let gb_repo = + gb_repository::Repository::open(self.local_data_dir.clone(), &project, user.as_ref()) + .context("failed to open repository")?; + + let sessions_before_fetch = gb_repo + .get_sessions_iterator()? + .filter_map(|s| s.ok()) + .collect::>(); + let fetch_result = if let Err(error) = gb_repo.fetch(user.as_ref()) { tracing::error!(project_id, ?error, "failed to fetch gitbutler data"); projects::FetchResult::Error { diff --git a/packages/tauri/src/watcher/handlers/fetch_project_data.rs b/packages/tauri/src/watcher/handlers/fetch_project_data.rs index 2ba7fe1c4..d99e63dfc 100644 --- a/packages/tauri/src/watcher/handlers/fetch_project_data.rs +++ b/packages/tauri/src/watcher/handlers/fetch_project_data.rs @@ -73,16 +73,6 @@ impl HandlerInner { let user = self.user_storage.get()?; - let gb_repo = gb_repository::Repository::open( - self.local_data_dir.clone(), - project_id, - self.project_storage.clone(), - user.as_ref(), - ) - .context("failed to open repository")?; - - let default_target = gb_repo.default_target()?.context("target not set")?; - // mark fetching self.project_storage .update_project(&projects::UpdateRequest { @@ -100,6 +90,11 @@ impl HandlerInner { .context("failed to get project")? .ok_or_else(|| anyhow::anyhow!("project not found"))?; + let gb_repo = + gb_repository::Repository::open(self.local_data_dir.clone(), &project, user.as_ref()) + .context("failed to open repository")?; + let default_target = gb_repo.default_target()?.context("target not set")?; + let key = match &project.preferred_key { projects::AuthKey::Generated => { let private_key = self.keys_controller.get_or_create()?; diff --git a/packages/tauri/src/watcher/handlers/flush_session.rs b/packages/tauri/src/watcher/handlers/flush_session.rs index 092dbb80a..31d158cf3 100644 --- a/packages/tauri/src/watcher/handlers/flush_session.rs +++ b/packages/tauri/src/watcher/handlers/flush_session.rs @@ -44,13 +44,9 @@ impl Handler { let user = self.user_store.get()?; - let gb_repo = gb_repository::Repository::open( - &self.local_data_dir, - project_id, - self.project_store.clone(), - user.as_ref(), - ) - .context("failed to open repository")?; + let gb_repo = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open repository")?; let session = gb_repo .flush_session( diff --git a/packages/tauri/src/watcher/handlers/index_handler.rs b/packages/tauri/src/watcher/handlers/index_handler.rs index 2bd14821b..042c5eeda 100644 --- a/packages/tauri/src/watcher/handlers/index_handler.rs +++ b/packages/tauri/src/watcher/handlers/index_handler.rs @@ -72,14 +72,14 @@ impl Handler { pub fn reindex(&self, project_id: &str) -> Result> { let user = self.user_store.get()?; + let project = self + .project_store + .get_project(project_id)? + .context(format!("failed to get project with id {}", project_id))?; - let gb_repository = gb_repository::Repository::open( - self.local_data_dir.clone(), - project_id, - self.project_store.clone(), - user.as_ref(), - ) - .context("failed to open repository")?; + let gb_repository = + gb_repository::Repository::open(self.local_data_dir.clone(), &project, user.as_ref()) + .context("failed to open repository")?; let sessions_iter = gb_repository.get_sessions_iterator()?; let mut events = vec![]; @@ -95,14 +95,14 @@ impl Handler { session: &sessions::Session, ) -> Result> { let user = self.user_store.get()?; + let project = self + .project_store + .get_project(project_id)? + .context(format!("failed to get project with id {}", project_id))?; - let gb_repository = gb_repository::Repository::open( - self.local_data_dir.clone(), - project_id, - self.project_store.clone(), - user.as_ref(), - ) - .context("failed to open repository")?; + let gb_repository = + gb_repository::Repository::open(self.local_data_dir.clone(), &project, user.as_ref()) + .context("failed to open repository")?; // first of all, index session for searching. searhcer keeps it's own state to // decide if the actual indexing needed diff --git a/packages/tauri/src/watcher/handlers/project_file_change.rs b/packages/tauri/src/watcher/handlers/project_file_change.rs index 0d3e9512b..a5585ad64 100644 --- a/packages/tauri/src/watcher/handlers/project_file_change.rs +++ b/packages/tauri/src/watcher/handlers/project_file_change.rs @@ -98,13 +98,9 @@ impl Handler { let user = self.user_store.get().context("failed to get user")?; - let gb_repository = gb_repository::Repository::open( - &self.local_data_dir, - project_id, - self.project_store.clone(), - user.as_ref(), - ) - .context("failed to open gb repository")?; + let gb_repository = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open gb repository")?; // If current session's branch is not the same as the project's head, flush it first. if let Some(session) = gb_repository diff --git a/packages/tauri/src/watcher/handlers/push_gitbutler_data.rs b/packages/tauri/src/watcher/handlers/push_gitbutler_data.rs index aa0e8b0b3..4e40671e6 100644 --- a/packages/tauri/src/watcher/handlers/push_gitbutler_data.rs +++ b/packages/tauri/src/watcher/handlers/push_gitbutler_data.rs @@ -78,14 +78,14 @@ impl HandlerInner { }; let user = self.user_storage.get()?; + let project = self + .project_storage + .get_project(project_id)? + .context("project not found")?; - let gb_repo = gb_repository::Repository::open( - &self.local_data_dir, - project_id, - self.project_storage.clone(), - user.as_ref(), - ) - .context("failed to open repository")?; + let gb_repo = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open repository")?; gb_repo.push(user.as_ref()).context("failed to push")?; diff --git a/packages/tauri/src/watcher/handlers/tick_handler.rs b/packages/tauri/src/watcher/handlers/tick_handler.rs index 1922758a7..9c4a2f078 100644 --- a/packages/tauri/src/watcher/handlers/tick_handler.rs +++ b/packages/tauri/src/watcher/handlers/tick_handler.rs @@ -36,19 +36,15 @@ impl Handler { pub fn handle(&self, project_id: &str, now: &time::SystemTime) -> Result> { let user = self.user_store.get()?; - let gb_repo = gb_repository::Repository::open( - &self.local_data_dir, - project_id, - self.project_store.clone(), - user.as_ref(), - ) - .context("failed to open repository")?; - let project = match self.project_store.get_project(project_id)? { None => return Ok(vec![]), Some(project) => project, }; + let gb_repo = + gb_repository::Repository::open(&self.local_data_dir, &project, user.as_ref()) + .context("failed to open repository")?; + let mut events = vec![]; if project From 8cd9431fc9cbbe028bffde6068789ae2d53d9b7f Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Wed, 4 Oct 2023 15:55:23 +0200 Subject: [PATCH 2/2] fix butler --- packages/butler/src/app.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/packages/butler/src/app.rs b/packages/butler/src/app.rs index 8bedba956..1148709fd 100644 --- a/packages/butler/src/app.rs +++ b/packages/butler/src/app.rs @@ -33,13 +33,9 @@ impl App { .context("failed to find project")?; let user = users_storage.get().context("failed to get user")?; - let gb_repository = gb_repository::Repository::open( - &local_data_dir, - &project.id, - projects_storage, - user.as_ref(), - ) - .context("failed to open repository")?; + let gb_repository = + gb_repository::Repository::open(&local_data_dir, &project, user.as_ref()) + .context("failed to open repository")?; let db_path = std::path::Path::new(&local_data_dir).join("database.sqlite3"); let database = database::Database::try_from(&db_path).context("failed to open database")?;