diff options
author | Marcelo Lima <marcelowind@gmail.com> | 2019-11-20 20:20:17 +0100 |
---|---|---|
committer | Marcelo Lima <marcelowind@gmail.com> | 2019-11-20 20:20:17 +0100 |
commit | 5313df149bb9f3e495393849cff72a11a66bef9b (patch) | |
tree | 1e21454e2916fbae5c4337c348d23c12a3000a5e /src/parse.rs | |
parent | 29bba742f69fd21a49db40d9d4080f5e2e795788 (diff) |
* Parse diff -u between directories
* Detect the input and passthrough if not a diff
* Show better header for diff -u between files
Diffstat (limited to 'src/parse.rs')
-rw-r--r-- | src/parse.rs | 40 |
1 files changed, 34 insertions, 6 deletions
diff --git a/src/parse.rs b/src/parse.rs index 5e5cc5df..3480ab8b 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -15,6 +15,16 @@ pub fn get_file_extension_from_diff_line(line: &str) -> Option<&str> { } } +/// Given input like +/// "--- one.rs 2019-11-20 06:16:08.000000000 +0100" +/// Return "rs" +pub fn get_file_extension_from_marker_line(line: &str) -> Option<&str> { + line.split('\t') + .next() + .and_then(|column| column.split(' ').nth(1)) + .and_then(|file| file.split('.').last()) +} + pub fn get_file_path_from_file_meta_line(line: &str, remove_prefix: bool) -> String { if line.starts_with("rename") { match line.split(' ').nth(2) { @@ -38,12 +48,20 @@ pub fn get_file_path_from_file_meta_line(line: &str, remove_prefix: bool) -> Str } } -pub fn get_file_change_description_from_file_paths(minus_file: &str, plus_file: &str) -> String { - match (minus_file, plus_file) { - (minus_file, plus_file) if minus_file == plus_file => minus_file.to_string(), - (minus_file, "/dev/null") => format!("deleted: {}", minus_file), - ("/dev/null", plus_file) => format!("added: {}", plus_file), - (minus_file, plus_file) => format!("renamed: {} ⟶ {}", minus_file, plus_file), +pub fn get_file_change_description_from_file_paths( + minus_file: &str, + plus_file: &str, + comparing: bool, +) -> String { + if comparing { + format!("comparing: {} ⟶ {}", minus_file, plus_file) + } else { + match (minus_file, plus_file) { + (minus_file, plus_file) if minus_file == plus_file => minus_file.to_string(), + (minus_file, "/dev/null") => format!("deleted: {}", minus_file), + ("/dev/null", plus_file) => format!("added: {}", plus_file), + (minus_file, plus_file) => format!("renamed: {} ⟶ {}", minus_file, plus_file), + } } } @@ -92,6 +110,16 @@ mod tests { } #[test] + fn test_get_file_extension_from_marker_line() { + assert_eq!( + get_file_extension_from_marker_line( + "--- src/one.rs 2019-11-20 06:47:56.000000000 +0100" + ), + Some("rs") + ); + } + + #[test] fn test_get_file_path_from_git_file_meta_line() { assert_eq!( get_file_path_from_file_meta_line("--- a/src/delta.rs", true), |