Order stacks by the workspace commit's parents, drop parent_order#14452
Closed
mtsgrd wants to merge 2 commits into
Closed
Order stacks by the workspace commit's parents, drop parent_order#14452mtsgrd wants to merge 2 commits into
mtsgrd wants to merge 2 commits into
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Updates workspace stack display ordering so it is derived from the workspace commit’s parent array (parent_order) instead of relying on petgraph edge iteration/insertion order, and refreshes many snapshot-based tests accordingly.
Changes:
- Order workspace stacks by
parent_orderon outgoing edges from the workspace tip segment. - Reframe/rename
move_branchorder assertions to treat the workspace commit’s parent array as the source of truth (not metadata). - Update numerous
instasnapshots across workspace/graph tests to reflect the new ordering.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/but-workspace/tests/workspace/upstream_integration.rs | Updates workspace rendering snapshots to reflect the new parent-array-derived stack order. |
| crates/but-workspace/tests/workspace/ref_info/with_workspace_commit/mod.rs | Updates expected ref_info stack/segment ordering and associated snapshot IDs/names. |
| crates/but-workspace/tests/workspace/commit/squash_commits.rs | Refreshes workspace graph snapshots for squash scenarios under the new stack ordering. |
| crates/but-workspace/tests/workspace/commit/move_commit.rs | Refreshes snapshots for commit-move scenarios to match parent-array stack ordering. |
| crates/but-workspace/tests/workspace/commit/discard_commit.rs | Refreshes snapshots for discard scenarios to match new ordering. |
| crates/but-workspace/tests/workspace/branch/tear_off_branch.rs | Refreshes snapshots for tear-off scenarios with updated stack ordering. |
| crates/but-workspace/tests/workspace/branch/move_branch.rs | Renames/reframes ordering tests and updates snapshots/assertions to match parent-array authority. |
| crates/but-workspace/tests/workspace/branch/create_reference.rs | Updates snapshots for reference creation scenarios under new ordering. |
| crates/but-workspace/tests/workspace/branch/apply_unapply.rs | Updates snapshots for apply/unapply/checkout scenarios under new ordering. |
| crates/but-graph/tests/graph/init/with_workspace.rs | Updates graph-workspace snapshots reflecting the new stack order behavior. |
| crates/but-graph/src/projection/workspace/init.rs | Implements stack-top ordering using parent_order from outgoing edges of the workspace tip segment. |
0375359 to
a68169f
Compare
aca6bec to
749331f
Compare
749331f to
9ed607b
Compare
9ed607b to
dffa882
Compare
dffa882 to
40e7a25
Compare
40e7a25 to
6c88d11
Compare
6c88d11 to
928d17e
Compare
928d17e to
c921cda
Compare
c921cda to
1b82a0d
Compare
1b82a0d to
1ede0ec
Compare
Two things, both in service of correct stack order: - Drop the cached `parent_order` edge weight and read the workspace merge commit's real parent array instead, so display order always matches the actual parents. - Give empty branches their own base: each keeps a real workspace-commit parent of its own, so two empty branches on distinct bases stay distinct instead of collapsing together. The parent array is now the single source of stack order. The ordering happens once, at graph-build time, so no consumer re-sorts: the graph's first-parent traversal, its debug display, and the workspace projection all read the same already-correct order off the edges. Details: - but-graph: remove parent_order; order the ws-commit's outgoing edges by the real parent array at build time (post.rs), and delete the projection's re-sort — it now reads the order directly off the edges. - but-graph: follow the first-parent edge by graph order (not dst id) when walking the excluded side, so upstream commits aren't miscounted for empty stacks. - but-rebase editor: order reparented edges by the child's own parents, so rebuilt merge commits keep their parents in sequence (tear-off and insert). Commit-less empty branches get distinct, increasing edge orders from a counter, so the step graph needs no tie-break reversal. - but-rebase: add first_ordered_parent so reference resolution stops at the first commit parent instead of collecting every parent just to take the first (materialize / commit / reword / rebase). - gitbutler-branch-actions: when the merge base already carries an empty branch, walk back to a distinct unused base for the new one (concise out-of-commits error). - but-graph projection: resolve each branch's own base after integrated-commit pruning instead of falling back to the workspace merge base. - Update test fixtures and snapshots (distinct bases in the three-stacks move scenario so emptied stacks don't collapse onto one parent). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
`create_workspace_commit_once` makes the first argument the workspace commit's first parent; with `A B` the merge of B (A's ancestor) is a no-op and no workspace commit is created at all. `B A` reproduces the upstream fixture's shape ([base, A]) — the same adjustment ws-with-empty-stack.sh already received. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1ede0ec to
6fcec19
Compare
Contributor
Author
|
Closing in favor of a consolidated draft PR from |
Contributor
Author
|
Consolidated draft PR: #14623 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stack display order now follows the workspace commit's real parent array instead of a cached
parent_orderedge weight — which had gone stale (it held metadata order), so octopus/multi-stack workspaces showed the wrong order.The parent array is the single source of stack order. Ordering happens once, at graph-build time, so nothing downstream re-sorts: the graph's first-parent traversal, its debug display, and the
but stlane order all read the same already-correct order off the edges.1. Drop
parent_order, read the real parentsparent_ids;Edge.parent_order, its accessor, and therebuild_edges_in_parent_orderheuristic are all gonepreferred_parent_order_by_commitre-keyed to segment ids — still steers the merge-walk to the entrypoint through diamonds, just no weightparent_ids[0];but-rebasederives its step order the same way2. Order once, at graph-build time
but-graphorders the ws-commit's outgoing edges by the real parent array inpost.rs:stack_entry_commitwalks first-parent edges (skipping empties) to find each lane's entry, then sorts by(by_parent, by_metadata)— metadata order stays as a secondary tie-break for lanes the parent array can't tell apart (e.g. two branches sharing one base)remerged_workspace_commit_v2(the non-graph writer) sorts its parent list bystack.orderinstead ofHashMap::values(), so the real app produces parents in a deterministic order matching what the display reads3. Empty branches
but-rebasegives commit-less empties distinct, increasingEdge.ordervalues from a counter, so the step graph never has tied parent orders and the old tie-breakv.reverse()is removed4. Fixtures + snapshots
git mergeof an ancestor would otherwise silently drop it)three-stacksmove scenario gives its stacks distinct bases, so emptied stacks resolve to different parents instead of collapsing onto onemove/squashcommit-order asserts are updated for the new order✅ but-graph / but-workspace / but-rebase / but green;
cargo fmt,clippy -D warnings, andpnpm begoodall clean.Note
The construction layer can still collapse two empty branches that genuinely share one git base onto a single ws-commit parent (the array then has fewer slots than stacks). This PR sidesteps that with distinct-base fixtures; the long-term fix is to have move/remerge materialise empties as distinct parents even on a shared base. Tracked in the branch handover.
5. Drive-by:
first_ordered_parent(but-rebase)Reference resolution in
materialize/commit/reword/rebaseonly needs the first parent, but calledcollect_ordered_parents(a full pruned DFS over every parent) and took.first(). Addedfirst_ordered_parent, which shares the DFS but stops at the first commit. No behaviour change; the all-parents call sites are unchanged.