Refactor Reconciler equality checks and enhance path handling

- Introduced a new `trueEquals` function in `trueEquals.lua` for shared value equality checks, improving consistency between `diff.lua` and `matching.lua`.
- Removed redundant equality logic from `diff.lua` and `matching.lua`, streamlining the codebase.
- Updated path handling in various test snapshots to ensure correct reference values, enhancing the accuracy of reconciliation tests.
- Implemented a post-processing step in `syncback` to fix `Rojo_Ref_*` attribute paths with correct dedup suffixes, improving path resolution.

These changes enhance the clarity and efficiency of the Reconciler's equality checks and path handling, paving the way for improved project management and user experience.
This commit is contained in:
Joe 2026-02-17 05:31:36 -06:00
parent aabbfb23b2
commit e207a398b1
14 changed files with 832 additions and 218 deletions

View file

@ -446,4 +446,54 @@ impl FsSnapshot {
removed_dirs.sort_unstable();
removed_dirs
}
/// Post-process `Rojo_Ref_*` attribute paths in meta/model JSON files.
///
/// For each entry in `substitutions` (old_path → new_path), finds all
/// `.meta.json5` and `.model.json5` files in the snapshot and replaces
/// occurrences of the old path with the new path. This fixes tentative
/// ref paths that didn't include dedup suffixes.
pub fn fix_ref_paths(&mut self, substitutions: &[(String, String)]) {
if substitutions.is_empty() {
return;
}
let ref_paths: Vec<PathBuf> = self
.added_files
.keys()
.filter(|p| {
let name = p.file_name().and_then(|f| f.to_str()).unwrap_or("");
name.ends_with(".meta.json5")
|| name.ends_with(".meta.json")
|| name.ends_with(".model.json5")
|| name.ends_with(".model.json")
})
.cloned()
.collect();
for path in ref_paths {
let Some(contents) = self.added_files.get_mut(&path) else {
continue;
};
let Ok(text) = std::str::from_utf8(contents) else {
continue;
};
if !text.contains("Rojo_Ref_") {
continue;
}
let mut modified = text.to_string();
for (old_path, new_path) in substitutions {
if old_path == new_path {
continue;
}
// Replace exact path matches and prefix matches (path + "/")
modified = modified.replace(old_path.as_str(), new_path.as_str());
}
if modified != text {
*contents = modified.into_bytes();
}
}
}
}