Skip to content

Commit 099957a

Browse files
committed
Add the head_info endpoint
With that the frontend can consume all relevant workspace data just once, instead of once for `stacks()` and once per stack (i.e. 1 + N vs 1).
1 parent c4066ab commit 099957a

File tree

5 files changed

+397
-71
lines changed

5 files changed

+397
-71
lines changed

crates/but-api/src/commands/workspace.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ fn ref_metadata_toml(project: &Project) -> anyhow::Result<VirtualBranchesTomlMet
2525
VirtualBranchesTomlMetadata::from_path(project.gb_dir().join("virtual_branches.toml"))
2626
}
2727

28+
#[api_cmd]
29+
#[tauri::command(async)]
30+
#[instrument(err(Debug))]
31+
pub fn head_info(project_id: ProjectId) -> Result<but_workspace::ref_info::ui::RefInfo, Error> {
32+
let project = gitbutler_project::get(project_id)?;
33+
let ctx = CommandContext::open(&project, AppSettings::load_from_default_path_creating()?)?;
34+
let repo = ctx.gix_repo_for_merging_non_persisting()?;
35+
let meta = ref_metadata_toml(ctx.project())?;
36+
but_workspace::head_info(
37+
&repo,
38+
&meta,
39+
but_workspace::ref_info::Options {
40+
traversal: but_graph::init::Options::limited(),
41+
expensive_commit_info: true,
42+
},
43+
)
44+
.map_err(Into::into)
45+
.and_then(|info| but_workspace::ref_info::ui::RefInfo::for_ui(info, &repo).map_err(Into::into))
46+
}
47+
2848
#[api_cmd]
2949
#[tauri::command(async)]
3050
#[instrument(err(Debug))]

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ pub struct Stack {
431431
pub base: Option<gix::ObjectId>,
432432
/// The branch-name denoted segments of the stack from its tip to the point of reference, typically a merge-base.
433433
/// This array is never empty.
434-
pub segments: Vec<ref_info::ui::Segment>,
434+
pub segments: Vec<ref_info::Segment>,
435435
}
436436

437437
impl Stack {

0 commit comments

Comments
 (0)