mirror of
https://github.com/rojo-rbx/rojo.git
synced 2026-10-24 06:34:09 +00:00
Enhance matching module with valid children tracking and code readability improvements
- Added a `validChildren` field to the `VCache` structure to track valid child instances during the matching process. - Refactored the `cacheVirtual` function to improve readability by formatting parameters across multiple lines. - Updated the `computePairCost` function to utilize the new `validChildren` field for more accurate cost calculations. - Simplified the `matchChildren` function by removing redundant code and improving the handling of matched instances. - Enhanced test cases for the `matchChildren` function to ensure consistent behavior and validate the new changes. These updates improve the efficiency and clarity of the matching process, ensuring better performance and maintainability.
This commit is contained in:
parent
b687c8862d
commit
ddd47b9afa
9 changed files with 287 additions and 363 deletions
|
|
@ -4,7 +4,6 @@ use std::{
|
|||
mem::forget,
|
||||
net::{IpAddr, Ipv4Addr, SocketAddr},
|
||||
path::{Path, PathBuf},
|
||||
process::{Command, Stdio},
|
||||
sync::Arc,
|
||||
};
|
||||
|
||||
|
|
@ -131,7 +130,7 @@ fn run_live_syncback(project_path: &Path, payload: SyncbackPayload) -> anyhow::R
|
|||
result.fs_snapshot.removed_paths().len()
|
||||
);
|
||||
|
||||
refresh_git_index(base_path);
|
||||
crate::git::refresh_git_index(base_path);
|
||||
|
||||
forget(session_old);
|
||||
|
||||
|
|
@ -231,30 +230,3 @@ fn fixup_ref_properties(dom: &mut WeakDom, ref_map: &HashMap<Ref, Ref>) {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn refresh_git_index(project_dir: &Path) {
|
||||
let mut check_dir = Some(project_dir);
|
||||
let mut is_git_repo = false;
|
||||
while let Some(dir) = check_dir {
|
||||
if dir.join(".git").exists() {
|
||||
is_git_repo = true;
|
||||
break;
|
||||
}
|
||||
check_dir = dir.parent();
|
||||
}
|
||||
|
||||
if is_git_repo {
|
||||
log::info!("Refreshing git index...");
|
||||
match Command::new("git")
|
||||
.args(["update-index", "--refresh", "-q"])
|
||||
.current_dir(project_dir)
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status()
|
||||
{
|
||||
Ok(_) => log::info!("Git index refreshed."),
|
||||
Err(e) => log::warn!("Failed to run git update-index --refresh: {}", e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ use std::{
|
|||
io::{self, BufReader, Write as _},
|
||||
mem::forget,
|
||||
path::{Path, PathBuf},
|
||||
process::{Command, Stdio},
|
||||
time::Instant,
|
||||
};
|
||||
|
||||
|
|
@ -280,8 +279,7 @@ impl SyncbackCommand {
|
|||
result.fs_snapshot.removed_paths().len()
|
||||
);
|
||||
|
||||
// Refresh git index if in a git repository
|
||||
refresh_git_index(base_path);
|
||||
crate::git::refresh_git_index(base_path);
|
||||
|
||||
// Delete input file if using default Project.rbxl location
|
||||
if let Some(input_path) = &delete_input_after_syncback {
|
||||
|
|
@ -386,42 +384,6 @@ fn download_place(place_id: u64) -> anyhow::Result<NamedTempFile> {
|
|||
Ok(temp_file)
|
||||
}
|
||||
|
||||
/// Refreshes the git index if the project is in a git repository.
|
||||
///
|
||||
/// This is useful because syncback may rewrite files with identical content,
|
||||
/// which can cause git to report them as modified due to timestamp changes.
|
||||
fn refresh_git_index(project_dir: &Path) {
|
||||
// Check if .git exists in project dir or any parent
|
||||
let mut check_dir = Some(project_dir);
|
||||
let mut is_git_repo = false;
|
||||
while let Some(dir) = check_dir {
|
||||
if dir.join(".git").exists() {
|
||||
is_git_repo = true;
|
||||
break;
|
||||
}
|
||||
check_dir = dir.parent();
|
||||
}
|
||||
|
||||
if is_git_repo {
|
||||
log::info!("Refreshing git index...");
|
||||
// Exit code 1 is normal - it just means files were refreshed.
|
||||
// We only warn if git itself fails to run.
|
||||
match Command::new("git")
|
||||
.args(["update-index", "--refresh", "-q"])
|
||||
.current_dir(project_dir)
|
||||
.stdin(Stdio::null())
|
||||
.stdout(Stdio::null())
|
||||
.stderr(Stdio::null())
|
||||
.status()
|
||||
{
|
||||
Ok(_) => log::info!("Git index refreshed."),
|
||||
Err(e) => log::warn!("Failed to run git update-index --refresh: {}", e),
|
||||
}
|
||||
} else {
|
||||
log::debug!("Not a git repository, skipping index refresh.");
|
||||
}
|
||||
}
|
||||
|
||||
fn read_dom(path: &Path, file_kind: FileKind) -> anyhow::Result<WeakDom> {
|
||||
let content = BufReader::new(File::open(path)?);
|
||||
match file_kind {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue