mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-16 00:56:23 +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::cli_util::CommandHelper;
|
||||||
use crate::command_error::{user_error, CommandError};
|
use crate::command_error::{user_error, CommandError};
|
||||||
use crate::description_util::{
|
use crate::description_util::{description_template, edit_description, join_message_paragraphs};
|
||||||
description_template_for_commit, edit_description, join_message_paragraphs,
|
|
||||||
};
|
|
||||||
use crate::ui::Ui;
|
use crate::ui::Ui;
|
||||||
|
|
||||||
/// Update the description and create a new change on top.
|
/// 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());
|
commit_builder.set_description(command.settings().default_description());
|
||||||
}
|
}
|
||||||
let temp_commit = commit_builder.write_hidden()?;
|
let temp_commit = commit_builder.write_hidden()?;
|
||||||
let template =
|
let template = description_template(ui, tx.base_workspace_helper(), "", &temp_commit)?;
|
||||||
description_template_for_commit(ui, tx.base_workspace_helper(), "", &temp_commit)?;
|
|
||||||
edit_description(tx.base_repo(), &template, command.settings())?
|
edit_description(tx.base_repo(), &template, command.settings())?
|
||||||
};
|
};
|
||||||
commit_builder.set_description(description);
|
commit_builder.set_description(description);
|
||||||
|
|
|
@ -19,9 +19,7 @@ use tracing::instrument;
|
||||||
|
|
||||||
use crate::cli_util::{CommandHelper, RevisionArg};
|
use crate::cli_util::{CommandHelper, RevisionArg};
|
||||||
use crate::command_error::CommandError;
|
use crate::command_error::CommandError;
|
||||||
use crate::description_util::{
|
use crate::description_util::{description_template, edit_description, join_message_paragraphs};
|
||||||
description_template_for_describe, edit_description, join_message_paragraphs,
|
|
||||||
};
|
|
||||||
use crate::ui::Ui;
|
use crate::ui::Ui;
|
||||||
|
|
||||||
/// Update the change description or other metadata
|
/// Update the change description or other metadata
|
||||||
|
@ -92,8 +90,7 @@ pub(crate) fn cmd_describe(
|
||||||
commit_builder.set_description(command.settings().default_description());
|
commit_builder.set_description(command.settings().default_description());
|
||||||
}
|
}
|
||||||
let temp_commit = commit_builder.write_hidden()?;
|
let temp_commit = commit_builder.write_hidden()?;
|
||||||
let template =
|
let template = description_template(ui, tx.base_workspace_helper(), "", &temp_commit)?;
|
||||||
description_template_for_describe(ui, tx.base_workspace_helper(), &temp_commit)?;
|
|
||||||
edit_description(tx.base_repo(), &template, command.settings())?
|
edit_description(tx.base_repo(), &template, command.settings())?
|
||||||
};
|
};
|
||||||
commit_builder.set_description(description);
|
commit_builder.set_description(description);
|
||||||
|
|
|
@ -19,7 +19,7 @@ use tracing::instrument;
|
||||||
|
|
||||||
use crate::cli_util::{CommandHelper, RevisionArg};
|
use crate::cli_util::{CommandHelper, RevisionArg};
|
||||||
use crate::command_error::{user_error_with_hint, CommandError};
|
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;
|
use crate::ui::Ui;
|
||||||
|
|
||||||
/// Split a revision in two
|
/// Split a revision in two
|
||||||
|
@ -132,7 +132,7 @@ the operation will be aborted.
|
||||||
commit_builder.set_description(command.settings().default_description());
|
commit_builder.set_description(command.settings().default_description());
|
||||||
}
|
}
|
||||||
let temp_commit = commit_builder.write_hidden()?;
|
let temp_commit = commit_builder.write_hidden()?;
|
||||||
let template = description_template_for_commit(
|
let template = description_template(
|
||||||
ui,
|
ui,
|
||||||
tx.base_workspace_helper(),
|
tx.base_workspace_helper(),
|
||||||
"Enter a description for the first commit.",
|
"Enter a description for the first commit.",
|
||||||
|
@ -175,7 +175,7 @@ the operation will be aborted.
|
||||||
"".to_string()
|
"".to_string()
|
||||||
} else {
|
} else {
|
||||||
let temp_commit = commit_builder.write_hidden()?;
|
let temp_commit = commit_builder.write_hidden()?;
|
||||||
let template = description_template_for_commit(
|
let template = description_template(
|
||||||
ui,
|
ui,
|
||||||
tx.base_workspace_helper(),
|
tx.base_workspace_helper(),
|
||||||
"Enter a description for the second commit.",
|
"Enter a description for the second commit.",
|
||||||
|
|
|
@ -89,28 +89,7 @@ pub fn join_message_paragraphs(paragraphs: &[String]) -> String {
|
||||||
.join("\n")
|
.join("\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn description_template_for_describe(
|
pub fn description_template(
|
||||||
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(
|
|
||||||
ui: &Ui,
|
ui: &Ui,
|
||||||
workspace_command: &WorkspaceCommandHelper,
|
workspace_command: &WorkspaceCommandHelper,
|
||||||
intro: &str,
|
intro: &str,
|
||||||
|
|
Loading…
Reference in a new issue