on master help sign in
Skip non-file inputs when using --diff
commit23afc8e90c4c98c405a07c1d0bfc54a8d719852c authorsharkdp <davidpeter@web.de> dateFri 24 Apr 2020, 16:06 (7 years ago) parent8e18786
3 files changed+23−19
src/config.rs+1−1 src/controller.rs+21−17 src/printer.rs+1−1
src/config.rs+1−1
@@ -16,7 +16,7 @@ pub enum VisibleLines {
1616}
1717
1818impl VisibleLines {
19− pub fn diff_context(&self) -> bool {
19+ pub fn diff_mode(&self) -> bool {
2020 match self {
2121 Self::Ranges(_) => false,
2222 #[cfg(feature = "git")]
src/controller.rs+21−17
@@ -73,26 +73,30 @@ impl<'b> Controller<'b> {
7373 }
7474 Ok(mut opened_input) => {
7575 #[cfg(feature = "git")]
76− let line_changes = if self.config.visible_lines.diff_context()
76+ let line_changes = if self.config.visible_lines.diff_mode()
7777 || (!self.config.loop_through && self.config.style_components.changes())
7878 {
79− if let crate::input::OpenedInputKind::OrdinaryFile(ref path) =
80− opened_input.kind
81− {
82− let diff = get_git_diff(path);
83−
84− if self.config.visible_lines.diff_context()
85− && diff
86− .as_ref()
87− .map(|changes| changes.is_empty())
88− .unwrap_or(false)
89− {
79+ match opened_input.kind {
80+ crate::input::OpenedInputKind::OrdinaryFile(ref path) => {
81+ let diff = get_git_diff(path);
82+
83+ // Skip files without Git modifications
84+ if self.config.visible_lines.diff_mode()
85+ && diff
86+ .as_ref()
87+ .map(|changes| changes.is_empty())
88+ .unwrap_or(false)
89+ {
90+ continue;
91+ }
92+
93+ diff
94+ }
95+ _ if self.config.visible_lines.diff_mode() => {
96+ // Skip non-file inputs in diff mode
9097 continue;
9198 }
92−
93− diff
94− } else {
95− None
99+ _ => None,
96100 }
97101 } else {
98102 None
@@ -134,7 +138,7 @@ impl<'b> Controller<'b> {
134138 printer: &mut dyn Printer,
135139 writer: &mut dyn Write,
136140 input: &mut OpenedInput,
137− #[cfg(feature = "git")] line_changes: &Option<LineChanges>,
141+ line_changes: &Option<LineChanges>,
138142 ) -> Result<()> {
139143 if !input.reader.first_line.is_empty() || self.config.style_components.header() {
140144 printer.print_header(writer, input)?;
src/printer.rs+1−1
@@ -101,7 +101,7 @@ impl<'a> InteractivePrinter<'a> {
101101 config: &'a Config,
102102 assets: &'a HighlightingAssets,
103103 input: &mut OpenedInput,
104− #[cfg(feature = "git")] line_changes: &'a Option<LineChanges>,
104+ line_changes: &'a Option<LineChanges>,
105105 ) -> Self {
106106 let theme = assets.get_theme(&config.theme);
107107