mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-08-16 15:50:37 +03:00
simplify virtual branches controller deps graph
users controller is not a real dependency
This commit is contained in:
parent
6add0a40cc
commit
3dded08458
@ -17,29 +17,22 @@ use super::{
|
|||||||
use crate::{
|
use crate::{
|
||||||
git, project_repository,
|
git, project_repository,
|
||||||
projects::{self, ProjectId},
|
projects::{self, ProjectId},
|
||||||
users,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Controller {
|
pub struct Controller {
|
||||||
projects: projects::Controller,
|
projects: projects::Controller,
|
||||||
users: users::Controller,
|
|
||||||
helper: git::credentials::Helper,
|
helper: git::credentials::Helper,
|
||||||
|
|
||||||
semaphore: Arc<Semaphore>,
|
semaphore: Arc<Semaphore>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Controller {
|
impl Controller {
|
||||||
pub fn new(
|
pub fn new(projects: projects::Controller, helper: git::credentials::Helper) -> Self {
|
||||||
projects: projects::Controller,
|
|
||||||
users: users::Controller,
|
|
||||||
helper: git::credentials::Helper,
|
|
||||||
) -> Self {
|
|
||||||
Self {
|
Self {
|
||||||
semaphore: Arc::new(Semaphore::new(1)),
|
semaphore: Arc::new(Semaphore::new(1)),
|
||||||
|
|
||||||
projects,
|
projects,
|
||||||
users,
|
|
||||||
helper,
|
helper,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -53,7 +46,7 @@ impl Controller {
|
|||||||
run_hooks: bool,
|
run_hooks: bool,
|
||||||
) -> Result<git2::Oid> {
|
) -> Result<git2::Oid> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let snapshot_tree = project_repository.project().prepare_snapshot();
|
let snapshot_tree = project_repository.project().prepare_snapshot();
|
||||||
let result =
|
let result =
|
||||||
super::commit(project_repository, branch_id, message, ownership, run_hooks)
|
super::commit(project_repository, branch_id, message, ownership, run_hooks)
|
||||||
@ -86,7 +79,7 @@ impl Controller {
|
|||||||
) -> Result<(Vec<super::VirtualBranch>, Vec<git::diff::FileDiff>)> {
|
) -> Result<(Vec<super::VirtualBranch>, Vec<git::diff::FileDiff>)> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
super::list_virtual_branches(project_repository).map_err(Into::into)
|
super::list_virtual_branches(project_repository).map_err(Into::into)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -98,7 +91,7 @@ impl Controller {
|
|||||||
) -> Result<BranchId> {
|
) -> Result<BranchId> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let branch_id = super::create_virtual_branch(project_repository, create)?.id;
|
let branch_id = super::create_virtual_branch(project_repository, create)?.id;
|
||||||
Ok(branch_id)
|
Ok(branch_id)
|
||||||
})
|
})
|
||||||
@ -111,7 +104,7 @@ impl Controller {
|
|||||||
) -> Result<BranchId> {
|
) -> Result<BranchId> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
super::create_virtual_branch_from_branch(project_repository, branch).map_err(Into::into)
|
super::create_virtual_branch_from_branch(project_repository, branch).map_err(Into::into)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -162,7 +155,7 @@ impl Controller {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let _ = project_repository
|
let _ = project_repository
|
||||||
.project()
|
.project()
|
||||||
.create_snapshot(SnapshotDetails::new(OperationKind::MergeUpstream));
|
.create_snapshot(SnapshotDetails::new(OperationKind::MergeUpstream));
|
||||||
@ -173,7 +166,7 @@ impl Controller {
|
|||||||
pub async fn update_base_branch(&self, project_id: ProjectId) -> Result<Vec<ReferenceName>> {
|
pub async fn update_base_branch(&self, project_id: ProjectId) -> Result<Vec<ReferenceName>> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let _ = project_repository
|
let _ = project_repository
|
||||||
.project()
|
.project()
|
||||||
.create_snapshot(SnapshotDetails::new(OperationKind::UpdateWorkspaceBase));
|
.create_snapshot(SnapshotDetails::new(OperationKind::UpdateWorkspaceBase));
|
||||||
@ -195,7 +188,7 @@ impl Controller {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
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
|
||||||
.project()
|
.project()
|
||||||
@ -222,7 +215,7 @@ impl Controller {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
super::delete_branch(project_repository, branch_id)
|
super::delete_branch(project_repository, branch_id)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -234,7 +227,7 @@ impl Controller {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let _ = project_repository
|
let _ = project_repository
|
||||||
.project()
|
.project()
|
||||||
.create_snapshot(SnapshotDetails::new(OperationKind::DiscardHunk));
|
.create_snapshot(SnapshotDetails::new(OperationKind::DiscardHunk));
|
||||||
@ -245,7 +238,7 @@ impl Controller {
|
|||||||
pub async fn reset_files(&self, project_id: ProjectId, files: &Vec<String>) -> Result<()> {
|
pub async fn reset_files(&self, project_id: ProjectId, files: &Vec<String>) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let _ = project_repository
|
let _ = project_repository
|
||||||
.project()
|
.project()
|
||||||
.create_snapshot(SnapshotDetails::new(OperationKind::DiscardFile));
|
.create_snapshot(SnapshotDetails::new(OperationKind::DiscardFile));
|
||||||
@ -262,7 +255,7 @@ impl Controller {
|
|||||||
) -> Result<git2::Oid> {
|
) -> Result<git2::Oid> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let _ = project_repository
|
let _ = project_repository
|
||||||
.project()
|
.project()
|
||||||
.create_snapshot(SnapshotDetails::new(OperationKind::AmendCommit));
|
.create_snapshot(SnapshotDetails::new(OperationKind::AmendCommit));
|
||||||
@ -280,7 +273,7 @@ impl Controller {
|
|||||||
) -> Result<git2::Oid> {
|
) -> Result<git2::Oid> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let _ = project_repository
|
let _ = project_repository
|
||||||
.project()
|
.project()
|
||||||
.create_snapshot(SnapshotDetails::new(OperationKind::MoveCommitFile));
|
.create_snapshot(SnapshotDetails::new(OperationKind::MoveCommitFile));
|
||||||
@ -303,7 +296,7 @@ impl Controller {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let snapshot_tree = project_repository.project().prepare_snapshot();
|
let snapshot_tree = project_repository.project().prepare_snapshot();
|
||||||
let result: Result<()> =
|
let result: Result<()> =
|
||||||
super::undo_commit(project_repository, branch_id, commit_oid).map_err(Into::into);
|
super::undo_commit(project_repository, branch_id, commit_oid).map_err(Into::into);
|
||||||
@ -327,7 +320,7 @@ impl Controller {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let _ = project_repository
|
let _ = project_repository
|
||||||
.project()
|
.project()
|
||||||
.create_snapshot(SnapshotDetails::new(OperationKind::InsertBlankCommit));
|
.create_snapshot(SnapshotDetails::new(OperationKind::InsertBlankCommit));
|
||||||
@ -345,7 +338,7 @@ impl Controller {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let _ = project_repository
|
let _ = project_repository
|
||||||
.project()
|
.project()
|
||||||
.create_snapshot(SnapshotDetails::new(OperationKind::ReorderCommit));
|
.create_snapshot(SnapshotDetails::new(OperationKind::ReorderCommit));
|
||||||
@ -362,7 +355,7 @@ impl Controller {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let _ = project_repository
|
let _ = project_repository
|
||||||
.project()
|
.project()
|
||||||
.create_snapshot(SnapshotDetails::new(OperationKind::UndoCommit));
|
.create_snapshot(SnapshotDetails::new(OperationKind::UndoCommit));
|
||||||
@ -379,7 +372,7 @@ impl Controller {
|
|||||||
) -> Result<ReferenceName> {
|
) -> Result<ReferenceName> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let snapshot_tree = project_repository.project().prepare_snapshot();
|
let snapshot_tree = project_repository.project().prepare_snapshot();
|
||||||
let result = super::convert_to_real_branch(
|
let result = super::convert_to_real_branch(
|
||||||
project_repository,
|
project_repository,
|
||||||
@ -405,7 +398,7 @@ impl Controller {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
let helper = self.helper.clone();
|
let helper = self.helper.clone();
|
||||||
self.with_verify_branch_async(project_id, move |project_repository, _| {
|
self.with_verify_branch_async(project_id, move |project_repository| {
|
||||||
super::push(project_repository, branch_id, with_force, &helper, askpass)
|
super::push(project_repository, branch_id, with_force, &helper, askpass)
|
||||||
})?
|
})?
|
||||||
.await?
|
.await?
|
||||||
@ -438,7 +431,7 @@ impl Controller {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let _ = project_repository
|
let _ = project_repository
|
||||||
.project()
|
.project()
|
||||||
.create_snapshot(SnapshotDetails::new(OperationKind::SquashCommit));
|
.create_snapshot(SnapshotDetails::new(OperationKind::SquashCommit));
|
||||||
@ -454,7 +447,7 @@ impl Controller {
|
|||||||
message: &str,
|
message: &str,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let _ = project_repository
|
let _ = project_repository
|
||||||
.project()
|
.project()
|
||||||
.create_snapshot(SnapshotDetails::new(OperationKind::UpdateCommitMessage));
|
.create_snapshot(SnapshotDetails::new(OperationKind::UpdateCommitMessage));
|
||||||
@ -530,7 +523,7 @@ impl Controller {
|
|||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let _permit = self.semaphore.acquire().await;
|
let _permit = self.semaphore.acquire().await;
|
||||||
|
|
||||||
self.with_verify_branch(project_id, |project_repository, _| {
|
self.with_verify_branch(project_id, |project_repository| {
|
||||||
let _ = project_repository
|
let _ = project_repository
|
||||||
.project()
|
.project()
|
||||||
.create_snapshot(SnapshotDetails::new(OperationKind::MoveCommit));
|
.create_snapshot(SnapshotDetails::new(OperationKind::MoveCommit));
|
||||||
@ -543,28 +536,24 @@ impl Controller {
|
|||||||
fn with_verify_branch<T>(
|
fn with_verify_branch<T>(
|
||||||
&self,
|
&self,
|
||||||
project_id: ProjectId,
|
project_id: ProjectId,
|
||||||
action: impl FnOnce(&project_repository::Repository, Option<&users::User>) -> Result<T>,
|
action: impl FnOnce(&project_repository::Repository) -> Result<T>,
|
||||||
) -> Result<T> {
|
) -> Result<T> {
|
||||||
let project = self.projects.get(project_id)?;
|
let project = self.projects.get(project_id)?;
|
||||||
let project_repository = project_repository::Repository::open(&project)?;
|
let project_repository = project_repository::Repository::open(&project)?;
|
||||||
let user = self.users.get_user()?;
|
|
||||||
super::integration::verify_branch(&project_repository)?;
|
super::integration::verify_branch(&project_repository)?;
|
||||||
action(&project_repository, user.as_ref())
|
action(&project_repository)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_verify_branch_async<T: Send + 'static>(
|
fn with_verify_branch_async<T: Send + 'static>(
|
||||||
&self,
|
&self,
|
||||||
project_id: ProjectId,
|
project_id: ProjectId,
|
||||||
action: impl FnOnce(&project_repository::Repository, Option<&users::User>) -> Result<T>
|
action: impl FnOnce(&project_repository::Repository) -> Result<T> + Send + 'static,
|
||||||
+ Send
|
|
||||||
+ 'static,
|
|
||||||
) -> Result<JoinHandle<Result<T>>> {
|
) -> Result<JoinHandle<Result<T>>> {
|
||||||
let project = self.projects.get(project_id)?;
|
let project = self.projects.get(project_id)?;
|
||||||
let project_repository = project_repository::Repository::open(&project)?;
|
let project_repository = project_repository::Repository::open(&project)?;
|
||||||
let user = self.users.get_user()?;
|
|
||||||
super::integration::verify_branch(&project_repository)?;
|
super::integration::verify_branch(&project_repository)?;
|
||||||
Ok(tokio::task::spawn_blocking(move || {
|
Ok(tokio::task::spawn_blocking(move || {
|
||||||
action(&project_repository, user.as_ref())
|
action(&project_repository)
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,12 +4,11 @@ use super::*;
|
|||||||
async fn twice() {
|
async fn twice() {
|
||||||
let data_dir = paths::data_dir();
|
let data_dir = paths::data_dir();
|
||||||
let projects = projects::Controller::from_path(data_dir.path());
|
let projects = projects::Controller::from_path(data_dir.path());
|
||||||
let users = users::Controller::from_path(data_dir.path());
|
|
||||||
let helper = git::credentials::Helper::from_path(data_dir.path());
|
let helper = git::credentials::Helper::from_path(data_dir.path());
|
||||||
|
|
||||||
let test_project = TestProject::default();
|
let test_project = TestProject::default();
|
||||||
|
|
||||||
let controller = Controller::new(projects.clone(), users, helper);
|
let controller = Controller::new(projects.clone(), helper);
|
||||||
|
|
||||||
{
|
{
|
||||||
let project = projects
|
let project = projects
|
||||||
|
@ -5,7 +5,6 @@ use gitbutler_core::error::Marker;
|
|||||||
use gitbutler_core::{
|
use gitbutler_core::{
|
||||||
git,
|
git,
|
||||||
projects::{self, Project, ProjectId},
|
projects::{self, Project, ProjectId},
|
||||||
users,
|
|
||||||
virtual_branches::{branch, Controller},
|
virtual_branches::{branch, Controller},
|
||||||
};
|
};
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
@ -33,7 +32,6 @@ impl Default for Test {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
let data_dir = paths::data_dir();
|
let data_dir = paths::data_dir();
|
||||||
let projects = projects::Controller::from_path(data_dir.path());
|
let projects = projects::Controller::from_path(data_dir.path());
|
||||||
let users = users::Controller::from_path(data_dir.path());
|
|
||||||
let helper = git::credentials::Helper::from_path(data_dir.path());
|
let helper = git::credentials::Helper::from_path(data_dir.path());
|
||||||
|
|
||||||
let test_project = TestProject::default();
|
let test_project = TestProject::default();
|
||||||
@ -44,7 +42,7 @@ impl Default for Test {
|
|||||||
Self {
|
Self {
|
||||||
repository: test_project,
|
repository: test_project,
|
||||||
project_id: project.id,
|
project_id: project.id,
|
||||||
controller: Controller::new(projects.clone(), users, helper),
|
controller: Controller::new(projects.clone(), helper),
|
||||||
projects,
|
projects,
|
||||||
project,
|
project,
|
||||||
data_dir: Some(data_dir),
|
data_dir: Some(data_dir),
|
||||||
|
@ -139,7 +139,6 @@ fn main() {
|
|||||||
|
|
||||||
app_handle.manage(gitbutler_core::virtual_branches::controller::Controller::new(
|
app_handle.manage(gitbutler_core::virtual_branches::controller::Controller::new(
|
||||||
projects_controller.clone(),
|
projects_controller.clone(),
|
||||||
users_controller.clone(),
|
|
||||||
git_credentials_controller.clone(),
|
git_credentials_controller.clone(),
|
||||||
));
|
));
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user