Skip to content

Commit

Permalink
changes noted during proofreading
Browse files Browse the repository at this point in the history
  • Loading branch information
claytonrcarter committed Mar 25, 2022
1 parent 440b6b7 commit 226de83
Showing 1 changed file with 56 additions and 52 deletions.
108 changes: 56 additions & 52 deletions src/commands/reword.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,8 @@ use crate::core::eventlog::{EventLogDb, EventReplayer};
use crate::core::formatting::{printable_styled_string, Glyphs};
use crate::core::node_descriptors::{render_node_descriptors, CommitOidDescriptor, NodeObject};
use crate::core::rewrite::{
execute_rebase_plan,
BuildRebasePlanOptions,
ExecuteRebasePlanOptions,
// BuildRebasePlanError,
ExecuteRebasePlanResult,
RebasePlanBuilder,
RepoResource,
execute_rebase_plan, BuildRebasePlanOptions, ExecuteRebasePlanOptions, ExecuteRebasePlanResult,
RebasePlanBuilder, RepoResource,
};
use crate::git::{CheckOutCommitOptions, Commit, GitRunInfo, MaybeZeroOid, NonZeroOid, Repo};

Expand Down Expand Up @@ -119,7 +114,7 @@ pub fn reword(
writeln!(
effects.get_output_stream(),
"###
BUG: rebase plan indicates nothing to do, but rewording should always so something.
BUG: rebase plan indicates nothing to do, but rewording should always do something.
Stopping; nothing reworded.
###"
)?;
Expand Down Expand Up @@ -150,49 +145,7 @@ pub fn reword(

let exit_code = match result {
ExecuteRebasePlanResult::Succeeded { rewritten_oids } => {
let glyphs = Glyphs::detect();
let num_commits = commits.len();
for original_commit in commits {
let replacement_oid = match rewritten_oids.get(&original_commit.get_oid()).unwrap()
{
MaybeZeroOid::NonZero(new_oid) => new_oid,
MaybeZeroOid::Zero => {
warn!(
"Encountered ZeroOid after success rewriting commit {}",
original_commit.get_oid()
);
continue;
}
};
let replacement_commit = repo.find_commit(*replacement_oid)?.unwrap();
writeln!(
effects.get_output_stream(),
"Reworded commit {} as {}",
printable_styled_string(
&glyphs,
// Commit doesn't offer `friendly_describe_oid`, so we'll do it ourselves
render_node_descriptors(
&glyphs,
&NodeObject::Commit {
commit: original_commit.clone(),
},
&mut [&mut CommitOidDescriptor::new(true)?],
)?
)?,
printable_styled_string(
&glyphs,
replacement_commit.friendly_describe(&glyphs)?
)?
)?;
}

if num_commits != 1 {
writeln!(
effects.get_output_stream(),
"Reworded {} commits with same message. If this was unintentional, run: git undo",
num_commits,
)?;
}
render_status_report(&repo, effects, &commits, &rewritten_oids)?;

0
}
Expand Down Expand Up @@ -275,7 +228,8 @@ fn build_messages(
_ => {
// TODO(bulk edit) build a bulk edit message for multiple commits
format!(
"Enter a commit message to apply to {} commits",
"{} Enter a commit message to apply to {} commits",
comment_char.unwrap(),
commits.len()
)
}
Expand Down Expand Up @@ -352,3 +306,53 @@ fn find_subtree_roots<'repo>(

Ok(root_commits)
}

/// Print a basic status report of what commits were reworded.
fn render_status_report(
repo: &Repo,
effects: &Effects,
commits: &[Commit],
rewritten_oids: &HashMap<NonZeroOid, MaybeZeroOid>,
) -> eyre::Result<()> {
let glyphs = Glyphs::detect();
let num_commits = commits.len();
for original_commit in commits {
let replacement_oid = match rewritten_oids.get(&original_commit.get_oid()).unwrap() {
MaybeZeroOid::NonZero(new_oid) => new_oid,
MaybeZeroOid::Zero => {
warn!(
"Encountered ZeroOid after success rewriting commit {}",
original_commit.get_oid()
);
continue;
}
};
let replacement_commit = repo.find_commit(*replacement_oid)?.unwrap();
writeln!(
effects.get_output_stream(),
"Reworded commit {} as {}",
printable_styled_string(
&glyphs,
// Commit doesn't offer `friendly_describe_oid`, so we'll do it ourselves
render_node_descriptors(
&glyphs,
&NodeObject::Commit {
commit: original_commit.clone(),
},
&mut [&mut CommitOidDescriptor::new(true)?],
)?
)?,
printable_styled_string(&glyphs, replacement_commit.friendly_describe(&glyphs)?)?
)?;
}

if num_commits != 1 {
writeln!(
effects.get_output_stream(),
"Reworded {} commits with same message. If this was unintentional, run: git undo",
num_commits,
)?;
}

Ok(())
}

0 comments on commit 226de83

Please sign in to comment.