mirror of
https://github.com/dandavison/delta.git
synced 2024-10-05 04:17:21 +03:00
Rename: FileMeta => DiffHeader
This commit is contained in:
parent
d0d1f09d24
commit
b121d60c6e
@ -148,7 +148,7 @@ impl Config {
|
||||
State::HunkMinus(_) => &self.minus_style,
|
||||
State::HunkPlus(_) => &self.plus_style,
|
||||
State::CommitMeta => &self.commit_style,
|
||||
State::FileMeta => &self.file_style,
|
||||
State::DiffHeader => &self.file_style,
|
||||
State::HunkHeader(_, _) => &self.hunk_header_style,
|
||||
State::SubmoduleLog => &self.file_style,
|
||||
_ => delta_unreachable("Unreachable code reached in get_style."),
|
||||
|
32
src/delta.rs
32
src/delta.rs
@ -15,16 +15,16 @@ use crate::style::DecorationStyle;
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum State {
|
||||
CommitMeta, // In commit metadata section
|
||||
FileMeta, // In diff metadata section, between (possible) commit metadata and first hunk
|
||||
DiffHeader, // In diff header section, between (possible) commit metadata and first hunk
|
||||
HunkHeader(String, String), // In hunk metadata line (line, raw_line)
|
||||
HunkZero, // In hunk; unchanged line
|
||||
HunkZero, // In hunk; unchanged line
|
||||
HunkMinus(Option<String>), // In hunk; removed line (raw_line)
|
||||
HunkPlus(Option<String>), // In hunk; added line (raw_line)
|
||||
SubmoduleLog, // In a submodule section, with gitconfig diff.submodule = log
|
||||
SubmoduleShort(String), // In a submodule section, with gitconfig diff.submodule = short
|
||||
Blame(String, Option<String>), // In a line of `git blame` output (commit, repeat_blame_line).
|
||||
GitShowFile, // In a line of `git show $revision:./path/to/file.ext` output
|
||||
Grep, // In a line of `git grep` output
|
||||
Grep, // In a line of `git grep` output
|
||||
Unknown,
|
||||
// The following elements are created when a line is wrapped to display it:
|
||||
HunkZeroWrapped, // Wrapped unchanged line
|
||||
@ -42,10 +42,10 @@ pub enum Source {
|
||||
// Possible transitions, with actions on entry:
|
||||
//
|
||||
//
|
||||
// | from \ to | CommitMeta | FileMeta | HunkHeader | HunkZero | HunkMinus | HunkPlus |
|
||||
// | from \ to | CommitMeta | DiffHeader | HunkHeader | HunkZero | HunkMinus | HunkPlus |
|
||||
// |-------------+-------------+-------------+-------------+-------------+-------------+----------|
|
||||
// | CommitMeta | emit | emit | | | | |
|
||||
// | FileMeta | | emit | emit | | | |
|
||||
// | DiffHeader | | emit | emit | | | |
|
||||
// | HunkHeader | | | | emit | push | push |
|
||||
// | HunkZero | emit | emit | emit | emit | push | push |
|
||||
// | HunkMinus | flush, emit | flush, emit | flush, emit | flush, emit | push | push |
|
||||
@ -58,8 +58,8 @@ pub struct StateMachine<'a> {
|
||||
pub source: Source,
|
||||
pub minus_file: String,
|
||||
pub plus_file: String,
|
||||
pub minus_file_event: handlers::file_meta::FileEvent,
|
||||
pub plus_file_event: handlers::file_meta::FileEvent,
|
||||
pub minus_file_event: handlers::diff_header::FileEvent,
|
||||
pub plus_file_event: handlers::diff_header::FileEvent,
|
||||
pub diff_line: String,
|
||||
pub painter: Painter<'a>,
|
||||
pub config: &'a Config,
|
||||
@ -70,7 +70,7 @@ pub struct StateMachine<'a> {
|
||||
// a file is renamed with changes, both are present, and we rely on the following variables to
|
||||
// avoid emitting the file meta header line twice (#245).
|
||||
pub current_file_pair: Option<(String, String)>,
|
||||
pub handled_file_meta_header_line_file_pair: Option<(String, String)>,
|
||||
pub handled_diff_header_header_line_file_pair: Option<(String, String)>,
|
||||
pub blame_commit_colors: HashMap<String, String>,
|
||||
}
|
||||
|
||||
@ -90,11 +90,11 @@ impl<'a> StateMachine<'a> {
|
||||
source: Source::Unknown,
|
||||
minus_file: "".to_string(),
|
||||
plus_file: "".to_string(),
|
||||
minus_file_event: handlers::file_meta::FileEvent::NoEvent,
|
||||
plus_file_event: handlers::file_meta::FileEvent::NoEvent,
|
||||
minus_file_event: handlers::diff_header::FileEvent::NoEvent,
|
||||
plus_file_event: handlers::diff_header::FileEvent::NoEvent,
|
||||
diff_line: "".to_string(),
|
||||
current_file_pair: None,
|
||||
handled_file_meta_header_line_file_pair: None,
|
||||
handled_diff_header_header_line_file_pair: None,
|
||||
painter: Painter::new(writer, config),
|
||||
config,
|
||||
blame_commit_colors: HashMap::new(),
|
||||
@ -118,11 +118,11 @@ impl<'a> StateMachine<'a> {
|
||||
// handle it).
|
||||
let _ = self.handle_commit_meta_header_line()?
|
||||
|| self.handle_diff_stat_line()?
|
||||
|| self.handle_file_meta_diff_line()?
|
||||
|| self.handle_file_meta_minus_line()?
|
||||
|| self.handle_file_meta_plus_line()?
|
||||
|| self.handle_diff_header_diff_line()?
|
||||
|| self.handle_diff_header_minus_line()?
|
||||
|| self.handle_diff_header_plus_line()?
|
||||
|| self.handle_hunk_header_line()?
|
||||
|| self.handle_file_meta_misc_line()?
|
||||
|| self.handle_diff_header_misc_line()?
|
||||
|| self.handle_submodule_log_line()?
|
||||
|| self.handle_submodule_short_line()?
|
||||
|| self.handle_hunk_line()?
|
||||
@ -171,7 +171,7 @@ impl<'a> StateMachine<'a> {
|
||||
|
||||
/// Skip file metadata lines unless a raw diff style has been requested.
|
||||
fn should_skip_line(&self) -> bool {
|
||||
self.state == State::FileMeta && self.should_handle() && !self.config.color_only
|
||||
self.state == State::DiffHeader && self.should_handle() && !self.config.color_only
|
||||
}
|
||||
|
||||
/// Emit unchanged any line that delta does not handle.
|
||||
|
@ -23,21 +23,21 @@ pub enum FileEvent {
|
||||
|
||||
impl<'a> StateMachine<'a> {
|
||||
#[inline]
|
||||
fn test_file_meta_minus_line(&self) -> bool {
|
||||
(self.state == State::FileMeta || self.source == Source::DiffUnified)
|
||||
fn test_diff_header_minus_line(&self) -> bool {
|
||||
(self.state == State::DiffHeader || self.source == Source::DiffUnified)
|
||||
&& (self.line.starts_with("--- ")
|
||||
|| self.line.starts_with("rename from ")
|
||||
|| self.line.starts_with("copy from ")
|
||||
|| self.line.starts_with("old mode "))
|
||||
}
|
||||
|
||||
pub fn handle_file_meta_minus_line(&mut self) -> std::io::Result<bool> {
|
||||
if !self.test_file_meta_minus_line() {
|
||||
pub fn handle_diff_header_minus_line(&mut self) -> std::io::Result<bool> {
|
||||
if !self.test_diff_header_minus_line() {
|
||||
return Ok(false);
|
||||
}
|
||||
let mut handled_line = false;
|
||||
|
||||
let (path_or_mode, file_event) = parse_file_meta_line(
|
||||
let (path_or_mode, file_event) = parse_diff_header_line(
|
||||
&self.line,
|
||||
self.source == Source::GitDiff,
|
||||
if self.config.relative_paths {
|
||||
@ -57,22 +57,22 @@ impl<'a> StateMachine<'a> {
|
||||
self.minus_file_event = file_event;
|
||||
|
||||
if self.source == Source::DiffUnified {
|
||||
self.state = State::FileMeta;
|
||||
self.state = State::DiffHeader;
|
||||
self.painter
|
||||
.set_syntax(get_file_extension_from_marker_line(&self.line));
|
||||
} else {
|
||||
self.painter
|
||||
.set_syntax(get_file_extension_from_file_meta_line_file_path(
|
||||
.set_syntax(get_file_extension_from_diff_header_line_file_path(
|
||||
&self.minus_file,
|
||||
));
|
||||
}
|
||||
|
||||
// In color_only mode, raw_line's structure shouldn't be changed.
|
||||
// So it needs to avoid fn _handle_file_meta_header_line
|
||||
// So it needs to avoid fn _handle_diff_header_header_line
|
||||
// (it connects the plus_file and minus_file),
|
||||
// and to call fn handle_generic_file_meta_header_line directly.
|
||||
// and to call fn handle_generic_diff_header_header_line directly.
|
||||
if self.config.color_only {
|
||||
write_generic_file_meta_header_line(
|
||||
write_generic_diff_header_header_line(
|
||||
&self.line,
|
||||
&self.raw_line,
|
||||
&mut self.painter,
|
||||
@ -84,20 +84,20 @@ impl<'a> StateMachine<'a> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn test_file_meta_plus_line(&self) -> bool {
|
||||
(self.state == State::FileMeta || self.source == Source::DiffUnified)
|
||||
fn test_diff_header_plus_line(&self) -> bool {
|
||||
(self.state == State::DiffHeader || self.source == Source::DiffUnified)
|
||||
&& (self.line.starts_with("+++ ")
|
||||
|| self.line.starts_with("rename to ")
|
||||
|| self.line.starts_with("copy to ")
|
||||
|| self.line.starts_with("new mode "))
|
||||
}
|
||||
|
||||
pub fn handle_file_meta_plus_line(&mut self) -> std::io::Result<bool> {
|
||||
if !self.test_file_meta_plus_line() {
|
||||
pub fn handle_diff_header_plus_line(&mut self) -> std::io::Result<bool> {
|
||||
if !self.test_diff_header_plus_line() {
|
||||
return Ok(false);
|
||||
}
|
||||
let mut handled_line = false;
|
||||
let (path_or_mode, file_event) = parse_file_meta_line(
|
||||
let (path_or_mode, file_event) = parse_diff_header_line(
|
||||
&self.line,
|
||||
self.source == Source::GitDiff,
|
||||
if self.config.relative_paths {
|
||||
@ -116,17 +116,17 @@ impl<'a> StateMachine<'a> {
|
||||
};
|
||||
self.plus_file_event = file_event;
|
||||
self.painter
|
||||
.set_syntax(get_file_extension_from_file_meta_line_file_path(
|
||||
.set_syntax(get_file_extension_from_diff_header_line_file_path(
|
||||
&self.plus_file,
|
||||
));
|
||||
self.current_file_pair = Some((self.minus_file.clone(), self.plus_file.clone()));
|
||||
|
||||
// In color_only mode, raw_line's structure shouldn't be changed.
|
||||
// So it needs to avoid fn _handle_file_meta_header_line
|
||||
// So it needs to avoid fn _handle_diff_header_header_line
|
||||
// (it connects the plus_file and minus_file),
|
||||
// and to call fn handle_generic_file_meta_header_line directly.
|
||||
// and to call fn handle_generic_diff_header_header_line directly.
|
||||
if self.config.color_only {
|
||||
write_generic_file_meta_header_line(
|
||||
write_generic_diff_header_header_line(
|
||||
&self.line,
|
||||
&self.raw_line,
|
||||
&mut self.painter,
|
||||
@ -134,17 +134,17 @@ impl<'a> StateMachine<'a> {
|
||||
)?;
|
||||
handled_line = true
|
||||
} else if self.should_handle()
|
||||
&& self.handled_file_meta_header_line_file_pair != self.current_file_pair
|
||||
&& self.handled_diff_header_header_line_file_pair != self.current_file_pair
|
||||
{
|
||||
self.painter.emit()?;
|
||||
self._handle_file_meta_header_line(self.source == Source::DiffUnified)?;
|
||||
self.handled_file_meta_header_line_file_pair = self.current_file_pair.clone()
|
||||
self._handle_diff_header_header_line(self.source == Source::DiffUnified)?;
|
||||
self.handled_diff_header_header_line_file_pair = self.current_file_pair.clone()
|
||||
}
|
||||
Ok(handled_line)
|
||||
}
|
||||
|
||||
/// Construct file change line from minus and plus file and write with FileMeta styling.
|
||||
fn _handle_file_meta_header_line(&mut self, comparing: bool) -> std::io::Result<()> {
|
||||
/// Construct file change line from minus and plus file and write with DiffHeader styling.
|
||||
fn _handle_diff_header_header_line(&mut self, comparing: bool) -> std::io::Result<()> {
|
||||
let line = get_file_change_description_from_file_paths(
|
||||
&self.minus_file,
|
||||
&self.plus_file,
|
||||
@ -154,12 +154,12 @@ impl<'a> StateMachine<'a> {
|
||||
self.config,
|
||||
);
|
||||
// FIXME: no support for 'raw'
|
||||
write_generic_file_meta_header_line(&line, &line, &mut self.painter, self.config)
|
||||
write_generic_diff_header_header_line(&line, &line, &mut self.painter, self.config)
|
||||
}
|
||||
}
|
||||
|
||||
/// Write `line` with FileMeta styling.
|
||||
pub fn write_generic_file_meta_header_line(
|
||||
/// Write `line` with DiffHeader styling.
|
||||
pub fn write_generic_diff_header_header_line(
|
||||
line: &str,
|
||||
raw_line: &str,
|
||||
painter: &mut Painter,
|
||||
@ -173,10 +173,8 @@ pub fn write_generic_file_meta_header_line(
|
||||
}
|
||||
let (mut draw_fn, pad, decoration_ansi_term_style) =
|
||||
draw::get_draw_function(config.file_style.decoration_style);
|
||||
// Prints the new line below file-meta-line.
|
||||
// However in the case of color_only mode,
|
||||
// we won't print it because we can't change raw_line structure.
|
||||
if !config.color_only {
|
||||
// Maintain 1-1 correspondence between input and output lines.
|
||||
writeln!(painter.writer)?;
|
||||
}
|
||||
draw_fn(
|
||||
@ -201,7 +199,7 @@ fn get_file_extension_from_marker_line(line: &str) -> Option<&str> {
|
||||
.and_then(|file| file.split('.').last())
|
||||
}
|
||||
|
||||
fn get_file_extension_from_file_meta_line_file_path(path: &str) -> Option<&str> {
|
||||
fn get_file_extension_from_diff_header_line_file_path(path: &str) -> Option<&str> {
|
||||
if path.is_empty() || path == "/dev/null" {
|
||||
None
|
||||
} else {
|
||||
@ -218,7 +216,7 @@ pub fn get_extension(s: &str) -> Option<&str> {
|
||||
.or_else(|| path.file_name().and_then(|s| s.to_str()))
|
||||
}
|
||||
|
||||
fn parse_file_meta_line(
|
||||
fn parse_diff_header_line(
|
||||
line: &str,
|
||||
git_diff_name: bool,
|
||||
relative_path_base: Option<&str>,
|
||||
@ -390,41 +388,41 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_file_extension_from_file_meta_line() {
|
||||
fn test_get_file_extension_from_diff_header_line() {
|
||||
assert_eq!(
|
||||
get_file_extension_from_file_meta_line_file_path("a/src/parse.rs"),
|
||||
get_file_extension_from_diff_header_line_file_path("a/src/parse.rs"),
|
||||
Some("rs")
|
||||
);
|
||||
assert_eq!(
|
||||
get_file_extension_from_file_meta_line_file_path("b/src/pa rse.rs"),
|
||||
get_file_extension_from_diff_header_line_file_path("b/src/pa rse.rs"),
|
||||
Some("rs")
|
||||
);
|
||||
assert_eq!(
|
||||
get_file_extension_from_file_meta_line_file_path("src/pa rse.rs"),
|
||||
get_file_extension_from_diff_header_line_file_path("src/pa rse.rs"),
|
||||
Some("rs")
|
||||
);
|
||||
assert_eq!(
|
||||
get_file_extension_from_file_meta_line_file_path("wat hello.rs"),
|
||||
get_file_extension_from_diff_header_line_file_path("wat hello.rs"),
|
||||
Some("rs")
|
||||
);
|
||||
assert_eq!(
|
||||
get_file_extension_from_file_meta_line_file_path("/dev/null"),
|
||||
get_file_extension_from_diff_header_line_file_path("/dev/null"),
|
||||
None
|
||||
);
|
||||
assert_eq!(
|
||||
get_file_extension_from_file_meta_line_file_path("Dockerfile"),
|
||||
get_file_extension_from_diff_header_line_file_path("Dockerfile"),
|
||||
Some("Dockerfile")
|
||||
);
|
||||
assert_eq!(
|
||||
get_file_extension_from_file_meta_line_file_path("Makefile"),
|
||||
get_file_extension_from_diff_header_line_file_path("Makefile"),
|
||||
Some("Makefile")
|
||||
);
|
||||
assert_eq!(
|
||||
get_file_extension_from_file_meta_line_file_path("a/src/Makefile"),
|
||||
get_file_extension_from_diff_header_line_file_path("a/src/Makefile"),
|
||||
Some("Makefile")
|
||||
);
|
||||
assert_eq!(
|
||||
get_file_extension_from_file_meta_line_file_path("src/Makefile"),
|
||||
get_file_extension_from_diff_header_line_file_path("src/Makefile"),
|
||||
Some("Makefile")
|
||||
);
|
||||
}
|
||||
@ -444,47 +442,47 @@ mod tests {
|
||||
//
|
||||
// but we don't attempt that currently.
|
||||
#[test]
|
||||
fn test_get_file_path_from_git_file_meta_line() {
|
||||
fn test_get_file_path_from_git_diff_header_line() {
|
||||
assert_eq!(
|
||||
parse_file_meta_line("--- /dev/null", true, None),
|
||||
parse_diff_header_line("--- /dev/null", true, None),
|
||||
("/dev/null".to_string(), FileEvent::Change)
|
||||
);
|
||||
for prefix in &DIFF_PREFIXES {
|
||||
assert_eq!(
|
||||
parse_file_meta_line(&format!("--- {}src/delta.rs", prefix), true, None),
|
||||
parse_diff_header_line(&format!("--- {}src/delta.rs", prefix), true, None),
|
||||
("src/delta.rs".to_string(), FileEvent::Change)
|
||||
);
|
||||
}
|
||||
assert_eq!(
|
||||
parse_file_meta_line("--- src/delta.rs", true, None),
|
||||
parse_diff_header_line("--- src/delta.rs", true, None),
|
||||
("src/delta.rs".to_string(), FileEvent::Change)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_file_meta_line("+++ src/delta.rs", true, None),
|
||||
parse_diff_header_line("+++ src/delta.rs", true, None),
|
||||
("src/delta.rs".to_string(), FileEvent::Change)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_file_path_from_git_file_meta_line_containing_spaces() {
|
||||
fn test_get_file_path_from_git_diff_header_line_containing_spaces() {
|
||||
assert_eq!(
|
||||
parse_file_meta_line("+++ a/my src/delta.rs", true, None),
|
||||
parse_diff_header_line("+++ a/my src/delta.rs", true, None),
|
||||
("my src/delta.rs".to_string(), FileEvent::Change)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_file_meta_line("+++ my src/delta.rs", true, None),
|
||||
parse_diff_header_line("+++ my src/delta.rs", true, None),
|
||||
("my src/delta.rs".to_string(), FileEvent::Change)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_file_meta_line("+++ a/src/my delta.rs", true, None),
|
||||
parse_diff_header_line("+++ a/src/my delta.rs", true, None),
|
||||
("src/my delta.rs".to_string(), FileEvent::Change)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_file_meta_line("+++ a/my src/my delta.rs", true, None),
|
||||
parse_diff_header_line("+++ a/my src/my delta.rs", true, None),
|
||||
("my src/my delta.rs".to_string(), FileEvent::Change)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_file_meta_line("+++ b/my src/my enough/my delta.rs", true, None),
|
||||
parse_diff_header_line("+++ b/my src/my enough/my delta.rs", true, None),
|
||||
(
|
||||
"my src/my enough/my delta.rs".to_string(),
|
||||
FileEvent::Change
|
||||
@ -493,29 +491,29 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_file_path_from_git_file_meta_line_rename() {
|
||||
fn test_get_file_path_from_git_diff_header_line_rename() {
|
||||
assert_eq!(
|
||||
parse_file_meta_line("rename from nospace/file2.el", true, None),
|
||||
parse_diff_header_line("rename from nospace/file2.el", true, None),
|
||||
("nospace/file2.el".to_string(), FileEvent::Rename)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_get_file_path_from_git_file_meta_line_rename_containing_spaces() {
|
||||
fn test_get_file_path_from_git_diff_header_line_rename_containing_spaces() {
|
||||
assert_eq!(
|
||||
parse_file_meta_line("rename from with space/file1.el", true, None),
|
||||
parse_diff_header_line("rename from with space/file1.el", true, None),
|
||||
("with space/file1.el".to_string(), FileEvent::Rename)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_file_meta_line() {
|
||||
fn test_parse_diff_header_line() {
|
||||
assert_eq!(
|
||||
parse_file_meta_line("--- src/delta.rs", false, None),
|
||||
parse_diff_header_line("--- src/delta.rs", false, None),
|
||||
("src/delta.rs".to_string(), FileEvent::Change)
|
||||
);
|
||||
assert_eq!(
|
||||
parse_file_meta_line("+++ src/delta.rs", false, None),
|
||||
parse_diff_header_line("+++ src/delta.rs", false, None),
|
||||
("src/delta.rs".to_string(), FileEvent::Change)
|
||||
);
|
||||
}
|
@ -2,18 +2,18 @@ use crate::delta::{State, StateMachine};
|
||||
|
||||
impl<'a> StateMachine<'a> {
|
||||
#[inline]
|
||||
fn test_file_meta_diff_line(&self) -> bool {
|
||||
fn test_diff_header_diff_line(&self) -> bool {
|
||||
self.line.starts_with("diff ")
|
||||
}
|
||||
|
||||
#[allow(clippy::unnecessary_wraps)]
|
||||
pub fn handle_file_meta_diff_line(&mut self) -> std::io::Result<bool> {
|
||||
if !self.test_file_meta_diff_line() {
|
||||
pub fn handle_diff_header_diff_line(&mut self) -> std::io::Result<bool> {
|
||||
if !self.test_diff_header_diff_line() {
|
||||
return Ok(false);
|
||||
}
|
||||
self.painter.paint_buffered_minus_and_plus_lines();
|
||||
self.state = State::FileMeta;
|
||||
self.handled_file_meta_header_line_file_pair = None;
|
||||
self.state = State::DiffHeader;
|
||||
self.handled_diff_header_header_line_file_pair = None;
|
||||
self.diff_line = self.line.clone();
|
||||
Ok(false)
|
||||
}
|
@ -2,15 +2,15 @@ use crate::delta::{Source, State, StateMachine};
|
||||
|
||||
impl<'a> StateMachine<'a> {
|
||||
#[inline]
|
||||
fn test_file_meta_misc_cases(&self) -> bool {
|
||||
fn test_diff_header_misc_cases(&self) -> bool {
|
||||
self.source == Source::DiffUnified && self.line.starts_with("Only in ")
|
||||
|| self.line.starts_with("Binary files ")
|
||||
}
|
||||
|
||||
pub fn handle_file_meta_misc_line(&mut self) -> std::io::Result<bool> {
|
||||
if !self.test_file_meta_misc_cases() {
|
||||
pub fn handle_diff_header_misc_line(&mut self) -> std::io::Result<bool> {
|
||||
if !self.test_diff_header_misc_cases() {
|
||||
return Ok(false);
|
||||
}
|
||||
self.handle_additional_cases(State::FileMeta)
|
||||
self.handle_additional_cases(State::DiffHeader)
|
||||
}
|
||||
}
|
@ -57,7 +57,7 @@ impl<'a> StateMachine<'a> {
|
||||
|
||||
// Emit syntax-highlighted code
|
||||
// TODO: Determine the language less frequently, e.g. only when the file changes.
|
||||
if let Some(lang) = handlers::file_meta::get_extension(&grep_line.path)
|
||||
if let Some(lang) = handlers::diff_header::get_extension(&grep_line.path)
|
||||
.or_else(|| self.config.default_language.as_deref())
|
||||
{
|
||||
self.painter.set_syntax(Some(lang));
|
||||
|
@ -2,11 +2,11 @@
|
||||
/// main `StateMachine::consume()` loop.
|
||||
pub mod blame;
|
||||
pub mod commit_meta;
|
||||
pub mod diff_header;
|
||||
pub mod diff_header_diff;
|
||||
pub mod diff_header_misc;
|
||||
pub mod diff_stat;
|
||||
pub mod draw;
|
||||
pub mod file_meta;
|
||||
pub mod file_meta_diff;
|
||||
pub mod file_meta_misc;
|
||||
pub mod git_show_file;
|
||||
pub mod grep;
|
||||
pub mod hunk;
|
||||
@ -37,7 +37,7 @@ impl<'a> StateMachine<'a> {
|
||||
self.state = to_state;
|
||||
if self.should_handle() {
|
||||
self.painter.emit()?;
|
||||
file_meta::write_generic_file_meta_header_line(
|
||||
diff_header::write_generic_diff_header_header_line(
|
||||
&self.line,
|
||||
&self.raw_line,
|
||||
&mut self.painter,
|
||||
|
@ -568,7 +568,7 @@ impl<'p> Painter<'p> {
|
||||
State::Grep => true,
|
||||
State::Unknown
|
||||
| State::CommitMeta
|
||||
| State::FileMeta
|
||||
| State::DiffHeader
|
||||
| State::HunkMinusWrapped
|
||||
| State::HunkZeroWrapped
|
||||
| State::HunkPlusWrapped
|
||||
|
@ -138,7 +138,7 @@ mod tests {
|
||||
assert_eq!(lines.nth(7).unwrap(), "This is different from b");
|
||||
// File uniqueness
|
||||
assert_eq!(lines.nth(2).unwrap(), "Only in a/: just_a");
|
||||
// FileMeta divider
|
||||
// DiffHeader divider
|
||||
assert!(lines.next().unwrap().starts_with("───────"));
|
||||
// Next hunk
|
||||
assert_eq!(
|
||||
|
Loading…
Reference in New Issue
Block a user