git: Compute and synchronize diffs from HEAD (#23626)

This PR builds on #21258 to make it possible to use HEAD as a diff base.
The buffer store is extended to support holding multiple change sets,
and collab gains support for synchronizing the committed text of files
when any collaborator requires it.

Not implemented in this PR:

- Exposing the diff from HEAD to the user
- Decorating the diff from HEAD with information about which hunks are
staged

`test_random_multibuffer` now fails first at `SEED=13277`, similar to
the previous high-water mark, but with various bugs in the multibuffer
logic now shaken out.

Release Notes:

- N/A

---------

Co-authored-by: Max <max@zed.dev>
Co-authored-by: Ben <ben@zed.dev>
Co-authored-by: Max Brunsfeld <maxbrunsfeld@gmail.com>
Co-authored-by: Conrad Irwin <conrad.irwin@gmail.com>
Co-authored-by: Conrad <conrad@zed.dev>
This commit is contained in:
Cole Miller 2025-02-04 15:29:10 -05:00 committed by GitHub
parent 871f98bc4d
commit 5704b50fb1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
29 changed files with 2799 additions and 603 deletions

View file

@ -129,7 +129,7 @@ message Envelope {
GetPrivateUserInfo get_private_user_info = 102;
GetPrivateUserInfoResponse get_private_user_info_response = 103;
UpdateUserPlan update_user_plan = 234;
UpdateDiffBase update_diff_base = 104;
UpdateDiffBases update_diff_bases = 104;
AcceptTermsOfService accept_terms_of_service = 239;
AcceptTermsOfServiceResponse accept_terms_of_service_response = 240;
@ -304,15 +304,18 @@ message Envelope {
SyncExtensionsResponse sync_extensions_response = 286;
InstallExtension install_extension = 287;
GetStagedText get_staged_text = 288;
GetStagedTextResponse get_staged_text_response = 289;
OpenUnstagedChanges open_unstaged_changes = 288;
OpenUnstagedChangesResponse open_unstaged_changes_response = 289;
RegisterBufferWithLanguageServers register_buffer_with_language_servers = 290;
Stage stage = 293;
Unstage unstage = 294;
Commit commit = 295;
OpenCommitMessageBuffer open_commit_message_buffer = 296; // current max
OpenCommitMessageBuffer open_commit_message_buffer = 296;
OpenUncommittedChanges open_uncommitted_changes = 297;
OpenUncommittedChangesResponse open_uncommitted_changes_response = 298; // current max
}
reserved 87 to 88;
@ -2035,21 +2038,53 @@ message WorktreeMetadata {
string abs_path = 4;
}
message UpdateDiffBase {
message UpdateDiffBases {
uint64 project_id = 1;
uint64 buffer_id = 2;
enum Mode {
// No collaborator is using the unstaged diff.
HEAD_ONLY = 0;
// No collaborator is using the diff from HEAD.
INDEX_ONLY = 1;
// Both the unstaged and uncommitted diffs are demanded,
// and the contents of the index and HEAD are the same for this path.
INDEX_MATCHES_HEAD = 2;
// Both the unstaged and uncommitted diffs are demanded,
// and the contents of the index and HEAD differ for this path,
// where None means the path doesn't exist in that state of the repo.
INDEX_AND_HEAD = 3;
}
optional string staged_text = 3;
optional string committed_text = 4;
Mode mode = 5;
}
message GetStagedText {
message OpenUnstagedChanges {
uint64 project_id = 1;
uint64 buffer_id = 2;
}
message GetStagedTextResponse {
message OpenUnstagedChangesResponse {
optional string staged_text = 1;
}
message OpenUncommittedChanges {
uint64 project_id = 1;
uint64 buffer_id = 2;
}
message OpenUncommittedChangesResponse {
enum Mode {
INDEX_MATCHES_HEAD = 0;
INDEX_AND_HEAD = 1;
}
optional string staged_text = 1;
optional string committed_text = 2;
Mode mode = 3;
}
message GetNotifications {
optional uint64 before_id = 1;
}

View file

@ -219,8 +219,10 @@ messages!(
(GetImplementationResponse, Background),
(GetLlmToken, Background),
(GetLlmTokenResponse, Background),
(GetStagedText, Foreground),
(GetStagedTextResponse, Foreground),
(OpenUnstagedChanges, Foreground),
(OpenUnstagedChangesResponse, Foreground),
(OpenUncommittedChanges, Foreground),
(OpenUncommittedChangesResponse, Foreground),
(GetUsers, Foreground),
(Hello, Foreground),
(IncomingCall, Foreground),
@ -309,7 +311,7 @@ messages!(
(UpdateUserChannels, Foreground),
(UpdateContacts, Foreground),
(UpdateDiagnosticSummary, Foreground),
(UpdateDiffBase, Foreground),
(UpdateDiffBases, Foreground),
(UpdateFollowers, Foreground),
(UpdateInviteInfo, Foreground),
(UpdateLanguageServer, Foreground),
@ -422,7 +424,8 @@ request_messages!(
(GetProjectSymbols, GetProjectSymbolsResponse),
(GetReferences, GetReferencesResponse),
(GetSignatureHelp, GetSignatureHelpResponse),
(GetStagedText, GetStagedTextResponse),
(OpenUnstagedChanges, OpenUnstagedChangesResponse),
(OpenUncommittedChanges, OpenUncommittedChangesResponse),
(GetSupermavenApiKey, GetSupermavenApiKeyResponse),
(GetTypeDefinition, GetTypeDefinitionResponse),
(LinkedEditingRange, LinkedEditingRangeResponse),
@ -543,7 +546,8 @@ entity_messages!(
GetProjectSymbols,
GetReferences,
GetSignatureHelp,
GetStagedText,
OpenUnstagedChanges,
OpenUncommittedChanges,
GetTypeDefinition,
InlayHints,
JoinProject,
@ -575,7 +579,7 @@ entity_messages!(
UpdateBuffer,
UpdateBufferFile,
UpdateDiagnosticSummary,
UpdateDiffBase,
UpdateDiffBases,
UpdateLanguageServer,
UpdateProject,
UpdateProjectCollaborator,