From e7d9e1ff9cfcc6c597c8c0fd8dac0103f66021ed Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Thu, 22 Dec 2022 16:08:37 +0900 Subject: [PATCH] cli: inline diff_util::diff_as_bytes() I'll add a similar function that uses show_patch() instead of show_diff(), and I don't think it's worth duplicating _as_bytes() part for that. --- src/commands.rs | 6 ++++-- src/diff_util.rs | 22 +--------------------- 2 files changed, 5 insertions(+), 23 deletions(-) diff --git a/src/commands.rs b/src/commands.rs index 373f7fa81..2e8b7e4ca 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -58,7 +58,7 @@ use crate::cli_util::{ }; use crate::config::FullCommandArgs; use crate::diff_util::{self, DiffFormat, DiffFormatArgs}; -use crate::formatter::Formatter; +use crate::formatter::{Formatter, PlainTextFormatter}; use crate::graphlog::{AsciiGraphDrawer, Edge}; use crate::progress::Progress; use crate::template_parser::TemplateParser; @@ -2464,7 +2464,9 @@ fn description_template_for_cmd_split( from_tree: &Tree, to_tree: &Tree, ) -> Result { - let diff_summary_bytes = diff_util::diff_as_bytes( + let mut diff_summary_bytes = Vec::new(); + diff_util::show_diff( + &mut PlainTextFormatter::new(&mut diff_summary_bytes), workspace_command, from_tree, to_tree, diff --git a/src/diff_util.rs b/src/diff_util.rs index 75e8edab0..3aed11674 100644 --- a/src/diff_util.rs +++ b/src/diff_util.rs @@ -29,7 +29,7 @@ use jujutsu_lib::tree::{Tree, TreeDiffIterator}; use jujutsu_lib::{conflicts, diff, files, rewrite, tree}; use crate::cli_util::{CommandError, WorkspaceCommandHelper}; -use crate::formatter::{Formatter, PlainTextFormatter}; +use crate::formatter::Formatter; use crate::ui::Ui; #[derive(clap::Args, Clone, Debug)] @@ -139,26 +139,6 @@ pub fn show_patch( ) } -pub fn diff_as_bytes( - workspace_command: &WorkspaceCommandHelper, - from_tree: &Tree, - to_tree: &Tree, - matcher: &dyn Matcher, - formats: &[DiffFormat], -) -> Result, CommandError> { - let mut diff_bytes: Vec = vec![]; - let mut formatter = PlainTextFormatter::new(&mut diff_bytes); - show_diff( - &mut formatter, - workspace_command, - from_tree, - to_tree, - matcher, - formats, - )?; - Ok(diff_bytes) -} - fn show_color_words_diff_hunks( left: &[u8], right: &[u8],