forked from mirrors/jj
cli: make default diff format configurable
This change adds a `diff.format` config option, which can be set to "git", "color-words", or "summary". Closes #33.
This commit is contained in:
parent
7add35999f
commit
ebcd946732
1 changed files with 39 additions and 7 deletions
|
@ -652,6 +652,13 @@ With the `--from` and/or `--to` options, shows the difference from/to the given
|
|||
.conflicts_with("summary")
|
||||
.help("Show a Git-format diff"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("color-words")
|
||||
.long("color-words")
|
||||
.conflicts_with("summary")
|
||||
.conflicts_with("git")
|
||||
.help("Show a word-level diff with changes indicated only by color"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("revision")
|
||||
.long("revision")
|
||||
|
@ -1481,13 +1488,38 @@ fn cmd_diff(
|
|||
let repo = repo_command.repo();
|
||||
let matcher =
|
||||
matcher_from_values(ui, repo.working_copy_path(), sub_matches.values_of("paths"))?;
|
||||
if sub_matches.is_present("summary") {
|
||||
let summary = from_tree.diff_summary(&to_tree, matcher.as_ref());
|
||||
show_diff_summary(ui, repo.working_copy_path(), &summary)?;
|
||||
} else if sub_matches.is_present("git") {
|
||||
show_git_diff(ui, repo, from_tree.diff(&to_tree, matcher.as_ref()))?;
|
||||
} else {
|
||||
show_diff(ui, repo, from_tree.diff(&to_tree, matcher.as_ref()))?;
|
||||
enum Format {
|
||||
Summary,
|
||||
Git,
|
||||
ColorWords,
|
||||
}
|
||||
let format = {
|
||||
if sub_matches.is_present("summary") {
|
||||
Format::Summary
|
||||
} else if sub_matches.is_present("git") {
|
||||
Format::Git
|
||||
} else if sub_matches.is_present("color-words") {
|
||||
Format::ColorWords
|
||||
} else {
|
||||
match ui.settings().config().get_str("diff.format") {
|
||||
Ok(value) if &value == "summary" => Format::Summary,
|
||||
Ok(value) if &value == "git" => Format::Git,
|
||||
Ok(value) if &value == "color-words" => Format::ColorWords,
|
||||
_ => Format::ColorWords,
|
||||
}
|
||||
}
|
||||
};
|
||||
match format {
|
||||
Format::Summary => {
|
||||
let summary = from_tree.diff_summary(&to_tree, matcher.as_ref());
|
||||
show_diff_summary(ui, repo.working_copy_path(), &summary)?;
|
||||
}
|
||||
Format::Git => {
|
||||
show_git_diff(ui, repo, from_tree.diff(&to_tree, matcher.as_ref()))?;
|
||||
}
|
||||
Format::ColorWords => {
|
||||
show_diff(ui, repo, from_tree.diff(&to_tree, matcher.as_ref()))?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue