From 74ee31689a620c2220b50d7c13abf36f80666047 Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 11 Dec 2025 08:32:21 +0800 Subject: Match moved files using latest hash instead of initial hash --- crates/vcs_data/src/data/local/file_status.rs | 29 +++++++++++++++++++-------- crates/vcs_data/src/data/local/local_sheet.rs | 11 +++++++++- 2 files changed, 31 insertions(+), 9 deletions(-) (limited to 'crates/vcs_data/src') diff --git a/crates/vcs_data/src/data/local/file_status.rs b/crates/vcs_data/src/data/local/file_status.rs index b8b5952..7841237 100644 --- a/crates/vcs_data/src/data/local/file_status.rs +++ b/crates/vcs_data/src/data/local/file_status.rs @@ -79,13 +79,14 @@ impl<'a> AnalyzeResult<'a> { } if entry.file_type().is_file() - && let Ok(relative_path) = entry.path().strip_prefix(local_path) { - let format = format_path(relative_path.to_path_buf()); - let Ok(format) = format else { - continue; - }; - paths.insert(format); - } + && let Ok(relative_path) = entry.path().strip_prefix(local_path) + { + let format = format_path(relative_path.to_path_buf()); + let Ok(format) = format else { + continue; + }; + paths.insert(format); + } } paths @@ -174,7 +175,16 @@ impl<'a> AnalyzeResult<'a> { .iter() .filter_map(|f| { local_sheet.mapping_data(f).ok().map(|mapping_data| { - (mapping_data.hash_when_updated.clone(), (*f).clone()) + ( + // Using the most recently recorded Hash can more accurately identify moved items, + // but if it doesn't exist, fall back to the initially recorded Hash + mapping_data + .last_modifiy_check_hash + .as_ref() + .cloned() + .unwrap_or(mapping_data.hash_when_updated.clone()), + (*f).clone(), + ) }) }) .collect(), @@ -270,6 +280,9 @@ impl<'a> AnalyzeResult<'a> { mapping_data.last_modifiy_check_time = modified_time; mapping_data.last_modifiy_check_result = false; } + + // Record latest hash + mapping_data.last_modifiy_check_hash = Some(hash_calc.hash) } // Persist the local sheet data diff --git a/crates/vcs_data/src/data/local/local_sheet.rs b/crates/vcs_data/src/data/local/local_sheet.rs index f1daaba..378d589 100644 --- a/crates/vcs_data/src/data/local/local_sheet.rs +++ b/crates/vcs_data/src/data/local/local_sheet.rs @@ -45,6 +45,7 @@ pub struct LocalMappingMetadata { pub(crate) hash_when_updated: String, /// Time when the file was downloaded to the local workspace + #[serde(rename = "time")] pub(crate) time_when_updated: SystemTime, /// Size of the file when downloaded to the local workspace @@ -52,7 +53,7 @@ pub struct LocalMappingMetadata { pub(crate) size_when_updated: u64, /// Version description when the file was downloaded to the local workspace - #[serde(rename = "version_desc")] + #[serde(rename = "desc")] pub(crate) version_desc_when_updated: VirtualFileVersionDescription, /// Version when the file was downloaded to the local workspace @@ -64,10 +65,16 @@ pub struct LocalMappingMetadata { pub(crate) mapping_vfid: VirtualFileId, /// Latest modifiy check time + #[serde(rename = "check_time")] pub(crate) last_modifiy_check_time: SystemTime, /// Latest modifiy check result + #[serde(rename = "modified")] pub(crate) last_modifiy_check_result: bool, + + /// Latest modifiy check hash result + #[serde(rename = "current_hash")] + pub(crate) last_modifiy_check_hash: Option, } impl LocalSheetData { @@ -109,6 +116,7 @@ impl LocalMappingMetadata { mapping_vfid, last_modifiy_check_time, last_modifiy_check_result, + last_modifiy_check_hash: None, } } @@ -204,6 +212,7 @@ impl Default for LocalMappingMetadata { mapping_vfid: Default::default(), last_modifiy_check_time: SystemTime::now(), last_modifiy_check_result: false, + last_modifiy_check_hash: None, } } } -- cgit