Skip to content

Commit

Permalink
cli: merge description_template_for_*() functions
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Jul 25, 2024
1 parent 45d16f4 commit 5a19eb6
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 35 deletions.
7 changes: 2 additions & 5 deletions cli/src/commands/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ use tracing::instrument;

use crate::cli_util::CommandHelper;
use crate::command_error::{user_error, CommandError};
use crate::description_util::{
description_template_for_commit, edit_description, join_message_paragraphs,
};
use crate::description_util::{description_template, edit_description, join_message_paragraphs};
use crate::ui::Ui;

/// Update the description and create a new change on top.
Expand Down Expand Up @@ -113,8 +111,7 @@ new working-copy commit.
commit_builder.set_description(command.settings().default_description());
}
let temp_commit = commit_builder.write_hidden()?;
let template =
description_template_for_commit(ui, tx.base_workspace_helper(), "", &temp_commit)?;
let template = description_template(ui, tx.base_workspace_helper(), "", &temp_commit)?;
edit_description(tx.base_repo(), &template, command.settings())?
};
commit_builder.set_description(description);
Expand Down
7 changes: 2 additions & 5 deletions cli/src/commands/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ use tracing::instrument;

use crate::cli_util::{CommandHelper, RevisionArg};
use crate::command_error::CommandError;
use crate::description_util::{
description_template_for_describe, edit_description, join_message_paragraphs,
};
use crate::description_util::{description_template, edit_description, join_message_paragraphs};
use crate::ui::Ui;

/// Update the change description or other metadata
Expand Down Expand Up @@ -92,8 +90,7 @@ pub(crate) fn cmd_describe(
commit_builder.set_description(command.settings().default_description());
}
let temp_commit = commit_builder.write_hidden()?;
let template =
description_template_for_describe(ui, tx.base_workspace_helper(), &temp_commit)?;
let template = description_template(ui, tx.base_workspace_helper(), "", &temp_commit)?;
edit_description(tx.base_repo(), &template, command.settings())?
};
commit_builder.set_description(description);
Expand Down
6 changes: 3 additions & 3 deletions cli/src/commands/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use tracing::instrument;

use crate::cli_util::{CommandHelper, RevisionArg};
use crate::command_error::{user_error_with_hint, CommandError};
use crate::description_util::{description_template_for_commit, edit_description};
use crate::description_util::{description_template, edit_description};
use crate::ui::Ui;

/// Split a revision in two
Expand Down Expand Up @@ -132,7 +132,7 @@ the operation will be aborted.
commit_builder.set_description(command.settings().default_description());
}
let temp_commit = commit_builder.write_hidden()?;
let template = description_template_for_commit(
let template = description_template(
ui,
tx.base_workspace_helper(),
"Enter a description for the first commit.",
Expand Down Expand Up @@ -175,7 +175,7 @@ the operation will be aborted.
"".to_string()
} else {
let temp_commit = commit_builder.write_hidden()?;
let template = description_template_for_commit(
let template = description_template(
ui,
tx.base_workspace_helper(),
"Enter a description for the second commit.",
Expand Down
23 changes: 1 addition & 22 deletions cli/src/description_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,28 +89,7 @@ pub fn join_message_paragraphs(paragraphs: &[String]) -> String {
.join("\n")
}

pub fn description_template_for_describe(
ui: &Ui,
workspace_command: &WorkspaceCommandHelper,
commit: &Commit,
) -> Result<String, CommandError> {
let mut diff_summary_bytes = Vec::new();
let diff_renderer = workspace_command.diff_renderer(vec![DiffFormat::Summary]);
diff_renderer.show_patch(
ui,
&mut PlainTextFormatter::new(&mut diff_summary_bytes),
commit,
&EverythingMatcher,
)?;
let description = commit.description().to_owned();
if diff_summary_bytes.is_empty() {
Ok(description)
} else {
Ok(description + "\n" + &diff_summary_to_description(&diff_summary_bytes))
}
}

pub fn description_template_for_commit(
pub fn description_template(
ui: &Ui,
workspace_command: &WorkspaceCommandHelper,
intro: &str,
Expand Down

0 comments on commit 5a19eb6

Please sign in to comment.