summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-11-22 19:24:51 -0500
committerDan Davison <dandavison7@gmail.com>2020-11-22 20:26:34 -0500
commitaf27c560f7f272bb70306461146984882afa8e56 (patch)
tree18f360635cf17c3937f44a6ed463bf9cf48965c3
parentc6dd83575242348a4c8561ef898faa0a978fd39d (diff)
Handle copied files
Fixes #392
-rw-r--r--src/cli.rs4
-rw-r--r--src/config.rs2
-rw-r--r--src/delta.rs8
-rw-r--r--src/options/set.rs1
-rw-r--r--src/parse.rs8
5 files changed, 21 insertions, 2 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 8daa8efc..a366f529 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -437,6 +437,10 @@ pub struct Opt {
/// Text to display in front of a added file path.
pub file_added_label: String,
+ #[structopt(long = "file-copied-label", default_value = "copied:")]
+ /// Text to display in front of a copied file path.
+ pub file_copied_label: String,
+
#[structopt(long = "file-renamed-label", default_value = "renamed:")]
/// Text to display in front of a renamed file path.
pub file_renamed_label: String,
diff --git a/src/config.rs b/src/config.rs
index 9a26b677..28983b6d 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -23,6 +23,7 @@ pub struct Config {
pub commit_style: Style,
pub decorations_width: cli::Width,
pub file_added_label: String,
+ pub file_copied_label: String,
pub file_modified_label: String,
pub file_removed_label: String,
pub file_renamed_label: String,
@@ -151,6 +152,7 @@ impl From<cli::Opt> for Config {
commit_style,
decorations_width: opt.computed.decorations_width,
file_added_label: opt.file_added_label,
+ file_copied_label: opt.file_copied_label,
file_modified_label: opt.file_modified_label,
file_removed_label: opt.file_removed_label,
file_renamed_label: opt.file_renamed_label,
diff --git a/src/delta.rs b/src/delta.rs
index 180a3893..af4106a3 100644
--- a/src/delta.rs
+++ b/src/delta.rs
@@ -98,7 +98,9 @@ where
state = State::FileMeta;
handled_file_meta_header_line_file_pair = None;
} else if (state == State::FileMeta || source == Source::DiffUnified)
- && (line.starts_with("--- ") || line.starts_with("rename from "))
+ && (line.starts_with("--- ")
+ || line.starts_with("rename from ")
+ || line.starts_with("copy from "))
{
let parsed_file_meta_line =
parse::parse_file_meta_line(&line, source == Source::GitDiff);
@@ -114,7 +116,9 @@ where
));
}
} else if (state == State::FileMeta || source == Source::DiffUnified)
- && (line.starts_with("+++ ") || line.starts_with("rename to "))
+ && (line.starts_with("+++ ")
+ || line.starts_with("rename to ")
+ || line.starts_with("copy to "))
{
let parsed_file_meta_line =
parse::parse_file_meta_line(&line, source == Source::GitDiff);
diff --git a/src/options/set.rs b/src/options/set.rs
index 67a5e21d..87eef7d4 100644
--- a/src/options/set.rs
+++ b/src/options/set.rs
@@ -129,6 +129,7 @@ pub fn set_options(
commit_decoration_style,
commit_style,
file_added_label,
+ file_copied_label,
file_decoration_style,
file_modified_label,
file_removed_label,
diff --git a/src/parse.rs b/src/parse.rs
index 05b0ceb5..7e39c772 100644
--- a/src/parse.rs
+++ b/src/parse.rs
@@ -22,6 +22,7 @@ pub fn get_file_extension_from_marker_line(line: &str) -> Option<&str> {
#[derive(Debug, PartialEq)]
pub enum FileEvent {
Change,
+ Copy,
Rename,
NoEvent,
}
@@ -47,6 +48,12 @@ pub fn parse_file_meta_line(line: &str, git_diff_name: bool) -> (String, FileEve
line if line.starts_with("rename to ") => {
(line[10..].to_string(), FileEvent::Rename) // "rename to ".len()
}
+ line if line.starts_with("copy from ") => {
+ (line[10..].to_string(), FileEvent::Copy) // "copy from ".len()
+ }
+ line if line.starts_with("copy to ") => {
+ (line[8..].to_string(), FileEvent::Copy) // "copy to ".len()
+ }
_ => ("".to_string(), FileEvent::NoEvent),
}
}
@@ -103,6 +110,7 @@ pub fn get_file_change_description_from_file_paths(
"{}{} ⟶ {}",
format_label(match file_event {
FileEvent::Rename => &config.file_renamed_label,
+ FileEvent::Copy => &config.file_copied_label,
_ => "",
}),
format_file(minus_file),