ok/jj
1
0
Fork 0
forked from mirrors/jj

cli: move show_patch() to diff_util

I think this belongs to the same category as show_diff().
This commit is contained in:
Yuya Nishihara 2022-12-14 14:40:24 +09:00
parent dff53b1200
commit dce45794df
2 changed files with 20 additions and 18 deletions

View file

@ -33,7 +33,7 @@ use jujutsu_lib::commit_builder::CommitBuilder;
use jujutsu_lib::dag_walk::topo_order_reverse;
use jujutsu_lib::git::{GitFetchError, GitRefUpdate};
use jujutsu_lib::index::IndexEntry;
use jujutsu_lib::matchers::{EverythingMatcher, Matcher};
use jujutsu_lib::matchers::EverythingMatcher;
use jujutsu_lib::op_store::{BranchTarget, RefTarget, WorkspaceId};
use jujutsu_lib::operation::Operation;
use jujutsu_lib::refs::{classify_branch_push_action, BranchPushAction, BranchPushUpdate};
@ -1586,7 +1586,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
}
if let Some(diff_format) = diff_format {
let mut formatter = ui.new_formatter(&mut buffer);
show_patch(
diff_util::show_patch(
formatter.as_mut(),
&workspace_command,
&commit,
@ -1612,7 +1612,7 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
let commit = store.get_commit(&index_entry.commit_id())?;
template.format(&commit, formatter)?;
if let Some(diff_format) = diff_format {
show_patch(
diff_util::show_patch(
formatter,
&workspace_command,
&commit,
@ -1647,20 +1647,6 @@ fn cmd_log(ui: &mut Ui, command: &CommandHelper, args: &LogArgs) -> Result<(), C
Ok(())
}
fn show_patch(
formatter: &mut dyn Formatter,
workspace_command: &WorkspaceCommandHelper,
commit: &Commit,
matcher: &dyn Matcher,
format: DiffFormat,
) -> Result<(), CommandError> {
let parents = commit.parents();
let from_tree = merge_commit_trees(workspace_command.repo().as_repo_ref(), &parents);
let to_tree = commit.tree();
let diff_iterator = from_tree.diff(&to_tree, matcher);
diff_util::show_diff(formatter, workspace_command, diff_iterator, format)
}
fn cmd_obslog(ui: &mut Ui, command: &CommandHelper, args: &ObslogArgs) -> Result<(), CommandError> {
let workspace_command = command.workspace_helper(ui)?;

View file

@ -20,12 +20,14 @@ use std::sync::Arc;
use clap::ArgGroup;
use itertools::Itertools;
use jujutsu_lib::backend::TreeValue;
use jujutsu_lib::commit::Commit;
use jujutsu_lib::diff::{Diff, DiffHunk};
use jujutsu_lib::files::DiffLine;
use jujutsu_lib::matchers::Matcher;
use jujutsu_lib::repo::ReadonlyRepo;
use jujutsu_lib::repo_path::RepoPath;
use jujutsu_lib::tree::TreeDiffIterator;
use jujutsu_lib::{conflicts, diff, files, tree};
use jujutsu_lib::{conflicts, diff, files, rewrite, tree};
use crate::cli_util::{CommandError, WorkspaceCommandHelper};
use crate::formatter::{Formatter, PlainTextFormatter};
@ -89,6 +91,20 @@ pub fn show_diff(
Ok(())
}
pub fn show_patch(
formatter: &mut dyn Formatter,
workspace_command: &WorkspaceCommandHelper,
commit: &Commit,
matcher: &dyn Matcher,
format: DiffFormat,
) -> Result<(), CommandError> {
let parents = commit.parents();
let from_tree = rewrite::merge_commit_trees(workspace_command.repo().as_repo_ref(), &parents);
let to_tree = commit.tree();
let diff_iterator = from_tree.diff(&to_tree, matcher);
show_diff(formatter, workspace_command, diff_iterator, format)
}
pub fn diff_as_bytes(
workspace_command: &WorkspaceCommandHelper,
tree_diff: TreeDiffIterator,