mirror of
https://github.com/martinvonz/jj.git
synced 2025-02-11 15:07:06 +00:00
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")
|
.conflicts_with("summary")
|
||||||
.help("Show a Git-format diff"),
|
.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(
|
||||||
Arg::with_name("revision")
|
Arg::with_name("revision")
|
||||||
.long("revision")
|
.long("revision")
|
||||||
|
@ -1481,14 +1488,39 @@ fn cmd_diff(
|
||||||
let repo = repo_command.repo();
|
let repo = repo_command.repo();
|
||||||
let matcher =
|
let matcher =
|
||||||
matcher_from_values(ui, repo.working_copy_path(), sub_matches.values_of("paths"))?;
|
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") {
|
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());
|
let summary = from_tree.diff_summary(&to_tree, matcher.as_ref());
|
||||||
show_diff_summary(ui, repo.working_copy_path(), &summary)?;
|
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()))?;
|
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()))?;
|
show_diff(ui, repo, from_tree.diff(&to_tree, matcher.as_ref()))?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue