Refactor: factor out _parse_file_path function

This commit is contained in:
Dan Davison 2021-05-19 20:58:19 -04:00
parent ec3bb68be5
commit 5ece1944f1

View File

@ -36,15 +36,7 @@ pub fn parse_file_meta_line(
let (mut path, file_event) = match line {
line if line.starts_with("--- ") || line.starts_with("+++ ") => {
let offset = 4;
let file = match &line[offset..] {
path if path == "/dev/null" => "/dev/null",
path if git_diff_name && DIFF_PREFIXES.iter().any(|s| path.starts_with(s)) => {
&path[2..]
}
path if git_diff_name => &path,
path => path.split('\t').next().unwrap_or(""),
}
.to_string();
let file = _parse_file_path(&line[offset..], git_diff_name);
(file, FileEvent::Change)
}
line if line.starts_with("rename from ") => {
@ -73,6 +65,16 @@ pub fn parse_file_meta_line(
(path, file_event)
}
fn _parse_file_path(s: &str, git_diff_name: bool) -> String {
match s {
path if path == "/dev/null" => "/dev/null",
path if git_diff_name && DIFF_PREFIXES.iter().any(|s| path.starts_with(s)) => &path[2..],
path if git_diff_name => &path,
path => path.split('\t').next().unwrap_or(""),
}
.to_string()
}
// A regex to capture the path, and the content from the pipe onwards, in lines
// like these:
// " src/delta.rs | 14 ++++++++++----"