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

op diff: create formatter by show_op_diff() callers

This will help embed operation diffs in "op log".
This commit is contained in:
Yuya Nishihara 2024-09-03 17:54:58 +09:00
parent ea8f543d5a
commit 5bff5cdef0
2 changed files with 8 additions and 6 deletions

View file

@ -113,7 +113,8 @@ pub fn cmd_op_diff(
let commit_summary_template = tx.commit_summary_template(); let commit_summary_template = tx.commit_summary_template();
ui.request_pager(); ui.request_pager();
ui.stdout_formatter().with_label("op_log", |formatter| { let mut formatter = ui.stdout_formatter();
formatter.with_label("op_log", |formatter| {
write!(formatter, "From operation ")?; write!(formatter, "From operation ")?;
write!( write!(
formatter.labeled("id"), formatter.labeled("id"),
@ -152,6 +153,7 @@ pub fn cmd_op_diff(
show_op_diff( show_op_diff(
ui, ui,
formatter.as_mut(),
tx.repo(), tx.repo(),
&from_repo, &from_repo,
&to_repo, &to_repo,
@ -168,7 +170,8 @@ pub fn cmd_op_diff(
/// into it. /// into it.
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]
pub fn show_op_diff( pub fn show_op_diff(
ui: &mut Ui, ui: &Ui,
formatter: &mut dyn Formatter,
current_repo: &dyn Repo, current_repo: &dyn Repo,
from_repo: &Arc<ReadonlyRepo>, from_repo: &Arc<ReadonlyRepo>,
to_repo: &Arc<ReadonlyRepo>, to_repo: &Arc<ReadonlyRepo>,
@ -205,9 +208,6 @@ pub fn show_op_diff(
|change_id: &ChangeId| change_parents.get(change_id).unwrap().clone(), |change_id: &ChangeId| change_parents.get(change_id).unwrap().clone(),
); );
let mut formatter = ui.stdout_formatter();
let formatter = formatter.as_mut();
if !ordered_change_ids.is_empty() { if !ordered_change_ids.is_empty() {
writeln!(formatter)?; writeln!(formatter)?;
writeln!(formatter, "Changed commits:")?; writeln!(formatter, "Changed commits:")?;

View file

@ -81,10 +81,12 @@ pub fn cmd_op_show(
} }
ui.request_pager(); ui.request_pager();
template.format(&op, ui.stdout_formatter().as_mut())?; let mut formatter = ui.stdout_formatter();
template.format(&op, formatter.as_mut())?;
show_op_diff( show_op_diff(
ui, ui,
formatter.as_mut(),
repo.as_ref(), repo.as_ref(),
&parent_repo, &parent_repo,
&repo, &repo,