ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: commit, split: pass temporary commit object to description helper

This commit is contained in:
Yuya Nishihara 2024-07-20 17:08:12 +09:00
parent b9cc61b535
commit 6395d32358
3 changed files with 21 additions and 30 deletions

View file

@ -89,8 +89,7 @@ new working-copy commit.
matcher.as_ref(),
format_instructions,
)?;
let middle_tree = tx.repo().store().get_root_tree(&tree_id)?;
if !args.paths.is_empty() && middle_tree.id() == base_tree.id() {
if !args.paths.is_empty() && tree_id == base_tree.id() {
writeln!(
ui.warning_default(),
"The given paths do not match any file: {}",
@ -107,19 +106,17 @@ new working-copy commit.
commit_builder.set_author(commit_builder.committer().clone());
}
let template = description_template_for_commit(
ui,
command.settings(),
tx.base_workspace_helper(),
"",
commit.description(),
&base_tree,
&middle_tree,
)?;
let description = if !args.message_paragraphs.is_empty() {
join_message_paragraphs(&args.message_paragraphs)
} else {
let temp_commit = commit_builder.write_hidden()?;
let template = description_template_for_commit(
ui,
command.settings(),
tx.base_workspace_helper(),
"",
&temp_commit,
)?;
edit_description(tx.base_repo(), &template, command.settings())?
};
commit_builder.set_description(description);

View file

@ -128,14 +128,13 @@ the operation will be aborted.
.rewrite_commit(command.settings(), &commit)
.detach();
commit_builder.set_tree_id(selected_tree_id);
let temp_commit = commit_builder.write_hidden()?;
let template = description_template_for_commit(
ui,
command.settings(),
tx.base_workspace_helper(),
"Enter a description for the first commit.",
commit.description(),
&base_tree,
&selected_tree,
&temp_commit,
)?;
let description = edit_description(tx.base_repo(), &template, command.settings())?;
commit_builder.set_description(description);
@ -145,13 +144,13 @@ the operation will be aborted.
// Create the second commit, which includes everything the user didn't
// select.
let second_commit = {
let (new_tree, base_tree) = if args.parallel {
let new_tree = if args.parallel {
// Merge the original commit tree with its parent using the tree
// containing the user selected changes as the base for the merge.
// This results in a tree with the changes the user didn't select.
(end_tree.merge(&selected_tree, &base_tree)?, &base_tree)
end_tree.merge(&selected_tree, &base_tree)?
} else {
(end_tree, &selected_tree)
end_tree
};
let parents = if args.parallel {
commit.parent_ids().to_vec()
@ -173,14 +172,13 @@ the operation will be aborted.
// second commit.
"".to_string()
} else {
let temp_commit = commit_builder.write_hidden()?;
let template = description_template_for_commit(
ui,
command.settings(),
tx.base_workspace_helper(),
"Enter a description for the second commit.",
commit.description(),
base_tree,
&new_tree,
&temp_commit,
)?;
edit_description(tx.base_repo(), &template, command.settings())?
};

View file

@ -1,7 +1,6 @@
use itertools::Itertools;
use jj_lib::commit::Commit;
use jj_lib::matchers::EverythingMatcher;
use jj_lib::merged_tree::MergedTree;
use jj_lib::repo::ReadonlyRepo;
use jj_lib::settings::UserSettings;
@ -116,27 +115,24 @@ pub fn description_template_for_commit(
settings: &UserSettings,
workspace_command: &WorkspaceCommandHelper,
intro: &str,
overall_commit_description: &str,
from_tree: &MergedTree,
to_tree: &MergedTree,
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_diff(
diff_renderer.show_patch(
ui,
&mut PlainTextFormatter::new(&mut diff_summary_bytes),
from_tree,
to_tree,
commit,
&EverythingMatcher,
)?;
let mut template_chunks = Vec::new();
if !intro.is_empty() {
template_chunks.push(format!("JJ: {intro}\n"));
}
template_chunks.push(if overall_commit_description.is_empty() {
template_chunks.push(if commit.description().is_empty() {
settings.default_description()
} else {
overall_commit_description.to_owned()
commit.description().to_owned()
});
if !diff_summary_bytes.is_empty() {
template_chunks.push("\n".to_owned());