Skip to content

Commit

Permalink
diff: pass tree diff stream in to inner show_*() functions as before
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Aug 22, 2024
1 parent a9e625b commit 88ce7b0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 71 deletions.
33 changes: 5 additions & 28 deletions cli/src/commit_templater.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ impl TreeDiff {
from_tree: commit.parent_tree(repo)?,
to_tree: commit.tree()?,
matcher,
copy_records: Default::default(),
copy_records: Default::default(), // TODO: real copy tracking
})
}

Expand Down Expand Up @@ -1372,20 +1372,8 @@ fn builtin_tree_diff_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, T
let template = (self_property, context_property)
.map(|(diff, context)| {
let context = context.unwrap_or(diff_util::DEFAULT_CONTEXT_LINES);
// TODO: don't pass separate copies of from_tree/to_tree/matcher
let from_tree = diff.from_tree.clone();
let to_tree = diff.to_tree.clone();
let matcher = diff.matcher.clone();
diff.into_formatted(move |formatter, store, _tree_diff| {
diff_util::show_git_diff(
formatter,
store,
&from_tree,
&to_tree,
matcher.as_ref(),
&Default::default(), // TODO: real copy tracking
context,
)
diff.into_formatted(move |formatter, store, tree_diff| {
diff_util::show_git_diff(formatter, store, tree_diff, context)
})
})
.into_template();
Expand All @@ -1412,19 +1400,8 @@ fn builtin_tree_diff_methods<'repo>() -> CommitTemplateBuildMethodFnMap<'repo, T
let path_converter = language.path_converter;
let template = self_property
.map(move |diff| {
// TODO: don't pass separate copies of from_tree/to_tree/matcher
let from_tree = diff.from_tree.clone();
let to_tree = diff.to_tree.clone();
let matcher = diff.matcher.clone();
diff.into_formatted(move |formatter, _store, _tree_diff| {
diff_util::show_diff_summary(
formatter,
path_converter,
&from_tree,
&to_tree,
matcher.as_ref(),
&Default::default(), // TODO: real copy tracking
)
diff.into_formatted(move |formatter, _store, tree_diff| {
diff_util::show_diff_summary(formatter, tree_diff, path_converter)
})
})
.into_template();
Expand Down
55 changes: 12 additions & 43 deletions cli/src/diff_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,45 +285,29 @@ impl<'a> DiffRenderer<'a> {
for format in &self.formats {
match format {
DiffFormat::Summary => {
show_diff_summary(
formatter,
path_converter,
from_tree,
to_tree,
matcher,
copy_records,
)?;
let tree_diff =
from_tree.diff_stream_with_copies(to_tree, matcher, copy_records);
show_diff_summary(formatter, tree_diff, path_converter)?;
}
DiffFormat::Stat => {
let tree_diff =
from_tree.diff_stream_with_copies(to_tree, matcher, copy_records);
show_diff_stat(formatter, store, tree_diff, path_converter, width)?;
}
DiffFormat::Types => {
show_types(
formatter,
path_converter,
from_tree,
to_tree,
matcher,
copy_records,
)?;
let tree_diff =
from_tree.diff_stream_with_copies(to_tree, matcher, copy_records);
show_types(formatter, tree_diff, path_converter)?;
}
DiffFormat::NameOnly => {
let tree_diff =
from_tree.diff_stream_with_copies(to_tree, matcher, copy_records);
show_names(formatter, tree_diff, path_converter)?;
}
DiffFormat::Git { context } => {
show_git_diff(
formatter,
store,
from_tree,
to_tree,
matcher,
copy_records,
*context,
)?;
let tree_diff =
from_tree.diff_stream_with_copies(to_tree, matcher, copy_records);
show_git_diff(formatter, store, tree_diff, *context)?;
}
DiffFormat::ColorWords(options) => {
let tree_diff =
Expand Down Expand Up @@ -1244,15 +1228,10 @@ fn show_diff_line_tokens(
pub fn show_git_diff(
formatter: &mut dyn Formatter,
store: &Store,
from_tree: &MergedTree,
to_tree: &MergedTree,
matcher: &dyn Matcher,
copy_records: &CopyRecords,
tree_diff: BoxStream<CopiesTreeDiffEntry>,
num_context_lines: usize,
) -> Result<(), DiffRenderError> {
let tree_diff = from_tree.diff_stream_with_copies(to_tree, matcher, copy_records);
let mut diff_stream = materialized_diff_stream(store, tree_diff);

async {
while let Some(MaterializedTreeDiffEntry { path, values }) = diff_stream.next().await {
let left_path = path.source();
Expand Down Expand Up @@ -1345,14 +1324,9 @@ pub fn show_git_diff(
#[instrument(skip_all)]
pub fn show_diff_summary(
formatter: &mut dyn Formatter,
mut tree_diff: BoxStream<CopiesTreeDiffEntry>,
path_converter: &RepoPathUiConverter,
from_tree: &MergedTree,
to_tree: &MergedTree,
matcher: &dyn Matcher,
copy_records: &CopyRecords,
) -> Result<(), DiffRenderError> {
let mut tree_diff = from_tree.diff_stream_with_copies(to_tree, matcher, copy_records);

async {
while let Some(CopiesTreeDiffEntry { path, values }) = tree_diff.next().await {
let (before, after) = values?;
Expand Down Expand Up @@ -1507,14 +1481,9 @@ pub fn show_diff_stat(

pub fn show_types(
formatter: &mut dyn Formatter,
mut tree_diff: BoxStream<CopiesTreeDiffEntry>,
path_converter: &RepoPathUiConverter,
from_tree: &MergedTree,
to_tree: &MergedTree,
matcher: &dyn Matcher,
copy_records: &CopyRecords,
) -> Result<(), DiffRenderError> {
let mut tree_diff = from_tree.diff_stream_with_copies(to_tree, matcher, copy_records);

async {
while let Some(CopiesTreeDiffEntry { path, values }) = tree_diff.next().await {
let (before, after) = values?;
Expand Down

0 comments on commit 88ce7b0

Please sign in to comment.