mirror of
https://github.com/sharkdp/bat.git
synced 2025-08-17 19:42:19 +02:00
format: Run cargo fmt
.
This commit is contained in:
@@ -1,8 +1,7 @@
|
|||||||
use std::io::{self, BufRead, Write};
|
|
||||||
use crate::assets::HighlightingAssets;
|
use crate::assets::HighlightingAssets;
|
||||||
use crate::config::{Config, VisibleLines};
|
use crate::config::{Config, VisibleLines};
|
||||||
#[cfg(feature = "git")]
|
#[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::error::*;
|
||||||
use crate::input::{Input, InputReader, OpenedInput};
|
use crate::input::{Input, InputReader, OpenedInput};
|
||||||
#[cfg(feature = "lessopen")]
|
#[cfg(feature = "lessopen")]
|
||||||
@@ -14,6 +13,7 @@ use crate::output::OutputType;
|
|||||||
#[cfg(feature = "paging")]
|
#[cfg(feature = "paging")]
|
||||||
use crate::paging::PagingMode;
|
use crate::paging::PagingMode;
|
||||||
use crate::printer::{InteractivePrinter, OutputHandle, Printer, SimplePrinter};
|
use crate::printer::{InteractivePrinter, OutputHandle, Printer, SimplePrinter};
|
||||||
|
use std::io::{self, BufRead, Write};
|
||||||
|
|
||||||
use clircle::{Clircle, Identifier};
|
use clircle::{Clircle, Identifier};
|
||||||
|
|
||||||
@@ -174,8 +174,7 @@ impl<'b> Controller<'b> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
#[cfg(feature = "git")]
|
#[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 {
|
match opened_input.kind {
|
||||||
crate::input::OpenedInputKind::OrdinaryFile(ref path) => {
|
crate::input::OpenedInputKind::OrdinaryFile(ref path) => {
|
||||||
let blame_format = self.config.blame_format.clone();
|
let blame_format = self.config.blame_format.clone();
|
||||||
@@ -183,9 +182,9 @@ impl<'b> Controller<'b> {
|
|||||||
|
|
||||||
// Skip files without Git modifications
|
// Skip files without Git modifications
|
||||||
if blames
|
if blames
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|changes| changes.is_empty())
|
.map(|changes| changes.is_empty())
|
||||||
.unwrap_or(false)
|
.unwrap_or(false)
|
||||||
{
|
{
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
#[cfg(feature = "git")]
|
#[cfg(feature = "git")]
|
||||||
use crate::diff::{LineChange};
|
use crate::diff::LineChange;
|
||||||
use crate::printer::{Colors, InteractivePrinter};
|
use crate::printer::{Colors, InteractivePrinter};
|
||||||
use nu_ansi_term::Style;
|
use nu_ansi_term::Style;
|
||||||
|
|
||||||
|
25
src/diff.rs
25
src/diff.rs
@@ -1,9 +1,9 @@
|
|||||||
#![cfg(feature = "git")]
|
#![cfg(feature = "git")]
|
||||||
|
|
||||||
|
use git2::{Blame, BlameHunk, BlameOptions, Commit, DiffOptions, IntoCString, Repository};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use git2::{Commit, BlameHunk, Blame, BlameOptions, DiffOptions, IntoCString, Repository};
|
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub enum LineChange {
|
pub enum LineChange {
|
||||||
@@ -82,7 +82,12 @@ pub fn get_git_diff(filename: &Path) -> Option<LineChanges> {
|
|||||||
Some(line_changes)
|
Some(line_changes)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_blame_line(blame: &Blame, filename: &Path, line: u32, blame_format: &str) -> Option<String> {
|
pub fn get_blame_line(
|
||||||
|
blame: &Blame,
|
||||||
|
filename: &Path,
|
||||||
|
line: u32,
|
||||||
|
blame_format: &str,
|
||||||
|
) -> Option<String> {
|
||||||
let repo = Repository::discover(filename).ok()?;
|
let repo = Repository::discover(filename).ok()?;
|
||||||
let default_return = "Unknown".to_string();
|
let default_return = "Unknown".to_string();
|
||||||
let diff = get_git_diff(filename).unwrap();
|
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)
|
Some(default_return)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub fn format_blame(blame_hunk: &BlameHunk, commit: &Commit, blame_format: &str) -> String {
|
pub fn format_blame(blame_hunk: &BlameHunk, commit: &Commit, blame_format: &str) -> String {
|
||||||
let mut result = String::from(blame_format);
|
let mut result = String::from(blame_format);
|
||||||
let abbreviated_id_buf = commit.as_object().short_id();
|
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();
|
let signature = blame_hunk.final_signature();
|
||||||
result = result.replace("%an", signature.name().unwrap_or("Unknown"));
|
result = result.replace("%an", signature.name().unwrap_or("Unknown"));
|
||||||
result = result.replace("%ae", signature.email().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<LineBlames>
|
|||||||
let filepath_absolute = fs::canonicalize(filename).ok()?;
|
let filepath_absolute = fs::canonicalize(filename).ok()?;
|
||||||
let filepath_relative_to_repo = filepath_absolute.strip_prefix(&repo_path_absolute).ok()?;
|
let filepath_relative_to_repo = filepath_absolute.strip_prefix(&repo_path_absolute).ok()?;
|
||||||
|
|
||||||
let blame = repo.blame_file(
|
let blame = repo
|
||||||
filepath_relative_to_repo,
|
.blame_file(filepath_relative_to_repo, Some(&mut blame_options))
|
||||||
Some(&mut blame_options),
|
.ok()?;
|
||||||
).ok()?;
|
|
||||||
for i in 0..lines_in_file {
|
for i in 0..lines_in_file {
|
||||||
if let Some(str_result) = get_blame_line(&blame, filename, i as u32, blame_format) {
|
if let Some(str_result) = get_blame_line(&blame, filename, i as u32, blame_format) {
|
||||||
result.insert(i as u32, str_result);
|
result.insert(i as u32, str_result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(result)
|
Some(result)
|
||||||
}
|
}
|
||||||
|
@@ -23,11 +23,11 @@ use unicode_width::UnicodeWidthChar;
|
|||||||
use crate::assets::{HighlightingAssets, SyntaxReferenceInSet};
|
use crate::assets::{HighlightingAssets, SyntaxReferenceInSet};
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
#[cfg(feature = "git")]
|
#[cfg(feature = "git")]
|
||||||
use crate::decorations::{LineChangesDecoration, LineBlamesDecoration};
|
|
||||||
#[cfg(feature = "git")]
|
|
||||||
use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration};
|
use crate::decorations::{Decoration, GridBorderDecoration, LineNumberDecoration};
|
||||||
#[cfg(feature = "git")]
|
#[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::error::*;
|
||||||
use crate::input::OpenedInput;
|
use crate::input::OpenedInput;
|
||||||
use crate::line_range::RangeCheckResult;
|
use crate::line_range::RangeCheckResult;
|
||||||
|
Reference in New Issue
Block a user