more lints (#648)

This commit is contained in:
Stephan Dilly 2021-04-18 00:08:35 +02:00 committed by GitHub
parent 2a3071fd52
commit 524add843d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 16 deletions

7
Cargo.lock generated
View file

@ -46,6 +46,7 @@ name = "asyncgit"
version = "0.14.0" version = "0.14.0"
dependencies = [ dependencies = [
"crossbeam-channel", "crossbeam-channel",
"easy-cast",
"git2", "git2",
"invalidstring", "invalidstring",
"log", "log",
@ -294,6 +295,12 @@ dependencies = [
"winapi", "winapi",
] ]
[[package]]
name = "easy-cast"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4bd102ee8c418348759919b83b81cdbdc933ffe29740b903df448b4bafaa348e"
[[package]] [[package]]
name = "either" name = "either"
version = "1.6.1" version = "1.6.1"

View file

@ -20,6 +20,7 @@ log = "0.4"
thiserror = "1.0" thiserror = "1.0"
url = "2.2" url = "2.2"
unicode-truncate = "0.2.0" unicode-truncate = "0.2.0"
easy-cast = "0.4"
[dev-dependencies] [dev-dependencies]
tempfile = "3.2" tempfile = "3.2"

View file

@ -32,6 +32,9 @@ pub enum Error {
#[error("TryFromInt error:{0}")] #[error("TryFromInt error:{0}")]
IntConversion(#[from] TryFromIntError), IntConversion(#[from] TryFromIntError),
#[error("EasyCast error:{0}")]
EasyCast(#[from] easy_cast::Error),
} }
pub type Result<T> = std::result::Result<T, Error>; pub type Result<T> = std::result::Result<T, Error>;

View file

@ -16,15 +16,9 @@
#![deny(clippy::needless_update)] #![deny(clippy::needless_update)]
#![allow(clippy::module_name_repetitions)] #![allow(clippy::module_name_repetitions)]
#![allow(clippy::must_use_candidate)] #![allow(clippy::must_use_candidate)]
#![allow(clippy::missing_errors_doc)]
//TODO: get this in someday since expect still leads us to crashes sometimes //TODO: get this in someday since expect still leads us to crashes sometimes
// #![deny(clippy::expect_used)] // #![deny(clippy::expect_used)]
//TODO:
#![allow(clippy::missing_errors_doc)]
#![allow(clippy::too_many_lines)]
#![allow(clippy::cast_possible_wrap)]
#![allow(clippy::cast_sign_loss)]
#![allow(clippy::cast_possible_truncation)]
#![allow(clippy::cast_precision_loss)]
pub mod cached; pub mod cached;
mod commit_files; mod commit_files;

View file

@ -1,5 +1,6 @@
//! //!
use easy_cast::{Conv, ConvFloat};
use std::cmp; use std::cmp;
/// ///
@ -12,9 +13,9 @@ pub struct ProgressPercent {
impl ProgressPercent { impl ProgressPercent {
/// ///
pub fn new(current: usize, total: usize) -> Self { pub fn new(current: usize, total: usize) -> Self {
let total = cmp::max(current, total) as f32; let total = f64::conv(cmp::max(current, total));
let progress = current as f32 / total * 100.0; let progress = f64::conv(current) / total * 100.0;
let progress = progress as u8; let progress = u8::conv_nearest(progress);
Self { progress } Self { progress }
} }
/// ///

View file

@ -14,11 +14,11 @@ use std::{
time::{SystemTime, UNIX_EPOCH}, time::{SystemTime, UNIX_EPOCH},
}; };
fn current_tick() -> u64 { fn current_tick() -> u128 {
SystemTime::now() SystemTime::now()
.duration_since(UNIX_EPOCH) .duration_since(UNIX_EPOCH)
.expect("time before unix epoch!") .expect("time before unix epoch!")
.as_millis() as u64 .as_millis()
} }
#[derive(Default, Hash, Clone)] #[derive(Default, Hash, Clone)]
@ -29,7 +29,7 @@ pub struct Status {
/// ///
#[derive(Default, Hash, Copy, Clone, PartialEq)] #[derive(Default, Hash, Copy, Clone, PartialEq)]
pub struct StatusParams { pub struct StatusParams {
tick: u64, tick: u128,
status_type: StatusType, status_type: StatusType,
include_untracked: bool, include_untracked: bool,
} }

View file

@ -6,6 +6,7 @@ use super::{
CommitId, CommitId,
}; };
use crate::{error::Error, error::Result, hash}; use crate::{error::Error, error::Result, hash};
use easy_cast::Conv;
use git2::{ use git2::{
Delta, Diff, DiffDelta, DiffFormat, DiffHunk, DiffOptions, Patch, Delta, Diff, DiffDelta, DiffFormat, DiffHunk, DiffOptions, Patch,
Repository, Repository,
@ -186,6 +187,8 @@ pub fn get_diff_commit(
} }
/// ///
//TODO: refactor into helper type with the inline closures as dedicated functions
#[allow(clippy::too_many_lines)]
fn raw_diff_to_file_diff<'a>( fn raw_diff_to_file_diff<'a>(
diff: &'a Diff, diff: &'a Diff,
work_dir: &Path, work_dir: &Path,
@ -216,8 +219,9 @@ fn raw_diff_to_file_diff<'a>(
delta.old_file().size(), delta.old_file().size(),
delta.new_file().size(), delta.new_file().size(),
); );
res.size_delta = (res.sizes.1 as i64) //TODO: use try_conv
.saturating_sub(res.sizes.0 as i64); res.size_delta = (i64::conv(res.sizes.1))
.saturating_sub(i64::conv(res.sizes.0));
} }
if let Some(hunk) = hunk { if let Some(hunk) = hunk {
let hunk_header = HunkHeader::from(hunk); let hunk_header = HunkHeader::from(hunk);

View file

@ -6,6 +6,7 @@ use crate::{
patches::get_file_diff_patch_and_hunklines, utils::repo, patches::get_file_diff_patch_and_hunklines, utils::repo,
}, },
}; };
use easy_cast::Conv;
use scopetime::scope_time; use scopetime::scope_time;
use std::path::Path; use std::path::Path;
@ -49,7 +50,7 @@ pub fn stage_lines(
let blob_id = repo.blob(new_content.as_bytes())?; let blob_id = repo.blob(new_content.as_bytes())?;
idx.id = blob_id; idx.id = blob_id;
idx.file_size = new_content.as_bytes().len() as u32; idx.file_size = u32::try_conv(new_content.as_bytes().len())?;
//TODO: can we simply use add_frombuffer? //TODO: can we simply use add_frombuffer?
index.add(&idx)?; index.add(&idx)?;