mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-29 23:57:51 +00:00
diff: extract inter-diff helper
This isn't as primitive as show_diff() or show_patch(), but there are three callers. Let's add a helper method to remove repo argument.
This commit is contained in:
parent
f473d7bb7e
commit
03487af192
4 changed files with 39 additions and 41 deletions
|
@ -16,8 +16,6 @@ use itertools::Itertools;
|
||||||
use jj_lib::commit::Commit;
|
use jj_lib::commit::Commit;
|
||||||
use jj_lib::dag_walk::topo_order_reverse_ok;
|
use jj_lib::dag_walk::topo_order_reverse_ok;
|
||||||
use jj_lib::matchers::EverythingMatcher;
|
use jj_lib::matchers::EverythingMatcher;
|
||||||
use jj_lib::repo::Repo;
|
|
||||||
use jj_lib::rewrite::rebase_to_dest_parent;
|
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use super::log::get_node_template;
|
use super::log::get_node_template;
|
||||||
|
@ -80,7 +78,6 @@ pub(crate) fn cmd_evolog(
|
||||||
args: &EvologArgs,
|
args: &EvologArgs,
|
||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
let workspace_command = command.workspace_helper(ui)?;
|
let workspace_command = command.workspace_helper(ui)?;
|
||||||
let repo = workspace_command.repo().as_ref();
|
|
||||||
|
|
||||||
let start_commit = workspace_command.resolve_single_rev(&args.revision)?;
|
let start_commit = workspace_command.resolve_single_rev(&args.revision)?;
|
||||||
|
|
||||||
|
@ -164,7 +161,7 @@ pub(crate) fn cmd_evolog(
|
||||||
if let Some(renderer) = &diff_renderer {
|
if let Some(renderer) = &diff_renderer {
|
||||||
let mut formatter = ui.new_formatter(&mut buffer);
|
let mut formatter = ui.new_formatter(&mut buffer);
|
||||||
let width = usize::saturating_sub(ui.term_width(), graph_width());
|
let width = usize::saturating_sub(ui.term_width(), graph_width());
|
||||||
show_predecessor_patch(ui, repo, renderer, formatter.as_mut(), &commit, width)?;
|
show_predecessor_patch(ui, renderer, formatter.as_mut(), &commit, width)?;
|
||||||
}
|
}
|
||||||
let node_symbol = format_template(ui, &Some(commit.clone()), &node_template);
|
let node_symbol = format_template(ui, &Some(commit.clone()), &node_template);
|
||||||
graph.add_node(
|
graph.add_node(
|
||||||
|
@ -180,7 +177,7 @@ pub(crate) fn cmd_evolog(
|
||||||
.write(formatter, |formatter| template.format(&commit, formatter))?;
|
.write(formatter, |formatter| template.format(&commit, formatter))?;
|
||||||
if let Some(renderer) = &diff_renderer {
|
if let Some(renderer) = &diff_renderer {
|
||||||
let width = ui.term_width();
|
let width = ui.term_width();
|
||||||
show_predecessor_patch(ui, repo, renderer, formatter, &commit, width)?;
|
show_predecessor_patch(ui, renderer, formatter, &commit, width)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -190,22 +187,18 @@ pub(crate) fn cmd_evolog(
|
||||||
|
|
||||||
fn show_predecessor_patch(
|
fn show_predecessor_patch(
|
||||||
ui: &Ui,
|
ui: &Ui,
|
||||||
repo: &dyn Repo,
|
|
||||||
renderer: &DiffRenderer,
|
renderer: &DiffRenderer,
|
||||||
formatter: &mut dyn Formatter,
|
formatter: &mut dyn Formatter,
|
||||||
commit: &Commit,
|
commit: &Commit,
|
||||||
width: usize,
|
width: usize,
|
||||||
) -> Result<(), CommandError> {
|
) -> Result<(), CommandError> {
|
||||||
let predecessors: Vec<_> = commit.predecessors().try_collect()?;
|
let predecessors: Vec<_> = commit.predecessors().try_collect()?;
|
||||||
let predecessor_tree = rebase_to_dest_parent(repo, &predecessors, commit)?;
|
renderer.show_inter_diff(
|
||||||
let tree = commit.tree()?;
|
|
||||||
renderer.show_diff(
|
|
||||||
ui,
|
ui,
|
||||||
formatter,
|
formatter,
|
||||||
&predecessor_tree,
|
&predecessors,
|
||||||
&tree,
|
&commit,
|
||||||
&EverythingMatcher,
|
&EverythingMatcher,
|
||||||
&Default::default(),
|
|
||||||
width,
|
width,
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
use std::slice;
|
use std::slice;
|
||||||
|
|
||||||
use clap::ArgGroup;
|
use clap::ArgGroup;
|
||||||
use jj_lib::rewrite::rebase_to_dest_parent;
|
|
||||||
use tracing::instrument;
|
use tracing::instrument;
|
||||||
|
|
||||||
use crate::cli_util::CommandHelper;
|
use crate::cli_util::CommandHelper;
|
||||||
|
@ -55,25 +54,17 @@ pub(crate) fn cmd_interdiff(
|
||||||
let from =
|
let from =
|
||||||
workspace_command.resolve_single_rev(args.from.as_ref().unwrap_or(&RevisionArg::AT))?;
|
workspace_command.resolve_single_rev(args.from.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||||
let to = workspace_command.resolve_single_rev(args.to.as_ref().unwrap_or(&RevisionArg::AT))?;
|
let to = workspace_command.resolve_single_rev(args.to.as_ref().unwrap_or(&RevisionArg::AT))?;
|
||||||
|
|
||||||
let from_tree = rebase_to_dest_parent(
|
|
||||||
workspace_command.repo().as_ref(),
|
|
||||||
slice::from_ref(&from),
|
|
||||||
&to,
|
|
||||||
)?;
|
|
||||||
let to_tree = to.tree()?;
|
|
||||||
let matcher = workspace_command
|
let matcher = workspace_command
|
||||||
.parse_file_patterns(&args.paths)?
|
.parse_file_patterns(&args.paths)?
|
||||||
.to_matcher();
|
.to_matcher();
|
||||||
let diff_renderer = workspace_command.diff_renderer_for(&args.format)?;
|
let diff_renderer = workspace_command.diff_renderer_for(&args.format)?;
|
||||||
ui.request_pager();
|
ui.request_pager();
|
||||||
diff_renderer.show_diff(
|
diff_renderer.show_inter_diff(
|
||||||
ui,
|
ui,
|
||||||
ui.stdout_formatter().as_mut(),
|
ui.stdout_formatter().as_mut(),
|
||||||
&from_tree,
|
slice::from_ref(&from),
|
||||||
&to_tree,
|
&to,
|
||||||
matcher.as_ref(),
|
matcher.as_ref(),
|
||||||
&Default::default(),
|
|
||||||
ui.term_width(),
|
ui.term_width(),
|
||||||
)?;
|
)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -34,7 +34,6 @@ use jj_lib::repo::ReadonlyRepo;
|
||||||
use jj_lib::repo::Repo;
|
use jj_lib::repo::Repo;
|
||||||
use jj_lib::revset;
|
use jj_lib::revset;
|
||||||
use jj_lib::revset::RevsetIteratorExt as _;
|
use jj_lib::revset::RevsetIteratorExt as _;
|
||||||
use jj_lib::rewrite::rebase_to_dest_parent;
|
|
||||||
|
|
||||||
use crate::cli_util::short_change_hash;
|
use crate::cli_util::short_change_hash;
|
||||||
use crate::cli_util::short_operation_hash;
|
use crate::cli_util::short_operation_hash;
|
||||||
|
@ -260,7 +259,6 @@ pub fn show_op_diff(
|
||||||
show_change_diff(
|
show_change_diff(
|
||||||
ui,
|
ui,
|
||||||
formatter.as_mut(),
|
formatter.as_mut(),
|
||||||
current_repo,
|
|
||||||
diff_renderer,
|
diff_renderer,
|
||||||
modified_change,
|
modified_change,
|
||||||
width,
|
width,
|
||||||
|
@ -287,14 +285,7 @@ pub fn show_op_diff(
|
||||||
)?;
|
)?;
|
||||||
if let Some(diff_renderer) = &diff_renderer {
|
if let Some(diff_renderer) = &diff_renderer {
|
||||||
let width = ui.term_width();
|
let width = ui.term_width();
|
||||||
show_change_diff(
|
show_change_diff(ui, formatter, diff_renderer, modified_change, width)?;
|
||||||
ui,
|
|
||||||
formatter,
|
|
||||||
current_repo,
|
|
||||||
diff_renderer,
|
|
||||||
modified_change,
|
|
||||||
width,
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -563,7 +554,6 @@ fn compute_operation_commits_diff(
|
||||||
fn show_change_diff(
|
fn show_change_diff(
|
||||||
ui: &Ui,
|
ui: &Ui,
|
||||||
formatter: &mut dyn Formatter,
|
formatter: &mut dyn Formatter,
|
||||||
repo: &dyn Repo,
|
|
||||||
diff_renderer: &DiffRenderer,
|
diff_renderer: &DiffRenderer,
|
||||||
change: &ModifiedChange,
|
change: &ModifiedChange,
|
||||||
width: usize,
|
width: usize,
|
||||||
|
@ -572,15 +562,12 @@ fn show_change_diff(
|
||||||
(predecessors @ ([] | [_]), [commit]) => {
|
(predecessors @ ([] | [_]), [commit]) => {
|
||||||
// New or modified change. If the modification involved a rebase,
|
// New or modified change. If the modification involved a rebase,
|
||||||
// show diffs from the rebased tree.
|
// show diffs from the rebased tree.
|
||||||
let predecessor_tree = rebase_to_dest_parent(repo, predecessors, commit)?;
|
diff_renderer.show_inter_diff(
|
||||||
let tree = commit.tree()?;
|
|
||||||
diff_renderer.show_diff(
|
|
||||||
ui,
|
ui,
|
||||||
formatter,
|
formatter,
|
||||||
&predecessor_tree,
|
predecessors,
|
||||||
&tree,
|
commit,
|
||||||
&EverythingMatcher,
|
&EverythingMatcher,
|
||||||
&Default::default(),
|
|
||||||
width,
|
width,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,6 +51,7 @@ use jj_lib::object_id::ObjectId;
|
||||||
use jj_lib::repo::Repo;
|
use jj_lib::repo::Repo;
|
||||||
use jj_lib::repo_path::RepoPath;
|
use jj_lib::repo_path::RepoPath;
|
||||||
use jj_lib::repo_path::RepoPathUiConverter;
|
use jj_lib::repo_path::RepoPathUiConverter;
|
||||||
|
use jj_lib::rewrite::rebase_to_dest_parent;
|
||||||
use jj_lib::settings::ConfigResultExt as _;
|
use jj_lib::settings::ConfigResultExt as _;
|
||||||
use jj_lib::settings::UserSettings;
|
use jj_lib::settings::UserSettings;
|
||||||
use jj_lib::store::Store;
|
use jj_lib::store::Store;
|
||||||
|
@ -357,6 +358,32 @@ impl<'a> DiffRenderer<'a> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generates diff between `from_commits` and `to_commit` based off their
|
||||||
|
/// parents. The `from_commits` will temporarily be rebased onto the
|
||||||
|
/// `to_commit` parents to exclude unrelated changes.
|
||||||
|
pub fn show_inter_diff(
|
||||||
|
&self,
|
||||||
|
ui: &Ui,
|
||||||
|
formatter: &mut dyn Formatter,
|
||||||
|
from_commits: &[Commit],
|
||||||
|
to_commit: &Commit,
|
||||||
|
matcher: &dyn Matcher,
|
||||||
|
width: usize,
|
||||||
|
) -> Result<(), DiffRenderError> {
|
||||||
|
let from_tree = rebase_to_dest_parent(self.repo, from_commits, to_commit)?;
|
||||||
|
let to_tree = to_commit.tree()?;
|
||||||
|
let copy_records = CopyRecords::default(); // TODO
|
||||||
|
self.show_diff(
|
||||||
|
ui,
|
||||||
|
formatter,
|
||||||
|
&from_tree,
|
||||||
|
&to_tree,
|
||||||
|
matcher,
|
||||||
|
©_records,
|
||||||
|
width,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/// Generates diff of the given `commit` compared to its parents.
|
/// Generates diff of the given `commit` compared to its parents.
|
||||||
pub fn show_patch(
|
pub fn show_patch(
|
||||||
&self,
|
&self,
|
||||||
|
|
Loading…
Reference in a new issue