Compare commits

...

1 Commits

Author SHA1 Message Date
Agus Zubiaga
f3ffbcc5ab commit view: Join file diff tasks
Co-authored-by: MrSubidubi <dev@bahn.sh>
2025-12-10 12:02:47 -03:00

View File

@@ -222,66 +222,75 @@ impl CommitView {
let repository_clone = repository.clone(); let repository_clone = repository.clone();
cx.spawn(async move |this, cx| { cx.spawn(async move |this, cx| {
for file in commit_diff.files { let diff_tasks = commit_diff.files.into_iter().map(|file| {
let is_deleted = file.new_text.is_none(); let this = this.clone();
let new_text = file.new_text.unwrap_or_default(); let language_registry = language_registry.clone();
let old_text = file.old_text; let commit_sha = commit_sha.clone();
let worktree_id = repository_clone let repository_clone = repository_clone.clone();
.update(cx, |repository, cx| { cx.spawn(async move |cx| {
repository let is_deleted = file.new_text.is_none();
.repo_path_to_project_path(&file.path, cx) let new_text = file.new_text.unwrap_or_default();
.map(|path| path.worktree_id) let old_text = file.old_text;
.or(first_worktree_id) let worktree_id = repository_clone
})? .update(cx, |repository, cx| {
.context("project has no worktrees")?; repository
let short_sha = commit_sha.get(0..7).unwrap_or(&commit_sha); .repo_path_to_project_path(&file.path, cx)
let file_name = file .map(|path| path.worktree_id)
.path .or(first_worktree_id)
.file_name() })?
.map(|name| name.to_string()) .context("project has no worktrees")?;
.unwrap_or_else(|| file.path.display(PathStyle::Posix).to_string()); let short_sha = commit_sha.get(0..7).unwrap_or(&commit_sha);
let display_name: Arc<str> = let file_name = file
Arc::from(format!("{short_sha} - {file_name}").into_boxed_str()); .path
.file_name()
.map(|name| name.to_string())
.unwrap_or_else(|| file.path.display(PathStyle::Posix).to_string());
let display_name: Arc<str> =
Arc::from(format!("{short_sha} - {file_name}").into_boxed_str());
let file = Arc::new(GitBlob { let file = Arc::new(GitBlob {
path: file.path.clone(), path: file.path.clone(),
is_deleted, is_deleted,
worktree_id, worktree_id,
display_name, display_name,
}) as Arc<dyn language::File>; }) as Arc<dyn language::File>;
let buffer = build_buffer(new_text, file, &language_registry, cx).await?; let buffer = build_buffer(new_text, file, &language_registry, cx).await?;
let buffer_diff = let buffer_diff =
build_buffer_diff(old_text, &buffer, &language_registry, cx).await?; build_buffer_diff(old_text, &buffer, &language_registry, cx).await?;
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
this.multibuffer.update(cx, |multibuffer, cx| { this.multibuffer.update(cx, |multibuffer, cx| {
let snapshot = buffer.read(cx).snapshot(); let snapshot = buffer.read(cx).snapshot();
let path = snapshot.file().unwrap().path().clone(); let path = snapshot.file().unwrap().path().clone();
let excerpt_ranges = { let excerpt_ranges = {
let mut hunks = buffer_diff.read(cx).hunks(&snapshot, cx).peekable(); let mut hunks =
if hunks.peek().is_none() { buffer_diff.read(cx).hunks(&snapshot, cx).peekable();
vec![language::Point::zero()..snapshot.max_point()] if hunks.peek().is_none() {
} else { vec![language::Point::zero()..snapshot.max_point()]
hunks } else {
.map(|hunk| hunk.buffer_range.to_point(&snapshot)) hunks
.collect::<Vec<_>>() .map(|hunk| hunk.buffer_range.to_point(&snapshot))
} .collect::<Vec<_>>()
}; }
};
let _is_newly_added = multibuffer.set_excerpts_for_path( let _is_newly_added = multibuffer.set_excerpts_for_path(
PathKey::with_sort_prefix(FILE_NAMESPACE_SORT_PREFIX, path), PathKey::with_sort_prefix(FILE_NAMESPACE_SORT_PREFIX, path),
buffer, buffer,
excerpt_ranges, excerpt_ranges,
multibuffer_context_lines(cx), multibuffer_context_lines(cx),
cx, cx,
); );
multibuffer.add_diff(buffer_diff, cx); multibuffer.add_diff(buffer_diff, cx);
}); });
})?; })?;
}
anyhow::Ok(()) anyhow::Ok(())
})
});
futures::future::try_join_all(diff_tasks).await
}) })
.detach(); .detach();