Skip to content

feat(usd): add UndoStage::discard_oldest - #140

Open
bresilla wants to merge 1 commit into
mxpv:mainfrom
bresilla:feat/undo-pruning
Open

bresilla wants to merge 1 commit into
mxpv:mainfrom
bresilla:feat/undo-pruning

Conversation

@bresilla

@bresilla bresilla commented Oct 4, 2026

Copy link
Copy Markdown
Contributor

Another small one from the same batch as #139.

with_capacity drops the oldest transaction once the stack is full, but in an editor one undo step is usually a few transactions (even define_prim + set_type_name is two). So eviction can cut a command in half, and undoing it later only reverts part of it.

This adds discard_oldest(count) so the stage can stay unbounded and the editor trims the history itself, on its own command boundaries. It's basically a partial reset: it flushes pending edits first, drops up to count of the oldest transactions, leaves the scene alone and returns how many it dropped.

C++ doesn't have an undo stack at all (it just reports undoable edits to SdfLayerStateDelegate and leaves history to the app), so this is only on the Rust side.

Copilot AI balanced review requested due to automatic review settings October 4, 2026 15:30

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

🟢 Approval recommended

The focused implementation has behavioral coverage, and only minor test-naming feedback remains.

Review effort: Balanced
Findings: 2 Low severity

Open (2)
What changed in this PR

Adds UndoStage::discard_oldest(count) so editors can trim undo history at
command boundaries while preserving the current scene.

Changes:

  • Flushes pending edits, removes up to count oldest transactions, and returns the number removed.
  • Tests retained undo behavior, scene preservation, count limits, and pending direct edits.
File Description
crates/​openusd/​src/​usd/​capture.rs Adds the history-trimming method, documentation, and tests.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

/// untouched, the newer transactions still undo, and the discarded edits
/// become permanent.
#[test]
fn discard_oldest_keeps_recent_transactions_and_scene() -> Result<()> {
/// `discard_oldest` drains a still-pending direct `layer_mut` edit into the
/// stack first, so that edit is the one discarded.
#[test]
fn discard_oldest_drains_pending_direct_edits() -> Result<()> {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants