Skip to content

Commit c9a0bdd

Browse files
committed
Refactor set_stack_head so that it does not take command context
1 parent 1d59d22 commit c9a0bdd

File tree

13 files changed

+62
-33
lines changed

13 files changed

+62
-33
lines changed

crates/gitbutler-branch-actions/src/branch_manager/branch_creation.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,12 @@ impl BranchManager<'_> {
249249
if let (Some(pr_number), Some(head)) = (pr_number, branch.heads().last()) {
250250
branch.set_pr_number(self.ctx, head, Some(pr_number))?;
251251
}
252-
branch.set_stack_head(self.ctx, head_commit.id(), Some(head_commit_tree.id()))?;
252+
branch.set_stack_head(
253+
&vb_state,
254+
&repo.to_gix()?,
255+
head_commit.id(),
256+
Some(head_commit_tree.id()),
257+
)?;
253258
self.ctx.add_branch_reference(&branch)?;
254259

255260
match self.apply_branch(branch.id, perm) {
@@ -361,7 +366,8 @@ impl BranchManager<'_> {
361366
};
362367

363368
stack.set_stack_head(
364-
self.ctx,
369+
&vb_state,
370+
&gix_repo,
365371
new_head.id(),
366372
Some(repo.find_real_tree(&new_head, Default::default())?.id()),
367373
)?;

crates/gitbutler-branch-actions/src/branch_upstream_integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub fn integrate_upstream_commits_for_series(
8585
integrate_upstream_context.inner_integrate_upstream_commits_for_series(series_head.id())?;
8686

8787
let mut branch = stack.clone();
88-
branch.set_stack_head(ctx, head, tree)?;
88+
branch.set_stack_head(&vb_state, &gix_repo, head, tree)?;
8989
let new_workspace = WorkspaceState::create(ctx, perm.read_permission())?;
9090
if ctx.app_settings().feature_flags.v3 {
9191
update_uncommited_changes(ctx, old_workspace, new_workspace, perm)?;

crates/gitbutler-branch-actions/src/integration.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,8 @@ fn verify_head_is_clean(ctx: &CommandContext, perm: &mut WorktreeWritePermission
383383
.context("failed to create virtual branch")?;
384384

385385
// rebasing the extra commits onto the new branch
386-
let mut head = new_branch.head(&ctx.repo().to_gix()?)?;
386+
let gix_repo = ctx.repo().to_gix()?;
387+
let mut head = new_branch.head(&gix_repo)?;
387388
for commit in extra_commits {
388389
let new_branch_head = ctx
389390
.repo()
@@ -411,7 +412,12 @@ fn verify_head_is_clean(ctx: &CommandContext, perm: &mut WorktreeWritePermission
411412
rebased_commit_oid
412413
))?;
413414

414-
new_branch.set_stack_head(ctx, rebased_commit.id(), Some(rebased_commit.tree_id()))?;
415+
new_branch.set_stack_head(
416+
&vb_handle,
417+
&gix_repo,
418+
rebased_commit.id(),
419+
Some(rebased_commit.tree_id()),
420+
)?;
415421

416422
head = rebased_commit.id();
417423
}

crates/gitbutler-branch-actions/src/move_commits.rs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use gitbutler_hunk_dependency::locks::HunkDependencyResult;
99
use gitbutler_oxidize::{ObjectIdExt, OidExt, RepoExt};
1010
use gitbutler_project::access::WorktreeWritePermission;
1111
use gitbutler_stack::stack_context::CommandContextExt;
12-
use gitbutler_stack::StackId;
12+
use gitbutler_stack::{StackId, VirtualBranchesHandle};
1313
use gitbutler_workspace::branch_trees::{update_uncommited_changes, WorkspaceState};
1414
#[allow(deprecated)]
1515
use gitbutler_workspace::{checkout_branch_trees, compute_updated_branch_head};
@@ -72,7 +72,7 @@ pub(crate) fn move_commit(
7272
&workspace_dependencies,
7373
)?;
7474

75-
move_commit_to_destination_stack(ctx, repo, destination_stack, subject_commit_oid)?;
75+
move_commit_to_destination_stack(&vb_state, ctx, repo, destination_stack, subject_commit_oid)?;
7676

7777
let new_workspace = WorkspaceState::create(ctx, perm.read_permission())?;
7878
if ctx.app_settings().feature_flags.v3 {
@@ -164,12 +164,14 @@ fn take_commit_from_source_stack(
164164
};
165165

166166
source_stack.set_heads_from_rebase_output(ctx, output.references)?;
167-
source_stack.set_stack_head(ctx, new_head_oid, new_tree_oid)?;
167+
let vb_state = ctx.project().virtual_branches();
168+
source_stack.set_stack_head(&vb_state, &gix_repo, new_head_oid, new_tree_oid)?;
168169
Ok(())
169170
}
170171

171172
/// Move the commit to the destination stack.
172173
fn move_commit_to_destination_stack(
174+
vb_state: &VirtualBranchesHandle,
173175
ctx: &CommandContext,
174176
repo: &git2::Repository,
175177
mut destination_stack: gitbutler_stack::Stack,
@@ -204,6 +206,11 @@ fn move_commit_to_destination_stack(
204206
};
205207

206208
destination_stack.set_heads_from_rebase_output(ctx, output.references)?;
207-
destination_stack.set_stack_head(ctx, new_destination_head_oid, new_destination_tree_oid)?;
209+
destination_stack.set_stack_head(
210+
vb_state,
211+
&gix_repo,
212+
new_destination_head_oid,
213+
new_destination_tree_oid,
214+
)?;
208215
Ok(())
209216
}

crates/gitbutler-branch-actions/src/reorder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn reorder_stack(
8181
};
8282

8383
// Ensure the stack head is set to the new oid after rebasing
84-
stack.set_stack_head(ctx, new_head_oid, new_tree_oid)?;
84+
stack.set_stack_head(&state, &gix_repo, new_head_oid, new_tree_oid)?;
8585

8686
stack.set_heads_from_rebase_output(ctx, output.references.clone())?;
8787

crates/gitbutler-branch-actions/src/squash.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ fn do_squash_commits(
210210
(res.head, Some(res.tree))
211211
};
212212

213-
stack.set_stack_head(ctx, new_head_oid, new_tree_oid)?;
213+
stack.set_stack_head(&vb_state, &gix_repo, new_head_oid, new_tree_oid)?;
214214

215215
let new_workspace = WorkspaceState::create(ctx, perm.read_permission())?;
216216
if ctx.app_settings().feature_flags.v3 {

crates/gitbutler-branch-actions/src/undo_commit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ pub(crate) fn undo_commit(
5858
}
5959

6060
let new_head = output.top_commit.to_git2();
61-
stack.set_stack_head(ctx, new_head, None)?;
61+
stack.set_stack_head(&vb_state, &repo, new_head, None)?;
6262

6363
stack.set_heads_from_rebase_output(ctx, output.references)?;
6464

crates/gitbutler-branch-actions/src/upstream_integration.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ pub(crate) fn integrate_upstream(
583583
if let Some(output) = rebase_output {
584584
stack.set_heads_from_rebase_output(command_context, output.references.clone())?;
585585
}
586-
stack.set_stack_head(command_context, *head, *tree)?;
586+
stack.set_stack_head(&virtual_branches_state, &gix_repo, *head, *tree)?;
587587

588588
let delete_local_refs = resolutions
589589
.iter()

crates/gitbutler-branch-actions/src/virtual.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -696,7 +696,7 @@ pub(crate) fn reset_branch(
696696
// what hunks were released by this reset, and assign them to this branch.
697697
let old_head = get_workspace_head(ctx)?;
698698

699-
stack.set_stack_head(ctx, target_commit_id, None)?;
699+
stack.set_stack_head(&vb_state, &gix_repo, target_commit_id, None)?;
700700

701701
let updated_head = get_workspace_head(ctx)?;
702702
let repo = ctx.repo();
@@ -829,7 +829,7 @@ pub fn commit(
829829
};
830830

831831
let vb_state = ctx.project().virtual_branches();
832-
branch.set_stack_head(ctx, commit_oid, Some(tree_oid))?;
832+
branch.set_stack_head(&vb_state, &gix_repo, commit_oid, Some(tree_oid))?;
833833

834834
crate::integration::update_workspace_commit(&vb_state, ctx)
835835
.context("failed to update gitbutler workspace")?;
@@ -1320,7 +1320,7 @@ pub(crate) fn move_commit_file(
13201320

13211321
// if there are no upstream commits (the "to" commit was the branch head), then we're done
13221322
if upstream_commits.is_empty() {
1323-
target_stack.set_stack_head(ctx, commit_oid, None)?;
1323+
target_stack.set_stack_head(&vb_state, &gix_repo, commit_oid, None)?;
13241324
crate::integration::update_workspace_commit(&vb_state, ctx)?;
13251325
return Ok(commit_oid);
13261326
}
@@ -1331,7 +1331,7 @@ pub(crate) fn move_commit_file(
13311331

13321332
// if that rebase worked, update the branch head and the gitbutler workspace
13331333
if let Some(new_head) = new_head {
1334-
target_stack.set_stack_head(ctx, new_head, None)?;
1334+
target_stack.set_stack_head(&vb_state, &gix_repo, new_head, None)?;
13351335
crate::integration::update_workspace_commit(&vb_state, ctx)?;
13361336
Ok(commit_oid)
13371337
} else {
@@ -1401,7 +1401,7 @@ pub(crate) fn insert_blank_commit(
14011401
let output = rebase.rebase()?;
14021402
stack.set_heads_from_rebase_output(ctx, output.references)?;
14031403

1404-
stack.set_stack_head(ctx, output.top_commit.to_git2(), None)?;
1404+
stack.set_stack_head(&vb_state, &repo, output.top_commit.to_git2(), None)?;
14051405

14061406
crate::integration::update_workspace_commit(&vb_state, ctx)
14071407
.context("failed to update gitbutler workspace")?;
@@ -1470,7 +1470,7 @@ pub(crate) fn update_commit_message(
14701470
let output = rebase.rebase()?;
14711471

14721472
let new_head = output.top_commit.to_git2();
1473-
stack.set_stack_head(ctx, new_head, None)?;
1473+
stack.set_stack_head(&vb_state, &gix_repo, new_head, None)?;
14741474
stack.set_heads_from_rebase_output(ctx, output.references)?;
14751475

14761476
crate::integration::update_workspace_commit(&vb_state, ctx)

crates/gitbutler-branch-actions/tests/extra/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -851,7 +851,7 @@ fn merge_vbranch_upstream_clean_rebase() -> Result<()> {
851851
"update target",
852852
)?;
853853

854-
branch.set_stack_head(ctx, last_push, None)?;
854+
branch.set_stack_head(&vb_state, &ctx.gix_repository()?, last_push, None)?;
855855

856856
// create the branch
857857
let list_result = internal::list_virtual_branches(ctx, guard.write_permission())?;
@@ -974,7 +974,7 @@ fn merge_vbranch_upstream_conflict() -> Result<()> {
974974
)?;
975975

976976
branch.upstream = Some(remote_branch.clone());
977-
branch.set_stack_head(ctx, last_push, None)?;
977+
branch.set_stack_head(&vb_state, &ctx.gix_repository()?, last_push, None)?;
978978

979979
//update repo ref refs/remotes/origin/master to up_target oid
980980
ctx.repo().reference(

0 commit comments

Comments
 (0)