pub fn status_paths(output: &[u8]) -> Vec<Vec<u8>> {
let mut paths: Vec<Vec<u8>> = Vec::<Vec<u8>>::new();
let mut entries = output.split(|byte| { return *byte == 0; }).filter(|entry| { return !entry.is_empty(); });
while let Some(entry) = entries.next() {
if entry.len() < 4 {
continue;
}
paths.push(entry[3..].to_vec());
let renamed: bool = matches!(entry[0], b'R' | b'C') || matches!(entry[1], b'R' | b'C');
if renamed && let Some(original) = entries.next() {
paths.push(original.to_vec());
}
}
return paths;
}
pub fn diff_paths(output: &[u8]) -> Vec<Vec<u8>> {
return output
.split(|byte| { return *byte == 0; })
.filter(|path| { return !path.is_empty(); })
.map(<[u8]>::to_vec)
.collect();
}
pub fn overlapping_paths(dirty: &[Vec<u8>], incoming: &[Vec<u8>]) -> Vec<Vec<u8>> {
let mut overlap: Vec<Vec<u8>> = Vec::<Vec<u8>>::new();
for path in dirty {
if incoming.contains(path) && !overlap.contains(path) {
overlap.push(path.clone());
}
}
return overlap;
}
const LISTED_LIMIT: usize = 5;
pub fn listed(paths: &[Vec<u8>]) -> String {
let mut names: Vec<String> = paths
.iter()
.take(LISTED_LIMIT)
.map(|path| { return String::from_utf8_lossy(path).into_owned(); })
.collect();
if paths.len() > LISTED_LIMIT {
names.push(format!("and {} more", paths.len() - LISTED_LIMIT));
}
return names.join(", ");
}
#[cfg(test)]
#[path = "auto_push_dirty_paths_tests.rs"]
mod tests;