Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion crates/but-action/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ pub fn handle_changes(

fn default_target_setting_if_none(
ctx: &Context,
vb_state: &VirtualBranchesHandle,
vb_state: &mut VirtualBranchesHandle,
) -> anyhow::Result<Target> {
if let Ok(default_target) = vb_state.get_default_target() {
return Ok(default_target);
Expand Down
8 changes: 4 additions & 4 deletions crates/but-action/src/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ pub(crate) fn handle_changes(
let mut guard = ctx.exclusive_worktree_access();
let perm = guard.write_permission();

let vb_state = &VirtualBranchesHandle::new(ctx.project_data_dir());
default_target_setting_if_none(ctx, vb_state)?; // Create a default target if none exists.
let mut vb_state = VirtualBranchesHandle::new(ctx.project_data_dir());
default_target_setting_if_none(ctx, &mut vb_state)?; // Create a default target if none exists.

let snapshot_before = ctx.create_snapshot(
SnapshotDetails::new(OperationKind::AutoHandleChangesBefore),
Expand All @@ -45,7 +45,7 @@ pub(crate) fn handle_changes(
ctx,
change_summary,
external_prompt.clone(),
vb_state,
&mut vb_state,
perm,
exclusive_stack,
);
Expand Down Expand Up @@ -73,7 +73,7 @@ fn handle_changes_simple_inner(
ctx: &mut Context,
change_summary: &str,
external_prompt: Option<String>,
vb_state: &VirtualBranchesHandle,
vb_state: &mut VirtualBranchesHandle,
perm: &mut RepoExclusive,
exclusive_stack: Option<StackId>,
) -> anyhow::Result<Outcome> {
Expand Down
17 changes: 4 additions & 13 deletions crates/but-api/src/legacy/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,10 @@ pub fn update_workspace_rule(
#[but_api]
#[instrument(err(Debug))]
pub fn list_workspace_rules(ctx: &mut Context) -> Result<Vec<WorkspaceRule>> {
let repo = ctx.clone_repo_for_merging_non_persisting()?;

let in_workspace = {
let meta = ctx.legacy_meta()?;
let mut cache = ctx.cache.get_cache_mut()?;
but_workspace::legacy::stacks_v3(
&repo,
&meta,
but_workspace::legacy::StacksFilter::InWorkspace,
None,
&mut cache,
)
}?
let in_workspace = crate::legacy::workspace::stacks_v3_from_ctx(
ctx,
but_workspace::legacy::StacksFilter::InWorkspace,
)?
.iter()
.filter_map(|s| s.id)
.collect::<Vec<StackId>>();
Expand Down
26 changes: 18 additions & 8 deletions crates/but-api/src/legacy/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use but_core::{RepositoryExt, sync::RepoExclusive};
use but_ctx::Context;
use but_hunk_assignment::HunkAssignmentRequest;
use but_settings::AppSettings;
use but_workspace::{commit_engine, commit_engine::StackSegmentId, legacy::ui::StackEntry};
use but_workspace::{
commit_engine::{self, StackSegmentId},
legacy::{StacksFilter, ui::StackEntry},
};
use gitbutler_branch_actions::{BranchManagerExt, update_workspace_commit};
use gitbutler_commit::commit_ext::CommitExt;
use gitbutler_oplog::{
Expand Down Expand Up @@ -52,7 +55,7 @@ mod json {
#[instrument(err(Debug))]
pub fn head_info(ctx: &but_ctx::Context) -> Result<but_workspace::RefInfo> {
let repo = ctx.clone_repo_for_merging_non_persisting()?;
let meta = ctx.legacy_meta()?;
let meta = ctx.meta()?;
let mut cache = ctx.cache.get_cache_mut()?;
but_workspace::head_info(
&repo,
Expand All @@ -72,24 +75,31 @@ pub fn stacks(
ctx: &Context,
filter: Option<but_workspace::legacy::StacksFilter>,
) -> Result<Vec<StackEntry>> {
stacks_v3_from_ctx(ctx, filter.unwrap_or_default())
}
///
/// Return stack information for the repository that `ctx` refers to using legacy metadata.
pub(crate) fn stacks_v3_from_ctx(
ctx: &Context,
filter: StacksFilter,
) -> anyhow::Result<Vec<but_workspace::legacy::ui::StackEntry>> {
let repo = ctx.clone_repo_for_merging_non_persisting()?;
let meta = ctx.legacy_meta()?;
let meta = ctx.meta()?;
let mut cache = ctx.cache.get_cache_mut()?;
but_workspace::legacy::stacks_v3(&repo, &meta, filter.unwrap_or_default(), None, &mut cache)
but_workspace::legacy::stacks_v3(&repo, &meta, filter, None, &mut cache)
}

#[cfg(unix)]
#[but_api]
#[instrument(err(Debug))]
pub fn show_graph_svg(ctx: &Context) -> Result<()> {
let repo = ctx.open_isolated_repo()?;
let meta = ctx.legacy_meta()?;
let meta = ctx.meta()?;
let mut graph = but_graph::Graph::from_head(
&repo,
&meta,
but_graph::init::Options {
collect_tags: true,
extra_target_commit_id: meta.data().default_target.as_ref().map(|t| t.sha),
..but_graph::init::Options::limited()
},
)?;
Expand Down Expand Up @@ -175,7 +185,7 @@ pub fn stack_details(
) -> Result<but_workspace::ui::StackDetails> {
let mut details = {
let repo = ctx.clone_repo_for_merging_non_persisting()?;
let meta = ctx.legacy_meta()?;
let meta = ctx.meta()?;
let mut cache = ctx.cache.get_cache_mut()?;
but_workspace::legacy::stack_details_v3(stack_id, &repo, &meta, &mut cache)
}?;
Expand Down Expand Up @@ -263,7 +273,7 @@ pub fn branch_details(
) -> Result<but_workspace::ui::BranchDetails> {
let mut details = {
let repo = ctx.clone_repo_for_merging_non_persisting()?;
let meta = ctx.legacy_meta()?;
let meta = ctx.meta()?;
let ref_name: gix::refs::FullName = match remote.as_deref() {
None => {
format!("refs/heads/{branch_name}")
Expand Down
2 changes: 1 addition & 1 deletion crates/but-workspace/src/legacy/commit_engine/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ pub fn create_commit_and_update_refs_with_project(
context_lines: u32,
_perm: &mut RepoExclusive,
) -> anyhow::Result<CreateCommitOutcome> {
let vbh = VirtualBranchesHandle::new(project_data_dir);
let mut vbh = VirtualBranchesHandle::new(project_data_dir);
let mut vb = vbh.read_file()?;
let frame = match maybe_stackid {
None => {
Expand Down
2 changes: 1 addition & 1 deletion crates/but-workspace/src/legacy/head.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub fn remerged_workspace_tree_v2(
ctx: &Context,
repo: &gix::Repository,
) -> Result<(gix::ObjectId, Vec<Stack>, gix::ObjectId)> {
let vb_state = VirtualBranchesHandle::new(ctx.project_data_dir());
let mut vb_state = VirtualBranchesHandle::new(ctx.project_data_dir());
let target = vb_state
.get_default_target()
.context("failed to get target")?;
Expand Down
Loading
Loading