From 5ece1944f1a7df30d342452d7a85d4871c16a42c Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Wed, 19 May 2021 20:58:19 -0400 Subject: Refactor: factor out _parse_file_path function --- src/parse.rs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/parse.rs b/src/parse.rs index d811fb8a..ab51702e 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -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 ++++++++++----" -- cgit v1.2.3