Merge pull request #3728 from gitbutlerapp/update-branch-name-with-old-name

compose traits for nicer snapshotting functions
This commit is contained in:
Kiril Videlov 2024-05-08 00:26:27 +02:00 committed by GitHub
commit 7cf237b8d6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 31 additions and 5 deletions

View File

@ -59,6 +59,10 @@ impl SnapshotDetails {
trailers: vec![],
}
}
pub fn with_trailers(mut self, trailers: Vec<Trailer>) -> Self {
self.trailers = trailers;
self
}
}
impl FromStr for SnapshotDetails {

View File

@ -1,4 +1,5 @@
pub mod entry;
mod reflog;
pub mod snapshot;
pub mod snapshoter;
mod state;

View File

@ -0,0 +1,23 @@
use crate::{
snapshots::entry::{OperationType, SnapshotDetails},
virtual_branches::Branch,
};
use super::{entry::Trailer, snapshot::Oplog};
pub trait Snapshoter {
fn snapshot_deletion(&self, oplog: &dyn Oplog) -> anyhow::Result<()>;
}
impl Snapshoter for Branch {
fn snapshot_deletion(&self, oplog: &dyn Oplog) -> anyhow::Result<()> {
let details =
SnapshotDetails::new(OperationType::DeleteBranch).with_trailers(vec![Trailer {
key: "name".to_string(),
value: self.name.to_string(),
}]);
oplog.create_snapshot(details)?;
Ok(())
}
}

View File

@ -709,11 +709,7 @@ impl ControllerInner {
let _permit = self.semaphore.acquire().await;
self.with_verify_branch(project_id, |project_repository, _| {
super::delete_branch(project_repository, branch_id)?;
let _ = project_repository
.project()
.create_snapshot(SnapshotDetails::new(OperationType::DeleteBranch));
Ok(())
super::delete_branch(project_repository, branch_id)
})
}

View File

@ -25,6 +25,7 @@ use super::{
branch_to_remote_branch, errors, target, RemoteBranch, VirtualBranchesHandle,
};
use crate::git::diff::{diff_files_into_hunks, trees, FileDiff};
use crate::snapshots::snapshoter::Snapshoter;
use crate::virtual_branches::branch::HunkHash;
use crate::{
dedup::{dedup, dedup_fmt},
@ -1493,6 +1494,7 @@ pub fn delete_branch(
ensure_selected_for_changes(&vb_state).context("failed to ensure selected for changes")?;
_ = branch.snapshot_deletion(project_repository.project());
Ok(())
}