From f6d4d333d5c06f66643622206f384a3410c14c61 Mon Sep 17 00:00:00 2001 From: Dan Davison Date: Thu, 6 Feb 2020 13:40:45 -0600 Subject: Tighten up state machine parser. Fixes #89 Prior to this commit, in a language in which -- at the beginning of a line is valid (e.g. a Haskell or SQL comment), then removal of such a line was being confused with the --- marker used in unified/git diff to introduce the file paths. --- src/delta.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/delta.rs b/src/delta.rs index 527e5885..1425bf15 100644 --- a/src/delta.rs +++ b/src/delta.rs @@ -86,7 +86,10 @@ where painter.paint_buffered_lines(); state = State::FileMeta; painter.set_syntax(parse::get_file_extension_from_diff_line(&line)); - } else if (line.starts_with("--- ") || line.starts_with("rename from ")) + } else if (state == State::FileMeta || source == Source::DiffUnified) + // FIXME: For unified diff input, removal ("-") of a line starting with "--" (e.g. a + // Haskell or SQL comment) will be confused with the "---" file metadata marker. + && (line.starts_with("--- ") || line.starts_with("rename from ")) && config.opt.file_style != cli::SectionStyle::Plain { if source == Source::DiffUnified { -- cgit v1.2.3