From 85f1ac37c6afcef41d8499b1d946db135eb1df75 Mon Sep 17 00:00:00 2001 From: dploch Date: Tue, 8 Oct 2024 08:18:51 -0400 Subject: [PATCH] description_util: remove dependency on WorkspaceCommandHelper --- cli/src/commands/commit.rs | 6 +++++- cli/src/commands/describe.rs | 7 +++++-- cli/src/commands/split.rs | 13 ++++++++++--- cli/src/commands/squash.rs | 2 +- cli/src/commands/unsquash.rs | 2 +- cli/src/description_util.rs | 10 +++++----- 6 files changed, 27 insertions(+), 13 deletions(-) diff --git a/cli/src/commands/commit.rs b/cli/src/commands/commit.rs index 5d572f601..86208b3d8 100644 --- a/cli/src/commands/commit.rs +++ b/cli/src/commands/commit.rs @@ -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())?; diff --git a/cli/src/commands/describe.rs b/cli/src/commands/describe.rs index 9b42a4775..d40a08096 100644 --- a/cli/src/commands/describe.rs +++ b/cli/src/commands/describe.rs @@ -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 { diff --git a/cli/src/commands/split.rs b/cli/src/commands/split.rs index 2cb890809..80bdae510 100644 --- a/cli/src/commands/split.rs +++ b/cli/src/commands/split.rs @@ -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())? diff --git a/cli/src/commands/squash.rs b/cli/src/commands/squash.rs index 8d54a62fa..657a8f5ff 100644 --- a/cli/src/commands/squash.rs +++ b/cli/src/commands/squash.rs @@ -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, diff --git a/cli/src/commands/unsquash.rs b/cli/src/commands/unsquash.rs index 220e4f721..d83911bb4 100644 --- a/cli/src/commands/unsquash.rs +++ b/cli/src/commands/unsquash.rs @@ -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(), diff --git a/cli/src/description_util.rs b/cli/src/description_util.rs index e44fa542f..1d9da6f85 100644 --- a/cli/src/description_util.rs +++ b/cli/src/description_util.rs @@ -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 { @@ -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.