mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-12-18 14:31:30 +03:00
Merge pull request #3728 from gitbutlerapp/update-branch-name-with-old-name
compose traits for nicer snapshotting functions
This commit is contained in:
commit
7cf237b8d6
@ -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 {
|
||||
|
@ -1,4 +1,5 @@
|
||||
pub mod entry;
|
||||
mod reflog;
|
||||
pub mod snapshot;
|
||||
pub mod snapshoter;
|
||||
mod state;
|
||||
|
23
crates/gitbutler-core/src/snapshots/snapshoter.rs
Normal file
23
crates/gitbutler-core/src/snapshots/snapshoter.rs
Normal 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(())
|
||||
}
|
||||
}
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -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(())
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user