Skip to content

Commit 1f3e463

Browse files
authored
Merge pull request #13660 from gitbutlerapp/remove-dead-split-commit
remove unused legacy implementations in but-workspace
2 parents b65ac90 + 86e77be commit 1f3e463

5 files changed

Lines changed: 3 additions & 307 deletions

File tree

crates/but-workspace/src/legacy/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ pub use stacks::{
2525
};
2626
pub use tree_manipulation::{
2727
MoveChangesResult,
28-
remove_changes_from_commit_in_stack::remove_changes_from_commit_in_stack,
2928
split_branch::{split_branch, split_into_dependent_branch},
30-
split_commit::{CommitFiles, CommmitSplitOutcome, split_commit},
3129
};
3230

3331
/// Various types for the frontend.

crates/but-workspace/src/legacy/tree_manipulation/mod.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,29 +11,6 @@ pub struct MoveChangesResult {
1111
pub replaced_commits: Vec<(gix::ObjectId, gix::ObjectId)>,
1212
}
1313

14-
impl MoveChangesResult {
15-
/// Merges the changes from another `MoveChangesResult` into this one.
16-
pub fn merge(&mut self, other: MoveChangesResult) {
17-
let mut new_replaced_commits = self.replaced_commits.clone();
18-
19-
for (before, after) in other.replaced_commits {
20-
let matching_commit_mapping =
21-
new_replaced_commits.iter_mut().find(|(_, a)| *a == before);
22-
if let Some(found_matching_mapping) = matching_commit_mapping {
23-
// If we found a matching commit mapping, we update the "after" id
24-
// to the new "after" id.
25-
found_matching_mapping.1 = after;
26-
} else {
27-
// Otherwise, we add the new mapping.
28-
new_replaced_commits.push((before, after));
29-
}
30-
}
31-
32-
self.replaced_commits = new_replaced_commits;
33-
}
34-
}
35-
3614
pub(super) mod remove_changes_from_commit_in_stack;
3715
pub(super) mod split_branch;
38-
pub(super) mod split_commit;
3916
mod utils;

crates/but-workspace/src/legacy/tree_manipulation/remove_changes_from_commit_in_stack.rs

Lines changed: 3 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,10 @@
1-
#![expect(
2-
deprecated,
3-
reason = "VirtualBranchesHandle should be replaced with ctx.workspace_* helpers"
4-
)]
5-
61
use anyhow::{Result, bail};
7-
use but_core::{DiffSpec, TreeChange, ref_metadata::StackId, sync::RepoExclusive};
2+
use but_core::{DiffSpec, TreeChange, sync::RepoExclusive};
83
use but_ctx::Context;
9-
use but_rebase::{Rebase, replace_commit_tree};
10-
use gitbutler_stack::VirtualBranchesHandle;
4+
use but_rebase::replace_commit_tree;
115
use gix::ObjectId;
126

13-
use super::MoveChangesResult;
14-
use crate::legacy::{
15-
stack_ext::StackExt,
16-
tree_manipulation::utils::{
17-
ChangesSource, create_tree_without_diff, rebase_mapping_with_overrides,
18-
replace_pick_with_commit,
19-
},
20-
};
21-
22-
/// Removes the specified changes from a given commit.
23-
///
24-
/// This only updates the specified stack. After calling you may want to call
25-
/// `update_workspace_commit` such that the workspace commit now contains the
26-
/// updated head of the stack.
27-
///
28-
/// You may want to make use of `update_uncommitted_changes`. Using it will
29-
/// cause the specified change to be dropped from the working directory. Not
30-
/// using it will result in the change showing up as an uncommitted change.
31-
///
32-
/// ## Assumptions
33-
///
34-
/// Currently this function does not take into consideration the possibility
35-
/// that the commit _might_ be part of two different stacks. As such, the
36-
/// other stacks may end up referring to stale commits and potentially cause
37-
/// a merge conflict when combining them in the workspace.
38-
pub fn remove_changes_from_commit_in_stack(
39-
ctx: &mut Context,
40-
source_stack_id: StackId,
41-
source_commit_id: gix::ObjectId,
42-
changes: impl IntoIterator<Item = DiffSpec>,
43-
perm: &mut RepoExclusive,
44-
) -> Result<MoveChangesResult> {
45-
let vb_state = VirtualBranchesHandle::new(ctx.project_data_dir());
46-
let source_stack = vb_state.get_stack(source_stack_id)?;
47-
48-
let rewritten_source_commit = remove_changes_from_commit(ctx, source_commit_id, changes, perm)?;
49-
50-
let mut steps = source_stack.as_rebase_steps(ctx)?;
51-
replace_pick_with_commit(&mut steps, source_commit_id, rewritten_source_commit)?;
52-
let base = source_stack.merge_base(ctx)?;
53-
54-
let result = {
55-
let repo = ctx.repo.get()?;
56-
let mut rebase = Rebase::new(&repo, base, None)?;
57-
rebase.steps(steps)?;
58-
rebase.rebase_noops(false);
59-
rebase.rebase()?
60-
};
61-
let commit_mapping =
62-
rebase_mapping_with_overrides(&result, [(source_commit_id, rewritten_source_commit)]);
63-
64-
let mut source_stack = source_stack;
65-
source_stack.set_heads_from_rebase_output(ctx, result.references)?;
66-
67-
let meta = ctx.meta()?;
68-
let (repo, mut ws, _) = ctx.workspace_mut_and_db_with_perm(perm)?;
69-
ws.refresh_from_head(&repo, &meta)?;
70-
71-
Ok(MoveChangesResult {
72-
replaced_commits: commit_mapping.into_iter().collect(),
73-
})
74-
}
7+
use crate::legacy::tree_manipulation::utils::{ChangesSource, create_tree_without_diff};
758

769
/// Removes the specified changes from a commit.
7710
///

crates/but-workspace/src/legacy/tree_manipulation/split_commit.rs

Lines changed: 0 additions & 111 deletions
This file was deleted.
Lines changed: 0 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,105 +1,4 @@
11
//! Utility types related to discarding changes in the worktree.
22
3-
use std::collections::HashMap;
4-
5-
use but_rebase::{RebaseOutput, RebaseStep};
6-
73
// Re-export from non-legacy location for backward compatibility
84
pub use crate::tree_manipulation::{ChangesSource, create_tree_without_diff};
9-
10-
/// Takes a rebase output and returns the commit mapping with any extra
11-
/// mapping overrides provided.
12-
///
13-
/// This will only include commits that have actually changed. If a commit was
14-
/// mapped to itself it will not be included in the resulting HashMap.
15-
///
16-
/// Overrides are used to handle the case where the caller of the rebase engine
17-
/// has manually replaced a particular commit with a rewritten one. This is
18-
/// needed because a manually re-written commit that ends up matching the
19-
/// base when the rebase occurs will end up showing up as a no-op in the
20-
/// resulting commit_mapping.
21-
///
22-
/// Overrides should be provided as a vector that contains tuples of object
23-
/// ids, where the first item is the before object_id, and the second item is
24-
/// the after object_id.
25-
pub(crate) fn rebase_mapping_with_overrides(
26-
rebase_output: &RebaseOutput,
27-
overrides: impl IntoIterator<Item = (gix::ObjectId, gix::ObjectId)>,
28-
) -> HashMap<gix::ObjectId, gix::ObjectId> {
29-
let mut mapping = rebase_output
30-
.commit_mapping
31-
.iter()
32-
.filter(|(_, old, new)| old != new)
33-
.map(|(_, old, new)| (*old, *new))
34-
.collect::<HashMap<_, _>>();
35-
36-
for (old, new) in overrides {
37-
if old != new {
38-
mapping.insert(old, new);
39-
}
40-
}
41-
42-
mapping
43-
}
44-
45-
pub fn replace_pick_with_commit(
46-
steps: &mut Vec<RebaseStep>,
47-
target_commit_id: gix::ObjectId,
48-
replacement_commit_id: gix::ObjectId,
49-
) -> anyhow::Result<()> {
50-
let mut found = false;
51-
for step in steps {
52-
if step.commit_id() != Some(&target_commit_id) {
53-
continue;
54-
}
55-
let RebaseStep::Pick { commit_id, .. } = step else {
56-
continue;
57-
};
58-
found = true;
59-
*commit_id = replacement_commit_id;
60-
}
61-
62-
if found {
63-
Ok(())
64-
} else {
65-
Err(anyhow::anyhow!(
66-
"Failed to replace pick step {target_commit_id} with {replacement_commit_id}"
67-
))
68-
}
69-
}
70-
71-
pub fn replace_pick_with_multiple_commits(
72-
steps: &mut Vec<RebaseStep>,
73-
target_commit_id: gix::ObjectId,
74-
replacement_commit_ids: &[(gix::ObjectId, Option<String>)],
75-
) -> anyhow::Result<()> {
76-
let mut found = false;
77-
let mut new_steps =
78-
Vec::with_capacity(steps.len() + replacement_commit_ids.len().saturating_sub(1));
79-
for step in steps.drain(..) {
80-
if step.commit_id() == Some(&target_commit_id) {
81-
let RebaseStep::Pick { .. } = step else {
82-
new_steps.push(step);
83-
continue;
84-
};
85-
found = true;
86-
for (replacement_commit_id, new_message) in replacement_commit_ids {
87-
new_steps.push(RebaseStep::Pick {
88-
commit_id: *replacement_commit_id,
89-
new_message: new_message.clone().map(|msg| msg.into()),
90-
});
91-
}
92-
} else {
93-
new_steps.push(step);
94-
}
95-
}
96-
*steps = new_steps;
97-
98-
if found {
99-
Ok(())
100-
} else {
101-
Err(anyhow::anyhow!(
102-
"Failed to replace pick step {target_commit_id} with multiple commits"
103-
))
104-
}
105-
}

0 commit comments

Comments
 (0)