description_util: remove dependency on WorkspaceCommandHelper

This commit is contained in:
dploch 2024-10-08 08:18:51 -04:00 committed by Daniel Ploch
parent 09d91efea5
commit 85f1ac37c6
6 changed files with 27 additions and 13 deletions

View file

@ -135,7 +135,11 @@ new working-copy commit.
}
let temp_commit = commit_builder.write_hidden()?;
let template = description_template(ui, &tx, "", &temp_commit)?;
edit_description(tx.base_workspace_helper(), &template, command.settings())?
edit_description(
tx.base_workspace_helper().repo_path(),
&template,
command.settings(),
)?
};
commit_builder.set_description(description);
let new_commit = commit_builder.write(tx.repo_mut())?;

View file

@ -166,8 +166,11 @@ pub(crate) fn cmd_describe(
if let [(_, temp_commit)] = &*temp_commits {
let template = description_template(ui, &tx, "", temp_commit)?;
let description =
edit_description(tx.base_workspace_helper(), &template, command.settings())?;
let description = edit_description(
tx.base_workspace_helper().repo_path(),
&template,
command.settings(),
)?;
vec![(&commits[0], description)]
} else {

View file

@ -140,8 +140,11 @@ The remainder will be in the second commit.
"Enter a description for the first commit.",
&temp_commit,
)?;
let description =
edit_description(tx.base_workspace_helper(), &template, command.settings())?;
let description = edit_description(
tx.base_workspace_helper().repo_path(),
&template,
command.settings(),
)?;
commit_builder.set_description(description);
commit_builder.write(tx.repo_mut())?
};
@ -184,7 +187,11 @@ The remainder will be in the second commit.
"Enter a description for the second commit.",
&temp_commit,
)?;
edit_description(tx.base_workspace_helper(), &template, command.settings())?
edit_description(
tx.base_workspace_helper().repo_path(),
&template,
command.settings(),
)?
};
commit_builder.set_description(description);
commit_builder.write(tx.repo_mut())?

View file

@ -308,7 +308,7 @@ from the source will be moved into the destination.
.filter_map(|source| source.abandon.then_some(source.commit))
.collect_vec();
combine_messages(
tx.base_workspace_helper(),
tx.base_workspace_helper().repo_path(),
&abandoned_commits,
destination,
settings,

View file

@ -117,7 +117,7 @@ aborted.
if new_parent_tree_id == parent_base_tree.id() {
tx.repo_mut().record_abandoned_commit(parent.id().clone());
let description = combine_messages(
tx.base_workspace_helper(),
tx.base_workspace_helper().repo_path(),
&[&parent],
&commit,
command.settings(),

View file

@ -1,5 +1,6 @@
use std::collections::HashMap;
use std::io::Write as _;
use std::path::Path;
use bstr::ByteVec as _;
use indexmap::IndexMap;
@ -12,7 +13,6 @@ use thiserror::Error;
use crate::cli_util::edit_temp_file;
use crate::cli_util::short_commit_hash;
use crate::cli_util::WorkspaceCommandHelper;
use crate::cli_util::WorkspaceCommandTransaction;
use crate::command_error::CommandError;
use crate::formatter::PlainTextFormatter;
@ -34,7 +34,7 @@ where
}
pub fn edit_description(
workspace_command: &WorkspaceCommandHelper,
repo_path: &Path,
description: &str,
settings: &UserSettings,
) -> Result<String, CommandError> {
@ -47,7 +47,7 @@ JJ: Lines starting with "JJ: " (like this one) will be removed.
let description = edit_temp_file(
"description",
".jjdescription",
workspace_command.repo_path(),
repo_path,
&description,
settings,
)?;
@ -178,7 +178,7 @@ where
/// then that one is used. Otherwise we concatenate the messages and ask the
/// user to edit the result in their editor.
pub fn combine_messages(
workspace_command: &WorkspaceCommandHelper,
repo_path: &Path,
sources: &[&Commit],
destination: &Commit,
settings: &UserSettings,
@ -208,7 +208,7 @@ pub fn combine_messages(
combined.push_str("\nJJ: Description from source commit:\n");
combined.push_str(commit.description());
}
edit_description(workspace_command, &combined, settings)
edit_description(repo_path, &combined, settings)
}
/// Create a description from a list of paragraphs.