Refactor filesystem name retrieval in ref_target_path_from_tree

- Replaced the manual derivation of filesystem names with a call to `tree.filesystem_name_for(current)`, simplifying the code and improving maintainability.
- This change enhances clarity by centralizing the logic for obtaining filesystem names, reducing redundancy in the function.
This commit is contained in:
Joe 2026-02-18 23:22:18 -06:00
parent d3a9155e10
commit b0f9b06cbb

View file

@ -154,35 +154,7 @@ pub fn ref_target_path_from_tree(tree: &crate::snapshot::RojoTree, target_ref: R
None => break, None => break,
}; };
// Derive the filesystem name for this instance. components.push(tree.filesystem_name_for(current));
let fs_name = if let Some(meta) = tree.get_metadata(current) {
if let Some(source) = &meta.instigating_source {
match source {
crate::snapshot::InstigatingSource::Path(_) => {
// File-backed instance: use the filename from disk.
source
.path()
.file_name()
.and_then(|f| f.to_str())
.unwrap_or(&inst.name)
.to_string()
}
crate::snapshot::InstigatingSource::ProjectNode { .. } => {
// Project-sourced instance: use instance name, not the
// project file path (which would be e.g. "default.project.json5").
inst.name.clone()
}
}
} else {
// No instigating source (newly added) -- use name.
inst.name.clone()
}
} else {
// No metadata at all -- use instance name.
inst.name.clone()
};
components.push(fs_name);
current = inst.parent(); current = inst.parent();
} }