Skip to content

Commit 6a38f31

Browse files
committed
cleanup: fix latest clippy issues
1 parent 35c2a3b commit 6a38f31

File tree

11 files changed

+75
-73
lines changed

11 files changed

+75
-73
lines changed

git-branchless-lib/src/core/effects.rs

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
//! Wrappers around various side effects.
22
33
use bstr::ByteSlice;
4-
use std::convert::TryInto;
5-
use std::fmt::{Debug, Write};
4+
use std::fmt::{Debug, Display, Write};
65
use std::io::{stderr, stdout, Stderr, Stdout, Write as WriteIo};
76
use std::mem::take;
87
use std::sync::{Arc, Mutex, RwLock};
@@ -51,45 +50,46 @@ pub enum OperationType {
5150
WalkCommits,
5251
}
5352

54-
impl ToString for OperationType {
55-
fn to_string(&self) -> String {
56-
let s = match self {
57-
OperationType::BuildRebasePlan => "Building rebase plan",
58-
OperationType::CalculateDiff => "Computing diffs",
59-
OperationType::CalculatePatchId => "Hashing commit contents",
60-
OperationType::CheckForCycles => "Checking for cycles",
61-
OperationType::ConstrainCommits => "Creating commit constraints",
62-
OperationType::DetectDuplicateCommits => "Checking for duplicate commits",
53+
impl Display for OperationType {
54+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55+
match self {
56+
OperationType::BuildRebasePlan => write!(f, "Building rebase plan"),
57+
OperationType::CalculateDiff => write!(f, "Computing diffs"),
58+
OperationType::CalculatePatchId => write!(f, "Hashing commit contents"),
59+
OperationType::CheckForCycles => write!(f, "Checking for cycles"),
60+
OperationType::ConstrainCommits => write!(f, "Creating commit constraints"),
61+
OperationType::DetectDuplicateCommits => write!(f, "Checking for duplicate commits"),
6362
OperationType::EvaluateRevset(revset) => {
64-
return format!("Evaluating revset: {revset}");
63+
write!(f, "Evaluating revset: {revset}")
64+
}
65+
OperationType::FilterByTouchedPaths => {
66+
write!(f, "Filtering upstream commits by touched paths")
6567
}
66-
OperationType::FilterByTouchedPaths => "Filtering upstream commits by touched paths",
67-
OperationType::FilterCommits => "Filtering commits",
68-
OperationType::FindPathToMergeBase => "Finding path to merge-base",
69-
OperationType::GetMergeBase => "Calculating merge-bases",
70-
OperationType::GetTouchedPaths => "Getting touched paths",
71-
OperationType::GetUpstreamPatchIds => "Enumerating patch IDs",
72-
OperationType::InitializeRebase => "Initializing rebase",
73-
OperationType::MakeGraph => "Examining local history",
74-
OperationType::PushCommits => "Pushing branches",
75-
OperationType::ProcessEvents => "Processing events",
76-
OperationType::QueryWorkingCopy => "Querying the working copy",
77-
OperationType::ReadingFromCache => "Reading from cache",
78-
OperationType::RebaseCommits => "Rebasing commits",
79-
OperationType::RepairBranches => "Checking for broken branches",
80-
OperationType::RepairCommits => "Checking for broken commits",
68+
OperationType::FilterCommits => write!(f, "Filtering commits"),
69+
OperationType::FindPathToMergeBase => write!(f, "Finding path to merge-base"),
70+
OperationType::GetMergeBase => write!(f, "Calculating merge-bases"),
71+
OperationType::GetTouchedPaths => write!(f, "Getting touched paths"),
72+
OperationType::GetUpstreamPatchIds => write!(f, "Enumerating patch IDs"),
73+
OperationType::InitializeRebase => write!(f, "Initializing rebase"),
74+
OperationType::MakeGraph => write!(f, "Examining local history"),
75+
OperationType::PushCommits => write!(f, "Pushing branches"),
76+
OperationType::ProcessEvents => write!(f, "Processing events"),
77+
OperationType::QueryWorkingCopy => write!(f, "Querying the working copy"),
78+
OperationType::ReadingFromCache => write!(f, "Reading from cache"),
79+
OperationType::RebaseCommits => write!(f, "Rebasing commits"),
80+
OperationType::RepairBranches => write!(f, "Checking for broken branches"),
81+
OperationType::RepairCommits => write!(f, "Checking for broken commits"),
8182
OperationType::RunGitCommand(command) => {
82-
return format!("Running Git command: {}", &command)
83+
write!(f, "Running Git command: {}", &command)
8384
}
84-
OperationType::RunTests(command) => return format!("Running command: {command}"),
85-
OperationType::RunTestOnCommit(commit) => return format!("Waiting to run on {commit}"),
86-
OperationType::SortCommits => "Sorting commits",
87-
OperationType::SyncCommits => "Syncing commit stacks",
88-
OperationType::UpdateCommits => "Updating commits",
89-
OperationType::UpdateCommitGraph => "Updating commit graph",
90-
OperationType::WalkCommits => "Walking commits",
91-
};
92-
s.to_string()
85+
OperationType::RunTests(command) => write!(f, "Running command: {command}"),
86+
OperationType::RunTestOnCommit(commit) => write!(f, "Waiting to run on {commit}"),
87+
OperationType::SortCommits => write!(f, "Sorting commits"),
88+
OperationType::SyncCommits => write!(f, "Syncing commit stacks"),
89+
OperationType::UpdateCommits => write!(f, "Updating commits"),
90+
OperationType::UpdateCommitGraph => write!(f, "Updating commit graph"),
91+
OperationType::WalkCommits => write!(f, "Walking commits"),
92+
}
9393
}
9494
}
9595

git-branchless-lib/src/core/eventlog.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use std::cmp::Ordering;
99
use std::collections::{HashMap, HashSet};
1010
use std::convert::{TryFrom, TryInto};
1111

12+
use std::fmt::Display;
1213
use std::str::FromStr;
1314
use std::time::{Duration, SystemTime};
1415

@@ -62,11 +63,11 @@ pub enum EventTransactionId {
6263
Suppressed,
6364
}
6465

65-
impl ToString for EventTransactionId {
66-
fn to_string(&self) -> String {
66+
impl Display for EventTransactionId {
67+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
6768
match self {
68-
EventTransactionId::Id(event_id) => event_id.to_string(),
69-
EventTransactionId::Suppressed => "SUPPRESSED".to_string(),
69+
EventTransactionId::Id(event_id) => write!(f, "{event_id}"),
70+
EventTransactionId::Suppressed => write!(f, "SUPPRESSED"),
7071
}
7172
}
7273
}

git-branchless-lib/src/core/rewrite/execute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1103,7 +1103,7 @@ mod on_disk {
11031103
rebase_plan
11041104
.commands
11051105
.iter()
1106-
.map(|command| format!("{}\n", command.to_string()))
1106+
.map(|command| format!("{}\n", command.to_rebase_command()))
11071107
.collect::<String>(),
11081108
)
11091109
.wrap_err_with(|| {

git-branchless-lib/src/core/rewrite/plan.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,10 @@ pub enum RebaseCommand {
125125
},
126126
}
127127

128-
/// Represents a sequence of commands that can be executed to carry out a rebase
129-
/// operation.
130-
#[derive(Debug)]
131-
pub struct RebasePlan {
132-
/// The first commit OID that will be checked out. This is necessary to
133-
/// support on-disk rebases.
134-
pub first_dest_oid: NonZeroOid,
135-
136-
/// The commands to run.
137-
pub commands: Vec<RebaseCommand>,
138-
}
139-
140-
impl ToString for RebaseCommand {
141-
fn to_string(&self) -> String {
128+
impl RebaseCommand {
129+
/// Convert the command to a string that's used in the `git rebase` plan
130+
/// format.
131+
pub fn to_rebase_command(&self) -> String {
142132
match self {
143133
RebaseCommand::CreateLabel { label_name } => format!("label {label_name}"),
144134
RebaseCommand::Reset { target } => format!("reset {target}"),
@@ -195,6 +185,18 @@ impl ToString for RebaseCommand {
195185
}
196186
}
197187

188+
/// Represents a sequence of commands that can be executed to carry out a rebase
189+
/// operation.
190+
#[derive(Debug)]
191+
pub struct RebasePlan {
192+
/// The first commit OID that will be checked out. This is necessary to
193+
/// support on-disk rebases.
194+
pub first_dest_oid: NonZeroOid,
195+
196+
/// The commands to run.
197+
pub commands: Vec<RebaseCommand>,
198+
}
199+
198200
/// A token representing that the rebase plan has been checked for validity.
199201
#[derive(Clone, Debug)]
200202
pub struct RebasePlanPermissions {

git-branchless-lib/src/git/index.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ pub fn update_index(
141141
write!(
142142
&mut buf,
143143
"{mode} {sha1} {stage}\t{path}\0",
144-
mode = mode.to_string(),
145144
sha1 = oid,
146145
stage = i32::from(*stage),
147146
path = path.display(),

git-branchless-lib/src/git/status.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::fmt::Display;
12
use std::path::PathBuf;
23
use std::str::FromStr;
34

@@ -146,16 +147,16 @@ impl FromStr for FileMode {
146147
}
147148
}
148149

149-
impl ToString for FileMode {
150-
fn to_string(&self) -> String {
150+
impl Display for FileMode {
151+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
151152
match self {
152-
FileMode::Unreadable => "000000".to_string(),
153-
FileMode::Tree => "040000".to_string(),
154-
FileMode::Blob => "100644".to_string(),
155-
FileMode::BlobExecutable => "100755".to_string(),
156-
FileMode::BlobGroupWritable => "100664".to_string(),
157-
FileMode::Link => "120000".to_string(),
158-
FileMode::Commit => "160000".to_string(),
153+
FileMode::Unreadable => write!(f, "000000"),
154+
FileMode::Tree => write!(f, "040000"),
155+
FileMode::Blob => write!(f, "100644"),
156+
FileMode::BlobExecutable => write!(f, "100755"),
157+
FileMode::BlobGroupWritable => write!(f, "100664"),
158+
FileMode::Link => write!(f, "120000"),
159+
FileMode::Commit => write!(f, "160000"),
159160
}
160161
}
161162
}

git-branchless-revset/src/eval.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,15 +350,13 @@ pub(super) fn eval_number_rhs(
350350
mod tests {
351351
use std::borrow::Cow;
352352

353-
use lib::core::effects::Effects;
354353
use lib::core::eventlog::{EventLogDb, EventReplayer};
355354
use lib::core::formatting::Glyphs;
356355
use lib::core::repo_ext::RepoExt;
357356
use lib::git::Commit;
358357
use lib::testing::{make_git, GitRunOptions};
359358

360359
use super::*;
361-
use crate::Expr;
362360

363361
fn eval_and_sort<'a>(
364362
effects: &Effects,

git-branchless-revset/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ pub use resolve::{check_revset_syntax, resolve_commits, resolve_default_smartlog
2424

2525
use lalrpop_util::lalrpop_mod;
2626
lalrpop_mod!(
27-
#[allow(clippy::all, clippy::as_conversions)]
27+
#[allow(clippy::all, clippy::as_conversions, dead_code)]
2828
grammar,
2929
"/grammar.rs"
3030
);

git-branchless-submit/src/github.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,7 @@ mod client {
826826

827827
#[derive(Debug)]
828828
pub struct RealGithubClient {
829+
#[allow(dead_code)] // FIXME: destructure and use in `run_gh`?
829830
pub gh_run_info: GitRunInfo,
830831
}
831832

@@ -996,7 +997,7 @@ mod client {
996997
"--title",
997998
&title,
998999
"--body-file",
999-
&body_file.path().to_str().unwrap(),
1000+
(body_file.path().to_str().unwrap()),
10001001
],
10011002
)?);
10021003
Ok(Ok(()))

git-branchless-submit/tests/test_github_forge.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ fn test_github_forge_no_include_unsubmitted_commits_in_stack() -> eyre::Result<(
447447
{
448448
let (stdout, _stderr) = local_repo.branchless_with_options(
449449
"submit",
450-
&[&"--forge", "github", "--create", "HEAD^^"],
450+
&["--forge", "github", "--create", "HEAD^^"],
451451
&GitRunOptions {
452452
env: mock_env(&remote_repo),
453453
..Default::default()
@@ -537,7 +537,7 @@ fn test_github_forge_multiple_commits_in_pull_request() -> eyre::Result<()> {
537537
{
538538
let (stdout, _stderr) = local_repo.branchless_with_options(
539539
"submit",
540-
&[&"--forge", "github", "--create", "HEAD"],
540+
&["--forge", "github", "--create", "HEAD"],
541541
&GitRunOptions {
542542
env: mock_env(&remote_repo),
543543
..Default::default()

0 commit comments

Comments
 (0)