|
1 | 1 | //! Wrappers around various side effects.
|
2 | 2 |
|
3 | 3 | use bstr::ByteSlice;
|
4 |
| -use std::convert::TryInto; |
5 |
| -use std::fmt::{Debug, Write}; |
| 4 | +use std::fmt::{Debug, Display, Write}; |
6 | 5 | use std::io::{stderr, stdout, Stderr, Stdout, Write as WriteIo};
|
7 | 6 | use std::mem::take;
|
8 | 7 | use std::sync::{Arc, Mutex, RwLock};
|
@@ -51,45 +50,46 @@ pub enum OperationType {
|
51 | 50 | WalkCommits,
|
52 | 51 | }
|
53 | 52 |
|
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"), |
63 | 62 | 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") |
65 | 67 | }
|
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"), |
81 | 82 | OperationType::RunGitCommand(command) => {
|
82 |
| - return format!("Running Git command: {}", &command) |
| 83 | + write!(f, "Running Git command: {}", &command) |
83 | 84 | }
|
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 | + } |
93 | 93 | }
|
94 | 94 | }
|
95 | 95 |
|
|
0 commit comments