mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-15 16:53:25 +00:00
cli: merge description_template_for_*() functions
This commit is contained in:
parent
45d16f4b34
commit
5a19eb6331
4 changed files with 8 additions and 35 deletions
|
@ -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.
|
||||
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
@ -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.",
|
||||
|
@ -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.",
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue