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

@ -84,18 +84,15 @@ async fn test_basic_remote_editing(cx: &mut TestAppContext, server_cx: &mut Test
})
.await
.unwrap();
let change_set = project
let diff = project
.update(cx, |project, cx| {
project.open_unstaged_changes(buffer.clone(), cx)
project.open_unstaged_diff(buffer.clone(), cx)
})
.await
.unwrap();
change_set.update(cx, |change_set, _| {
assert_eq!(
change_set.base_text_string().unwrap(),
"fn one() -> usize { 0 }"
);
diff.update(cx, |diff, _| {
assert_eq!(diff.base_text_string().unwrap(), "fn one() -> usize { 0 }");
});
buffer.update(cx, |buffer, cx| {
@ -155,9 +152,9 @@ async fn test_basic_remote_editing(cx: &mut TestAppContext, server_cx: &mut Test
&[("src/lib2.rs".into(), "fn one() -> usize { 100 }".into())],
);
cx.executor().run_until_parked();
change_set.update(cx, |change_set, _| {
diff.update(cx, |diff, _| {
assert_eq!(
change_set.base_text_string().unwrap(),
diff.base_text_string().unwrap(),
"fn one() -> usize { 100 }"
);
});
@ -1239,18 +1236,17 @@ async fn test_remote_git_diffs(cx: &mut TestAppContext, server_cx: &mut TestAppC
})
.await
.unwrap();
let change_set = project
let diff = project
.update(cx, |project, cx| {
project.open_uncommitted_changes(buffer.clone(), cx)
project.open_uncommitted_diff(buffer.clone(), cx)
})
.await
.unwrap();
change_set.read_with(cx, |change_set, cx| {
assert_eq!(change_set.base_text_string().unwrap(), text_1);
diff.read_with(cx, |diff, cx| {
assert_eq!(diff.base_text_string().unwrap(), text_1);
assert_eq!(
change_set
.unstaged_change_set
diff.unstaged_diff
.as_ref()
.unwrap()
.read(cx)
@ -1267,11 +1263,10 @@ async fn test_remote_git_diffs(cx: &mut TestAppContext, server_cx: &mut TestAppC
);
cx.executor().run_until_parked();
change_set.read_with(cx, |change_set, cx| {
assert_eq!(change_set.base_text_string().unwrap(), text_1);
diff.read_with(cx, |diff, cx| {
assert_eq!(diff.base_text_string().unwrap(), text_1);
assert_eq!(
change_set
.unstaged_change_set
diff.unstaged_diff
.as_ref()
.unwrap()
.read(cx)
@ -1288,11 +1283,10 @@ async fn test_remote_git_diffs(cx: &mut TestAppContext, server_cx: &mut TestAppC
);
cx.executor().run_until_parked();
change_set.read_with(cx, |change_set, cx| {
assert_eq!(change_set.base_text_string().unwrap(), text_2);
diff.read_with(cx, |diff, cx| {
assert_eq!(diff.base_text_string().unwrap(), text_2);
assert_eq!(
change_set
.unstaged_change_set
diff.unstaged_diff
.as_ref()
.unwrap()
.read(cx)