From 30c776ea9b4a15d75d9a88955175ab25e5c62c7c Mon Sep 17 00:00:00 2001 From: Bark Date: Mon, 12 Feb 2024 09:29:07 +0200 Subject: [PATCH] format: Run `cargo fmt`. --- src/controller.rs | 13 ++++++------- src/decorations.rs | 2 +- src/diff.rs | 25 ++++++++++++++++--------- src/printer.rs | 6 +++--- 4 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/controller.rs b/src/controller.rs index 94b37fe1..f11108a0 100644 --- a/src/controller.rs +++ b/src/controller.rs @@ -1,8 +1,7 @@ -use std::io::{self, BufRead, Write}; use crate::assets::HighlightingAssets; use crate::config::{Config, VisibleLines}; #[cfg(feature = "git")] -use crate::diff::{get_git_diff, LineChanges, get_blame_file}; +use crate::diff::{get_blame_file, get_git_diff, LineChanges}; use crate::error::*; use crate::input::{Input, InputReader, OpenedInput}; #[cfg(feature = "lessopen")] @@ -14,6 +13,7 @@ use crate::output::OutputType; #[cfg(feature = "paging")] use crate::paging::PagingMode; use crate::printer::{InteractivePrinter, OutputHandle, Printer, SimplePrinter}; +use std::io::{self, BufRead, Write}; use clircle::{Clircle, Identifier}; @@ -174,8 +174,7 @@ impl<'b> Controller<'b> { }; #[cfg(feature = "git")] - let line_blames = if !self.config.loop_through && self.config.style_components.blame() - { + let line_blames = if !self.config.loop_through && self.config.style_components.blame() { match opened_input.kind { crate::input::OpenedInputKind::OrdinaryFile(ref path) => { let blame_format = self.config.blame_format.clone(); @@ -183,9 +182,9 @@ impl<'b> Controller<'b> { // Skip files without Git modifications if blames - .as_ref() - .map(|changes| changes.is_empty()) - .unwrap_or(false) + .as_ref() + .map(|changes| changes.is_empty()) + .unwrap_or(false) { return Ok(()); } diff --git a/src/decorations.rs b/src/decorations.rs index 0841f76b..62ec9d13 100644 --- a/src/decorations.rs +++ b/src/decorations.rs @@ -1,5 +1,5 @@ #[cfg(feature = "git")] -use crate::diff::{LineChange}; +use crate::diff::LineChange; use crate::printer::{Colors, InteractivePrinter}; use nu_ansi_term::Style; diff --git a/src/diff.rs b/src/diff.rs index 95fe87e8..f3325aff 100644 --- a/src/diff.rs +++ b/src/diff.rs @@ -1,9 +1,9 @@ #![cfg(feature = "git")] +use git2::{Blame, BlameHunk, BlameOptions, Commit, DiffOptions, IntoCString, Repository}; use std::collections::HashMap; use std::fs; use std::path::Path; -use git2::{Commit, BlameHunk, Blame, BlameOptions, DiffOptions, IntoCString, Repository}; #[derive(Copy, Clone, Debug)] pub enum LineChange { @@ -82,7 +82,12 @@ pub fn get_git_diff(filename: &Path) -> Option { Some(line_changes) } -pub fn get_blame_line(blame: &Blame, filename: &Path, line: u32, blame_format: &str) -> Option { +pub fn get_blame_line( + blame: &Blame, + filename: &Path, + line: u32, + blame_format: &str, +) -> Option { let repo = Repository::discover(filename).ok()?; let default_return = "Unknown".to_string(); let diff = get_git_diff(filename).unwrap(); @@ -104,11 +109,14 @@ pub fn get_blame_line(blame: &Blame, filename: &Path, line: u32, blame_format: & Some(default_return) } - pub fn format_blame(blame_hunk: &BlameHunk, commit: &Commit, blame_format: &str) -> String { let mut result = String::from(blame_format); let abbreviated_id_buf = commit.as_object().short_id(); - let abbreviated_id = abbreviated_id_buf.as_ref().ok().map(|id| id.as_str()).unwrap_or(Some("")); + let abbreviated_id = abbreviated_id_buf + .as_ref() + .ok() + .map(|id| id.as_str()) + .unwrap_or(Some("")); let signature = blame_hunk.final_signature(); result = result.replace("%an", signature.name().unwrap_or("Unknown")); result = result.replace("%ae", signature.email().unwrap_or("Unknown")); @@ -132,14 +140,13 @@ pub fn get_blame_file(filename: &Path, blame_format: &str) -> Option let filepath_absolute = fs::canonicalize(filename).ok()?; let filepath_relative_to_repo = filepath_absolute.strip_prefix(&repo_path_absolute).ok()?; - let blame = repo.blame_file( - filepath_relative_to_repo, - Some(&mut blame_options), - ).ok()?; + let blame = repo + .blame_file(filepath_relative_to_repo, Some(&mut blame_options)) + .ok()?; for i in 0..lines_in_file { if let Some(str_result) = get_blame_line(&blame, filename, i as u32, blame_format) { result.insert(i as u32, str_result); } } Some(result) -} \ No newline at end of file +} diff --git a/src/printer.rs b/src/printer.rs index 86ff6886..af7a602d 100644 --- a/src/printer.rs +++ b/src/printer.rs @@ -23,11 +23,11 @@ use unicode_width::UnicodeWidthChar; use crate::assets::{HighlightingAssets, SyntaxReferenceInSet}; use crate::config::Config; #[cfg(feature = "git")] -use crate::decorations::{LineChangesDecoration, LineBlamesDecoration}; -#[cfg(feature = "git")] use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration}; #[cfg(feature = "git")] -use crate::diff::{LineChanges, LineBlames}; +use crate::decorations::{LineBlamesDecoration, LineChangesDecoration}; +#[cfg(feature = "git")] +use crate::diff::{LineBlames, LineChanges}; use crate::error::*; use crate::input::OpenedInput; use crate::line_range::RangeCheckResult;