mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-12 15:16:35 +00:00
diff: make show_diff_summary() reuse locked stdout formatter
This parepares for "log --patch" option, where the formatter will be passed as a function argument. Unlike diff/show, graphlog needs a temporary output buffer per commit.
This commit is contained in:
parent
e34dfe00df
commit
71e29792f6
1 changed files with 24 additions and 11 deletions
|
@ -2480,27 +2480,40 @@ fn show_diff_summary(
|
|||
workspace_root: &Path,
|
||||
tree_diff: TreeDiffIterator,
|
||||
) -> io::Result<()> {
|
||||
ui.stdout_formatter().add_label(String::from("diff"))?;
|
||||
let mut formatter = ui.stdout_formatter();
|
||||
formatter.add_label(String::from("diff"))?;
|
||||
for (repo_path, diff) in tree_diff {
|
||||
match diff {
|
||||
tree::Diff::Modified(_, _) => {
|
||||
ui.stdout_formatter().add_label(String::from("modified"))?;
|
||||
writeln!(ui, "M {}", ui.format_file_path(workspace_root, &repo_path))?;
|
||||
ui.stdout_formatter().remove_label()?;
|
||||
formatter.add_label(String::from("modified"))?;
|
||||
writeln!(
|
||||
formatter,
|
||||
"M {}",
|
||||
ui.format_file_path(workspace_root, &repo_path)
|
||||
)?;
|
||||
formatter.remove_label()?;
|
||||
}
|
||||
tree::Diff::Added(_) => {
|
||||
ui.stdout_formatter().add_label(String::from("added"))?;
|
||||
writeln!(ui, "A {}", ui.format_file_path(workspace_root, &repo_path))?;
|
||||
ui.stdout_formatter().remove_label()?;
|
||||
formatter.add_label(String::from("added"))?;
|
||||
writeln!(
|
||||
formatter,
|
||||
"A {}",
|
||||
ui.format_file_path(workspace_root, &repo_path)
|
||||
)?;
|
||||
formatter.remove_label()?;
|
||||
}
|
||||
tree::Diff::Removed(_) => {
|
||||
ui.stdout_formatter().add_label(String::from("removed"))?;
|
||||
writeln!(ui, "R {}", ui.format_file_path(workspace_root, &repo_path))?;
|
||||
ui.stdout_formatter().remove_label()?;
|
||||
formatter.add_label(String::from("removed"))?;
|
||||
writeln!(
|
||||
formatter,
|
||||
"R {}",
|
||||
ui.format_file_path(workspace_root, &repo_path)
|
||||
)?;
|
||||
formatter.remove_label()?;
|
||||
}
|
||||
}
|
||||
}
|
||||
ui.stdout_formatter().remove_label()?;
|
||||
formatter.remove_label()?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue