MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / compare_file_sets

Function compare_file_sets

atomic-cli/src/commands/git/shim.rs:3279–3311  ·  view source on GitHub ↗
(
    git: &BTreeMap<String, Vec<u8>>,
    atomic: &BTreeMap<String, Vec<u8>>,
)

Source from the content-addressed store, hash-verified

3277}
3278
3279fn compare_file_sets(
3280 git: &BTreeMap<String, Vec<u8>>,
3281 atomic: &BTreeMap<String, Vec<u8>>,
3282) -> Result<(), String> {
3283 let missing: Vec<_> = git
3284 .keys()
3285 .filter(|path| !atomic.contains_key(*path))
3286 .collect();
3287 let extra: Vec<_> = atomic
3288 .keys()
3289 .filter(|path| !git.contains_key(*path))
3290 .collect();
3291 let changed: Vec<_> = git
3292 .iter()
3293 .filter_map(|(path, content)| {
3294 atomic
3295 .get(path)
3296 .filter(|other| *other != content)
3297 .map(|_| path)
3298 })
3299 .collect();
3300
3301 if missing.is_empty() && extra.is_empty() && changed.is_empty() {
3302 return Ok(());
3303 }
3304
3305 Err(format!(
3306 "Git HEAD and Atomic view differ (missing in Atomic: {}; extra in Atomic: {}; different bytes: {})",
3307 format_paths(&missing),
3308 format_paths(&extra),
3309 format_paths(&changed)
3310 ))
3311}
3312
3313fn format_paths<T: AsRef<str>>(paths: &[&T]) -> String {
3314 if paths.is_empty() {

Calls 5

contains_keyMethod · 0.80
getMethod · 0.65
collectMethod · 0.45
iterMethod · 0.45
is_emptyMethod · 0.45