diff: pass formatter to show_diff() as argument

We might want to split show_diff() into config/option handling part and
diff displayer function, but I'm not sure. Since some of the show_diff
functions depends on ui, we can't isolate show_diff() from the ui object
anyway.

  let opts = parse_diff_option(ui, args);  // map config/option to diff opts
  show_diff(ui, formatter, opts, ...);  // would be nice if ui could be removed
This commit is contained in:
Yuya Nishihara 2022-03-28 17:59:08 +09:00 committed by Martin von Zweigbergk
parent c2fe008817
commit 9923bab3ba

View File

@ -1993,7 +1993,14 @@ fn cmd_diff(ui: &mut Ui, command: &CommandHelper, args: &DiffArgs) -> Result<(),
let workspace_root = workspace_command.workspace_root();
let matcher = matcher_from_values(ui, workspace_root, &args.paths)?;
let diff_iterator = from_tree.diff(&to_tree, matcher.as_ref());
show_diff(ui, repo, workspace_root, &args.format, diff_iterator)?;
show_diff(
ui,
ui.stdout_formatter().as_mut(),
repo,
workspace_root,
&args.format,
diff_iterator,
)?;
Ok(())
}
@ -2023,13 +2030,23 @@ fn cmd_show(ui: &mut Ui, command: &CommandHelper, args: &ShowArgs) -> Result<(),
&workspace_command.workspace_id(),
template_string,
);
template.format(&commit, ui.stdout_formatter().as_mut())?;
show_diff(ui, repo, workspace_root, &args.format, diff_iterator)?;
let mut formatter = ui.stdout_formatter();
let formatter = formatter.as_mut();
template.format(&commit, formatter)?;
show_diff(
ui,
formatter,
repo,
workspace_root,
&args.format,
diff_iterator,
)?;
Ok(())
}
fn show_diff(
ui: &mut Ui,
ui: &Ui,
formatter: &mut dyn Formatter,
repo: &Arc<ReadonlyRepo>,
workspace_root: &Path,
args: &DiffFormat,
@ -2056,8 +2073,6 @@ fn show_diff(
}
}
};
let mut formatter = ui.stdout_formatter();
let formatter = formatter.as_mut();
match format {
Format::Summary => {
show_diff_summary(ui, formatter, workspace_root, tree_diff)?;