Store ad-hoc branch order metadata#14513
Conversation
There was a problem hiding this comment.
Pull request overview
This PR introduces durable storage and consumption of ad-hoc (single-branch mode) dependent-branch ordering metadata by persisting refname parent pointers in the project SQLite database and using that ordering during graph post-processing to preserve/split same-tip dependent branches.
Changes:
- Add a new
branch_orderSQLite table (with read/write handles) and migrations/tests inbut-db. - Add
RefMetadataAPIs for reading/writing ad-hoc branch stack order and aBranchOrderMetadataimplementation that combines legacy TOML metadata with DB-backed ordering. - Teach
but-graphpost-processing and workspace projection to consume persisted ad-hoc ordering (e.g., keeping empty top segments and handling ordered lower bounds).
Reviewed changes
Copilot reviewed 17 out of 17 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| crates/but-core/src/lib.rs | Extends RefMetadata with branch stack order read/write capability (default no-op / unsupported). |
| crates/but-meta/src/lib.rs | Re-exports BranchOrderMetadata from the legacy module for consumers under the legacy feature. |
| crates/but-meta/src/legacy/mod.rs | Adds BranchOrderMetadata combining legacy TOML metadata with DB-backed branch ordering persistence. |
| crates/but-db/src/handle.rs | Adds read-only “open existing DB” helpers to avoid creating/migrating DBs for projections. |
| crates/but-db/src/lib.rs | Exposes branch-order handles and registers branch-order migrations. |
| crates/but-db/src/table/mod.rs | Wires the new branch_order table module into the table registry. |
| crates/but-db/src/table/branch_order.rs | Implements the branch_order table schema, read path (order_for_reference), and write path (set_order, remove_reference). |
| crates/but-db/tests/db/migration.rs | Updates the migration snapshot to include the branch_order table/index and schema version. |
| crates/but-db/tests/db/handle.rs | Adds coverage for read-only DB open behavior (doesn’t create DB; observes existing DB). |
| crates/but-db/tests/db/table/mod.rs | Registers the new branch-order table tests module. |
| crates/but-db/tests/db/table/branch_order.rs | Adds unit tests for branch-order chain updates/removals and cycle degradation behavior. |
| crates/but-graph/src/lib.rs | Adds ad_hoc_branch_stack_orders state to retain ordered refs for downstream projection decisions. |
| crates/but-graph/src/init/mod.rs | Adds overlay plumbing for branch stack order overrides during traversal redo. |
| crates/but-graph/src/init/overlay.rs | Adds in-memory overrides for branch stack order and routes reads through overlay before metadata backend. |
| crates/but-graph/src/init/post.rs | Uses persisted ad-hoc ordering to split same-tip refs into explicit empty segments and records involved orders. |
| crates/but-graph/src/projection/workspace/init.rs | Uses recorded ad-hoc orders to treat ordered lower bounds specially and to keep ordered empty segments from being pruned. |
| crates/but-graph/tests/graph/init/mod.rs | Updates graph init fixtures to include the new ad_hoc_branch_stack_orders field. |
4f53898 to
9decbea
Compare
|
9decbea to
9a575ee
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9a575ee0ba
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
9a575ee to
fdff025
Compare
fdff025 to
b80da36
Compare
| self.ad_hoc_branch_stack_orders.push(matching_refs.clone()); | ||
|
|
||
| let bottom_segment_id = | ||
| ad_hoc_order_bottom_segment_id(self, bottom_ref.as_ref(), bottom_commit_id); | ||
| let Some(bottom_segment_id) = bottom_segment_id else { | ||
| return Ok(()); | ||
| }; | ||
|
|
||
| rebuild_same_tip_segment_chain_by_branch_order( | ||
| self, | ||
| bottom_segment_id, | ||
| matching_refs, | ||
| entrypoint_ref.as_ref(), | ||
| meta, | ||
| worktree_by_branch, | ||
| )?; | ||
| Ok(()) |
Store the branch ordering metadata for single branch mode, and use that to inform the ordering in the but-graph and projection.
Changes
This is part 1 of 2 in a stack made with GitButler: