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![],
|
trailers: vec![],
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
pub fn with_trailers(mut self, trailers: Vec<Trailer>) -> Self {
|
||||||
|
self.trailers = trailers;
|
||||||
|
self
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl FromStr for SnapshotDetails {
|
impl FromStr for SnapshotDetails {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
pub mod entry;
|
pub mod entry;
|
||||||
mod reflog;
|
mod reflog;
|
||||||
pub mod snapshot;
|
pub mod snapshot;
|
||||||
|
pub mod snapshoter;
|
||||||
mod state;
|
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;
|
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)
|
||||||
let _ = project_repository
|
|
||||||
.project()
|
|
||||||
.create_snapshot(SnapshotDetails::new(OperationType::DeleteBranch));
|
|
||||||
Ok(())
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ use super::{
|
|||||||
branch_to_remote_branch, errors, target, RemoteBranch, VirtualBranchesHandle,
|
branch_to_remote_branch, errors, target, RemoteBranch, VirtualBranchesHandle,
|
||||||
};
|
};
|
||||||
use crate::git::diff::{diff_files_into_hunks, trees, FileDiff};
|
use crate::git::diff::{diff_files_into_hunks, trees, FileDiff};
|
||||||
|
use crate::snapshots::snapshoter::Snapshoter;
|
||||||
use crate::virtual_branches::branch::HunkHash;
|
use crate::virtual_branches::branch::HunkHash;
|
||||||
use crate::{
|
use crate::{
|
||||||
dedup::{dedup, dedup_fmt},
|
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")?;
|
ensure_selected_for_changes(&vb_state).context("failed to ensure selected for changes")?;
|
||||||
|
|
||||||
|
_ = branch.snapshot_deletion(project_repository.project());
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user