forked from mirrors/jj
cli: get repo path from WorkspaceCommandHelper
, not from ReadonlyRepo
I'd like to remove `ReadonlyRepo::repo_path()` since it doesn't make sense when the repo is stored in a database.
This commit is contained in:
parent
b22d8fefd9
commit
bfb16a4c54
10 changed files with 36 additions and 22 deletions
|
@ -785,6 +785,10 @@ impl WorkspaceCommandHelper {
|
|||
&self.user_repo.repo
|
||||
}
|
||||
|
||||
pub fn repo_path(&self) -> &Path {
|
||||
self.workspace.repo_path()
|
||||
}
|
||||
|
||||
pub fn working_copy(&self) -> &dyn WorkingCopy {
|
||||
self.workspace.working_copy()
|
||||
}
|
||||
|
|
|
@ -115,7 +115,7 @@ new working-copy commit.
|
|||
}
|
||||
let temp_commit = commit_builder.write_hidden()?;
|
||||
let template = description_template(&tx, "", &temp_commit)?;
|
||||
edit_description(tx.base_repo(), &template, command.settings())?
|
||||
edit_description(tx.base_workspace_helper(), &template, command.settings())?
|
||||
};
|
||||
commit_builder.set_description(description);
|
||||
let new_commit = commit_builder.write(tx.repo_mut())?;
|
||||
|
|
|
@ -123,7 +123,6 @@ pub(crate) fn cmd_describe(
|
|||
})
|
||||
.collect()
|
||||
} else {
|
||||
let repo = tx.base_repo().clone();
|
||||
let temp_commits: Vec<(_, _)> = commits
|
||||
.iter()
|
||||
// Edit descriptions in topological order
|
||||
|
@ -147,7 +146,8 @@ pub(crate) fn cmd_describe(
|
|||
|
||||
if let [(_, temp_commit)] = &*temp_commits {
|
||||
let template = description_template(&tx, "", temp_commit)?;
|
||||
let description = edit_description(&repo, &template, command.settings())?;
|
||||
let description =
|
||||
edit_description(tx.base_workspace_helper(), &template, command.settings())?;
|
||||
|
||||
vec![(&commits[0], description)]
|
||||
} else {
|
||||
|
@ -156,7 +156,7 @@ pub(crate) fn cmd_describe(
|
|||
missing,
|
||||
duplicates,
|
||||
unexpected,
|
||||
} = edit_multiple_descriptions(&mut tx, &repo, &temp_commits, command.settings())?;
|
||||
} = edit_multiple_descriptions(&mut tx, &temp_commits, command.settings())?;
|
||||
if !missing.is_empty() {
|
||||
return Err(user_error(format!(
|
||||
"The description for the following commits were not found in the edited \
|
||||
|
|
|
@ -158,7 +158,7 @@ pub fn cmd_git_clone(
|
|||
let (mut workspace_command, stats) = clone_result?;
|
||||
if let Some(default_branch) = &stats.default_branch {
|
||||
// Set repository level `trunk()` alias to the default remote branch.
|
||||
let config_path = workspace_command.repo().repo_path().join("config.toml");
|
||||
let config_path = workspace_command.repo_path().join("config.toml");
|
||||
write_config_value_to_file(
|
||||
&ConfigNamePathBuf::from_iter(["revset-aliases", "trunk()"]),
|
||||
format!("{default_branch}@{remote_name}").into(),
|
||||
|
|
|
@ -28,6 +28,7 @@ use jj_lib::workspace::Workspace;
|
|||
use crate::cli_util::print_trackable_remote_branches;
|
||||
use crate::cli_util::start_repo_transaction;
|
||||
use crate::cli_util::CommandHelper;
|
||||
use crate::cli_util::WorkspaceCommandHelper;
|
||||
use crate::command_error::cli_error;
|
||||
use crate::command_error::user_error_with_hint;
|
||||
use crate::command_error::user_error_with_message;
|
||||
|
@ -171,7 +172,7 @@ pub fn do_init(
|
|||
let mut workspace_command = command.for_workable_repo(ui, workspace, repo)?;
|
||||
maybe_add_gitignore(&workspace_command)?;
|
||||
workspace_command.maybe_snapshot(ui)?;
|
||||
maybe_set_repository_level_trunk_alias(ui, workspace_command.repo())?;
|
||||
maybe_set_repository_level_trunk_alias(ui, &workspace_command)?;
|
||||
if !workspace_command.working_copy_shared_with_git() {
|
||||
let mut tx = workspace_command.start_transaction();
|
||||
jj_lib::git::import_head(tx.repo_mut())?;
|
||||
|
@ -234,9 +235,9 @@ fn init_git_refs(
|
|||
// Set repository level `trunk()` alias to the default branch for "origin".
|
||||
pub fn maybe_set_repository_level_trunk_alias(
|
||||
ui: &Ui,
|
||||
repo: &Arc<ReadonlyRepo>,
|
||||
workspace_command: &WorkspaceCommandHelper,
|
||||
) -> Result<(), CommandError> {
|
||||
let git_repo = get_git_repo(repo.store())?;
|
||||
let git_repo = get_git_repo(workspace_command.repo().store())?;
|
||||
if let Ok(reference) = git_repo.find_reference("refs/remotes/origin/HEAD") {
|
||||
if let Some(reference_name) = reference.symbolic_target() {
|
||||
if let Some(RefName::RemoteBranch {
|
||||
|
@ -244,7 +245,7 @@ pub fn maybe_set_repository_level_trunk_alias(
|
|||
..
|
||||
}) = parse_git_ref(reference_name)
|
||||
{
|
||||
let config_path = repo.repo_path().join("config.toml");
|
||||
let config_path = workspace_command.repo_path().join("config.toml");
|
||||
write_config_value_to_file(
|
||||
&ConfigNamePathBuf::from_iter(["revset-aliases", "trunk()"]),
|
||||
format!("{default_branch}@origin").into(),
|
||||
|
|
|
@ -154,7 +154,7 @@ fn cmd_sparse_edit(
|
|||
_args: &SparseEditArgs,
|
||||
) -> Result<(), CommandError> {
|
||||
let mut workspace_command = command.workspace_helper(ui)?;
|
||||
let repo_path = workspace_command.repo().repo_path().to_owned();
|
||||
let repo_path = workspace_command.repo_path().to_owned();
|
||||
update_sparse_patterns_with(ui, &mut workspace_command, |_ui, old_patterns| {
|
||||
let mut new_patterns = edit_sparse(&repo_path, old_patterns, command.settings())?;
|
||||
new_patterns.sort_unstable();
|
||||
|
|
|
@ -140,7 +140,8 @@ the operation will be aborted.
|
|||
"Enter a description for the first commit.",
|
||||
&temp_commit,
|
||||
)?;
|
||||
let description = edit_description(tx.base_repo(), &template, command.settings())?;
|
||||
let description =
|
||||
edit_description(tx.base_workspace_helper(), &template, command.settings())?;
|
||||
commit_builder.set_description(description);
|
||||
commit_builder.write(tx.repo_mut())?
|
||||
};
|
||||
|
@ -182,7 +183,7 @@ the operation will be aborted.
|
|||
"Enter a description for the second commit.",
|
||||
&temp_commit,
|
||||
)?;
|
||||
edit_description(tx.base_repo(), &template, command.settings())?
|
||||
edit_description(tx.base_workspace_helper(), &template, command.settings())?
|
||||
};
|
||||
commit_builder.set_description(description);
|
||||
commit_builder.write(tx.repo_mut())?
|
||||
|
|
|
@ -307,7 +307,12 @@ from the source will be moved into the destination.
|
|||
.iter()
|
||||
.filter_map(|source| source.abandon.then_some(source.commit))
|
||||
.collect_vec();
|
||||
combine_messages(tx.base_repo(), &abandoned_commits, destination, settings)?
|
||||
combine_messages(
|
||||
tx.base_workspace_helper(),
|
||||
&abandoned_commits,
|
||||
destination,
|
||||
settings,
|
||||
)?
|
||||
}
|
||||
};
|
||||
let mut predecessors = vec![destination.id().clone()];
|
||||
|
|
|
@ -107,8 +107,12 @@ aborted.
|
|||
// case).
|
||||
if new_parent_tree_id == parent_base_tree.id() {
|
||||
tx.repo_mut().record_abandoned_commit(parent.id().clone());
|
||||
let description =
|
||||
combine_messages(tx.base_repo(), &[&parent], &commit, command.settings())?;
|
||||
let description = combine_messages(
|
||||
tx.base_workspace_helper(),
|
||||
&[&parent],
|
||||
&commit,
|
||||
command.settings(),
|
||||
)?;
|
||||
// Commit the new child on top of the parent's parents.
|
||||
tx.repo_mut()
|
||||
.rewrite_commit(command.settings(), &commit)
|
||||
|
|
|
@ -7,12 +7,12 @@ use indoc::indoc;
|
|||
use itertools::Itertools;
|
||||
use jj_lib::backend::CommitId;
|
||||
use jj_lib::commit::Commit;
|
||||
use jj_lib::repo::ReadonlyRepo;
|
||||
use jj_lib::settings::UserSettings;
|
||||
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;
|
||||
|
@ -33,7 +33,7 @@ where
|
|||
}
|
||||
|
||||
pub fn edit_description(
|
||||
repo: &ReadonlyRepo,
|
||||
workspace_command: &WorkspaceCommandHelper,
|
||||
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",
|
||||
repo.repo_path(),
|
||||
workspace_command.repo_path(),
|
||||
&description,
|
||||
settings,
|
||||
)?;
|
||||
|
@ -58,7 +58,6 @@ JJ: Lines starting with "JJ: " (like this one) will be removed.
|
|||
/// Edits the descriptions of the given commits in a single editor session.
|
||||
pub fn edit_multiple_descriptions(
|
||||
tx: &mut WorkspaceCommandTransaction,
|
||||
repo: &ReadonlyRepo,
|
||||
commits: &[(&CommitId, Commit)],
|
||||
settings: &UserSettings,
|
||||
) -> Result<ParsedBulkEditMessage<CommitId>, CommandError> {
|
||||
|
@ -87,7 +86,7 @@ pub fn edit_multiple_descriptions(
|
|||
let bulk_message = edit_temp_file(
|
||||
"description",
|
||||
".jjdescription",
|
||||
repo.repo_path(),
|
||||
tx.base_workspace_helper().repo_path(),
|
||||
&bulk_message,
|
||||
settings,
|
||||
)?;
|
||||
|
@ -178,7 +177,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(
|
||||
repo: &ReadonlyRepo,
|
||||
workspace_command: &WorkspaceCommandHelper,
|
||||
sources: &[&Commit],
|
||||
destination: &Commit,
|
||||
settings: &UserSettings,
|
||||
|
@ -208,7 +207,7 @@ pub fn combine_messages(
|
|||
combined.push_str("\nJJ: Description from source commit:\n");
|
||||
combined.push_str(commit.description());
|
||||
}
|
||||
edit_description(repo, &combined, settings)
|
||||
edit_description(workspace_command, &combined, settings)
|
||||
}
|
||||
|
||||
/// Create a description from a list of paragraphs.
|
||||
|
|
Loading…
Reference in a new issue