diff --git a/src-tauri/src/app.rs b/src-tauri/src/app.rs index 44622ae22..ff346650d 100644 --- a/src-tauri/src/app.rs +++ b/src-tauri/src/app.rs @@ -332,24 +332,6 @@ impl App { Ok(()) } - pub async fn list_virtual_branches( - &self, - project_id: &str, - ) -> Result> { - let gb_repository = self.gb_repository(project_id)?; - let project = self.gb_project(project_id)?; - let project_repository = project_repository::Repository::open(&project) - .context("failed to open project repository")?; - - let mut semaphores = self.vbranch_semaphores.lock().await; - let semaphore = semaphores - .entry(project_id.to_string()) - .or_insert_with(|| Semaphore::new(1)); - let _permit = semaphore.acquire().await?; - - virtual_branches::list_virtual_branches(&gb_repository, &project_repository) - } - pub async fn create_virtual_branch( &self, project_id: &str, diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs index 824fb122c..eb8442395 100644 --- a/src-tauri/src/main.rs +++ b/src-tauri/src/main.rs @@ -524,20 +524,6 @@ async fn list_bookmarks( Ok(bookmarks) } -#[timed(duration(printer = "debug!"))] -#[tauri::command(async)] -async fn list_virtual_branches( - handle: tauri::AppHandle, - project_id: &str, -) -> Result, Error> { - let app = handle.state::(); - let branches = app - .list_virtual_branches(project_id) - .await - .context("failed to list virtual branches")?; - Ok(branches) -} - #[timed(duration(printer = "debug!"))] #[tauri::command(async)] async fn create_virtual_branch( @@ -952,7 +938,7 @@ fn main() { get_project_data_archive_path, upsert_bookmark, list_bookmarks, - list_virtual_branches, + virtual_branches::commands::list_virtual_branches, create_virtual_branch, virtual_branches::commands::commit_virtual_branch, get_base_branch_data, diff --git a/src-tauri/src/virtual_branches/commands.rs b/src-tauri/src/virtual_branches/commands.rs index 6925bc483..679c79419 100644 --- a/src-tauri/src/virtual_branches/commands.rs +++ b/src-tauri/src/virtual_branches/commands.rs @@ -21,3 +21,17 @@ pub async fn commit_virtual_branch( .context("failed to create commit")?; Ok(()) } + +#[timed(duration(printer = "debug!"))] +#[tauri::command(async)] +pub async fn list_virtual_branches( + handle: tauri::AppHandle, + project_id: &str, +) -> Result, Error> { + let branches = handle + .state::() + .list_virtual_branches(project_id) + .await + .context("failed to list virtual branches")?; + Ok(branches) +} diff --git a/src-tauri/src/virtual_branches/controller.rs b/src-tauri/src/virtual_branches/controller.rs index fb6c26472..3be723ce6 100644 --- a/src-tauri/src/virtual_branches/controller.rs +++ b/src-tauri/src/virtual_branches/controller.rs @@ -68,6 +68,31 @@ impl Controller { Ok(()) } + pub async fn list_virtual_branches( + &self, + project_id: &str, + ) -> Result, Error> { + let project = self + .projects_storage + .get_project(project_id) + .context("failed to get project")? + .context("project not found")?; + let project_repository = project + .as_ref() + .try_into() + .context("failed to open project repository")?; + let gb_repository = self.open_gb_repository(project_id)?; + + let mut semaphores = self.semaphores.lock().await; + let semaphore = semaphores + .entry(project_id.to_string()) + .or_insert_with(|| Semaphore::new(1)); + let _permit = semaphore.acquire().await?; + + let branches = super::list_virtual_branches(&gb_repository, &project_repository)?; + Ok(branches) + } + fn open_gb_repository(&self, project_id: &str) -> Result { gb_repository::Repository::open( self.local_data_dir.clone(),