From 71e29792f67ab4e8f68c20af48a346ebe4cd40cd Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Mon, 28 Mar 2022 16:46:00 +0900 Subject: [PATCH] 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. --- src/commands.rs | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 27ce62131..b1b56de88 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -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(()) }