summaryrefslogtreecommitdiffstats
path: root/src/parse.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-04-26 18:26:39 -0400
committerDan Davison <dandavison7@gmail.com>2020-04-26 18:33:27 -0400
commit8e9c43dffa2b8f5470590a3be76b0e841e6cd6b7 (patch)
tree1d339623430e486cb91fe6d06c131eaa5faf0cc3 /src/parse.rs
parentb2b75766947880049302664069a47d30409ece8a (diff)
Fix parsing file paths containing spaces
Fixes #127
Diffstat (limited to 'src/parse.rs')
-rw-r--r--src/parse.rs31
1 files changed, 20 insertions, 11 deletions
diff --git a/src/parse.rs b/src/parse.rs
index cd774a79..3d129ffa 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -26,20 +26,29 @@ pub fn get_file_extension_from_marker_line(line: &str) -> Option<&str> {
}
pub fn get_file_path_from_file_meta_line(line: &str, git_diff_name: bool) -> String {
- if line.starts_with("rename ") {
- line.split(' ').skip(2).collect::<Vec<&str>>().join(" ")
- } else {
- match line.split(' ').skip(1).collect::<Vec<&str>>().join(" ") {
- path if path == "/dev/null" => "/dev/null",
- path if git_diff_name && (path.starts_with("a/") || path.starts_with("b/")) => {
- &path[2..]
+ match line {
+ line if line.starts_with("rename from ") => {
+ let offset = "rename from ".len();
+ &line[offset..]
+ }
+ line if line.starts_with("rename to ") => {
+ let offset = "rename to ".len();
+ &line[offset..]
+ }
+ line if line.starts_with("--- ") || line.starts_with("+++ ") => {
+ let offset = 4;
+ match &line[offset..] {
+ path if path == "/dev/null" => "/dev/null",
+ path if git_diff_name && (path.starts_with("a/") || path.starts_with("b/")) => {
+ &path[2..]
+ }
+ path if git_diff_name => &path,
+ path => path.split('\t').next().unwrap_or(""),
}
- path if git_diff_name => path,
- path => path.split('\t').next().unwrap_or(""),
- _ => "",
}
- .to_string()
+ _ => "",
}
+ .to_string()
}
pub fn get_file_change_description_from_file_paths(