From 8d3ad340099dcd4b5850b22e9d95dc60e77e53e5 Mon Sep 17 00:00:00 2001 From: Martin von Zweigbergk Date: Fri, 17 Dec 2021 11:18:53 -0800 Subject: [PATCH] cli: extract function for showing diff style based on args and config I'm about to add a `jj show` command (like `git show`), and that'll have the same arguments and config for deciding which style of diff to show. --- src/commands.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index d9274405f..533912e4b 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -1744,6 +1744,18 @@ fn cmd_diff(ui: &mut Ui, command: &CommandHelper, args: &ArgMatches) -> Result<( let repo = workspace_command.repo(); let workspace_root = workspace_command.workspace_root(); let matcher = matcher_from_values(ui, workspace_root, args.values_of("paths"))?; + let diff_iterator = from_tree.diff(&to_tree, matcher.as_ref()); + show_diff(ui, repo, workspace_root, args, diff_iterator)?; + Ok(()) +} + +fn show_diff( + ui: &mut Ui, + repo: &Arc, + workspace_root: &Path, + args: &ArgMatches, + tree_diff: TreeDiffIterator, +) -> Result<(), CommandError> { enum Format { Summary, Git, @@ -1765,21 +1777,19 @@ fn cmd_diff(ui: &mut Ui, command: &CommandHelper, args: &ArgMatches) -> Result<( } } }; - let diff_iterator = from_tree.diff(&to_tree, matcher.as_ref()); match format { Format::Summary => { - show_diff_summary(ui, workspace_root, diff_iterator)?; + show_diff_summary(ui, workspace_root, tree_diff)?; } Format::Git => { - show_git_diff(ui, repo, diff_iterator)?; + show_git_diff(ui, repo, tree_diff)?; } Format::ColorWords => { - show_color_words_diff(ui, workspace_root, repo, diff_iterator)?; + show_color_words_diff(ui, workspace_root, repo, tree_diff)?; } } Ok(()) } - fn diff_content( repo: &Arc, path: &RepoPath,