Skip to content

Commit 1d59d22

Browse files
committed
Make stack.head private
1 parent 9772a01 commit 1d59d22

File tree

3 files changed

+52
-56
lines changed

3 files changed

+52
-56
lines changed

crates/but-workspace/src/virtual_branches_metadata.rs

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -328,34 +328,12 @@ impl RefMetadata for VirtualBranchesTomlMetadata {
328328
}
329329
None => {
330330
let now_ms = (gix::date::Time::now_utc().seconds * 1000) as u128;
331-
let stack = gitbutler_stack::Stack {
332-
id: StackId::default(),
333-
created_timestamp_ms: now_ms,
334-
updated_timestamp_ms: now_ms,
335-
order: self.snapshot.content.branches.len(),
336-
allow_rebasing: true, // default in V2
337-
in_workspace: ws.contains_ref(ref_name),
338-
heads: vec![branch_to_stack_branch(ref_name, value, false)],
339-
340-
// Don't keep redundant information
341-
tree: git2::Oid::zero(),
342-
head: git2::Oid::zero(),
343-
source_refname: None,
344-
upstream: None,
345-
upstream_head: None,
346-
347-
// Unused - everything is defined by the top-most branch name.
348-
name: "".to_string(),
349-
notes: "".to_string(),
350-
351-
// Related to ownership, obsolete.
352-
selected_for_changes: None,
353-
// unclear, obsolete
354-
not_in_workspace_wip_change_id: None,
355-
// unclear
356-
post_commits: false,
357-
ownership: Default::default(),
358-
};
331+
let stack = gitbutler_stack::Stack::new_with_just_heads(
332+
vec![branch_to_stack_branch(ref_name, value, false)],
333+
now_ms,
334+
self.snapshot.content.branches.len(),
335+
ws.contains_ref(ref_name),
336+
);
359337
*value.stack_id.borrow_mut() = Some(stack.id);
360338
self.snapshot.content.branches.insert(stack.id, stack);
361339
self.snapshot.changed_at = Some(Instant::now());

crates/but-workspace/tests/workspace/commit_engine/refs_update.rs

Lines changed: 9 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1026,7 +1026,7 @@ fn amend_on_top_of_branch_in_workspace() -> anyhow::Result<()> {
10261026

10271027
mod utils {
10281028
use but_testsupport::visualize_commit_graph;
1029-
use gitbutler_oxidize::{ObjectIdExt as _, OidExt};
1029+
use gitbutler_oxidize::OidExt;
10301030
use gitbutler_stack::{CommitOrChangeId, VirtualBranchesState};
10311031
use gix::refs::transaction::PreviousValue;
10321032

@@ -1051,35 +1051,17 @@ mod utils {
10511051

10521052
/// We are only interested in the head-related information, the rest is garbage.
10531053
pub fn stack_with_branches(
1054-
name: &str,
1055-
tip: gix::ObjectId,
1054+
_name: &str,
1055+
_tip: gix::ObjectId,
10561056
branches: impl IntoIterator<Item = (&'static str, gix::ObjectId)>,
10571057
repo: &gix::Repository,
10581058
) -> gitbutler_stack::Stack {
1059-
gitbutler_stack::Stack {
1060-
id: Default::default(),
1061-
name: name.into(),
1062-
tree: tip.kind().null().to_git2(),
1063-
head: tip.to_git2(),
1064-
heads: branches
1065-
.into_iter()
1066-
.map(|(name, target_id)| new_stack_branch(name, target_id, repo))
1067-
.filter_map(Result::ok)
1068-
.collect(),
1069-
notes: String::new(),
1070-
source_refname: None,
1071-
upstream: None,
1072-
upstream_head: None,
1073-
created_timestamp_ms: 0,
1074-
updated_timestamp_ms: 0,
1075-
ownership: Default::default(),
1076-
order: 0,
1077-
selected_for_changes: None,
1078-
allow_rebasing: false,
1079-
in_workspace: false,
1080-
not_in_workspace_wip_change_id: None,
1081-
post_commits: false,
1082-
}
1059+
let heads = branches
1060+
.into_iter()
1061+
.map(|(name, target_id)| new_stack_branch(name, target_id, repo))
1062+
.filter_map(Result::ok)
1063+
.collect();
1064+
gitbutler_stack::Stack::new_with_just_heads(heads, 0, 0, true)
10831065
}
10841066

10851067
fn new_stack_branch(

crates/gitbutler-stack/src/stack.rs

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ pub struct Stack {
7070
pub tree: git2::Oid,
7171
/// head is id of the last "virtual" commit in this branch
7272
#[serde(with = "gitbutler_serde::oid")]
73-
pub head: git2::Oid,
73+
head: git2::Oid,
7474
pub ownership: BranchOwnershipClaims,
7575
// order is the number by which UI should sort branches
7676
pub order: usize,
@@ -172,6 +172,42 @@ impl Stack {
172172
}
173173
}
174174

175+
pub fn new_with_just_heads(
176+
heads: Vec<StackBranch>,
177+
created_ms: u128,
178+
order: usize,
179+
in_workspace: bool,
180+
) -> Self {
181+
Stack {
182+
id: StackId::default(),
183+
created_timestamp_ms: created_ms,
184+
updated_timestamp_ms: created_ms,
185+
order,
186+
allow_rebasing: true, // default in V2
187+
in_workspace,
188+
heads,
189+
190+
// Don't keep redundant information
191+
tree: git2::Oid::zero(),
192+
head: git2::Oid::zero(),
193+
source_refname: None,
194+
upstream: None,
195+
upstream_head: None,
196+
197+
// Unused - everything is defined by the top-most branch name.
198+
name: "".to_string(),
199+
notes: "".to_string(),
200+
201+
// Related to ownership, obsolete.
202+
selected_for_changes: None,
203+
// unclear, obsolete
204+
not_in_workspace_wip_change_id: None,
205+
// unclear
206+
post_commits: false,
207+
ownership: Default::default(),
208+
}
209+
}
210+
175211
pub fn refname(&self) -> anyhow::Result<VirtualRefname> {
176212
self.try_into()
177213
}

0 commit comments

Comments
 (0)