Skip to content

Commit f0a367c

Browse files
author
Stephan Dilly
authored
more linting (#647)
1 parent 53b2c79 commit f0a367c

36 files changed

+194
-239
lines changed

asyncgit/src/commit_files.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,8 @@ impl AsyncCommitFiles {
3535
) -> Result<Option<(CommitId, ResultType)>> {
3636
let c = self.current.lock()?;
3737

38-
if let Some(c) = c.as_ref() {
39-
Ok(Some((c.0, c.1.clone())))
40-
} else {
41-
Ok(None)
42-
}
38+
c.as_ref()
39+
.map_or(Ok(None), |c| Ok(Some((c.0, c.1.clone()))))
4340
}
4441

4542
///
@@ -71,7 +68,7 @@ impl AsyncCommitFiles {
7168
self.pending.fetch_add(1, Ordering::Relaxed);
7269

7370
rayon_core::spawn(move || {
74-
Self::fetch_helper(id, arc_current)
71+
Self::fetch_helper(id, &arc_current)
7572
.expect("failed to fetch");
7673

7774
arc_pending.fetch_sub(1, Ordering::Relaxed);
@@ -86,7 +83,7 @@ impl AsyncCommitFiles {
8683

8784
fn fetch_helper(
8885
id: CommitId,
89-
arc_current: Arc<
86+
arc_current: &Arc<
9087
Mutex<Option<Request<CommitId, ResultType>>>,
9188
>,
9289
) -> Result<()> {

asyncgit/src/diff.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ impl AsyncDiff {
110110
self.pending.fetch_add(1, Ordering::Relaxed);
111111

112112
rayon_core::spawn(move || {
113-
let notify = AsyncDiff::get_diff_helper(
113+
let notify = Self::get_diff_helper(
114114
params,
115-
arc_last,
116-
arc_current,
115+
&arc_last,
116+
&arc_current,
117117
hash,
118118
);
119119

@@ -141,18 +141,18 @@ impl AsyncDiff {
141141

142142
fn get_diff_helper(
143143
params: DiffParams,
144-
arc_last: Arc<
144+
arc_last: &Arc<
145145
Mutex<Option<LastResult<DiffParams, FileDiff>>>,
146146
>,
147-
arc_current: Arc<Mutex<Request<u64, FileDiff>>>,
147+
arc_current: &Arc<Mutex<Request<u64, FileDiff>>>,
148148
hash: u64,
149149
) -> Result<bool> {
150150
let res = match params.diff_type {
151151
DiffType::Stage => {
152-
sync::diff::get_diff(CWD, params.path.clone(), true)?
152+
sync::diff::get_diff(CWD, &params.path, true)?
153153
}
154154
DiffType::WorkDir => {
155-
sync::diff::get_diff(CWD, params.path.clone(), false)?
155+
sync::diff::get_diff(CWD, &params.path, false)?
156156
}
157157
DiffType::Commit(id) => sync::diff::get_diff_commit(
158158
CWD,

asyncgit/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,6 @@ pub type Result<T> = std::result::Result<T, Error>;
3838

3939
impl<T> From<std::sync::PoisonError<T>> for Error {
4040
fn from(error: std::sync::PoisonError<T>) -> Self {
41-
Error::Generic(format!("poison error: {}", error))
41+
Self::Generic(format!("poison error: {}", error))
4242
}
4343
}

asyncgit/src/fetch.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl AsyncFetch {
7474
}
7575

7676
self.set_request(&params)?;
77-
RemoteProgress::set_progress(self.progress.clone(), None)?;
77+
RemoteProgress::set_progress(&self.progress, None)?;
7878

7979
let arc_state = Arc::clone(&self.state);
8080
let arc_res = Arc::clone(&self.last_result);
@@ -104,9 +104,9 @@ impl AsyncFetch {
104104

105105
handle.join().expect("joining thread failed");
106106

107-
Self::set_result(arc_res, res).expect("result error");
107+
Self::set_result(&arc_res, res).expect("result error");
108108

109-
Self::clear_request(arc_state).expect("clear error");
109+
Self::clear_request(&arc_state).expect("clear error");
110110

111111
sender
112112
.send(AsyncNotification::Fetch)
@@ -131,7 +131,7 @@ impl AsyncFetch {
131131
}
132132

133133
fn clear_request(
134-
state: Arc<Mutex<Option<FetchState>>>,
134+
state: &Arc<Mutex<Option<FetchState>>>,
135135
) -> Result<()> {
136136
let mut state = state.lock()?;
137137

@@ -141,7 +141,7 @@ impl AsyncFetch {
141141
}
142142

143143
fn set_result(
144-
arc_result: Arc<Mutex<Option<(usize, String)>>>,
144+
arc_result: &Arc<Mutex<Option<(usize, String)>>>,
145145
res: Result<usize>,
146146
) -> Result<()> {
147147
let mut last_res = arc_result.lock()?;

asyncgit/src/lib.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,23 @@
88
#![deny(clippy::all)]
99
#![deny(clippy::cargo)]
1010
#![deny(clippy::pedantic)]
11-
//TODO:
12-
// #![deny(clippy::nursery)]
11+
#![deny(clippy::nursery)]
1312
#![deny(clippy::unwrap_used)]
1413
#![deny(clippy::panic)]
1514
#![deny(clippy::perf)]
1615
#![deny(clippy::match_like_matches_macro)]
1716
#![deny(clippy::needless_update)]
1817
#![allow(clippy::module_name_repetitions)]
18+
#![allow(clippy::must_use_candidate)]
1919
//TODO: get this in someday since expect still leads us to crashes sometimes
2020
// #![deny(clippy::expect_used)]
2121
//TODO:
22-
#![allow(clippy::needless_pass_by_value)]
23-
#![allow(clippy::must_use_candidate)]
2422
#![allow(clippy::missing_errors_doc)]
25-
#![allow(clippy::map_unwrap_or)]
26-
#![allow(clippy::option_if_let_else)]
27-
#![allow(clippy::manual_ok_or)]
28-
#![allow(clippy::doc_markdown)]
23+
#![allow(clippy::too_many_lines)]
2924
#![allow(clippy::cast_possible_wrap)]
3025
#![allow(clippy::cast_sign_loss)]
3126
#![allow(clippy::cast_possible_truncation)]
3227
#![allow(clippy::cast_precision_loss)]
33-
#![allow(clippy::too_many_lines)]
3428

3529
pub mod cached;
3630
mod commit_files;

asyncgit/src/progress.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ impl ProgressPercent {
1818
Self { progress }
1919
}
2020
///
21-
pub fn empty() -> Self {
21+
pub const fn empty() -> Self {
2222
Self { progress: 0 }
2323
}
2424
///
25-
pub fn full() -> Self {
25+
pub const fn full() -> Self {
2626
Self { progress: 100 }
2727
}
2828
}

asyncgit/src/push.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ impl AsyncPush {
7676
}
7777

7878
self.set_request(&params)?;
79-
RemoteProgress::set_progress(self.progress.clone(), None)?;
79+
RemoteProgress::set_progress(&self.progress, None)?;
8080

8181
let arc_state = Arc::clone(&self.state);
8282
let arc_res = Arc::clone(&self.last_result);
@@ -108,9 +108,9 @@ impl AsyncPush {
108108

109109
handle.join().expect("joining thread failed");
110110

111-
Self::set_result(arc_res, res).expect("result error");
111+
Self::set_result(&arc_res, res).expect("result error");
112112

113-
Self::clear_request(arc_state).expect("clear error");
113+
Self::clear_request(&arc_state).expect("clear error");
114114

115115
sender
116116
.send(AsyncNotification::Push)
@@ -135,7 +135,7 @@ impl AsyncPush {
135135
}
136136

137137
fn clear_request(
138-
state: Arc<Mutex<Option<PushState>>>,
138+
state: &Arc<Mutex<Option<PushState>>>,
139139
) -> Result<()> {
140140
let mut state = state.lock()?;
141141

@@ -145,7 +145,7 @@ impl AsyncPush {
145145
}
146146

147147
fn set_result(
148-
arc_result: Arc<Mutex<Option<String>>>,
148+
arc_result: &Arc<Mutex<Option<String>>>,
149149
res: Result<()>,
150150
) -> Result<()> {
151151
let mut last_res = arc_result.lock()?;

asyncgit/src/push_tags.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl AsyncPushTags {
7272
}
7373

7474
self.set_request(&params)?;
75-
RemoteProgress::set_progress(self.progress.clone(), None)?;
75+
RemoteProgress::set_progress(&self.progress, None)?;
7676

7777
let arc_state = Arc::clone(&self.state);
7878
let arc_res = Arc::clone(&self.last_result);
@@ -98,9 +98,9 @@ impl AsyncPushTags {
9898

9999
handle.join().expect("joining thread failed");
100100

101-
Self::set_result(arc_res, res).expect("result error");
101+
Self::set_result(&arc_res, res).expect("result error");
102102

103-
Self::clear_request(arc_state).expect("clear error");
103+
Self::clear_request(&arc_state).expect("clear error");
104104

105105
sender
106106
.send(AsyncNotification::PushTags)
@@ -125,7 +125,7 @@ impl AsyncPushTags {
125125
}
126126

127127
fn clear_request(
128-
state: Arc<Mutex<Option<PushState>>>,
128+
state: &Arc<Mutex<Option<PushState>>>,
129129
) -> Result<()> {
130130
let mut state = state.lock()?;
131131

@@ -135,7 +135,7 @@ impl AsyncPushTags {
135135
}
136136

137137
fn set_result(
138-
arc_result: Arc<Mutex<Option<String>>>,
138+
arc_result: &Arc<Mutex<Option<String>>>,
139139
res: Result<()>,
140140
) -> Result<()> {
141141
let mut last_res = arc_result.lock()?;

asyncgit/src/remote_progress.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ impl RemoteProgress {
5252
}
5353

5454
///
55-
pub fn get_progress_percent(&self) -> u8 {
55+
pub const fn get_progress_percent(&self) -> u8 {
5656
self.progress.progress
5757
}
5858

5959
pub(crate) fn set_progress<T>(
60-
progress: Arc<Mutex<Option<T>>>,
60+
progress: &Arc<Mutex<Option<T>>>,
6161
state: Option<T>,
6262
) -> Result<()> {
6363
let mut progress = progress.lock()?;
@@ -81,7 +81,7 @@ impl RemoteProgress {
8181
match incoming {
8282
Ok(update) => {
8383
Self::set_progress(
84-
progress.clone(),
84+
&progress,
8585
Some(update.clone()),
8686
)
8787
.expect("set progress failed");
@@ -116,26 +116,22 @@ impl From<ProgressNotification> for RemoteProgress {
116116
current,
117117
total,
118118
} => match stage {
119-
PackBuilderStage::AddingObjects => {
120-
RemoteProgress::new(
121-
RemoteProgressState::PackingAddingObject,
122-
current,
123-
total,
124-
)
125-
}
126-
PackBuilderStage::Deltafication => {
127-
RemoteProgress::new(
128-
RemoteProgressState::PackingDeltafiction,
129-
current,
130-
total,
131-
)
132-
}
119+
PackBuilderStage::AddingObjects => Self::new(
120+
RemoteProgressState::PackingAddingObject,
121+
current,
122+
total,
123+
),
124+
PackBuilderStage::Deltafication => Self::new(
125+
RemoteProgressState::PackingDeltafiction,
126+
current,
127+
total,
128+
),
133129
},
134130
ProgressNotification::PushTransfer {
135131
current,
136132
total,
137133
..
138-
} => RemoteProgress::new(
134+
} => Self::new(
139135
RemoteProgressState::Pushing,
140136
current,
141137
total,
@@ -144,12 +140,12 @@ impl From<ProgressNotification> for RemoteProgress {
144140
objects,
145141
total_objects,
146142
..
147-
} => RemoteProgress::new(
143+
} => Self::new(
148144
RemoteProgressState::Transfer,
149145
objects,
150146
total_objects,
151147
),
152-
_ => RemoteProgress::new(RemoteProgressState::Done, 1, 1),
148+
_ => Self::new(RemoteProgressState::Done, 1, 1),
153149
}
154150
}
155151
}

asyncgit/src/revlog.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,9 @@ impl AsyncLog {
121121
rayon_core::spawn(move || {
122122
scope_time!("async::revlog");
123123

124-
AsyncLog::fetch_helper(
125-
arc_current,
126-
arc_background,
124+
Self::fetch_helper(
125+
&arc_current,
126+
&arc_background,
127127
&sender,
128128
)
129129
.expect("failed to fetch");
@@ -137,8 +137,8 @@ impl AsyncLog {
137137
}
138138

139139
fn fetch_helper(
140-
arc_current: Arc<Mutex<Vec<CommitId>>>,
141-
arc_background: Arc<AtomicBool>,
140+
arc_current: &Arc<Mutex<Vec<CommitId>>>,
141+
arc_background: &Arc<AtomicBool>,
142142
sender: &Sender<AsyncNotification>,
143143
) -> Result<()> {
144144
let mut entries = Vec::with_capacity(LIMIT_COUNT);
@@ -157,7 +157,7 @@ impl AsyncLog {
157157
if res_is_err || entries.len() <= 1 {
158158
break;
159159
}
160-
Self::notify(&sender);
160+
Self::notify(sender);
161161

162162
let sleep_duration =
163163
if arc_background.load(Ordering::Relaxed) {

0 commit comments

Comments
 (0)