diff options
author | Wilfred Hughes <me@wilfred.me.uk> | 2024-02-08 08:27:00 -0800 |
---|---|---|
committer | Wilfred Hughes <me@wilfred.me.uk> | 2024-02-08 08:48:56 -0800 |
commit | 81fa1c7096711b82d4d783e0bde7685384cec6bb (patch) | |
tree | 69521756e947657a3a1caf83c0deb3e84f47db20 | |
parent | 6ff761814483bb9c57df1e533b74d99679bebacd (diff) |
Pass lhs_path and rhs_path in DiffResult
-rw-r--r-- | src/main.rs | 28 | ||||
-rw-r--r-- | src/options.rs | 2 | ||||
-rw-r--r-- | src/summary.rs | 4 |
3 files changed, 31 insertions, 3 deletions
diff --git a/src/main.rs b/src/main.rs index 39373d7cc..c56313813 100644 --- a/src/main.rs +++ b/src/main.rs @@ -400,6 +400,8 @@ fn diff_file( let (mut lhs_src, mut rhs_src) = match (guess_content(&lhs_bytes), guess_content(&rhs_bytes)) { (ProbableFileKind::Binary, _) | (_, ProbableFileKind::Binary) => { return DiffResult { + lhs_path: lhs_path.clone(), + rhs_path: rhs_path.clone(), extra_info: renamed, display_path: display_path.to_owned(), file_format: FileFormat::Binary, @@ -510,6 +512,8 @@ fn diff_conflicts_file( } fn check_only_text( + lhs_path: &FileArgument, + rhs_path: &FileArgument, file_format: &FileFormat, display_path: &str, extra_info: Option<String>, @@ -519,6 +523,8 @@ fn check_only_text( let has_changes = lhs_src != rhs_src; DiffResult { + lhs_path: lhs_path.clone(), + rhs_path: rhs_path.clone(), display_path: display_path.to_string(), extra_info, file_format: file_format.clone(), @@ -535,7 +541,7 @@ fn check_only_text( fn diff_file_content( display_path: &str, extra_info: Option<String>, - _lhs_path: &FileArgument, + lhs_path: &FileArgument, rhs_path: &FileArgument, lhs_src: &str, rhs_src: &str, @@ -561,6 +567,8 @@ fn diff_file_content( // If the two files are byte-for-byte identical, return early // rather than doing any more work. return DiffResult { + lhs_path: lhs_path.clone(), + rhs_path: rhs_path.clone(), extra_info, display_path: display_path.to_string(), file_format, @@ -578,7 +586,15 @@ fn diff_file_content( None => { let file_format = FileFormat::PlainText; if diff_options.check_only { - return check_only_text(&file_format, display_path, extra_info, lhs_src, rhs_src); + return check_only_text( + lhs_path, + rhs_path, + &file_format, + display_path, + extra_info, + lhs_src, + rhs_src, + ); } let lhs_positions = line_parser::change_positions(lhs_src, rhs_src); @@ -602,6 +618,8 @@ fn diff_file_content( if diff_options.check_only { let has_syntactic_changes = lhs != rhs; return DiffResult { + lhs_path: lhs_path.clone(), + rhs_path: rhs_path.clone(), extra_info, display_path: display_path.to_string(), file_format: FileFormat::SupportedLanguage(language), @@ -688,6 +706,8 @@ fn diff_file_content( if diff_options.check_only { return check_only_text( + lhs_path, + rhs_path, &file_format, display_path, extra_info, @@ -712,6 +732,8 @@ fn diff_file_content( if diff_options.check_only { return check_only_text( + lhs_path, + rhs_path, &file_format, display_path, extra_info, @@ -743,6 +765,8 @@ fn diff_file_content( let has_syntactic_changes = !hunks.is_empty(); DiffResult { + lhs_path: lhs_path.clone(), + rhs_path: rhs_path.clone(), extra_info, display_path: display_path.to_string(), file_format, diff --git a/src/options.rs b/src/options.rs index 50c0aeb2a..0a3b367c5 100644 --- a/src/options.rs +++ b/src/options.rs @@ -306,7 +306,7 @@ pub(crate) enum DisplayMode { Json, } -#[derive(Eq, PartialEq, Debug)] +#[derive(Clone, Eq, PartialEq, Debug)] pub(crate) enum FileArgument { NamedPath(std::path::PathBuf), Stdin, diff --git a/src/summary.rs b/src/summary.rs index 733b1d541..6e6651406 100644 --- a/src/summary.rs +++ b/src/summary.rs @@ -4,6 +4,7 @@ use std::fmt::Display; use crate::{ display::hunks::Hunk, + options::FileArgument, parse::{ guess_language::{self, language_name}, syntax::MatchedPos, @@ -37,6 +38,9 @@ impl Display for FileFormat { #[derive(Debug)] pub(crate) struct DiffResult { + pub(crate) lhs_path: FileArgument, + pub(crate) rhs_path: FileArgument, + pub(crate) display_path: String, /// Additional information to display about this file, such as /// "Renamed from x.js to y.js". |