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
@@ -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,14 +1488,39 @@ fn cmd_diff(
let repo = repo_command.repo();
let matcher =
matcher_from_values(ui, repo.working_copy_path(), sub_matches.values_of("paths"))?;
+ 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)?;
- } else if sub_matches.is_present("git") {
+ }
+ Format::Git => {
show_git_diff(ui, repo, from_tree.diff(&to_tree, matcher.as_ref()))?;
- } else {
+ }
+ Format::ColorWords => {
show_diff(ui, repo, from_tree.diff(&to_tree, matcher.as_ref()))?;
}
+ }
Ok(())
}
