Skip to content

Commit 4ad945c

Browse files
authored
Merge pull request #10382 from Byron/next
Add the `head_info` endpoint
2 parents 27c7ab3 + 200da1d commit 4ad945c

File tree

13 files changed

+1133
-327
lines changed

13 files changed

+1133
-327
lines changed

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,30 @@ 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::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| {
46+
but_workspace::ui::RefInfo::for_ui(info, &repo)
47+
.map(|ref_info| ref_info.pruned_to_entrypoint())
48+
.map_err(Into::into)
49+
})
50+
}
51+
2852
#[api_cmd]
2953
#[tauri::command(async)]
3054
#[instrument(err(Debug))]

crates/but-core/src/ref_metadata.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ impl Workspace {
8181
}
8282

8383
/// Metadata about branches, associated with any Git branch.
84-
#[derive(Clone, Eq, PartialEq, Default)]
84+
#[derive(serde::Serialize, Clone, Eq, PartialEq, Default)]
85+
#[serde(rename_all = "camelCase")]
8586
pub struct Branch {
8687
/// Standard data we want to know about any ref.
8788
pub ref_info: RefInfo,
@@ -132,7 +133,8 @@ impl<T: std::fmt::Debug> std::fmt::Debug for MaybeDebug<'_, T> {
132133
///
133134
/// It allows keeping track of when it changed, but also if we created it initially, a useful
134135
/// bit of information.
135-
#[derive(Default, Clone, Eq, PartialEq)]
136+
#[derive(serde::Serialize, Default, Clone, Eq, PartialEq)]
137+
#[serde(rename_all = "camelCase")]
136138
pub struct RefInfo {
137139
/// The time of creation, *if we created the reference*.
138140
pub created_at: Option<gix::date::Time>,
@@ -219,7 +221,8 @@ impl WorkspaceStack {
219221
}
220222

221223
/// Metadata about branches, associated with any Git branch.
222-
#[derive(Clone, Eq, PartialEq, Default)]
224+
#[derive(serde::Serialize, Clone, Eq, PartialEq, Default)]
225+
#[serde(rename_all = "camelCase")]
223226
pub struct Review {
224227
/// The number for the PR that was associated with this branch.
225228
pub pull_request: Option<usize>,

crates/but-server/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ async fn handle_command(
164164
"assign_hunk" => diff::assign_hunk_cmd(request.params),
165165
// Workspace commands
166166
"stacks" => workspace::stacks_cmd(request.params),
167+
"head_info" => workspace::head_info_cmd(request.params),
167168
#[cfg(unix)]
168169
"show_graph_svg" => workspace::show_graph_svg_cmd(request.params),
169170
"stack_details" => workspace::stack_details_cmd(request.params),

crates/but-workspace/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ tempfile.workspace = true
3636

3737
[dev-dependencies]
3838
but-testsupport.workspace = true
39-
insta = "1.43.1"
39+
insta = { version = "1.43.1", features = ["json"] }
4040
but-core = { workspace = true, features = ["testing"] }
4141
# for stable hashes in `gitbuter-` crates while we use them.
4242
# TODO: remove once `gitbutler-repo` isn't needed anymore.

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 {

crates/but-workspace/src/changeset.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@
66
77
use crate::{
88
RefInfo,
9-
ref_info::{
10-
ui,
11-
ui::{LocalCommit, LocalCommitRelation},
12-
},
9+
ref_info::{LocalCommit, LocalCommitRelation},
1310
ui::PushStatus,
1411
};
1512
use bstr::{BStr, BString, ByteSlice, ByteVec};
@@ -94,7 +91,7 @@ impl RefInfo {
9491
repo,
9592
upstream_commits.iter().filter_map(|id| {
9693
but_core::Commit::from_id(id.attach(repo))
97-
.map(ui::Commit::from)
94+
.map(crate::ref_info::Commit::from)
9895
.ok()
9996
}),
10097
cost_info,
@@ -262,7 +259,7 @@ impl PushStatus {
262259

263260
fn changeset_identifier(
264261
repo: &gix::Repository,
265-
commit: Option<&ui::Commit>,
262+
commit: Option<&crate::ref_info::Commit>,
266263
elapsed: &mut Duration,
267264
) -> anyhow::Result<Option<Identifier>> {
268265
let Some(commit) = commit else {
@@ -296,7 +293,7 @@ enum ChangeId {
296293

297294
fn lookup_similar<'a>(
298295
map: &'a Identity,
299-
commit: &ui::Commit,
296+
commit: &crate::ref_info::Commit,
300297
expensive: Option<&Identifier>,
301298
change_id: ChangeId,
302299
) -> Option<&'a gix::ObjectId> {
@@ -312,7 +309,7 @@ fn lookup_similar<'a>(
312309
/// Returns the fully-loaded commits suitable to be passed to UI, to have better re-use.
313310
fn create_similarity_lut(
314311
repo: &gix::Repository,
315-
commits: impl Iterator<Item = impl Borrow<ui::Commit>>,
312+
commits: impl Iterator<Item = impl Borrow<crate::ref_info::Commit>>,
316313
(max_commits, num_tracked_files): (usize, usize),
317314
expensive: bool,
318315
) -> anyhow::Result<Identity> {
@@ -633,7 +630,7 @@ enum Identifier {
633630
ChangesetId(ChangesetID),
634631
}
635632

636-
fn commit_data_id(c: &ui::Commit) -> anyhow::Result<Identifier> {
633+
fn commit_data_id(c: &crate::ref_info::Commit) -> anyhow::Result<Identifier> {
637634
let mut hasher = gix::hash::hasher(gix::hash::Kind::Sha1);
638635

639636
let gix::actor::Signature {

crates/but-workspace/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ pub struct RefInfo {
222222
pub struct AncestorWorkspaceCommit {
223223
/// The commits along the first parent that are between the managed workspace reference and the managed workspace commit.
224224
/// The vec is never empty.
225-
pub commits_outside: Vec<ref_info::ui::Commit>,
225+
pub commits_outside: Vec<crate::ref_info::Commit>,
226226
/// The index of the segment that actually holds the managed workspace commit.
227227
pub segment_with_managed_commit: SegmentIndex,
228228
/// The index of the workspace commit within the `commits` array in its parent segment.

0 commit comments

Comments
 (0)