diff --git a/git-branchless-lib/src/core/effects.rs b/git-branchless-lib/src/core/effects.rs index 8c50018c9..7f3c0a74b 100644 --- a/git-branchless-lib/src/core/effects.rs +++ b/git-branchless-lib/src/core/effects.rs @@ -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}; @@ -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"), + } } } diff --git a/git-branchless-lib/src/core/eventlog.rs b/git-branchless-lib/src/core/eventlog.rs index bcdc214d1..6e44403e7 100644 --- a/git-branchless-lib/src/core/eventlog.rs +++ b/git-branchless-lib/src/core/eventlog.rs @@ -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}; @@ -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"), } } } diff --git a/git-branchless-lib/src/core/rewrite/execute.rs b/git-branchless-lib/src/core/rewrite/execute.rs index 46b861443..daa7684d7 100644 --- a/git-branchless-lib/src/core/rewrite/execute.rs +++ b/git-branchless-lib/src/core/rewrite/execute.rs @@ -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::(), ) .wrap_err_with(|| { diff --git a/git-branchless-lib/src/core/rewrite/plan.rs b/git-branchless-lib/src/core/rewrite/plan.rs index 5ebae0a98..00307ec37 100644 --- a/git-branchless-lib/src/core/rewrite/plan.rs +++ b/git-branchless-lib/src/core/rewrite/plan.rs @@ -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, -} - -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}"), @@ -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, +} + /// A token representing that the rebase plan has been checked for validity. #[derive(Clone, Debug)] pub struct RebasePlanPermissions { diff --git a/git-branchless-lib/src/git/index.rs b/git-branchless-lib/src/git/index.rs index 9082d0a5c..f83c3dd20 100644 --- a/git-branchless-lib/src/git/index.rs +++ b/git-branchless-lib/src/git/index.rs @@ -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(), diff --git a/git-branchless-lib/src/git/status.rs b/git-branchless-lib/src/git/status.rs index 601c3d689..72ba3368b 100644 --- a/git-branchless-lib/src/git/status.rs +++ b/git-branchless-lib/src/git/status.rs @@ -1,3 +1,4 @@ +use std::fmt::Display; use std::path::PathBuf; use std::str::FromStr; @@ -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"), } } } diff --git a/git-branchless-revset/src/eval.rs b/git-branchless-revset/src/eval.rs index dce037baf..63e18867b 100644 --- a/git-branchless-revset/src/eval.rs +++ b/git-branchless-revset/src/eval.rs @@ -350,7 +350,6 @@ 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; @@ -358,7 +357,6 @@ mod tests { use lib::testing::{make_git, GitRunOptions}; use super::*; - use crate::Expr; fn eval_and_sort<'a>( effects: &Effects, diff --git a/git-branchless-revset/src/lib.rs b/git-branchless-revset/src/lib.rs index 4dc82ceec..14efa735a 100644 --- a/git-branchless-revset/src/lib.rs +++ b/git-branchless-revset/src/lib.rs @@ -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" ); diff --git a/git-branchless-submit/src/github.rs b/git-branchless-submit/src/github.rs index 2e8abbbb7..39eef9c06 100644 --- a/git-branchless-submit/src/github.rs +++ b/git-branchless-submit/src/github.rs @@ -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, } @@ -996,7 +997,7 @@ mod client { "--title", &title, "--body-file", - &body_file.path().to_str().unwrap(), + (body_file.path().to_str().unwrap()), ], )?); Ok(Ok(())) diff --git a/git-branchless-submit/tests/test_github_forge.rs b/git-branchless-submit/tests/test_github_forge.rs index 6778beab5..2187c2b19 100644 --- a/git-branchless-submit/tests/test_github_forge.rs +++ b/git-branchless-submit/tests/test_github_forge.rs @@ -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() @@ -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() diff --git a/git-branchless-undo/src/tui/testing.rs b/git-branchless-undo/src/tui/testing.rs index b8593b517..4ae5e6a05 100644 --- a/git-branchless-undo/src/tui/testing.rs +++ b/git-branchless-undo/src/tui/testing.rs @@ -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) => {