diff --git a/app/buck2_file_watcher/src/edenfs/sapling.rs b/app/buck2_file_watcher/src/edenfs/sapling.rs index 5261a6d5f87b..1aac3180abc8 100644 --- a/app/buck2_file_watcher/src/edenfs/sapling.rs +++ b/app/buck2_file_watcher/src/edenfs/sapling.rs @@ -133,16 +133,14 @@ pub(crate) async fn get_status, F: AsRef, S: AsRef>( // Paths can have spaces, but are not quoted. fn process_one_status_line(line: &str) -> buck2_error::Result> { // Must include a status and at least one char path. - if line.len() >= 3 { - let mut chars = line.chars(); - let change = chars.next().unwrap(); - let path = chars.skip(1).collect::(); + let mut parts = line.split_whitespace(); + if let (Some(change), Some(path), None) = (parts.next(), parts.next(), parts.next()) { Ok(match change { - 'M' => Some((SaplingStatus::Modified, path)), - 'A' => Some((SaplingStatus::Added, path)), - 'R' => Some((SaplingStatus::Removed, path)), - '!' => Some((SaplingStatus::Missing, path)), - '?' => Some((SaplingStatus::NotTracked, path)), + "M" => Some((SaplingStatus::Modified, path.to_owned())), + "A" => Some((SaplingStatus::Added, path.to_owned())), + "R" => Some((SaplingStatus::Removed, path.to_owned())), + "!" => Some((SaplingStatus::Missing, path.to_owned())), + "?" => Some((SaplingStatus::NotTracked, path.to_owned())), _ => None, // Skip all others }) } else { @@ -206,6 +204,11 @@ mod tests { assert!(process_one_status_line("NO").is_err()); + assert!( + process_one_status_line("M:buck2/app/buck2_file_watcher/src/edenfs/sapling.rs") + .is_err() + ); + Ok(()) } }