summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2021-05-19 20:58:19 -0400
committerDan Davison <dandavison7@gmail.com>2021-05-19 21:00:37 -0400
commit5ece1944f1a7df30d342452d7a85d4871c16a42c (patch)
treefc95a39ee038118de3f10ed3ff975a772991f873
parentec3bb68be52f47bc252ce0d6d96d43c35fdcd89a (diff)
Refactor: factor out _parse_file_path function
-rw-r--r--src/parse.rs20
1 files 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 ++++++++++----"