Skip to content

Commit

Permalink
cleanup: fix latest clippy issues
Browse files Browse the repository at this point in the history
  • Loading branch information
arxanas committed May 12, 2024
1 parent 35c2a3b commit 8aba1e7
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 73 deletions.
74 changes: 37 additions & 37 deletions git-branchless-lib/src/core/effects.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
//! Wrappers around various side effects.

use bstr::ByteSlice;
use std::convert::TryInto;
use std::fmt::{Debug, Write};
use std::fmt::{Debug, Display, Write};
use std::io::{stderr, stdout, Stderr, Stdout, Write as WriteIo};
use std::mem::take;
use std::sync::{Arc, Mutex, RwLock};
Expand Down Expand Up @@ -51,45 +50,46 @@ pub enum OperationType {
WalkCommits,
}

impl ToString for OperationType {
fn to_string(&self) -> String {
let s = match self {
OperationType::BuildRebasePlan => "Building rebase plan",
OperationType::CalculateDiff => "Computing diffs",
OperationType::CalculatePatchId => "Hashing commit contents",
OperationType::CheckForCycles => "Checking for cycles",
OperationType::ConstrainCommits => "Creating commit constraints",
OperationType::DetectDuplicateCommits => "Checking for duplicate commits",
impl Display for OperationType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
OperationType::BuildRebasePlan => write!(f, "Building rebase plan"),
OperationType::CalculateDiff => write!(f, "Computing diffs"),
OperationType::CalculatePatchId => write!(f, "Hashing commit contents"),
OperationType::CheckForCycles => write!(f, "Checking for cycles"),
OperationType::ConstrainCommits => write!(f, "Creating commit constraints"),
OperationType::DetectDuplicateCommits => write!(f, "Checking for duplicate commits"),
OperationType::EvaluateRevset(revset) => {
return format!("Evaluating revset: {revset}");
write!(f, "Evaluating revset: {revset}")
}
OperationType::FilterByTouchedPaths => {
write!(f, "Filtering upstream commits by touched paths")
}
OperationType::FilterByTouchedPaths => "Filtering upstream commits by touched paths",
OperationType::FilterCommits => "Filtering commits",
OperationType::FindPathToMergeBase => "Finding path to merge-base",
OperationType::GetMergeBase => "Calculating merge-bases",
OperationType::GetTouchedPaths => "Getting touched paths",
OperationType::GetUpstreamPatchIds => "Enumerating patch IDs",
OperationType::InitializeRebase => "Initializing rebase",
OperationType::MakeGraph => "Examining local history",
OperationType::PushCommits => "Pushing branches",
OperationType::ProcessEvents => "Processing events",
OperationType::QueryWorkingCopy => "Querying the working copy",
OperationType::ReadingFromCache => "Reading from cache",
OperationType::RebaseCommits => "Rebasing commits",
OperationType::RepairBranches => "Checking for broken branches",
OperationType::RepairCommits => "Checking for broken commits",
OperationType::FilterCommits => write!(f, "Filtering commits"),
OperationType::FindPathToMergeBase => write!(f, "Finding path to merge-base"),
OperationType::GetMergeBase => write!(f, "Calculating merge-bases"),
OperationType::GetTouchedPaths => write!(f, "Getting touched paths"),
OperationType::GetUpstreamPatchIds => write!(f, "Enumerating patch IDs"),
OperationType::InitializeRebase => write!(f, "Initializing rebase"),
OperationType::MakeGraph => write!(f, "Examining local history"),
OperationType::PushCommits => write!(f, "Pushing branches"),
OperationType::ProcessEvents => write!(f, "Processing events"),
OperationType::QueryWorkingCopy => write!(f, "Querying the working copy"),
OperationType::ReadingFromCache => write!(f, "Reading from cache"),
OperationType::RebaseCommits => write!(f, "Rebasing commits"),
OperationType::RepairBranches => write!(f, "Checking for broken branches"),
OperationType::RepairCommits => write!(f, "Checking for broken commits"),
OperationType::RunGitCommand(command) => {
return format!("Running Git command: {}", &command)
write!(f, "Running Git command: {}", &command)
}
OperationType::RunTests(command) => return format!("Running command: {command}"),
OperationType::RunTestOnCommit(commit) => return format!("Waiting to run on {commit}"),
OperationType::SortCommits => "Sorting commits",
OperationType::SyncCommits => "Syncing commit stacks",
OperationType::UpdateCommits => "Updating commits",
OperationType::UpdateCommitGraph => "Updating commit graph",
OperationType::WalkCommits => "Walking commits",
};
s.to_string()
OperationType::RunTests(command) => write!(f, "Running command: {command}"),
OperationType::RunTestOnCommit(commit) => write!(f, "Waiting to run on {commit}"),
OperationType::SortCommits => write!(f, "Sorting commits"),
OperationType::SyncCommits => write!(f, "Syncing commit stacks"),
OperationType::UpdateCommits => write!(f, "Updating commits"),
OperationType::UpdateCommitGraph => write!(f, "Updating commit graph"),
OperationType::WalkCommits => write!(f, "Walking commits"),
}
}
}

Expand Down
9 changes: 5 additions & 4 deletions git-branchless-lib/src/core/eventlog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::cmp::Ordering;
use std::collections::{HashMap, HashSet};
use std::convert::{TryFrom, TryInto};

use std::fmt::Display;
use std::str::FromStr;
use std::time::{Duration, SystemTime};

Expand Down Expand Up @@ -62,11 +63,11 @@ pub enum EventTransactionId {
Suppressed,
}

impl ToString for EventTransactionId {
fn to_string(&self) -> String {
impl Display for EventTransactionId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
EventTransactionId::Id(event_id) => event_id.to_string(),
EventTransactionId::Suppressed => "SUPPRESSED".to_string(),
EventTransactionId::Id(event_id) => write!(f, "{event_id}"),
EventTransactionId::Suppressed => write!(f, "SUPPRESSED"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion git-branchless-lib/src/core/rewrite/execute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,7 @@ mod on_disk {
rebase_plan
.commands
.iter()
.map(|command| format!("{}\n", command.to_string()))
.map(|command| format!("{}\n", command.to_rebase_command()))
.collect::<String>(),
)
.wrap_err_with(|| {
Expand Down
30 changes: 16 additions & 14 deletions git-branchless-lib/src/core/rewrite/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,20 +125,10 @@ pub enum RebaseCommand {
},
}

/// Represents a sequence of commands that can be executed to carry out a rebase
/// operation.
#[derive(Debug)]
pub struct RebasePlan {
/// The first commit OID that will be checked out. This is necessary to
/// support on-disk rebases.
pub first_dest_oid: NonZeroOid,

/// The commands to run.
pub commands: Vec<RebaseCommand>,
}

impl ToString for RebaseCommand {
fn to_string(&self) -> String {
impl RebaseCommand {
/// Convert the command to a string that's used in the `git rebase` plan
/// format.
pub fn to_rebase_command(&self) -> String {
match self {
RebaseCommand::CreateLabel { label_name } => format!("label {label_name}"),
RebaseCommand::Reset { target } => format!("reset {target}"),
Expand Down Expand Up @@ -195,6 +185,18 @@ impl ToString for RebaseCommand {
}
}

/// Represents a sequence of commands that can be executed to carry out a rebase
/// operation.
#[derive(Debug)]
pub struct RebasePlan {
/// The first commit OID that will be checked out. This is necessary to
/// support on-disk rebases.
pub first_dest_oid: NonZeroOid,

/// The commands to run.
pub commands: Vec<RebaseCommand>,
}

/// A token representing that the rebase plan has been checked for validity.
#[derive(Clone, Debug)]
pub struct RebasePlanPermissions {
Expand Down
1 change: 0 additions & 1 deletion git-branchless-lib/src/git/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ pub fn update_index(
write!(
&mut buf,
"{mode} {sha1} {stage}\t{path}\0",
mode = mode.to_string(),
sha1 = oid,
stage = i32::from(*stage),
path = path.display(),
Expand Down
19 changes: 10 additions & 9 deletions git-branchless-lib/src/git/status.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::Display;
use std::path::PathBuf;
use std::str::FromStr;

Expand Down Expand Up @@ -146,16 +147,16 @@ impl FromStr for FileMode {
}
}

impl ToString for FileMode {
fn to_string(&self) -> String {
impl Display for FileMode {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
FileMode::Unreadable => "000000".to_string(),
FileMode::Tree => "040000".to_string(),
FileMode::Blob => "100644".to_string(),
FileMode::BlobExecutable => "100755".to_string(),
FileMode::BlobGroupWritable => "100664".to_string(),
FileMode::Link => "120000".to_string(),
FileMode::Commit => "160000".to_string(),
FileMode::Unreadable => write!(f, "000000"),
FileMode::Tree => write!(f, "040000"),
FileMode::Blob => write!(f, "100644"),
FileMode::BlobExecutable => write!(f, "100755"),
FileMode::BlobGroupWritable => write!(f, "100664"),
FileMode::Link => write!(f, "120000"),
FileMode::Commit => write!(f, "160000"),
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions git-branchless-revset/src/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,15 +350,13 @@ pub(super) fn eval_number_rhs(
mod tests {
use std::borrow::Cow;

use lib::core::effects::Effects;
use lib::core::eventlog::{EventLogDb, EventReplayer};
use lib::core::formatting::Glyphs;
use lib::core::repo_ext::RepoExt;
use lib::git::Commit;
use lib::testing::{make_git, GitRunOptions};

use super::*;
use crate::Expr;

fn eval_and_sort<'a>(
effects: &Effects,
Expand Down
2 changes: 1 addition & 1 deletion git-branchless-revset/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub use resolve::{check_revset_syntax, resolve_commits, resolve_default_smartlog

use lalrpop_util::lalrpop_mod;
lalrpop_mod!(
#[allow(clippy::all, clippy::as_conversions)]
#[allow(clippy::all, clippy::as_conversions, dead_code)]
grammar,
"/grammar.rs"
);
3 changes: 2 additions & 1 deletion git-branchless-submit/src/github.rs
Original file line number Diff line number Diff line change
Expand Up @@ -826,6 +826,7 @@ mod client {

#[derive(Debug)]
pub struct RealGithubClient {
#[allow(dead_code)] // FIXME: destructure and use in `run_gh`?
pub gh_run_info: GitRunInfo,
}

Expand Down Expand Up @@ -996,7 +997,7 @@ mod client {
"--title",
&title,
"--body-file",
&body_file.path().to_str().unwrap(),
(body_file.path().to_str().unwrap()),
],
)?);
Ok(Ok(()))
Expand Down
4 changes: 2 additions & 2 deletions git-branchless-submit/tests/test_github_forge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ fn test_github_forge_no_include_unsubmitted_commits_in_stack() -> eyre::Result<(
{
let (stdout, _stderr) = local_repo.branchless_with_options(
"submit",
&[&"--forge", "github", "--create", "HEAD^^"],
&["--forge", "github", "--create", "HEAD^^"],
&GitRunOptions {
env: mock_env(&remote_repo),
..Default::default()
Expand Down Expand Up @@ -537,7 +537,7 @@ fn test_github_forge_multiple_commits_in_pull_request() -> eyre::Result<()> {
{
let (stdout, _stderr) = local_repo.branchless_with_options(
"submit",
&[&"--forge", "github", "--create", "HEAD"],
&["--forge", "github", "--create", "HEAD"],
&GitRunOptions {
env: mock_env(&remote_repo),
..Default::default()
Expand Down
2 changes: 1 addition & 1 deletion git-branchless-undo/src/tui/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl Backend for CursiveTestingBackend {
match self.events.get(event_index)?.to_owned() {
CursiveTestingEvent::TakeScreenshot(screen_target) => {
let mut screen_target = (*screen_target).borrow_mut();
*screen_target = self.screen.borrow().clone();
screen_target.clone_from(&self.screen.borrow());
self.poll_event()
}
CursiveTestingEvent::Event(event) => {
Expand Down

0 comments on commit 8aba1e7

Please sign in to comment.