mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-12 07:13:34 +03:00
feat: add flush_vbranches method to Controller struct (#1383)
* feat: add flush_vbranches method to Controller struct The `flush_vbranches` method has been added to the `Controller` struct. This method allows flushing virtual branches as a tree for a specific project. It iterates over the virtual branches of the project and calls the `flush_vbranch_as_tree` function to flush each virtual branch. This method is used in the `Handler` struct to flush virtual branches for a project before flushing the session. * cleanup error handling * make controller async for consistency and block on the caller site
This commit is contained in:
parent
8dacd371a0
commit
ae3a6f3ebe
@ -17,6 +17,7 @@ use super::{
|
||||
RemoteBranchFile,
|
||||
};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Controller {
|
||||
local_data_dir: DataDir,
|
||||
semaphores: Arc<tokio::sync::Mutex<HashMap<String, Semaphore>>>,
|
||||
@ -530,4 +531,21 @@ impl Controller {
|
||||
let _permit = semaphore.acquire().await;
|
||||
action()
|
||||
}
|
||||
|
||||
pub async fn flush_vbranches(&self, project_id: ProjectId) -> Result<(), Error> {
|
||||
self.with_lock(&project_id, || {
|
||||
self.with_verify_branch(&project_id, |gb_repository, project_repository, _| {
|
||||
let vbranches = super::list_virtual_branches(gb_repository, project_repository)
|
||||
.map_err(Error::Other)?;
|
||||
|
||||
for b in &vbranches {
|
||||
super::flush_vbranch_as_tree(gb_repository, project_repository, &b.id, true)
|
||||
.map_err(Error::Other)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
})
|
||||
})
|
||||
.await
|
||||
}
|
||||
}
|
||||
|
@ -1,12 +1,12 @@
|
||||
use anyhow::{Context, Result};
|
||||
use tauri::AppHandle;
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
use crate::{
|
||||
gb_repository,
|
||||
paths::DataDir,
|
||||
project_repository,
|
||||
projects::{self, ProjectId},
|
||||
sessions, users,
|
||||
sessions, users, virtual_branches,
|
||||
};
|
||||
|
||||
use super::events;
|
||||
@ -15,6 +15,7 @@ use super::events;
|
||||
pub struct Handler {
|
||||
local_data_dir: DataDir,
|
||||
project_store: projects::Controller,
|
||||
vbrach_controller: virtual_branches::Controller,
|
||||
users: users::Controller,
|
||||
}
|
||||
|
||||
@ -25,6 +26,10 @@ impl TryFrom<&AppHandle> for Handler {
|
||||
Ok(Self {
|
||||
local_data_dir: DataDir::try_from(value)?,
|
||||
project_store: projects::Controller::try_from(value)?,
|
||||
vbrach_controller: value
|
||||
.state::<virtual_branches::Controller>()
|
||||
.inner()
|
||||
.clone(),
|
||||
users: users::Controller::from(value),
|
||||
})
|
||||
}
|
||||
@ -51,15 +56,11 @@ impl Handler {
|
||||
)
|
||||
.context("failed to open repository")?;
|
||||
|
||||
// TODO: fixme
|
||||
// if let Some(branch_id) = &session.meta.branch {
|
||||
// virtual_branches::flush_vbranch_as_tree(
|
||||
// &gb_repo,
|
||||
// &project_repository,
|
||||
// branch_id,
|
||||
// true,
|
||||
// )?;
|
||||
// }
|
||||
futures::executor::block_on(async {
|
||||
self.vbrach_controller
|
||||
.flush_vbranches(project_repository.project().id)
|
||||
.await
|
||||
})?;
|
||||
|
||||
let session = gb_repo
|
||||
.flush_session(&project_repository, session, user.as_ref())
|
||||
|
Loading…
Reference in New Issue
Block a user