summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2021-11-27 18:31:13 -0500
committerDan Davison <dandavison7@gmail.com>2021-11-29 08:41:24 -0500
commitb0e02830b27e7ee90a0fb820108a21546b82a1db (patch)
treee21e191a54cc7b49258313e9662be3fa3cb5f11e
parent0f66f753d0fadec50e957a655dbdc1e3c0ad08d1 (diff)
Do not handle --word-diff or --color-words output
Fixes #440 Ref #152
-rw-r--r--src/handlers/hunk.rs20
-rw-r--r--src/utils/process.rs21
2 files changed, 37 insertions, 4 deletions
diff --git a/src/handlers/hunk.rs b/src/handlers/hunk.rs
index e2aea705..f48a134a 100644
--- a/src/handlers/hunk.rs
+++ b/src/handlers/hunk.rs
@@ -1,15 +1,33 @@
+use lazy_static::lazy_static;
+
use crate::cli;
use crate::delta::{State, StateMachine};
use crate::style;
+use crate::utils::process::{self, CallingProcess};
use unicode_segmentation::UnicodeSegmentation;
+lazy_static! {
+ static ref IS_WORD_DIFF: bool = match process::calling_process().as_deref() {
+ Some(
+ CallingProcess::GitDiff(cmd_line)
+ | CallingProcess::GitShow(cmd_line, _)
+ | CallingProcess::GitLog(cmd_line)
+ | CallingProcess::GitReflog(cmd_line),
+ ) =>
+ cmd_line.long_options.contains("--word-diff")
+ || cmd_line.long_options.contains("--word-diff-regex")
+ || cmd_line.long_options.contains("--color-words"),
+ _ => false,
+ };
+}
+
impl<'a> StateMachine<'a> {
#[inline]
fn test_hunk_line(&self) -> bool {
matches!(
self.state,
State::HunkHeader(_, _) | State::HunkZero | State::HunkMinus(_) | State::HunkPlus(_)
- )
+ ) && !&*IS_WORD_DIFF
}
/// Handle a hunk line, i.e. a minus line, a plus line, or an unchanged line.
diff --git a/src/utils/process.rs b/src/utils/process.rs
index e8060cf3..63021b06 100644
--- a/src/utils/process.rs
+++ b/src/utils/process.rs
@@ -7,10 +7,14 @@ use lazy_static::lazy_static;
#[derive(Clone, Debug, PartialEq)]
pub enum CallingProcess {
+ GitDiff(CommandLine),
GitShow(CommandLine, Option<String>), // element 2 is file extension
+ GitLog(CommandLine),
+ GitReflog(CommandLine),
GitGrep(CommandLine),
OtherGrep, // rg, grep, ag, ack, etc
}
+// TODO: Git blame is currently handled differently
#[derive(Clone, Debug, PartialEq)]
pub struct CommandLine {
@@ -91,10 +95,12 @@ pub fn describe_calling_process(args: &[String]) -> ProcessArgs<CallingProcess>
match args.next() {
Some(command) => match Path::new(command).file_stem() {
Some(s) if s.to_str().map(|s| is_git_binary(s)).unwrap_or(false) => {
- let mut args = args.skip_while(|s| *s != "grep" && *s != "show");
+ let mut args = args.skip_while(|s| {
+ *s != "diff" && *s != "show" && *s != "log" && *s != "reflog" && *s != "grep"
+ });
match args.next() {
- Some("grep") => {
- ProcessArgs::Args(CallingProcess::GitGrep(parse_command_line(args)))
+ Some("diff") => {
+ ProcessArgs::Args(CallingProcess::GitDiff(parse_command_line(args)))
}
Some("show") => {
let command_line = parse_command_line(args);
@@ -110,6 +116,15 @@ pub fn describe_calling_process(args: &[String]) -> ProcessArgs<CallingProcess>
};
ProcessArgs::Args(CallingProcess::GitShow(command_line, extension))
}
+ Some("log") => {
+ ProcessArgs::Args(CallingProcess::GitLog(parse_command_line(args)))
+ }
+ Some("reflog") => {
+ ProcessArgs::Args(CallingProcess::GitReflog(parse_command_line(args)))
+ }
+ Some("grep") => {
+ ProcessArgs::Args(CallingProcess::GitGrep(parse_command_line(args)))
+ }
_ => {
// It's git, but not a subcommand that we parse. Don't
// look at any more processes.