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

diff: pass repo.store() to inner show_*_diff() functions, reorder arguments

This will help remove lifetimed &dyn Repo from diff object in templater.

Function arguments are reordered in a way that all show_*() functions have
common parameters in the same order.
This commit is contained in:
Yuya Nishihara 2024-07-15 20:35:36 +09:00
parent 18d60ad0d3
commit 4a63a1f660

View file

@ -246,7 +246,7 @@ impl<'a> DiffRenderer<'a> {
to_tree: &MergedTree, to_tree: &MergedTree,
matcher: &dyn Matcher, matcher: &dyn Matcher,
) -> Result<(), DiffRenderError> { ) -> Result<(), DiffRenderError> {
let repo = self.repo; let store = self.repo.store();
let path_converter = self.path_converter; let path_converter = self.path_converter;
for format in &self.formats { for format in &self.formats {
match format { match format {
@ -258,7 +258,7 @@ impl<'a> DiffRenderer<'a> {
let tree_diff = from_tree.diff_stream(to_tree, matcher); let tree_diff = from_tree.diff_stream(to_tree, matcher);
// TODO: In graph log, graph width should be subtracted // TODO: In graph log, graph width should be subtracted
let width = usize::from(ui.term_width().unwrap_or(80)); let width = usize::from(ui.term_width().unwrap_or(80));
show_diff_stat(repo, formatter, tree_diff, path_converter, width)?; show_diff_stat(formatter, store, tree_diff, path_converter, width)?;
} }
DiffFormat::Types => { DiffFormat::Types => {
let tree_diff = from_tree.diff_stream(to_tree, matcher); let tree_diff = from_tree.diff_stream(to_tree, matcher);
@ -270,11 +270,11 @@ impl<'a> DiffRenderer<'a> {
} }
DiffFormat::Git { context } => { DiffFormat::Git { context } => {
let tree_diff = from_tree.diff_stream(to_tree, matcher); let tree_diff = from_tree.diff_stream(to_tree, matcher);
show_git_diff(repo, formatter, *context, tree_diff)?; show_git_diff(formatter, store, tree_diff, *context)?;
} }
DiffFormat::ColorWords { context } => { DiffFormat::ColorWords { context } => {
let tree_diff = from_tree.diff_stream(to_tree, matcher); let tree_diff = from_tree.diff_stream(to_tree, matcher);
show_color_words_diff(repo, formatter, *context, tree_diff, path_converter)?; show_color_words_diff(formatter, store, tree_diff, path_converter, *context)?;
} }
DiffFormat::Tool(tool) => { DiffFormat::Tool(tool) => {
match tool.diff_invocation_mode { match tool.diff_invocation_mode {
@ -282,11 +282,11 @@ impl<'a> DiffRenderer<'a> {
let tree_diff = from_tree.diff_stream(to_tree, matcher); let tree_diff = from_tree.diff_stream(to_tree, matcher);
show_file_by_file_diff( show_file_by_file_diff(
ui, ui,
repo,
formatter, formatter,
tool, store,
tree_diff, tree_diff,
path_converter, path_converter,
tool,
) )
} }
DiffToolMode::Dir => { DiffToolMode::Dir => {
@ -527,14 +527,14 @@ fn basic_diff_file_type(value: &MaterializedTreeValue) -> &'static str {
} }
pub fn show_color_words_diff( pub fn show_color_words_diff(
repo: &dyn Repo,
formatter: &mut dyn Formatter, formatter: &mut dyn Formatter,
num_context_lines: usize, store: &Store,
tree_diff: TreeDiffStream, tree_diff: TreeDiffStream,
path_converter: &RepoPathUiConverter, path_converter: &RepoPathUiConverter,
num_context_lines: usize,
) -> Result<(), DiffRenderError> { ) -> Result<(), DiffRenderError> {
formatter.push_label("diff")?; formatter.push_label("diff")?;
let mut diff_stream = materialized_diff_stream(repo.store(), tree_diff); let mut diff_stream = materialized_diff_stream(store, tree_diff);
async { async {
while let Some((path, diff)) = diff_stream.next().await { while let Some((path, diff)) = diff_stream.next().await {
let ui_path = path_converter.format_file_path(&path); let ui_path = path_converter.format_file_path(&path);
@ -662,11 +662,11 @@ pub fn show_color_words_diff(
pub fn show_file_by_file_diff( pub fn show_file_by_file_diff(
ui: &Ui, ui: &Ui,
repo: &dyn Repo,
formatter: &mut dyn Formatter, formatter: &mut dyn Formatter,
tool: &ExternalMergeTool, store: &Store,
tree_diff: TreeDiffStream, tree_diff: TreeDiffStream,
path_converter: &RepoPathUiConverter, path_converter: &RepoPathUiConverter,
tool: &ExternalMergeTool,
) -> Result<(), DiffRenderError> { ) -> Result<(), DiffRenderError> {
fn create_file( fn create_file(
path: &RepoPath, path: &RepoPath,
@ -683,7 +683,7 @@ pub fn show_file_by_file_diff(
let temp_dir = new_utf8_temp_dir("jj-diff-")?; let temp_dir = new_utf8_temp_dir("jj-diff-")?;
let left_wc_dir = temp_dir.path().join("left"); let left_wc_dir = temp_dir.path().join("left");
let right_wc_dir = temp_dir.path().join("right"); let right_wc_dir = temp_dir.path().join("right");
let mut diff_stream = materialized_diff_stream(repo.store(), tree_diff); let mut diff_stream = materialized_diff_stream(store, tree_diff);
async { async {
while let Some((path, diff)) = diff_stream.next().await { while let Some((path, diff)) = diff_stream.next().await {
let ui_path = path_converter.format_file_path(&path); let ui_path = path_converter.format_file_path(&path);
@ -1020,14 +1020,14 @@ fn materialized_diff_stream<'a>(
} }
pub fn show_git_diff( pub fn show_git_diff(
repo: &dyn Repo,
formatter: &mut dyn Formatter, formatter: &mut dyn Formatter,
num_context_lines: usize, store: &Store,
tree_diff: TreeDiffStream, tree_diff: TreeDiffStream,
num_context_lines: usize,
) -> Result<(), DiffRenderError> { ) -> Result<(), DiffRenderError> {
formatter.push_label("diff")?; formatter.push_label("diff")?;
let mut diff_stream = materialized_diff_stream(repo.store(), tree_diff); let mut diff_stream = materialized_diff_stream(store, tree_diff);
async { async {
while let Some((path, diff)) = diff_stream.next().await { while let Some((path, diff)) = diff_stream.next().await {
let path_string = path.as_internal_file_string(); let path_string = path.as_internal_file_string();
@ -1163,8 +1163,8 @@ fn get_diff_stat(
} }
pub fn show_diff_stat( pub fn show_diff_stat(
repo: &dyn Repo,
formatter: &mut dyn Formatter, formatter: &mut dyn Formatter,
store: &Store,
tree_diff: TreeDiffStream, tree_diff: TreeDiffStream,
path_converter: &RepoPathUiConverter, path_converter: &RepoPathUiConverter,
display_width: usize, display_width: usize,
@ -1173,7 +1173,7 @@ pub fn show_diff_stat(
let mut max_path_width = 0; let mut max_path_width = 0;
let mut max_diffs = 0; let mut max_diffs = 0;
let mut diff_stream = materialized_diff_stream(repo.store(), tree_diff); let mut diff_stream = materialized_diff_stream(store, tree_diff);
async { async {
while let Some((repo_path, diff)) = diff_stream.next().await { while let Some((repo_path, diff)) = diff_stream.next().await {
let (left, right) = diff?; let (left, right) = diff?;