Skip to content

Commit

Permalink
cli: get settings from workspace where makes sense
Browse files Browse the repository at this point in the history
There should be no difference, but it's more consistent that all workspace/repo
commands use workspace_command.settings(), etc. than command.settings().
  • Loading branch information
yuja committed Jan 6, 2025
1 parent 6c14ccd commit 1f6e207
Show file tree
Hide file tree
Showing 19 changed files with 46 additions and 43 deletions.
4 changes: 3 additions & 1 deletion cli/src/commands/bookmark/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ pub fn cmd_bookmark_list(
let language = workspace_command.commit_template_language();
let text = match &args.template {
Some(value) => value.to_owned(),
None => command.settings().get("templates.bookmark_list")?,
None => workspace_command
.settings()
.get("templates.bookmark_list")?,
};
workspace_command
.parse_template(ui, &language, &text, CommitTemplateLanguage::wrap_ref_name)?
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/bookmark/track.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ pub fn cmd_bookmark_track(
if let Some(mut formatter) = ui.status_formatter() {
let template = {
let language = workspace_command.commit_template_language();
let text = command
let text = workspace_command
.settings()
.get::<String>("templates.bookmark_list")?;
workspace_command
Expand Down
3 changes: 1 addition & 2 deletions cli/src/commands/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@ new working-copy commit.
join_message_paragraphs(&args.message_paragraphs)
} else {
if commit_builder.description().is_empty() {
commit_builder
.set_description(command.settings().get_string("ui.default-description")?);
commit_builder.set_description(tx.settings().get_string("ui.default-description")?);
}
let temp_commit = commit_builder.write_hidden()?;
let template = description_template(ui, &tx, "", &temp_commit)?;
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/debug/watchman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ pub fn cmd_debug_watchman(
match subcommand {
DebugWatchmanCommand::Status => {
// TODO(ilyagr): It would be nice to add colors here
let config = match command.settings().fsmonitor_settings()? {
let config = match workspace_command.settings().fsmonitor_settings()? {
FsmonitorSettings::Watchman(config) => {
writeln!(ui.stdout(), "Watchman is enabled via `core.fsmonitor`.")?;
writeln!(
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/describe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ pub(crate) fn cmd_describe(
let mut commit_builder = tx.repo_mut().rewrite_commit(commit).detach();
if commit_builder.description().is_empty() {
commit_builder
.set_description(command.settings().get_string("ui.default-description")?);
.set_description(tx.settings().get_string("ui.default-description")?);
}
if args.reset_author {
let new_author = commit_builder.committer().clone();
Expand Down
8 changes: 4 additions & 4 deletions cli/src/commands/evolog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,16 +90,16 @@ pub(crate) fn cmd_evolog(
let start_commit = workspace_command.resolve_single_rev(ui, &args.revision)?;

let diff_renderer = workspace_command.diff_renderer_for_log(&args.diff_format, args.patch)?;
let graph_style = GraphStyle::from_settings(command.settings())?;
let with_content_format = LogContentFormat::new(ui, command.settings())?;
let graph_style = GraphStyle::from_settings(workspace_command.settings())?;
let with_content_format = LogContentFormat::new(ui, workspace_command.settings())?;

let template;
let node_template;
{
let language = workspace_command.commit_template_language();
let template_string = match &args.template {
Some(value) => value.to_string(),
None => command.settings().get_string("templates.log")?,
None => workspace_command.settings().get_string("templates.log")?,
};
template = workspace_command
.parse_template(
Expand All @@ -113,7 +113,7 @@ pub(crate) fn cmd_evolog(
.parse_template(
ui,
&language,
&get_node_template(graph_style, command.settings())?,
&get_node_template(graph_style, workspace_command.settings())?,
CommitTemplateLanguage::wrap_commit_opt,
)?
.labeled("node");
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/file/annotate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub(crate) fn cmd_file_annotate(
)));
}

let annotate_commit_summary_text = command
let annotate_commit_summary_text = workspace_command
.settings()
.get_string("templates.annotate_commit_summary")?;
let template = workspace_command.parse_commit_template(ui, &annotate_commit_summary_text)?;
Expand Down
4 changes: 2 additions & 2 deletions cli/src/commands/fix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ pub(crate) fn cmd_fix(
args: &FixArgs,
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let tools_config = get_tools_config(ui, command.settings())?;
let tools_config = get_tools_config(ui, workspace_command.settings())?;
let root_commits: Vec<CommitId> = if args.source.is_empty() {
let revs = command.settings().get_string("revsets.fix")?;
let revs = workspace_command.settings().get_string("revsets.fix")?;
workspace_command.parse_revset(ui, &RevisionArg::from(revs))?
} else {
workspace_command.parse_union_revsets(ui, &args.source)?
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/git/fetch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub fn cmd_git_fetch(
let remotes = if args.all_remotes {
get_all_remotes(&git_repo)?
} else if args.remotes.is_empty() {
get_default_fetch_remotes(ui, command.settings(), &git_repo)?
get_default_fetch_remotes(ui, workspace_command.settings(), &git_repo)?
} else {
args.remotes.clone()
};
Expand Down
3 changes: 2 additions & 1 deletion cli/src/commands/git/import.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ pub fn cmd_git_import(
_args: &GitImportArgs,
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let git_settings = workspace_command.settings().git_settings()?;
let mut tx = workspace_command.start_transaction();
// In non-colocated repo, Git HEAD will never be moved internally by jj.
// That's why cmd_git_export() doesn't export the HEAD ref.
git::import_head(tx.repo_mut())?;
let stats = git::import_refs(tx.repo_mut(), &command.settings().git_settings()?)?;
let stats = git::import_refs(tx.repo_mut(), &git_settings)?;
print_git_import_stats(ui, tx.repo(), &stats, true)?;
tx.finish(ui, "import git refs")?;
Ok(())
Expand Down
9 changes: 4 additions & 5 deletions cli/src/commands/git/push.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ pub fn cmd_git_push(
let remote = if let Some(name) = &args.remote {
name.clone()
} else {
get_default_push_remote(ui, command.settings(), &git_repo)?
get_default_push_remote(ui, workspace_command.settings(), &git_repo)?
};

let mut tx = workspace_command.start_transaction();
Expand Down Expand Up @@ -218,7 +218,7 @@ pub fn cmd_git_push(
let mut seen_bookmarks: HashSet<&str> = HashSet::new();

// Process --change bookmarks first because matching bookmarks can be moved.
let bookmark_prefix = get_change_bookmark_prefix(ui, command.settings())?;
let bookmark_prefix = get_change_bookmark_prefix(ui, tx.settings())?;
let change_bookmark_names =
update_change_bookmarks(ui, &mut tx, &args.change, &bookmark_prefix)?;
let change_bookmarks = change_bookmark_names.iter().map(|bookmark_name| {
Expand Down Expand Up @@ -295,7 +295,7 @@ pub fn cmd_git_push(
return Ok(());
}

validate_commits_ready_to_push(ui, &bookmark_updates, &remote, &tx, command, args)?;
validate_commits_ready_to_push(ui, &bookmark_updates, &remote, &tx, args)?;
if let Some(mut formatter) = ui.status_formatter() {
writeln!(formatter, "Changes to push to {remote}:")?;
print_commits_ready_to_push(formatter.as_mut(), tx.repo(), &bookmark_updates)?;
Expand Down Expand Up @@ -341,7 +341,6 @@ fn validate_commits_ready_to_push(
bookmark_updates: &[(String, BookmarkPushUpdate)],
remote: &str,
tx: &WorkspaceCommandTransaction,
command: &CommandHelper,
args: &GitPushArgs,
) -> Result<(), CommandError> {
let workspace_helper = tx.base_workspace_helper();
Expand All @@ -361,7 +360,7 @@ fn validate_commits_ready_to_push(
.union(workspace_helper.env().immutable_heads_expression())
.range(&RevsetExpression::commits(new_heads));

let settings = command.settings();
let settings = workspace_helper.settings();
let is_private = if let Ok(revset) = settings.get_string("git.private-commits") {
workspace_helper
.parse_revset(ui, &RevisionArg::from(revset))?
Expand Down
15 changes: 7 additions & 8 deletions cli/src/commands/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,13 @@ pub(crate) fn cmd_log(
args: &LogArgs,
) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;
let settings = workspace_command.settings();

let fileset_expression = workspace_command.parse_file_patterns(ui, &args.paths)?;
let revset_expression = {
// only use default revset if neither revset nor path are specified
let mut expression = if args.revisions.is_empty() && args.paths.is_empty() {
let revset_string = command.settings().get_string("revsets.log")?;
let revset_string = settings.get_string("revsets.log")?;
workspace_command.parse_revset(ui, &RevisionArg::from(revset_string))?
} else if !args.revisions.is_empty() {
workspace_command.parse_union_revsets(ui, &args.revisions)?
Expand All @@ -140,20 +141,18 @@ pub(crate) fn cmd_log(

let store = repo.store();
let diff_renderer = workspace_command.diff_renderer_for_log(&args.diff_format, args.patch)?;
let graph_style = GraphStyle::from_settings(command.settings())?;
let graph_style = GraphStyle::from_settings(settings)?;

let use_elided_nodes = command
.settings()
.get_bool("ui.log-synthetic-elided-nodes")?;
let with_content_format = LogContentFormat::new(ui, command.settings())?;
let use_elided_nodes = settings.get_bool("ui.log-synthetic-elided-nodes")?;
let with_content_format = LogContentFormat::new(ui, settings)?;

let template;
let node_template;
{
let language = workspace_command.commit_template_language();
let template_string = match &args.template {
Some(value) => value.to_string(),
None => command.settings().get_string("templates.log")?,
None => settings.get_string("templates.log")?,
};
template = workspace_command
.parse_template(
Expand All @@ -167,7 +166,7 @@ pub(crate) fn cmd_log(
.parse_template(
ui,
&language,
&get_node_template(graph_style, command.settings())?,
&get_node_template(graph_style, settings)?,
CommitTemplateLanguage::wrap_commit_opt,
)?
.labeled("node");
Expand Down
9 changes: 5 additions & 4 deletions cli/src/commands/operation/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ pub fn cmd_op_diff(
let workspace_command = command.workspace_helper(ui)?;
let workspace_env = workspace_command.env();
let repo_loader = workspace_command.workspace().repo_loader();
let settings = workspace_command.settings();
let from_op;
let to_op;
if args.from.is_some() || args.to.is_some() {
Expand All @@ -109,8 +110,8 @@ pub fn cmd_op_diff(
let to_op_parents: Vec<_> = to_op.parents().try_collect()?;
from_op = repo_loader.merge_operations(to_op_parents, None)?;
}
let graph_style = GraphStyle::from_settings(command.settings())?;
let with_content_format = LogContentFormat::new(ui, command.settings())?;
let graph_style = GraphStyle::from_settings(settings)?;
let with_content_format = LogContentFormat::new(ui, settings)?;

let from_repo = repo_loader.load_at(&from_op)?;
let to_repo = repo_loader.load_at(&to_op)?;
Expand All @@ -123,7 +124,7 @@ pub fn cmd_op_diff(
let merged_repo = tx.repo();

let diff_renderer = {
let formats = diff_formats_for_log(command.settings(), &args.diff_format, args.patch)?;
let formats = diff_formats_for_log(settings, &args.diff_format, args.patch)?;
let path_converter = workspace_env.path_converter();
let conflict_marker_style = workspace_env.conflict_marker_style();
(!formats.is_empty())
Expand All @@ -132,7 +133,7 @@ pub fn cmd_op_diff(
let id_prefix_context = workspace_env.new_id_prefix_context();
let commit_summary_template = {
let language = workspace_env.commit_template_language(merged_repo, &id_prefix_context);
let text = command.settings().get_string("templates.commit_summary")?;
let text = settings.get_string("templates.commit_summary")?;
workspace_env.parse_template(ui, &language, &text, CommitTemplateLanguage::wrap_commit)?
};

Expand Down
11 changes: 6 additions & 5 deletions cli/src/commands/operation/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub fn cmd_op_show(
let workspace_command = command.workspace_helper(ui)?;
let workspace_env = workspace_command.env();
let repo_loader = workspace_command.workspace().repo_loader();
let settings = workspace_command.settings();
let op = workspace_command.resolve_single_op(&args.operation)?;
let parents: Vec<_> = op.parents().try_collect()?;
let parent_op = repo_loader.merge_operations(parents, None)?;
Expand All @@ -64,14 +65,14 @@ pub fn cmd_op_show(
let id_prefix_context = workspace_env.new_id_prefix_context();
let commit_summary_template = {
let language = workspace_env.commit_template_language(repo.as_ref(), &id_prefix_context);
let text = command.settings().get_string("templates.commit_summary")?;
let text = settings.get_string("templates.commit_summary")?;
workspace_env.parse_template(ui, &language, &text, CommitTemplateLanguage::wrap_commit)?
};

let graph_style = GraphStyle::from_settings(command.settings())?;
let with_content_format = LogContentFormat::new(ui, command.settings())?;
let graph_style = GraphStyle::from_settings(settings)?;
let with_content_format = LogContentFormat::new(ui, settings)?;
let diff_renderer = {
let formats = diff_formats_for_log(command.settings(), &args.diff_format, args.patch)?;
let formats = diff_formats_for_log(settings, &args.diff_format, args.patch)?;
let path_converter = workspace_env.path_converter();
let conflict_marker_style = workspace_env.conflict_marker_style();
(!formats.is_empty()).then(|| {
Expand All @@ -86,7 +87,7 @@ pub fn cmd_op_show(

// TODO: Should we make this customizable via clap arg?
let template = {
let text = command.settings().get_string("templates.op_log")?;
let text = settings.get_string("templates.op_log")?;
workspace_command
.parse_operation_template(ui, &text)?
.labeled("operation")
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/show.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub(crate) fn cmd_show(
let commit = workspace_command.resolve_single_rev(ui, &args.revision)?;
let template_string = match &args.template {
Some(value) => value.to_string(),
None => command.settings().get_string("templates.show")?,
None => workspace_command.settings().get_string("templates.show")?,
};
let template = workspace_command.parse_commit_template(ui, &template_string)?;
let diff_renderer = workspace_command.diff_renderer_for(&args.format)?;
Expand Down
4 changes: 3 additions & 1 deletion cli/src/commands/simplify_parents.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ pub(crate) fn cmd_simplify_parents(
) -> Result<(), CommandError> {
let mut workspace_command = command.workspace_helper(ui)?;
let revs = if args.source.is_empty() && args.revisions.is_empty() {
let revs = command.settings().get_string("revsets.simplify-parents")?;
let revs = workspace_command
.settings()
.get_string("revsets.simplify-parents")?;
workspace_command
.parse_revset(ui, &RevisionArg::from(revs))?
.expression()
Expand Down
3 changes: 1 addition & 2 deletions cli/src/commands/split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,7 @@ The remainder will be in the second commit.
let mut commit_builder = tx.repo_mut().rewrite_commit(&commit).detach();
commit_builder.set_tree_id(selected_tree_id);
if commit_builder.description().is_empty() {
commit_builder
.set_description(command.settings().get_string("ui.default-description")?);
commit_builder.set_description(tx.settings().get_string("ui.default-description")?);
}
let temp_commit = commit_builder.write_hidden()?;
let template = description_template(
Expand Down
2 changes: 1 addition & 1 deletion cli/src/commands/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fn cmd_tag_list(
let language = workspace_command.commit_template_language();
let text = match &args.template {
Some(value) => value.to_owned(),
None => command.settings().get("templates.tag_list")?,
None => workspace_command.settings().get("templates.tag_list")?,
};
workspace_command
.parse_template(ui, &language, &text, CommitTemplateLanguage::wrap_ref_name)?
Expand Down
2 changes: 1 addition & 1 deletion cli/src/movement_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ pub(crate) fn move_to_commit(
.get_wc_commit_id()
.ok_or_else(|| user_error("This command requires a working copy"))?;

let config_edit_flag = command.settings().get_bool("ui.movement.edit")?;
let config_edit_flag = workspace_command.settings().get_bool("ui.movement.edit")?;
let args = MovementArgsInternal {
should_edit: args.edit || (!args.no_edit && config_edit_flag),
offset: args.offset,
Expand Down

0 comments on commit 1f6e207

Please sign in to comment.