From c76a26bd2d5d9d37fa62725bb3fa7fd179c0fbc8 Mon Sep 17 00:00:00 2001 From: Wayne Davison Date: Wed, 5 Jan 2022 13:54:18 -0800 Subject: Handle a mode change on a renamed file. (#875) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Handle a mode change on a renamed file. I changed the diff parsing to cache the mode info from the old/new mode lines until the parsing bumps into the start of the actual related diff, finds the diff line for an unrelated diff, or runs out of input. This allows the mode info to be output in conjunction with a file event instead of as a separate heading (that used to have an empty name when the mode change was for a rename). The mode info is passed down into the draw routines as a separate "addendum" string that the draw code can use as it likes. Currently that means that it appends the addendum string to the non-raw string in parens. I imagine that future draw routines could decide to put it in a separate box or some other per-routine method. There is currently a single function in src/handlers/draw.rs that joins the strings in the same way for everyone. A couple examples of how the new code looks: Δ foo.rs (mode +x) ─────────────────────────────────────────────────── renamed: old-longer-name → shorter-name (mode +x) ─────────────────────────────────────────────────── Would it look better on its own line? Δ foo.rs • mode +x ─────────────────────────────────────────────────── renamed: old-longer-name → shorter-name • mode +x ─────────────────────────────────────────────────── Would it look better appended after a "•" character? Δ foo.rs • mode +x ─────────────────────────────────────────────────── renamed: old-longer-name → shorter-name • mode +x ─────────────────────────────────────────────────── Should it be a user option? If so, we can do that later. --- src/handlers/diff_header_diff.rs | 1 + 1 file changed, 1 insertion(+) (limited to 'src/handlers/diff_header_diff.rs') diff --git a/src/handlers/diff_header_diff.rs b/src/handlers/diff_header_diff.rs index 7136716..fdd2d39 100644 --- a/src/handlers/diff_header_diff.rs +++ b/src/handlers/diff_header_diff.rs @@ -22,6 +22,7 @@ impl<'a> StateMachine<'a> { } else { State::DiffHeader(DiffType::Unified) }; + self.handle_pending_mode_line_with_diff_name()?; self.handled_diff_header_header_line_file_pair = None; self.diff_line = self.line.clone(); if !self.should_skip_line() { -- cgit v1.2.3