snapshots of (un)appy branches contains name

This commit is contained in:
Kiril Videlov 2024-05-14 14:35:47 +02:00
parent 158ed5c15d
commit 631bc86031
No known key found for this signature in database
4 changed files with 35 additions and 10 deletions

View File

@ -122,7 +122,7 @@
restored_from: {entry.details?.trailers restored_from: {entry.details?.trailers
.find((t) => t.key === 'restored_from') .find((t) => t.key === 'restored_from')
?.value?.slice(0, 7)} ?.value?.slice(0, 7)}
{:else if ['DeleteBranch', 'CreateBranch'].includes(entry.details?.operation || '')} {:else if ['DeleteBranch', 'CreateBranch', 'ApplyBranch', 'UnapplyBranch'].includes(entry.details?.operation || '')}
name: {entry.details?.trailers.find((t) => t.key === 'name')?.value} name: {entry.details?.trailers.find((t) => t.key === 'name')?.value}
{:else if ['ReorderBranches', 'UpdateBranchName', 'SelectDefaultVirtualBranch', 'UpdateBranchRemoteName'].includes(entry.details?.operation || '')} {:else if ['ReorderBranches', 'UpdateBranchName', 'SelectDefaultVirtualBranch', 'UpdateBranchRemoteName'].includes(entry.details?.operation || '')}
<div> <div>

View File

@ -10,6 +10,8 @@ use super::{entry::Trailer, oplog::Oplog};
pub trait Snapshot { pub trait Snapshot {
fn snapshot_branch_creation(&self, branch_name: String) -> anyhow::Result<()>; fn snapshot_branch_creation(&self, branch_name: String) -> anyhow::Result<()>;
fn snapshot_branch_deletion(&self, branch_name: String) -> anyhow::Result<()>; fn snapshot_branch_deletion(&self, branch_name: String) -> anyhow::Result<()>;
fn snapshot_branch_applied(&self, branch_name: String) -> anyhow::Result<()>;
fn snapshot_branch_unapplied(&self, branch_name: String) -> anyhow::Result<()>;
fn snapshot_branch_update( fn snapshot_branch_update(
&self, &self,
old_branch: Branch, old_branch: Branch,
@ -24,6 +26,24 @@ pub trait Snapshot {
} }
impl<T: Oplog> Snapshot for T { impl<T: Oplog> Snapshot for T {
fn snapshot_branch_applied(&self, branch_name: String) -> anyhow::Result<()> {
let details =
SnapshotDetails::new(OperationType::ApplyBranch).with_trailers(vec![Trailer {
key: "name".to_string(),
value: branch_name,
}]);
self.create_snapshot(details)?;
Ok(())
}
fn snapshot_branch_unapplied(&self, branch_name: String) -> anyhow::Result<()> {
let details =
SnapshotDetails::new(OperationType::UnapplyBranch).with_trailers(vec![Trailer {
key: "name".to_string(),
value: branch_name,
}]);
self.create_snapshot(details)?;
Ok(())
}
fn snapshot_commit_undo(&self, commit_sha: String) -> anyhow::Result<()> { fn snapshot_commit_undo(&self, commit_sha: String) -> anyhow::Result<()> {
let details = let details =
SnapshotDetails::new(OperationType::UndoCommit).with_trailers(vec![Trailer { SnapshotDetails::new(OperationType::UndoCommit).with_trailers(vec![Trailer {

View File

@ -715,9 +715,6 @@ impl ControllerInner {
let result = let result =
super::apply_branch(project_repository, branch_id, signing_key.as_ref(), user) super::apply_branch(project_repository, branch_id, signing_key.as_ref(), user)
.map_err(Into::into); .map_err(Into::into);
let _ = project_repository
.project()
.create_snapshot(SnapshotDetails::new(OperationType::ApplyBranch));
result result
}) })
} }
@ -883,13 +880,18 @@ impl ControllerInner {
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 result = super::unapply_branch(project_repository, branch_id) let result = super::unapply_branch(project_repository, branch_id);
.map(|_| ()) let branch_name = result
.map_err(Into::into); .as_ref()
.ok()
.cloned()
.flatten()
.map(|b| b.name)
.unwrap_or_default();
let _ = project_repository let _ = project_repository
.project() .project()
.create_snapshot(SnapshotDetails::new(OperationType::UnapplyBranch)); .snapshot_branch_unapplied(branch_name);
result result.map(|_| ()).map_err(Into::into)
}) })
} }

View File

@ -453,7 +453,7 @@ pub fn apply_branch(
// apply the branch // apply the branch
branch.applied = true; branch.applied = true;
vb_state.set_branch(branch)?; vb_state.set_branch(branch.clone())?;
ensure_selected_for_changes(&vb_state).context("failed to ensure selected for changes")?; ensure_selected_for_changes(&vb_state).context("failed to ensure selected for changes")?;
@ -465,6 +465,9 @@ pub fn apply_branch(
super::integration::update_gitbutler_integration(&vb_state, project_repository)?; super::integration::update_gitbutler_integration(&vb_state, project_repository)?;
_ = project_repository
.project()
.snapshot_branch_applied(branch.name);
Ok(()) Ok(())
} }