1mod ids;
2mod queries;
3mod tables;
4#[cfg(test)]
5pub mod tests;
6
7use crate::{Error, Result};
8use anyhow::{Context as _, anyhow};
9use collections::{BTreeMap, BTreeSet, HashMap, HashSet};
10use dashmap::DashMap;
11use futures::StreamExt;
12use project_repository_statuses::StatusKind;
13use rpc::ExtensionProvides;
14use rpc::{
15 ConnectionId, ExtensionMetadata,
16 proto::{self},
17};
18use sea_orm::{
19 ActiveValue, Condition, ConnectionTrait, DatabaseConnection, DatabaseTransaction,
20 FromQueryResult, IntoActiveModel, IsolationLevel, JoinType, QueryOrder, QuerySelect, Statement,
21 TransactionTrait,
22 entity::prelude::*,
23 sea_query::{Alias, Expr, OnConflict},
24};
25use semver::Version;
26use serde::{Deserialize, Serialize};
27use std::ops::RangeInclusive;
28use std::{
29 future::Future,
30 marker::PhantomData,
31 ops::{Deref, DerefMut},
32 rc::Rc,
33 sync::Arc,
34};
35use time::PrimitiveDateTime;
36use tokio::sync::{Mutex, OwnedMutexGuard};
37use util::paths::PathStyle;
38use worktree_settings_file::LocalSettingsKind;
39
40#[cfg(test)]
41pub use tests::TestDb;
42
43pub use ids::*;
44pub use queries::contributors::ContributorSelector;
45pub use sea_orm::ConnectOptions;
46pub use tables::user::Model as User;
47pub use tables::*;
48
49#[cfg(test)]
50pub struct DatabaseTestOptions {
51 pub executor: gpui::BackgroundExecutor,
52 pub runtime: tokio::runtime::Runtime,
53 pub query_failure_probability: parking_lot::Mutex<f64>,
54}
55
56/// Database gives you a handle that lets you access the database.
57/// It handles pooling internally.
58pub struct Database {
59 options: ConnectOptions,
60 pool: DatabaseConnection,
61 rooms: DashMap<RoomId, Arc<Mutex<()>>>,
62 projects: DashMap<ProjectId, Arc<Mutex<()>>>,
63 notification_kinds_by_id: HashMap<NotificationKindId, &'static str>,
64 notification_kinds_by_name: HashMap<String, NotificationKindId>,
65 #[cfg(test)]
66 test_options: Option<DatabaseTestOptions>,
67}
68
69// The `Database` type has so many methods that its impl blocks are split into
70// separate files in the `queries` folder.
71impl Database {
72 /// Connects to the database with the given options
73 pub async fn new(options: ConnectOptions) -> Result<Self> {
74 sqlx::any::install_default_drivers();
75 Ok(Self {
76 options: options.clone(),
77 pool: sea_orm::Database::connect(options).await?,
78 rooms: DashMap::with_capacity(16384),
79 projects: DashMap::with_capacity(16384),
80 notification_kinds_by_id: HashMap::default(),
81 notification_kinds_by_name: HashMap::default(),
82 #[cfg(test)]
83 test_options: None,
84 })
85 }
86
87 pub fn options(&self) -> &ConnectOptions {
88 &self.options
89 }
90
91 #[cfg(test)]
92 pub fn reset(&self) {
93 self.rooms.clear();
94 self.projects.clear();
95 }
96
97 pub async fn transaction<F, Fut, T>(&self, f: F) -> Result<T>
98 where
99 F: Send + Fn(TransactionHandle) -> Fut,
100 Fut: Send + Future<Output = Result<T>>,
101 {
102 let body = async {
103 let (tx, result) = self.with_transaction(&f).await?;
104 match result {
105 Ok(result) => match tx.commit().await.map_err(Into::into) {
106 Ok(()) => Ok(result),
107 Err(error) => Err(error),
108 },
109 Err(error) => {
110 tx.rollback().await?;
111 Err(error)
112 }
113 }
114 };
115
116 self.run(body).await
117 }
118
119 /// The same as room_transaction, but if you need to only optionally return a Room.
120 async fn optional_room_transaction<F, Fut, T>(
121 &self,
122 f: F,
123 ) -> Result<Option<TransactionGuard<T>>>
124 where
125 F: Send + Fn(TransactionHandle) -> Fut,
126 Fut: Send + Future<Output = Result<Option<(RoomId, T)>>>,
127 {
128 let body = async {
129 let (tx, result) = self.with_transaction(&f).await?;
130 match result {
131 Ok(Some((room_id, data))) => {
132 let lock = self.rooms.entry(room_id).or_default().clone();
133 let _guard = lock.lock_owned().await;
134 match tx.commit().await.map_err(Into::into) {
135 Ok(()) => Ok(Some(TransactionGuard {
136 data,
137 _guard,
138 _not_send: PhantomData,
139 })),
140 Err(error) => Err(error),
141 }
142 }
143 Ok(None) => match tx.commit().await.map_err(Into::into) {
144 Ok(()) => Ok(None),
145 Err(error) => Err(error),
146 },
147 Err(error) => {
148 tx.rollback().await?;
149 Err(error)
150 }
151 }
152 };
153
154 self.run(body).await
155 }
156
157 async fn project_transaction<F, Fut, T>(
158 &self,
159 project_id: ProjectId,
160 f: F,
161 ) -> Result<TransactionGuard<T>>
162 where
163 F: Send + Fn(TransactionHandle) -> Fut,
164 Fut: Send + Future<Output = Result<T>>,
165 {
166 let room_id = Database::room_id_for_project(self, project_id).await?;
167 let body = async {
168 let lock = if let Some(room_id) = room_id {
169 self.rooms.entry(room_id).or_default().clone()
170 } else {
171 self.projects.entry(project_id).or_default().clone()
172 };
173 let _guard = lock.lock_owned().await;
174 let (tx, result) = self.with_transaction(&f).await?;
175 match result {
176 Ok(data) => match tx.commit().await.map_err(Into::into) {
177 Ok(()) => Ok(TransactionGuard {
178 data,
179 _guard,
180 _not_send: PhantomData,
181 }),
182 Err(error) => Err(error),
183 },
184 Err(error) => {
185 tx.rollback().await?;
186 Err(error)
187 }
188 }
189 };
190
191 self.run(body).await
192 }
193
194 /// room_transaction runs the block in a transaction. It returns a RoomGuard, that keeps
195 /// the database locked until it is dropped. This ensures that updates sent to clients are
196 /// properly serialized with respect to database changes.
197 async fn room_transaction<F, Fut, T>(
198 &self,
199 room_id: RoomId,
200 f: F,
201 ) -> Result<TransactionGuard<T>>
202 where
203 F: Send + Fn(TransactionHandle) -> Fut,
204 Fut: Send + Future<Output = Result<T>>,
205 {
206 let body = async {
207 let lock = self.rooms.entry(room_id).or_default().clone();
208 let _guard = lock.lock_owned().await;
209 let (tx, result) = self.with_transaction(&f).await?;
210 match result {
211 Ok(data) => match tx.commit().await.map_err(Into::into) {
212 Ok(()) => Ok(TransactionGuard {
213 data,
214 _guard,
215 _not_send: PhantomData,
216 }),
217 Err(error) => Err(error),
218 },
219 Err(error) => {
220 tx.rollback().await?;
221 Err(error)
222 }
223 }
224 };
225
226 self.run(body).await
227 }
228
229 async fn with_transaction<F, Fut, T>(&self, f: &F) -> Result<(DatabaseTransaction, Result<T>)>
230 where
231 F: Send + Fn(TransactionHandle) -> Fut,
232 Fut: Send + Future<Output = Result<T>>,
233 {
234 let tx = self
235 .pool
236 .begin_with_config(Some(IsolationLevel::ReadCommitted), None)
237 .await?;
238
239 let mut tx = Arc::new(Some(tx));
240 let result = f(TransactionHandle(tx.clone())).await;
241 let tx = Arc::get_mut(&mut tx)
242 .and_then(|tx| tx.take())
243 .context("couldn't complete transaction because it's still in use")?;
244
245 Ok((tx, result))
246 }
247
248 async fn run<F, T>(&self, future: F) -> Result<T>
249 where
250 F: Future<Output = Result<T>>,
251 {
252 #[cfg(test)]
253 {
254 use rand::prelude::*;
255
256 let test_options = self.test_options.as_ref().unwrap();
257 test_options.executor.simulate_random_delay().await;
258 let fail_probability = *test_options.query_failure_probability.lock();
259 if test_options.executor.rng().random_bool(fail_probability) {
260 return Err(anyhow!("simulated query failure"))?;
261 }
262
263 test_options.runtime.block_on(future)
264 }
265
266 #[cfg(not(test))]
267 {
268 future.await
269 }
270 }
271}
272
273/// A handle to a [`DatabaseTransaction`].
274pub struct TransactionHandle(pub(crate) Arc<Option<DatabaseTransaction>>);
275
276impl Deref for TransactionHandle {
277 type Target = DatabaseTransaction;
278
279 fn deref(&self) -> &Self::Target {
280 self.0.as_ref().as_ref().unwrap()
281 }
282}
283
284/// [`TransactionGuard`] keeps a database transaction alive until it is dropped.
285/// It wraps data that depends on the state of the database and prevents an additional
286/// transaction from starting that would invalidate that data.
287pub struct TransactionGuard<T> {
288 data: T,
289 _guard: OwnedMutexGuard<()>,
290 _not_send: PhantomData<Rc<()>>,
291}
292
293impl<T> Deref for TransactionGuard<T> {
294 type Target = T;
295
296 fn deref(&self) -> &T {
297 &self.data
298 }
299}
300
301impl<T> DerefMut for TransactionGuard<T> {
302 fn deref_mut(&mut self) -> &mut T {
303 &mut self.data
304 }
305}
306
307impl<T> TransactionGuard<T> {
308 /// Returns the inner value of the guard.
309 pub fn into_inner(self) -> T {
310 self.data
311 }
312}
313
314#[derive(Clone, Debug, PartialEq, Eq)]
315pub enum Contact {
316 Accepted { user_id: UserId, busy: bool },
317 Outgoing { user_id: UserId },
318 Incoming { user_id: UserId },
319}
320
321impl Contact {
322 pub fn user_id(&self) -> UserId {
323 match self {
324 Contact::Accepted { user_id, .. } => *user_id,
325 Contact::Outgoing { user_id } => *user_id,
326 Contact::Incoming { user_id, .. } => *user_id,
327 }
328 }
329}
330
331pub type NotificationBatch = Vec<(UserId, proto::Notification)>;
332
333pub struct CreatedChannelMessage {
334 pub message_id: MessageId,
335 pub participant_connection_ids: HashSet<ConnectionId>,
336 pub notifications: NotificationBatch,
337}
338
339pub struct UpdatedChannelMessage {
340 pub message_id: MessageId,
341 pub participant_connection_ids: Vec<ConnectionId>,
342 pub notifications: NotificationBatch,
343 pub reply_to_message_id: Option<MessageId>,
344 pub timestamp: PrimitiveDateTime,
345 pub deleted_mention_notification_ids: Vec<NotificationId>,
346 pub updated_mention_notifications: Vec<rpc::proto::Notification>,
347}
348
349#[derive(Clone, Debug, PartialEq, Eq, FromQueryResult, Serialize, Deserialize)]
350pub struct Invite {
351 pub email_address: String,
352 pub email_confirmation_code: String,
353}
354
355#[derive(Clone, Debug, Deserialize)]
356pub struct NewSignup {
357 pub email_address: String,
358 pub platform_mac: bool,
359 pub platform_windows: bool,
360 pub platform_linux: bool,
361 pub editor_features: Vec<String>,
362 pub programming_languages: Vec<String>,
363 pub device_id: Option<String>,
364 pub added_to_mailing_list: bool,
365 pub created_at: Option<DateTime>,
366}
367
368#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, FromQueryResult)]
369pub struct WaitlistSummary {
370 pub count: i64,
371 pub linux_count: i64,
372 pub mac_count: i64,
373 pub windows_count: i64,
374 pub unknown_count: i64,
375}
376
377/// The parameters to create a new user.
378#[derive(Debug, Serialize, Deserialize)]
379pub struct NewUserParams {
380 pub github_login: String,
381 pub github_user_id: i32,
382}
383
384/// The result of creating a new user.
385#[derive(Debug)]
386pub struct NewUserResult {
387 pub user_id: UserId,
388 pub inviting_user_id: Option<UserId>,
389 pub signup_device_id: Option<String>,
390}
391
392/// The result of updating a channel membership.
393#[derive(Debug)]
394pub struct MembershipUpdated {
395 pub channel_id: ChannelId,
396 pub new_channels: ChannelsForUser,
397 pub removed_channels: Vec<ChannelId>,
398}
399
400/// The result of setting a member's role.
401#[derive(Debug)]
402
403pub enum SetMemberRoleResult {
404 InviteUpdated(Channel),
405 MembershipUpdated(MembershipUpdated),
406}
407
408/// The result of inviting a member to a channel.
409#[derive(Debug)]
410pub struct InviteMemberResult {
411 pub channel: Channel,
412 pub notifications: NotificationBatch,
413}
414
415#[derive(Debug)]
416pub struct RespondToChannelInvite {
417 pub membership_update: Option<MembershipUpdated>,
418 pub notifications: NotificationBatch,
419}
420
421#[derive(Debug)]
422pub struct RemoveChannelMemberResult {
423 pub membership_update: MembershipUpdated,
424 pub notification_id: Option<NotificationId>,
425}
426
427#[derive(Debug, PartialEq, Eq, Hash)]
428pub struct Channel {
429 pub id: ChannelId,
430 pub name: String,
431 pub visibility: ChannelVisibility,
432 /// parent_path is the channel ids from the root to this one (not including this one)
433 pub parent_path: Vec<ChannelId>,
434 pub channel_order: i32,
435}
436
437impl Channel {
438 pub fn from_model(value: channel::Model) -> Self {
439 Channel {
440 id: value.id,
441 visibility: value.visibility,
442 name: value.clone().name,
443 parent_path: value.ancestors().collect(),
444 channel_order: value.channel_order,
445 }
446 }
447
448 pub fn to_proto(&self) -> proto::Channel {
449 proto::Channel {
450 id: self.id.to_proto(),
451 name: self.name.clone(),
452 visibility: self.visibility.into(),
453 parent_path: self.parent_path.iter().map(|c| c.to_proto()).collect(),
454 channel_order: self.channel_order,
455 }
456 }
457
458 pub fn root_id(&self) -> ChannelId {
459 self.parent_path.first().copied().unwrap_or(self.id)
460 }
461}
462
463#[derive(Debug, PartialEq, Eq, Hash)]
464pub struct ChannelMember {
465 pub role: ChannelRole,
466 pub user_id: UserId,
467 pub kind: proto::channel_member::Kind,
468}
469
470impl ChannelMember {
471 pub fn to_proto(&self) -> proto::ChannelMember {
472 proto::ChannelMember {
473 role: self.role.into(),
474 user_id: self.user_id.to_proto(),
475 kind: self.kind.into(),
476 }
477 }
478}
479
480#[derive(Debug, PartialEq)]
481pub struct ChannelsForUser {
482 pub channels: Vec<Channel>,
483 pub channel_memberships: Vec<channel_member::Model>,
484 pub channel_participants: HashMap<ChannelId, Vec<UserId>>,
485 pub invited_channels: Vec<Channel>,
486
487 pub observed_buffer_versions: Vec<proto::ChannelBufferVersion>,
488 pub latest_buffer_versions: Vec<proto::ChannelBufferVersion>,
489}
490
491#[derive(Debug)]
492pub struct RejoinedChannelBuffer {
493 pub buffer: proto::RejoinedChannelBuffer,
494 pub old_connection_id: ConnectionId,
495}
496
497#[derive(Clone)]
498pub struct JoinRoom {
499 pub room: proto::Room,
500 pub channel: Option<channel::Model>,
501}
502
503pub struct RejoinedRoom {
504 pub room: proto::Room,
505 pub rejoined_projects: Vec<RejoinedProject>,
506 pub reshared_projects: Vec<ResharedProject>,
507 pub channel: Option<channel::Model>,
508}
509
510pub struct ResharedProject {
511 pub id: ProjectId,
512 pub old_connection_id: ConnectionId,
513 pub collaborators: Vec<ProjectCollaborator>,
514 pub worktrees: Vec<proto::WorktreeMetadata>,
515}
516
517pub struct RejoinedProject {
518 pub id: ProjectId,
519 pub old_connection_id: ConnectionId,
520 pub collaborators: Vec<ProjectCollaborator>,
521 pub worktrees: Vec<RejoinedWorktree>,
522 pub updated_repositories: Vec<proto::UpdateRepository>,
523 pub removed_repositories: Vec<u64>,
524 pub language_servers: Vec<LanguageServer>,
525}
526
527impl RejoinedProject {
528 pub fn to_proto(&self) -> proto::RejoinedProject {
529 let (language_servers, language_server_capabilities) = self
530 .language_servers
531 .clone()
532 .into_iter()
533 .map(|server| (server.server, server.capabilities))
534 .unzip();
535 proto::RejoinedProject {
536 id: self.id.to_proto(),
537 worktrees: self
538 .worktrees
539 .iter()
540 .map(|worktree| proto::WorktreeMetadata {
541 id: worktree.id,
542 root_name: worktree.root_name.clone(),
543 visible: worktree.visible,
544 abs_path: worktree.abs_path.clone(),
545 })
546 .collect(),
547 collaborators: self
548 .collaborators
549 .iter()
550 .map(|collaborator| collaborator.to_proto())
551 .collect(),
552 language_servers,
553 language_server_capabilities,
554 }
555 }
556}
557
558#[derive(Debug)]
559pub struct RejoinedWorktree {
560 pub id: u64,
561 pub abs_path: String,
562 pub root_name: String,
563 pub visible: bool,
564 pub updated_entries: Vec<proto::Entry>,
565 pub removed_entries: Vec<u64>,
566 pub updated_repositories: Vec<proto::RepositoryEntry>,
567 pub removed_repositories: Vec<u64>,
568 pub diagnostic_summaries: Vec<proto::DiagnosticSummary>,
569 pub settings_files: Vec<WorktreeSettingsFile>,
570 pub scan_id: u64,
571 pub completed_scan_id: u64,
572}
573
574pub struct LeftRoom {
575 pub room: proto::Room,
576 pub channel: Option<channel::Model>,
577 pub left_projects: HashMap<ProjectId, LeftProject>,
578 pub canceled_calls_to_user_ids: Vec<UserId>,
579 pub deleted: bool,
580}
581
582pub struct RefreshedRoom {
583 pub room: proto::Room,
584 pub channel: Option<channel::Model>,
585 pub stale_participant_user_ids: Vec<UserId>,
586 pub canceled_calls_to_user_ids: Vec<UserId>,
587}
588
589pub struct RefreshedChannelBuffer {
590 pub connection_ids: Vec<ConnectionId>,
591 pub collaborators: Vec<proto::Collaborator>,
592}
593
594pub struct Project {
595 pub id: ProjectId,
596 pub role: ChannelRole,
597 pub collaborators: Vec<ProjectCollaborator>,
598 pub worktrees: BTreeMap<u64, Worktree>,
599 pub repositories: Vec<proto::UpdateRepository>,
600 pub language_servers: Vec<LanguageServer>,
601 pub path_style: PathStyle,
602}
603
604pub struct ProjectCollaborator {
605 pub connection_id: ConnectionId,
606 pub user_id: UserId,
607 pub replica_id: ReplicaId,
608 pub is_host: bool,
609 pub committer_name: Option<String>,
610 pub committer_email: Option<String>,
611}
612
613impl ProjectCollaborator {
614 pub fn to_proto(&self) -> proto::Collaborator {
615 proto::Collaborator {
616 peer_id: Some(self.connection_id.into()),
617 replica_id: self.replica_id.0 as u32,
618 user_id: self.user_id.to_proto(),
619 is_host: self.is_host,
620 committer_name: self.committer_name.clone(),
621 committer_email: self.committer_email.clone(),
622 }
623 }
624}
625
626#[derive(Debug, Clone)]
627pub struct LanguageServer {
628 pub server: proto::LanguageServer,
629 pub capabilities: String,
630}
631
632#[derive(Debug)]
633pub struct LeftProject {
634 pub id: ProjectId,
635 pub should_unshare: bool,
636 pub connection_ids: Vec<ConnectionId>,
637}
638
639pub struct Worktree {
640 pub id: u64,
641 pub abs_path: String,
642 pub root_name: String,
643 pub visible: bool,
644 pub entries: Vec<proto::Entry>,
645 pub legacy_repository_entries: BTreeMap<u64, proto::RepositoryEntry>,
646 pub diagnostic_summaries: Vec<proto::DiagnosticSummary>,
647 pub settings_files: Vec<WorktreeSettingsFile>,
648 pub scan_id: u64,
649 pub completed_scan_id: u64,
650}
651
652#[derive(Debug)]
653pub struct WorktreeSettingsFile {
654 pub path: String,
655 pub content: String,
656 pub kind: LocalSettingsKind,
657}
658
659pub struct NewExtensionVersion {
660 pub name: String,
661 pub version: semver::Version,
662 pub description: String,
663 pub authors: Vec<String>,
664 pub repository: String,
665 pub schema_version: i32,
666 pub wasm_api_version: Option<String>,
667 pub provides: BTreeSet<ExtensionProvides>,
668 pub published_at: PrimitiveDateTime,
669}
670
671pub struct ExtensionVersionConstraints {
672 pub schema_versions: RangeInclusive<i32>,
673 pub wasm_api_versions: RangeInclusive<semver::Version>,
674}
675
676impl LocalSettingsKind {
677 pub fn from_proto(proto_kind: proto::LocalSettingsKind) -> Self {
678 match proto_kind {
679 proto::LocalSettingsKind::Settings => Self::Settings,
680 proto::LocalSettingsKind::Tasks => Self::Tasks,
681 proto::LocalSettingsKind::Editorconfig => Self::Editorconfig,
682 proto::LocalSettingsKind::Debug => Self::Debug,
683 }
684 }
685
686 pub fn to_proto(self) -> proto::LocalSettingsKind {
687 match self {
688 Self::Settings => proto::LocalSettingsKind::Settings,
689 Self::Tasks => proto::LocalSettingsKind::Tasks,
690 Self::Editorconfig => proto::LocalSettingsKind::Editorconfig,
691 Self::Debug => proto::LocalSettingsKind::Debug,
692 }
693 }
694}
695
696fn db_status_to_proto(
697 entry: project_repository_statuses::Model,
698) -> anyhow::Result<proto::StatusEntry> {
699 use proto::git_file_status::{Tracked, Unmerged, Variant};
700
701 let (simple_status, variant) =
702 match (entry.status_kind, entry.first_status, entry.second_status) {
703 (StatusKind::Untracked, None, None) => (
704 proto::GitStatus::Added as i32,
705 Variant::Untracked(Default::default()),
706 ),
707 (StatusKind::Ignored, None, None) => (
708 proto::GitStatus::Added as i32,
709 Variant::Ignored(Default::default()),
710 ),
711 (StatusKind::Unmerged, Some(first_head), Some(second_head)) => (
712 proto::GitStatus::Conflict as i32,
713 Variant::Unmerged(Unmerged {
714 first_head,
715 second_head,
716 }),
717 ),
718 (StatusKind::Tracked, Some(index_status), Some(worktree_status)) => {
719 let simple_status = if worktree_status != proto::GitStatus::Unmodified as i32 {
720 worktree_status
721 } else if index_status != proto::GitStatus::Unmodified as i32 {
722 index_status
723 } else {
724 proto::GitStatus::Unmodified as i32
725 };
726 (
727 simple_status,
728 Variant::Tracked(Tracked {
729 index_status,
730 worktree_status,
731 }),
732 )
733 }
734 _ => {
735 anyhow::bail!("Unexpected combination of status fields: {entry:?}");
736 }
737 };
738 Ok(proto::StatusEntry {
739 repo_path: entry.repo_path,
740 simple_status,
741 status: Some(proto::GitFileStatus {
742 variant: Some(variant),
743 }),
744 })
745}
746
747fn proto_status_to_db(
748 status_entry: proto::StatusEntry,
749) -> (String, StatusKind, Option<i32>, Option<i32>) {
750 use proto::git_file_status::{Tracked, Unmerged, Variant};
751
752 let (status_kind, first_status, second_status) = status_entry
753 .status
754 .clone()
755 .and_then(|status| status.variant)
756 .map_or(
757 (StatusKind::Untracked, None, None),
758 |variant| match variant {
759 Variant::Untracked(_) => (StatusKind::Untracked, None, None),
760 Variant::Ignored(_) => (StatusKind::Ignored, None, None),
761 Variant::Unmerged(Unmerged {
762 first_head,
763 second_head,
764 }) => (StatusKind::Unmerged, Some(first_head), Some(second_head)),
765 Variant::Tracked(Tracked {
766 index_status,
767 worktree_status,
768 }) => (
769 StatusKind::Tracked,
770 Some(index_status),
771 Some(worktree_status),
772 ),
773 },
774 );
775 (
776 status_entry.repo_path,
777 status_kind,
778 first_status,
779 second_status,
780 )
781}