Skip non-file inputs when using --diff

pull/945/head
sharkdp 5 years ago committed by David Peter
parent 8e18786556
commit 23afc8e90c

@ -16,7 +16,7 @@ pub enum VisibleLines {
} }
impl VisibleLines { impl VisibleLines {
pub fn diff_context(&self) -> bool { pub fn diff_mode(&self) -> bool {
match self { match self {
Self::Ranges(_) => false, Self::Ranges(_) => false,
#[cfg(feature = "git")] #[cfg(feature = "git")]

@ -73,15 +73,15 @@ impl<'b> Controller<'b> {
} }
Ok(mut opened_input) => { Ok(mut opened_input) => {
#[cfg(feature = "git")] #[cfg(feature = "git")]
let line_changes = if self.config.visible_lines.diff_context() let line_changes = if self.config.visible_lines.diff_mode()
|| (!self.config.loop_through && self.config.style_components.changes()) || (!self.config.loop_through && self.config.style_components.changes())
{ {
if let crate::input::OpenedInputKind::OrdinaryFile(ref path) = match opened_input.kind {
opened_input.kind crate::input::OpenedInputKind::OrdinaryFile(ref path) => {
{
let diff = get_git_diff(path); let diff = get_git_diff(path);
if self.config.visible_lines.diff_context() // Skip files without Git modifications
if self.config.visible_lines.diff_mode()
&& diff && diff
.as_ref() .as_ref()
.map(|changes| changes.is_empty()) .map(|changes| changes.is_empty())
@ -91,8 +91,12 @@ impl<'b> Controller<'b> {
} }
diff diff
} else { }
None _ if self.config.visible_lines.diff_mode() => {
// Skip non-file inputs in diff mode
continue;
}
_ => None,
} }
} else { } else {
None None
@ -134,7 +138,7 @@ impl<'b> Controller<'b> {
printer: &mut dyn Printer, printer: &mut dyn Printer,
writer: &mut dyn Write, writer: &mut dyn Write,
input: &mut OpenedInput, input: &mut OpenedInput,
#[cfg(feature = "git")] line_changes: &Option<LineChanges>, line_changes: &Option<LineChanges>,
) -> Result<()> { ) -> Result<()> {
if !input.reader.first_line.is_empty() || self.config.style_components.header() { if !input.reader.first_line.is_empty() || self.config.style_components.header() {
printer.print_header(writer, input)?; printer.print_header(writer, input)?;

@ -101,7 +101,7 @@ impl<'a> InteractivePrinter<'a> {
config: &'a Config, config: &'a Config,
assets: &'a HighlightingAssets, assets: &'a HighlightingAssets,
input: &mut OpenedInput, input: &mut OpenedInput,
#[cfg(feature = "git")] line_changes: &'a Option<LineChanges>, line_changes: &'a Option<LineChanges>,
) -> Self { ) -> Self {
let theme = assets.get_theme(&config.theme); let theme = assets.get_theme(&config.theme);

Loading…
Cancel
Save