Introduce diff crate to unite BufferDiff and BufferChangeSet (#24392)

This is a refactoring PR that does three things:

- First, it introduces a new `diff` crate that holds the previous
contents of the `git::diff` module, plus the `BufferChangeSet` type
formerly of `project::buffer_store`. The new crate is necessary since
simply moving `BufferChangeSet` into `git::diff` results in a dependency
cycle due to the use of `language::Buffer` to represent the diff base in
`BufferChangeSet`.
- Second, it renames the two main types in the new diff crate:
`BufferDiff` becomes `BufferDiffSnapshot`, and `BufferChangeSet` becomes
`BufferDiff`. This reflects that the relationship between these two
types (immutable cheaply-cloneable "value" type + stateful "resource
type" with subscriptions) mirrors existing pairs like
`Buffer`/`BufferSnapshot`. References to "change sets" throughout the
codebase are updated to refer to "diffs" instead.
- Finally, it moves the base_text field of the new BufferDiff type to
BufferDiffSnapshot.

Release Notes:

- N/A

---------

Co-authored-by: maxbrunsfeld <max@zed.dev>
This commit is contained in:
Cole Miller 2025-02-06 18:52:32 -05:00 committed by GitHub
parent ffcad71bfa
commit 73c487c222
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
31 changed files with 922 additions and 875 deletions

View file

@ -1,5 +1,5 @@
use crate::{Event, *};
use ::git::diff::assert_hunks;
use diff::assert_hunks;
use fs::FakeFs;
use futures::{future, StreamExt};
use gpui::{App, SemanticVersion, UpdateGlobal};
@ -5639,7 +5639,7 @@ async fn test_reordering_worktrees(cx: &mut gpui::TestAppContext) {
}
#[gpui::test]
async fn test_unstaged_changes_for_buffer(cx: &mut gpui::TestAppContext) {
async fn test_unstaged_diff_for_buffer(cx: &mut gpui::TestAppContext) {
init_test(cx);
let staged_contents = r#"
@ -5681,20 +5681,20 @@ async fn test_unstaged_changes_for_buffer(cx: &mut gpui::TestAppContext) {
})
.await
.unwrap();
let unstaged_changes = project
let unstaged_diff = project
.update(cx, |project, cx| {
project.open_unstaged_changes(buffer.clone(), cx)
project.open_unstaged_diff(buffer.clone(), cx)
})
.await
.unwrap();
cx.run_until_parked();
unstaged_changes.update(cx, |unstaged_changes, cx| {
unstaged_diff.update(cx, |unstaged_diff, cx| {
let snapshot = buffer.read(cx).snapshot();
assert_hunks(
unstaged_changes.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot),
unstaged_diff.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot),
&snapshot,
&unstaged_changes.base_text.as_ref().unwrap().text(),
&unstaged_diff.base_text_string().unwrap(),
&[
(0..1, "", "// print goodbye\n"),
(
@ -5719,19 +5719,19 @@ async fn test_unstaged_changes_for_buffer(cx: &mut gpui::TestAppContext) {
);
cx.run_until_parked();
unstaged_changes.update(cx, |unstaged_changes, cx| {
unstaged_diff.update(cx, |unstaged_diff, cx| {
let snapshot = buffer.read(cx).snapshot();
assert_hunks(
unstaged_changes.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot),
unstaged_diff.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot),
&snapshot,
&unstaged_changes.base_text.as_ref().unwrap().text(),
&unstaged_diff.snapshot.base_text.as_ref().unwrap().text(),
&[(2..3, "", " println!(\"goodbye world\");\n")],
);
});
}
#[gpui::test]
async fn test_uncommitted_changes_for_buffer(cx: &mut gpui::TestAppContext) {
async fn test_uncommitted_diff_for_buffer(cx: &mut gpui::TestAppContext) {
init_test(cx);
let committed_contents = r#"
@ -5783,20 +5783,20 @@ async fn test_uncommitted_changes_for_buffer(cx: &mut gpui::TestAppContext) {
})
.await
.unwrap();
let uncommitted_changes = project
let uncommitted_diff = project
.update(cx, |project, cx| {
project.open_uncommitted_changes(buffer.clone(), cx)
project.open_uncommitted_diff(buffer.clone(), cx)
})
.await
.unwrap();
cx.run_until_parked();
uncommitted_changes.update(cx, |uncommitted_changes, cx| {
uncommitted_diff.update(cx, |uncommitted_diff, cx| {
let snapshot = buffer.read(cx).snapshot();
assert_hunks(
uncommitted_changes.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot),
uncommitted_diff.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot),
&snapshot,
&uncommitted_changes.base_text.as_ref().unwrap().text(),
&uncommitted_diff.snapshot.base_text.as_ref().unwrap().text(),
&[
(0..1, "", "// print goodbye\n"),
(
@ -5821,12 +5821,12 @@ async fn test_uncommitted_changes_for_buffer(cx: &mut gpui::TestAppContext) {
);
cx.run_until_parked();
uncommitted_changes.update(cx, |uncommitted_changes, cx| {
uncommitted_diff.update(cx, |uncommitted_diff, cx| {
let snapshot = buffer.read(cx).snapshot();
assert_hunks(
uncommitted_changes.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot),
uncommitted_diff.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot),
&snapshot,
&uncommitted_changes.base_text.as_ref().unwrap().text(),
&uncommitted_diff.snapshot.base_text.as_ref().unwrap().text(),
&[(2..3, "", " println!(\"goodbye world\");\n")],
);
});
@ -5874,20 +5874,20 @@ async fn test_single_file_diffs(cx: &mut gpui::TestAppContext) {
})
.await
.unwrap();
let uncommitted_changes = project
let uncommitted_diff = project
.update(cx, |project, cx| {
project.open_uncommitted_changes(buffer.clone(), cx)
project.open_uncommitted_diff(buffer.clone(), cx)
})
.await
.unwrap();
cx.run_until_parked();
uncommitted_changes.update(cx, |uncommitted_changes, cx| {
uncommitted_diff.update(cx, |uncommitted_diff, cx| {
let snapshot = buffer.read(cx).snapshot();
assert_hunks(
uncommitted_changes.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot),
uncommitted_diff.diff_hunks_intersecting_range(Anchor::MIN..Anchor::MAX, &snapshot),
&snapshot,
&uncommitted_changes.base_text.as_ref().unwrap().text(),
&uncommitted_diff.snapshot.base_text.as_ref().unwrap().text(),
&[(
1..2,
" println!(\"hello from HEAD\");\n",