Merge pull request #4319 from gitbutlerapp/remove-virtual-branch-controller

remove virtual branch controller
This commit is contained in:
Kiril Videlov 2024-07-10 12:49:53 +02:00 committed by GitHub
commit 7f7928d40c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 45 additions and 133 deletions

View File

@ -128,8 +128,6 @@ fn main() {
let git_credentials_controller = Helper::default(); let git_credentials_controller = Helper::default();
app_handle.manage(git_credentials_controller.clone()); app_handle.manage(git_credentials_controller.clone());
app_handle.manage(gitbutler_virtual::controller::Controller::default());
let app = app::App::new( let app = app::App::new(
projects_controller, projects_controller,
); );

View File

@ -11,7 +11,7 @@ pub mod commands {
use gitbutler_virtual::base::BaseBranch; use gitbutler_virtual::base::BaseBranch;
use gitbutler_virtual::files::RemoteBranchFile; use gitbutler_virtual::files::RemoteBranchFile;
use gitbutler_virtual::remote::{RemoteBranch, RemoteBranchData}; use gitbutler_virtual::remote::{RemoteBranch, RemoteBranchData};
use gitbutler_virtual::{Controller, NameConflitResolution, VirtualBranches}; use gitbutler_virtual::{NameConflitResolution, VirtualBranchActions, VirtualBranches};
use tauri::{AppHandle, Manager}; use tauri::{AppHandle, Manager};
use tracing::instrument; use tracing::instrument;
@ -28,8 +28,7 @@ pub mod commands {
run_hooks: bool, run_hooks: bool,
) -> Result<String, Error> { ) -> Result<String, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let oid = handle let oid = VirtualBranchActions::default()
.state::<Controller>()
.create_commit(&project, branch, message, ownership.as_ref(), run_hooks) .create_commit(&project, branch, message, ownership.as_ref(), run_hooks)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -43,8 +42,7 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
) -> Result<VirtualBranches, Error> { ) -> Result<VirtualBranches, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let (branches, skipped_files) = handle let (branches, skipped_files) = VirtualBranchActions::default()
.state::<Controller>()
.list_virtual_branches(&project) .list_virtual_branches(&project)
.await?; .await?;
@ -62,8 +60,7 @@ pub mod commands {
branch: BranchCreateRequest, branch: BranchCreateRequest,
) -> Result<BranchId, Error> { ) -> Result<BranchId, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let branch_id = handle let branch_id = VirtualBranchActions::default()
.state::<Controller>()
.create_virtual_branch(&project, &branch) .create_virtual_branch(&project, &branch)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -78,8 +75,7 @@ pub mod commands {
branch: Refname, branch: Refname,
) -> Result<BranchId, Error> { ) -> Result<BranchId, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let branch_id = handle let branch_id = VirtualBranchActions::default()
.state::<Controller>()
.create_virtual_branch_from_branch(&project, &branch) .create_virtual_branch_from_branch(&project, &branch)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -94,8 +90,7 @@ pub mod commands {
branch: BranchId, branch: BranchId,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
handle VirtualBranchActions::default()
.state::<Controller>()
.integrate_upstream_commits(&project, branch) .integrate_upstream_commits(&project, branch)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -109,8 +104,7 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
) -> Result<Option<BaseBranch>, Error> { ) -> Result<Option<BaseBranch>, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
if let Ok(base_branch) = handle if let Ok(base_branch) = VirtualBranchActions::default()
.state::<Controller>()
.get_base_branch_data(&project) .get_base_branch_data(&project)
.await .await
{ {
@ -132,15 +126,14 @@ pub mod commands {
let branch_name = format!("refs/remotes/{}", branch) let branch_name = format!("refs/remotes/{}", branch)
.parse() .parse()
.context("Invalid branch name")?; .context("Invalid branch name")?;
let base_branch = handle let base_branch = VirtualBranchActions::default()
.state::<Controller>()
.set_base_branch(&project, &branch_name) .set_base_branch(&project, &branch_name)
.await?; .await?;
// if they also sent a different push remote, set that too // if they also sent a different push remote, set that too
if let Some(push_remote) = push_remote { if let Some(push_remote) = push_remote {
handle handle
.state::<Controller>() .state::<VirtualBranchActions>()
.set_target_push_remote(&project, push_remote) .set_target_push_remote(&project, push_remote)
.await?; .await?;
} }
@ -155,8 +148,7 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
) -> Result<Vec<ReferenceName>, Error> { ) -> Result<Vec<ReferenceName>, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let unapplied_branches = handle let unapplied_branches = VirtualBranchActions::default()
.state::<Controller>()
.update_base_branch(&project) .update_base_branch(&project)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -171,8 +163,7 @@ pub mod commands {
branch: BranchUpdateRequest, branch: BranchUpdateRequest,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
handle VirtualBranchActions::default()
.state::<Controller>()
.update_virtual_branch(&project, branch) .update_virtual_branch(&project, branch)
.await?; .await?;
@ -188,8 +179,7 @@ pub mod commands {
branch_id: BranchId, branch_id: BranchId,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
handle VirtualBranchActions::default()
.state::<Controller>()
.delete_virtual_branch(&project, branch_id) .delete_virtual_branch(&project, branch_id)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -205,8 +195,7 @@ pub mod commands {
name_conflict_resolution: NameConflitResolution, name_conflict_resolution: NameConflitResolution,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
handle VirtualBranchActions::default()
.state::<Controller>()
.convert_to_real_branch(&project, branch, name_conflict_resolution) .convert_to_real_branch(&project, branch, name_conflict_resolution)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -221,8 +210,7 @@ pub mod commands {
ownership: BranchOwnershipClaims, ownership: BranchOwnershipClaims,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
handle VirtualBranchActions::default()
.state::<Controller>()
.unapply_ownership(&project, &ownership) .unapply_ownership(&project, &ownership)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -242,8 +230,7 @@ pub mod commands {
.split('\n') .split('\n')
.map(std::string::ToString::to_string) .map(std::string::ToString::to_string)
.collect::<Vec<String>>(); .collect::<Vec<String>>();
handle VirtualBranchActions::default()
.state::<Controller>()
.reset_files(&project, &files) .reset_files(&project, &files)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -259,8 +246,7 @@ pub mod commands {
with_force: bool, with_force: bool,
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
handle VirtualBranchActions::default()
.state::<Controller>()
.push_virtual_branch(&project, branch_id, with_force, Some(Some(branch_id))) .push_virtual_branch(&project, branch_id, with_force, Some(Some(branch_id)))
.await .await
.map_err(|err| err.context(Code::Unknown))?; .map_err(|err| err.context(Code::Unknown))?;
@ -276,8 +262,7 @@ pub mod commands {
branch: RemoteRefname, branch: RemoteRefname,
) -> Result<bool, Error> { ) -> Result<bool, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
Ok(handle Ok(VirtualBranchActions::default()
.state::<Controller>()
.can_apply_remote_branch(&project, &branch) .can_apply_remote_branch(&project, &branch)
.await?) .await?)
} }
@ -291,8 +276,7 @@ pub mod commands {
) -> Result<Vec<RemoteBranchFile>, Error> { ) -> Result<Vec<RemoteBranchFile>, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
handle VirtualBranchActions::default()
.state::<Controller>()
.list_remote_commit_files(&project, commit_oid) .list_remote_commit_files(&project, commit_oid)
.await .await
.map_err(Into::into) .map_err(Into::into)
@ -308,8 +292,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?; let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
handle VirtualBranchActions::default()
.state::<Controller>()
.reset_virtual_branch(&project, branch_id, target_commit_oid) .reset_virtual_branch(&project, branch_id, target_commit_oid)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -327,8 +310,7 @@ pub mod commands {
) -> Result<String, Error> { ) -> Result<String, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
let oid = handle let oid = VirtualBranchActions::default()
.state::<Controller>()
.amend(&project, branch_id, commit_oid, &ownership) .amend(&project, branch_id, commit_oid, &ownership)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -348,8 +330,7 @@ pub mod commands {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let from_commit_oid = git2::Oid::from_str(&from_commit_oid).map_err(|e| anyhow!(e))?; let from_commit_oid = git2::Oid::from_str(&from_commit_oid).map_err(|e| anyhow!(e))?;
let to_commit_oid = git2::Oid::from_str(&to_commit_oid).map_err(|e| anyhow!(e))?; let to_commit_oid = git2::Oid::from_str(&to_commit_oid).map_err(|e| anyhow!(e))?;
let oid = handle let oid = VirtualBranchActions::default()
.state::<Controller>()
.move_commit_file( .move_commit_file(
&project, &project,
branch_id, branch_id,
@ -372,8 +353,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
handle VirtualBranchActions::default()
.state::<Controller>()
.undo_commit(&project, branch_id, commit_oid) .undo_commit(&project, branch_id, commit_oid)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -391,8 +371,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
handle VirtualBranchActions::default()
.state::<Controller>()
.insert_blank_commit(&project, branch_id, commit_oid, offset) .insert_blank_commit(&project, branch_id, commit_oid, offset)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -410,8 +389,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
handle VirtualBranchActions::default()
.state::<Controller>()
.reorder_commit(&project, branch_id, commit_oid, offset) .reorder_commit(&project, branch_id, commit_oid, offset)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -425,8 +403,7 @@ pub mod commands {
project_id: ProjectId, project_id: ProjectId,
) -> Result<Vec<RemoteBranch>, Error> { ) -> Result<Vec<RemoteBranch>, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let branches = handle let branches = VirtualBranchActions::default()
.state::<Controller>()
.list_remote_branches(project) .list_remote_branches(project)
.await?; .await?;
Ok(branches) Ok(branches)
@ -440,8 +417,7 @@ pub mod commands {
refname: Refname, refname: Refname,
) -> Result<RemoteBranchData, Error> { ) -> Result<RemoteBranchData, Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let branch_data = handle let branch_data = VirtualBranchActions::default()
.state::<Controller>()
.get_remote_branch_data(&project, &refname) .get_remote_branch_data(&project, &refname)
.await?; .await?;
Ok(branch_data) Ok(branch_data)
@ -457,8 +433,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?; let target_commit_oid = git2::Oid::from_str(&target_commit_oid).map_err(|e| anyhow!(e))?;
handle VirtualBranchActions::default()
.state::<Controller>()
.squash(&project, branch_id, target_commit_oid) .squash(&project, branch_id, target_commit_oid)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -475,8 +450,7 @@ pub mod commands {
let projects = handle.state::<projects::Controller>(); let projects = handle.state::<projects::Controller>();
let project = projects.get(project_id)?; let project = projects.get(project_id)?;
let project_data_last_fetched = handle let project_data_last_fetched = VirtualBranchActions::default()
.state::<Controller>()
.fetch_from_remotes( .fetch_from_remotes(
&project, &project,
Some(action.unwrap_or_else(|| "unknown".to_string())), Some(action.unwrap_or_else(|| "unknown".to_string())),
@ -495,8 +469,7 @@ pub mod commands {
.await .await
.context("failed to update project with last fetched timestamp")?; .context("failed to update project with last fetched timestamp")?;
let base_branch = handle let base_branch = VirtualBranchActions::default()
.state::<Controller>()
.get_base_branch_data(&project) .get_base_branch_data(&project)
.await?; .await?;
Ok(base_branch) Ok(base_branch)
@ -512,8 +485,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
handle VirtualBranchActions::default()
.state::<Controller>()
.move_commit(&project, target_branch_id, commit_oid) .move_commit(&project, target_branch_id, commit_oid)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;
@ -531,8 +503,7 @@ pub mod commands {
) -> Result<(), Error> { ) -> Result<(), Error> {
let project = handle.state::<projects::Controller>().get(project_id)?; let project = handle.state::<projects::Controller>().get(project_id)?;
let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?; let commit_oid = git2::Oid::from_str(&commit_oid).map_err(|e| anyhow!(e))?;
handle VirtualBranchActions::default()
.state::<Controller>()
.update_commit_message(&project, branch_id, commit_oid, message) .update_commit_message(&project, branch_id, commit_oid, message)
.await?; .await?;
emit_vbranches(&handle, project_id).await; emit_vbranches(&handle, project_id).await;

View File

@ -77,7 +77,7 @@ pub struct Watchers {
fn handler_from_app(app: &AppHandle) -> anyhow::Result<gitbutler_watcher::Handler> { fn handler_from_app(app: &AppHandle) -> anyhow::Result<gitbutler_watcher::Handler> {
let projects = app.state::<projects::Controller>().inner().clone(); let projects = app.state::<projects::Controller>().inner().clone();
let users = app.state::<users::Controller>().inner().clone(); let users = app.state::<users::Controller>().inner().clone();
let vbranches = app.state::<gitbutler_virtual::Controller>().inner().clone(); let vbranches = gitbutler_virtual::VirtualBranchActions::default();
Ok(gitbutler_watcher::Handler::new( Ok(gitbutler_watcher::Handler::new(
projects, projects,

View File

@ -15,9 +15,7 @@ use gitbutler_project::{FetchResult, Project};
use gitbutler_reference::{Refname, RemoteRefname}; use gitbutler_reference::{Refname, RemoteRefname};
use gitbutler_repo::{credentials::Helper, RepoActions, RepositoryExt}; use gitbutler_repo::{credentials::Helper, RepoActions, RepositoryExt};
use gitbutler_tagged_string::ReferenceName; use gitbutler_tagged_string::ReferenceName;
use std::{path::Path, sync::Arc}; use std::path::Path;
use tokio::sync::Semaphore;
use crate::{ use crate::{
base::{ base::{
@ -33,20 +31,10 @@ use super::r#virtual as branch;
use crate::files::RemoteBranchFile; use crate::files::RemoteBranchFile;
use gitbutler_branch::target; use gitbutler_branch::target;
#[derive(Clone)] #[derive(Clone, Default)]
pub struct Controller { pub struct VirtualBranchActions {}
semaphore: Arc<Semaphore>,
}
impl Default for Controller { impl VirtualBranchActions {
fn default() -> Self {
Self {
semaphore: Arc::new(Semaphore::new(1)),
}
}
}
impl Controller {
pub async fn create_commit( pub async fn create_commit(
&self, &self,
project: &Project, project: &Project,
@ -55,7 +43,6 @@ impl Controller {
ownership: Option<&BranchOwnershipClaims>, ownership: Option<&BranchOwnershipClaims>,
run_hooks: bool, run_hooks: bool,
) -> Result<git2::Oid> { ) -> Result<git2::Oid> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let snapshot_tree = project_repository.project().prepare_snapshot(); let snapshot_tree = project_repository.project().prepare_snapshot();
let result = branch::commit( let result = branch::commit(
@ -90,8 +77,6 @@ impl Controller {
&self, &self,
project: &Project, project: &Project,
) -> Result<(Vec<branch::VirtualBranch>, Vec<diff::FileDiff>)> { ) -> Result<(Vec<branch::VirtualBranch>, Vec<diff::FileDiff>)> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
branch::list_virtual_branches(&project_repository).map_err(Into::into) branch::list_virtual_branches(&project_repository).map_err(Into::into)
} }
@ -101,8 +86,6 @@ impl Controller {
project: &Project, project: &Project,
create: &BranchCreateRequest, create: &BranchCreateRequest,
) -> Result<BranchId> { ) -> Result<BranchId> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let branch_manager = project_repository.branch_manager(); let branch_manager = project_repository.branch_manager();
let branch_id = branch_manager.create_virtual_branch(create)?.id; let branch_id = branch_manager.create_virtual_branch(create)?.id;
@ -146,8 +129,6 @@ impl Controller {
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
) -> Result<()> { ) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let _ = project_repository let _ = project_repository
.project() .project()
@ -156,8 +137,6 @@ impl Controller {
} }
pub async fn update_base_branch(&self, project: &Project) -> Result<Vec<ReferenceName>> { pub async fn update_base_branch(&self, project: &Project) -> Result<Vec<ReferenceName>> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let _ = project_repository let _ = project_repository
.project() .project()
@ -170,8 +149,6 @@ impl Controller {
project: &Project, project: &Project,
branch_update: BranchUpdateRequest, branch_update: BranchUpdateRequest,
) -> Result<()> { ) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let snapshot_tree = project_repository.project().prepare_snapshot(); let snapshot_tree = project_repository.project().prepare_snapshot();
let old_branch = project_repository let old_branch = project_repository
@ -195,8 +172,6 @@ impl Controller {
project: &Project, project: &Project,
branch_id: BranchId, branch_id: BranchId,
) -> Result<()> { ) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let branch_manager = project_repository.branch_manager(); let branch_manager = project_repository.branch_manager();
branch_manager.delete_branch(branch_id) branch_manager.delete_branch(branch_id)
@ -207,8 +182,6 @@ impl Controller {
project: &Project, project: &Project,
ownership: &BranchOwnershipClaims, ownership: &BranchOwnershipClaims,
) -> Result<()> { ) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let _ = project_repository let _ = project_repository
.project() .project()
@ -217,8 +190,6 @@ impl Controller {
} }
pub async fn reset_files(&self, project: &Project, files: &Vec<String>) -> Result<()> { pub async fn reset_files(&self, project: &Project, files: &Vec<String>) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let _ = project_repository let _ = project_repository
.project() .project()
@ -233,8 +204,6 @@ impl Controller {
commit_oid: git2::Oid, commit_oid: git2::Oid,
ownership: &BranchOwnershipClaims, ownership: &BranchOwnershipClaims,
) -> Result<git2::Oid> { ) -> Result<git2::Oid> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let _ = project_repository let _ = project_repository
.project() .project()
@ -250,8 +219,6 @@ impl Controller {
to_commit_oid: git2::Oid, to_commit_oid: git2::Oid,
ownership: &BranchOwnershipClaims, ownership: &BranchOwnershipClaims,
) -> Result<git2::Oid> { ) -> Result<git2::Oid> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let _ = project_repository let _ = project_repository
.project() .project()
@ -272,8 +239,6 @@ impl Controller {
branch_id: BranchId, branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
) -> Result<()> { ) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let snapshot_tree = project_repository.project().prepare_snapshot(); let snapshot_tree = project_repository.project().prepare_snapshot();
let result: Result<()> = let result: Result<()> =
@ -295,8 +260,6 @@ impl Controller {
commit_oid: git2::Oid, commit_oid: git2::Oid,
offset: i32, offset: i32,
) -> Result<()> { ) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let _ = project_repository let _ = project_repository
.project() .project()
@ -312,8 +275,6 @@ impl Controller {
commit_oid: git2::Oid, commit_oid: git2::Oid,
offset: i32, offset: i32,
) -> Result<()> { ) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let _ = project_repository let _ = project_repository
.project() .project()
@ -328,8 +289,6 @@ impl Controller {
branch_id: BranchId, branch_id: BranchId,
target_commit_oid: git2::Oid, target_commit_oid: git2::Oid,
) -> Result<()> { ) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let _ = project_repository let _ = project_repository
.project() .project()
@ -343,8 +302,6 @@ impl Controller {
branch_id: BranchId, branch_id: BranchId,
name_conflict_resolution: branch::NameConflitResolution, name_conflict_resolution: branch::NameConflitResolution,
) -> Result<ReferenceName> { ) -> Result<ReferenceName> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let snapshot_tree = project_repository.project().prepare_snapshot(); let snapshot_tree = project_repository.project().prepare_snapshot();
let branch_manager = project_repository.branch_manager(); let branch_manager = project_repository.branch_manager();
@ -366,7 +323,6 @@ impl Controller {
with_force: bool, with_force: bool,
askpass: Option<Option<BranchId>>, askpass: Option<Option<BranchId>>,
) -> Result<()> { ) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let helper = Helper::default(); let helper = Helper::default();
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
branch::push(&project_repository, branch_id, with_force, &helper, askpass) branch::push(&project_repository, branch_id, with_force, &helper, askpass)
@ -392,8 +348,6 @@ impl Controller {
branch_id: BranchId, branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
) -> Result<()> { ) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let _ = project_repository let _ = project_repository
.project() .project()
@ -408,7 +362,6 @@ impl Controller {
commit_oid: git2::Oid, commit_oid: git2::Oid,
message: &str, message: &str,
) -> Result<()> { ) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let _ = project_repository let _ = project_repository
.project() .project()
@ -466,8 +419,6 @@ impl Controller {
target_branch_id: BranchId, target_branch_id: BranchId,
commit_oid: git2::Oid, commit_oid: git2::Oid,
) -> Result<()> { ) -> Result<()> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let _ = project_repository let _ = project_repository
.project() .project()
@ -480,20 +431,12 @@ impl Controller {
project: &Project, project: &Project,
branch: &Refname, branch: &Refname,
) -> Result<BranchId> { ) -> Result<BranchId> {
self.permit(project.ignore_project_semaphore).await;
let project_repository = open_with_verify(project)?; let project_repository = open_with_verify(project)?;
let branch_manager = project_repository.branch_manager(); let branch_manager = project_repository.branch_manager();
branch_manager branch_manager
.create_virtual_branch_from_branch(branch) .create_virtual_branch_from_branch(branch)
.map_err(Into::into) .map_err(Into::into)
} }
async fn permit(&self, ignore: bool) {
if !ignore {
let _ = self.semaphore.acquire().await.unwrap();
}
}
} }
fn open_with_verify(project: &Project) -> Result<ProjectRepository> { fn open_with_verify(project: &Project) -> Result<ProjectRepository> {

View File

@ -1,6 +1,6 @@
//! GitButler internal library containing functionaliry related to branches, i.e. the virtual branches implementation //! GitButler internal library containing functionaliry related to branches, i.e. the virtual branches implementation
pub mod controller; pub mod actions;
pub use controller::Controller; pub use actions::VirtualBranchActions;
pub mod r#virtual; pub mod r#virtual;
pub use r#virtual::*; pub use r#virtual::*;

View File

@ -134,7 +134,7 @@ fn commit_and_push_initial(repository: &TestProject) {
} }
async fn get_virtual_branch( async fn get_virtual_branch(
controller: &Controller, controller: &VirtualBranchActions,
project: &Project, project: &Project,
branch_id: Id<Branch>, branch_id: Id<Branch>,
) -> VirtualBranch { ) -> VirtualBranch {

View File

@ -7,7 +7,7 @@ async fn twice() {
let test_project = TestProject::default(); let test_project = TestProject::default();
let controller = Controller::default(); let controller = VirtualBranchActions {};
{ {
let project = projects let project = projects

View File

@ -5,7 +5,7 @@ use gitbutler_branch::branch;
use gitbutler_error::error::Marker; use gitbutler_error::error::Marker;
use gitbutler_project::{self as projects, Project, ProjectId}; use gitbutler_project::{self as projects, Project, ProjectId};
use gitbutler_reference::Refname; use gitbutler_reference::Refname;
use gitbutler_virtual::Controller; use gitbutler_virtual::VirtualBranchActions;
use tempfile::TempDir; use tempfile::TempDir;
use gitbutler_testsupport::{paths, TestProject, VAR_NO_CLEANUP}; use gitbutler_testsupport::{paths, TestProject, VAR_NO_CLEANUP};
@ -15,7 +15,7 @@ struct Test {
project_id: ProjectId, project_id: ProjectId,
project: Project, project: Project,
projects: projects::Controller, projects: projects::Controller,
controller: Controller, controller: VirtualBranchActions,
data_dir: Option<TempDir>, data_dir: Option<TempDir>,
} }
@ -40,7 +40,7 @@ impl Default for Test {
Self { Self {
repository: test_project, repository: test_project,
project_id: project.id, project_id: project.id,
controller: Controller::default(), controller: VirtualBranchActions {},
projects, projects,
project, project,
data_dir: Some(data_dir), data_dir: Some(data_dir),

View File

@ -30,7 +30,7 @@ pub struct Handler {
// need extra protection. // need extra protection.
projects: projects::Controller, projects: projects::Controller,
users: users::Controller, users: users::Controller,
vbranch_controller: gitbutler_virtual::Controller, vbranch_controller: gitbutler_virtual::VirtualBranchActions,
/// A function to send events - decoupled from app-handle for testing purposes. /// A function to send events - decoupled from app-handle for testing purposes.
#[allow(clippy::type_complexity)] #[allow(clippy::type_complexity)]
@ -43,7 +43,7 @@ impl Handler {
pub fn new( pub fn new(
projects: projects::Controller, projects: projects::Controller,
users: users::Controller, users: users::Controller,
vbranch_controller: gitbutler_virtual::Controller, vbranch_controller: gitbutler_virtual::VirtualBranchActions,
send_event: impl Fn(Change) -> Result<()> + Send + Sync + 'static, send_event: impl Fn(Change) -> Result<()> + Send + Sync + 'static,
) -> Self { ) -> Self {
Handler { Handler {