mirror of
https://github.com/martinvonz/jj.git
synced 2025-05-31 03:42:39 +00:00
cli: pass UserSettings in to diff_util::diff_formats_for*()
This and the subsequent patches prepare for the removal of ui.settings(). Ui will be a consumer of UserSettings (or config::Config) to make it clear that Ui can be constructed before UserSettings is fully set up.
This commit is contained in:
parent
d99c299ee0
commit
7232dac7e9
@ -1384,7 +1384,7 @@ fn cmd_diff(ui: &mut Ui, command: &CommandHelper, args: &DiffArgs) -> Result<(),
|
||||
&from_tree,
|
||||
&to_tree,
|
||||
matcher.as_ref(),
|
||||
&diff_util::diff_formats_for(ui, &args.format),
|
||||
&diff_util::diff_formats_for(ui.settings(), &args.format),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
@ -1424,7 +1424,7 @@ fn cmd_show(ui: &mut Ui, command: &CommandHelper, args: &ShowArgs) -> Result<(),
|
||||
&workspace_command,
|
||||
&commit,
|
||||
&EverythingMatcher,
|
||||
&diff_util::diff_formats_for(ui, &args.format),
|
||||
&diff_util::diff_formats_for(ui.settings(), &args.format),
|
||||
)?;
|
||||
Ok(())
|
||||
}
|
||||
@ -1594,7 +1594,8 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
|
||||
};
|
||||
|
||||
let store = repo.store();
|
||||
let diff_formats = diff_util::diff_formats_for_log(ui, &args.diff_format, args.patch);
|
||||
let diff_formats =
|
||||
diff_util::diff_formats_for_log(ui.settings(), &args.diff_format, args.patch);
|
||||
|
||||
let template_string = match &args.template {
|
||||
Some(value) => value.to_string(),
|
||||
@ -1734,7 +1735,8 @@ fn cmd_obslog(ui: &mut Ui, command: &CommandHelper, args: &ObslogArgs) -> Result
|
||||
.view()
|
||||
.get_wc_commit_id(&workspace_id);
|
||||
|
||||
let diff_formats = diff_util::diff_formats_for_log(ui, &args.diff_format, args.patch);
|
||||
let diff_formats =
|
||||
diff_util::diff_formats_for_log(ui.settings(), &args.diff_format, args.patch);
|
||||
|
||||
let template_string = match &args.template {
|
||||
Some(value) => value.to_string(),
|
||||
@ -1839,7 +1841,7 @@ fn cmd_interdiff(
|
||||
&from_tree,
|
||||
&to.tree(),
|
||||
matcher.as_ref(),
|
||||
&diff_util::diff_formats_for(ui, &args.format),
|
||||
&diff_util::diff_formats_for(ui.settings(), &args.format),
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -25,12 +25,12 @@ use jujutsu_lib::files::DiffLine;
|
||||
use jujutsu_lib::matchers::Matcher;
|
||||
use jujutsu_lib::repo::ReadonlyRepo;
|
||||
use jujutsu_lib::repo_path::RepoPath;
|
||||
use jujutsu_lib::settings::UserSettings;
|
||||
use jujutsu_lib::tree::{Tree, TreeDiffIterator};
|
||||
use jujutsu_lib::{conflicts, diff, files, rewrite, tree};
|
||||
|
||||
use crate::cli_util::{CommandError, WorkspaceCommandHelper};
|
||||
use crate::formatter::Formatter;
|
||||
use crate::ui::Ui;
|
||||
|
||||
#[derive(clap::Args, Clone, Debug)]
|
||||
pub struct DiffFormatArgs {
|
||||
@ -53,10 +53,10 @@ pub enum DiffFormat {
|
||||
}
|
||||
|
||||
/// Returns a list of requested diff formats, which will never be empty.
|
||||
pub fn diff_formats_for(ui: &Ui, args: &DiffFormatArgs) -> Vec<DiffFormat> {
|
||||
pub fn diff_formats_for(settings: &UserSettings, args: &DiffFormatArgs) -> Vec<DiffFormat> {
|
||||
let formats = diff_formats_from_args(args);
|
||||
if formats.is_empty() {
|
||||
vec![default_diff_format(ui)]
|
||||
vec![default_diff_format(settings)]
|
||||
} else {
|
||||
formats
|
||||
}
|
||||
@ -64,11 +64,15 @@ pub fn diff_formats_for(ui: &Ui, args: &DiffFormatArgs) -> Vec<DiffFormat> {
|
||||
|
||||
/// Returns a list of requested diff formats for log-like commands, which may be
|
||||
/// empty.
|
||||
pub fn diff_formats_for_log(ui: &Ui, args: &DiffFormatArgs, patch: bool) -> Vec<DiffFormat> {
|
||||
pub fn diff_formats_for_log(
|
||||
settings: &UserSettings,
|
||||
args: &DiffFormatArgs,
|
||||
patch: bool,
|
||||
) -> Vec<DiffFormat> {
|
||||
let mut formats = diff_formats_from_args(args);
|
||||
// --patch implies default if no format other than --summary is specified
|
||||
if patch && matches!(formats.as_slice(), [] | [DiffFormat::Summary]) {
|
||||
formats.push(default_diff_format(ui));
|
||||
formats.push(default_diff_format(settings));
|
||||
formats.dedup();
|
||||
}
|
||||
formats
|
||||
@ -85,8 +89,8 @@ fn diff_formats_from_args(args: &DiffFormatArgs) -> Vec<DiffFormat> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn default_diff_format(ui: &Ui) -> DiffFormat {
|
||||
match ui.settings().config().get_string("diff.format").as_deref() {
|
||||
fn default_diff_format(settings: &UserSettings) -> DiffFormat {
|
||||
match settings.config().get_string("diff.format").as_deref() {
|
||||
Ok("summary") => DiffFormat::Summary,
|
||||
Ok("git") => DiffFormat::Git,
|
||||
Ok("color-words") => DiffFormat::ColorWords,
|
||||
|
Loading…
x
Reference in New Issue
Block a user