cli: extract a function for showing a word-level diff
I'm about to add support for Git's unified diff format next and
`cmd_diff()` was already really long.
@@ -53,7 +53,7 @@ use jujutsu_lib::rewrite::{back_out_commit, merge_commit_trees, rebase_commit, D
use jujutsu_lib::settings::UserSettings;
use jujutsu_lib::store::Store;
use jujutsu_lib::transaction::Transaction;
-use jujutsu_lib::tree::{Diff, DiffSummary};
+use jujutsu_lib::tree::{Diff, DiffSummary, TreeDiffIterator};
use jujutsu_lib::working_copy::{CheckoutStats, WorkingCopy};
use jujutsu_lib::{conflicts, files, git, revset};
use maplit::{hashmap, hashset};
@@ -1477,9 +1477,19 @@ fn cmd_diff(
let summary = from_tree.diff_summary(&to_tree, matcher.as_ref());
show_diff_summary(ui, repo.working_copy_path(), &summary)?;
} else {
+ show_diff(ui, repo, from_tree.diff(&to_tree, matcher.as_ref()))?;
+ }
+ Ok(())
+}
+
+fn show_diff(
+ ui: &mut Ui,
+ repo: &Arc<ReadonlyRepo>,
+ tree_diff: TreeDiffIterator,
+) -> Result<(), CommandError> {
let mut formatter = ui.stdout_formatter();
formatter.add_label(String::from("diff"))?;
- for (path, diff) in from_tree.diff(&to_tree, matcher.as_ref()) {
+ for (path, diff) in tree_diff {
let ui_path = ui.format_file_path(repo.working_copy_path(), &path);
match diff {
Diff::Added(TreeValue::Normal {
@@ -1601,7 +1611,6 @@ fn cmd_diff(
}
}
formatter.remove_label()?;
- }
Ok(())
}
