Sdf-tier namespace edits: subtree remove + move#112
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
Adds namespace-edit helpers to mechanically remove or move authored Sdf specs within a single layer, including required child-list bookkeeping and basic safety checks.
Changes:
- Add
Layer::remove_spec_subtreeto delete a spec and its authored descendants plus detach from the parent child list. - Add
Layer::move_spec_subtreeto rename/reparent a spec subtree, scaffold missing destination prim chain, and update child lists. - Add helper utilities (
child_registration,remove_from_token_vec,subtree_paths) and a newnamespace_testsmodule.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if new_parent.is_abs_root() { | ||
| if data.spec_type(&new_parent).is_none() { | ||
| data.create_spec(new_parent.clone(), SpecType::PseudoRoot); | ||
| } | ||
| } else { |
| for old_path in subtree_paths(data, old) { | ||
| let new_path = old_path | ||
| .replace_prefix(old, new) | ||
| .expect("subtree_paths only yields `old` and its descendants"); | ||
| if let Some(spec) = data.erase_spec(&old_path) { | ||
| let ty = spec.ty; | ||
| *data.create_spec(new_path, ty) = spec; | ||
| } | ||
| } |
| fn subtree_paths(data: &Data, prefix: &Path) -> Vec<Path> { | ||
| data.paths().into_iter().filter(|p| p.has_prefix(prefix)).collect() | ||
| } |
| #[test] | ||
| fn reparent_prim_to_existing_parent() { | ||
| let mut layer = scene(); | ||
| layer.create_prim("/X", Specifier::Def, "Xform").unwrap(); | ||
| layer | ||
| .move_spec_subtree(&path("/A/B").unwrap(), &path("/X/B").unwrap()) | ||
| .unwrap(); |
|
Went ahead and built the actual editor on top of this in #113 - the |
|
Looks like my changes caused conflicts. Could you pls rebase? |
Heyyyy, yeah i saw that. Gonna do it later tonight or tomorrow :) |
c6ff108 to
c286c43
Compare
First piece of the namespace editing work (#102). This is just the sdf-tier mechanical half - two
Layermethods:remove_spec_subtree(path)- erase a spec and everything under it, and pull the leaf out of its parent'sprimChildren/propertyChildren.move_spec_subtree(old, new)- rename or reparent: re-home the whole subtree (keeping SpecType + fields), scaffold the destination parent as anoverif it's missing, and update both parents' child lists.It's basically the inverse of the bookkeeping
create_*already does. Single-layer only, and on purpose it does NOT touch relationship targets or connections that point at the moved paths - that fixup belongs in the stage-level editor, same as C++ where Sdf doesn't track backpointers.The actual
UsdNamespaceEditor(validation, multi-layer apply, target fixup) sits on top of these and comes next - wanted to land the foundation on its own since it's self-contained and easy to review.6 tests cover remove (prim subtree + property), rename, reparent to an existing and to a missing parent, and the rejections (collision / move-under-self / kind mismatch).