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

Function file_directory_swap

atomic-agent/src/record/mod.rs:1000–1013  ·  view source on GitHub ↗

The path where a commit puts a directory in place of a file, or a file in place of a directory, if it does. Git records that as removed paths plus added paths, one of which is a parent directory of the other. Atomic does not record the swap as one change: the turn would record the removals and lose the additions.

(changed: &[CommitPath])

Source from the content-addressed store, hash-verified

998/// parent directory of the other. Atomic does not record the swap as one
999/// change: the turn would record the removals and lose the additions.
1000fn file_directory_swap(changed: &[CommitPath]) -> Option<&str> {
1001 use std::collections::BTreeSet;
1002
1003 let paths_absent_on = |side: fn(&CommitPath) -> &str| -> BTreeSet<&str> {
1004 changed
1005 .iter()
1006 .filter(|entry| side(entry) == GIT_ABSENT_MODE)
1007 .map(|entry| entry.path.as_str())
1008 .collect()
1009 };
1010 let removed = paths_absent_on(|entry| &entry.new_mode);
1011 let added = paths_absent_on(|entry| &entry.old_mode);
1012 parent_directory_among(&added, &removed).or_else(|| parent_directory_among(&removed, &added))
1013}
1014
1015/// The first parent directory of a path in `paths` that is itself a path in
1016/// `others`.

Callers 1

Calls 5

parent_directory_amongFunction · 0.85
sideFunction · 0.50
collectMethod · 0.45
iterMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected