Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.
fs: Move Repository trait into git crate (#10768)
Piotr Osiewicz3273f5e4041f
diff --git a/Cargo.lock b/Cargo.lockindex 7468b537413..4e3473b6399 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -4318,7 +4318,9 @@ dependencies = ["git2","lazy_static","log",+ "parking_lot","pretty_assertions",+ "rope","serde","serde_json","smol",@@ -4327,6 +4329,7 @@ dependencies = ["time","unindent","url",+ "util","windows 0.53.0",]@@ -7375,6 +7378,7 @@ dependencies = ["db","editor","file_icons",+ "git","gpui","language","menu",@@ -10988,8 +10992,8 @@ name = "vcs_menu"version = "0.1.0"dependencies = ["anyhow",- "fs","fuzzy",+ "git","gpui","picker","ui",diff --git a/crates/collab/src/tests/integration_tests.rs b/crates/collab/src/tests/integration_tests.rsindex 4370eda090f..728c8806fe9 100644--- a/crates/collab/src/tests/integration_tests.rs+++ b/crates/collab/src/tests/integration_tests.rs@@ -9,8 +9,9 @@ use anyhow::{anyhow, Result};use call::{room, ActiveCall, ParticipantLocation, Room};use client::{User, RECEIVE_TIMEOUT};use collections::{HashMap, HashSet};-use fs::{repository::GitFileStatus, FakeFs, Fs as _, RemoveOptions};+use fs::{FakeFs, Fs as _, RemoveOptions};use futures::{channel::mpsc, StreamExt as _};+use git::repository::GitFileStatus;use gpui::{px, size, AppContext, BackgroundExecutor, BorrowAppContext, Model, Modifiers, MouseButton,MouseDownEvent, TestAppContext,diff --git a/crates/collab/src/tests/random_project_collaboration_tests.rs b/crates/collab/src/tests/random_project_collaboration_tests.rsindex 8674069dff7..e06b79d5a85 100644--- a/crates/collab/src/tests/random_project_collaboration_tests.rs+++ b/crates/collab/src/tests/random_project_collaboration_tests.rs@@ -5,8 +5,9 @@ use async_trait::async_trait;use call::ActiveCall;use collections::{BTreeMap, HashMap};use editor::Bias;-use fs::{repository::GitFileStatus, FakeFs, Fs as _};+use fs::{FakeFs, Fs as _};use futures::StreamExt;+use git::repository::GitFileStatus;use gpui::{BackgroundExecutor, Model, TestAppContext};use language::{range_to_lsp, FakeLspAdapter, Language, LanguageConfig, LanguageMatcher, PointUtf16,diff --git a/crates/editor/src/items.rs b/crates/editor/src/items.rsindex 8cba960c1fc..ac3b3e95c16 100644--- a/crates/editor/src/items.rs+++ b/crates/editor/src/items.rs@@ -6,6 +6,7 @@ use crate::{use anyhow::{anyhow, Context as _, Result};use collections::HashSet;use futures::future::try_join_all;+use git::repository::GitFileStatus;use gpui::{point, AnyElement, AppContext, AsyncWindowContext, Context, Entity, EntityId, EventEmitter,IntoElement, Model, ParentElement, Pixels, SharedString, Styled, Task, View, ViewContext,@@ -15,7 +16,6 @@ use language::{proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, CharKind, OffsetRangeExt,Point, SelectionGoal,};-use project::repository::GitFileStatus;use project::{search::SearchQuery, FormatTrigger, Item as _, Project, ProjectPath};use rpc::proto::{self, update_view, PeerId};use settings::Settings;diff --git a/crates/fs/Cargo.toml b/crates/fs/Cargo.tomlindex 9d1ec496f5f..83acc7f0f97 100644--- a/crates/fs/Cargo.toml+++ b/crates/fs/Cargo.toml@@ -16,7 +16,6 @@ collections.workspace = truerope.workspace = truetext.workspace = trueutil.workspace = true-sum_tree.workspace = trueanyhow.workspace = trueasync-tar.workspace = true@@ -29,9 +28,7 @@ smol.workspace = truegit.workspace = truegit2.workspace = trueserde.workspace = true-serde_derive.workspace = trueserde_json.workspace = true-log.workspace = truelibc = "0.2"time.workspace = true@@ -50,4 +47,4 @@ windows.workspace = truegpui = { workspace = true, features = ["test-support"] }[features]-test-support = ["gpui/test-support"]+test-support = ["gpui/test-support", "git/test-support"]diff --git a/crates/fs/src/fs.rs b/crates/fs/src/fs.rsindex 7837ec034d0..6748a94b005 100644--- a/crates/fs/src/fs.rs+++ b/crates/fs/src/fs.rs@@ -1,5 +1,3 @@-pub mod repository;-use anyhow::{anyhow, Result};#[cfg(unix)]@@ -7,9 +5,9 @@ use std::os::unix::fs::MetadataExt;use async_tar::Archive;use futures::{future::BoxFuture, AsyncRead, Stream, StreamExt};+use git::repository::{GitRepository, RealGitRepository};use git2::Repository as LibGitRepository;use parking_lot::Mutex;-use repository::{GitRepository, RealGitRepository};use rope::Rope;#[cfg(any(test, feature = "test-support"))]use smol::io::AsyncReadExt;@@ -29,7 +27,7 @@ use util::{paths, ResultExt};#[cfg(any(test, feature = "test-support"))]use collections::{btree_map, BTreeMap};#[cfg(any(test, feature = "test-support"))]-use repository::{FakeGitRepositoryState, GitFileStatus};+use git::repository::{FakeGitRepositoryState, GitFileStatus};#[cfg(any(test, feature = "test-support"))]use std::ffi::OsStr;@@ -525,7 +523,7 @@ enum FakeFsEntry {inode: u64,mtime: SystemTime,entries: BTreeMap<String, Arc<Mutex<FakeFsEntry>>>,- git_repo_state: Option<Arc<Mutex<repository::FakeGitRepositoryState>>>,+ git_repo_state: Option<Arc<Mutex<git::repository::FakeGitRepositoryState>>>,},Symlink {target: PathBuf,@@ -1417,7 +1415,7 @@ impl Fs for FakeFs {let state = git_repo_state.get_or_insert_with(|| Arc::new(Mutex::new(FakeGitRepositoryState::default()))).clone();- Some(repository::FakeGitRepository::open(state))+ Some(git::repository::FakeGitRepository::open(state))} else {None}diff --git a/crates/git/Cargo.toml b/crates/git/Cargo.tomlindex c839ee069e4..26585e2c0e7 100644--- a/crates/git/Cargo.toml+++ b/crates/git/Cargo.toml@@ -24,6 +24,9 @@ text.workspace = truetime.workspace = trueurl.workspace = trueserde.workspace = true+rope.workspace = true+util.workspace = true+parking_lot.workspace = truewindows.workspace = true[dev-dependencies]diff --git a/crates/git/src/git.rs b/crates/git/src/git.rsindex e48c677d97a..ddb7f11f5a1 100644--- a/crates/git/src/git.rs+++ b/crates/git/src/git.rs@@ -11,6 +11,7 @@ pub mod blame;pub mod commit;pub mod diff;pub mod permalink;+pub mod repository;lazy_static! {pub static ref DOT_GIT: &'static OsStr = OsStr::new(".git");diff --git a/crates/fs/src/repository.rs b/crates/git/src/repository.rssimilarity index 97%rename from crates/fs/src/repository.rsrename to crates/git/src/repository.rsindex e1a23911ab3..0b479162e03 100644--- a/crates/fs/src/repository.rs+++ b/crates/git/src/repository.rs@@ -1,10 +1,10 @@+use crate::blame::Blame;use anyhow::{Context, Result};use collections::HashMap;-use git::blame::Blame;use git2::{BranchType, StatusShow};use parking_lot::Mutex;use rope::Rope;-use serde_derive::{Deserialize, Serialize};+use serde::{Deserialize, Serialize};use std::{cmp::Ordering,path::{Component, Path, PathBuf},@@ -59,7 +59,7 @@ pub trait GitRepository: Send {fn change_branch(&self, _: &str) -> Result<()>;fn create_branch(&self, _: &str) -> Result<()>;- fn blame(&self, path: &Path, content: Rope) -> Result<git::blame::Blame>;+ fn blame(&self, path: &Path, content: Rope) -> Result<crate::blame::Blame>;}impl std::fmt::Debug for dyn GitRepository {@@ -231,7 +231,7 @@ impl GitRepository for RealGitRepository {Ok(())}- fn blame(&self, path: &Path, content: Rope) -> Result<git::blame::Blame> {+ fn blame(&self, path: &Path, content: Rope) -> Result<crate::blame::Blame> {let working_directory = self.repository.workdir()@@ -240,7 +240,7 @@ impl GitRepository for RealGitRepository {const REMOTE_NAME: &str = "origin";let remote_url = self.remote_url(REMOTE_NAME);- git::blame::Blame::for_path(+ crate::blame::Blame::for_path(&self.git_binary_path,working_directory,path,@@ -358,7 +358,7 @@ impl GitRepository for FakeGitRepository {Ok(())}- fn blame(&self, path: &Path, _content: Rope) -> Result<git::blame::Blame> {+ fn blame(&self, path: &Path, _content: Rope) -> Result<crate::blame::Blame> {let state = self.state.lock();state.blamesdiff --git a/crates/project/src/project.rs b/crates/project/src/project.rsindex 04af41ba71e..6113ea8e92b 100644--- a/crates/project/src/project.rs+++ b/crates/project/src/project.rs@@ -21,7 +21,6 @@ use clock::ReplicaId;use collections::{hash_map, BTreeMap, HashMap, HashSet, VecDeque};use copilot::Copilot;use debounced_delay::DebouncedDelay;-use fs::repository::GitRepository;use futures::{channel::{mpsc::{self, UnboundedReceiver},@@ -32,7 +31,7 @@ use futures::{stream::FuturesUnordered,AsyncWriteExt, Future, FutureExt, StreamExt, TryFutureExt,};-use git::blame::Blame;+use git::{blame::Blame, repository::GitRepository};use globset::{Glob, GlobSet, GlobSetBuilder};use gpui::{AnyModel, AppContext, AsyncAppContext, BackgroundExecutor, BorrowAppContext, Context, Entity,diff --git a/crates/project_panel/Cargo.toml b/crates/project_panel/Cargo.tomlindex b7b8f973137..92912bf007d 100644--- a/crates/project_panel/Cargo.toml+++ b/crates/project_panel/Cargo.toml@@ -18,6 +18,7 @@ collections.workspace = truedb.workspace = trueeditor.workspace = truefile_icons.workspace = true+git.workspace = truegpui.workspace = truemenu.workspace = truepretty_assertions.workspace = truediff --git a/crates/project_panel/src/project_panel.rs b/crates/project_panel/src/project_panel.rsindex 89f3c7e8d9b..b08f46b7e78 100644--- a/crates/project_panel/src/project_panel.rs+++ b/crates/project_panel/src/project_panel.rs@@ -8,6 +8,7 @@ use file_icons::FileIcons;use anyhow::{anyhow, Result};use collections::{hash_map, HashMap};+use git::repository::GitFileStatus;use gpui::{actions, anchored, deferred, div, impl_actions, px, uniform_list, Action, AppContext,AssetSource, AsyncWindowContext, ClipboardItem, DismissEvent, Div, EventEmitter, FocusHandle,@@ -16,10 +17,7 @@ use gpui::{UniformListScrollHandle, View, ViewContext, VisualContext as _, WeakView, WindowContext,};use menu::{Confirm, SelectNext, SelectPrev};-use project::{- repository::GitFileStatus, Entry, EntryKind, Fs, Project, ProjectEntryId, ProjectPath,- Worktree, WorktreeId,-};+use project::{Entry, EntryKind, Fs, Project, ProjectEntryId, ProjectPath, Worktree, WorktreeId};use project_panel_settings::{ProjectPanelDockPosition, ProjectPanelSettings};use serde::{Deserialize, Serialize};use std::{diff --git a/crates/vcs_menu/Cargo.toml b/crates/vcs_menu/Cargo.tomlindex 786e2ee6fce..75dcad83dff 100644--- a/crates/vcs_menu/Cargo.toml+++ b/crates/vcs_menu/Cargo.toml@@ -10,8 +10,8 @@ workspace = true[dependencies]anyhow.workspace = true-fs.workspace = truefuzzy.workspace = true+git.workspace = truegpui.workspace = truepicker.workspace = trueui.workspace = truediff --git a/crates/vcs_menu/src/lib.rs b/crates/vcs_menu/src/lib.rsindex affd27de580..9df2bafda80 100644--- a/crates/vcs_menu/src/lib.rs+++ b/crates/vcs_menu/src/lib.rs@@ -1,6 +1,6 @@use anyhow::{anyhow, bail, Result};-use fs::repository::Branch;use fuzzy::{StringMatch, StringMatchCandidate};+use git::repository::Branch;use gpui::{actions, rems, AnyElement, AppContext, DismissEvent, Element, EventEmitter, FocusHandle,FocusableView, InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled,diff --git a/crates/worktree/src/worktree.rs b/crates/worktree/src/worktree.rsindex 72e1b049be9..5e4556f3d21 100644--- a/crates/worktree/src/worktree.rs+++ b/crates/worktree/src/worktree.rs@@ -8,11 +8,8 @@ use anyhow::{anyhow, Context as _, Result};use client::{proto, Client};use clock::ReplicaId;use collections::{HashMap, HashSet, VecDeque};+use fs::Fs;use fs::{copy_recursive, RemoveOptions};-use fs::{- repository::{GitFileStatus, GitRepository, RepoPath},- Fs,-};use futures::{channel::{mpsc::{self, UnboundedSender},@@ -23,7 +20,10 @@ use futures::{FutureExt as _, Stream, StreamExt,};use fuzzy::CharBag;-use git::{DOT_GIT, GITIGNORE};+use git::{+ repository::{GitFileStatus, GitRepository, RepoPath},+ DOT_GIT, GITIGNORE,+};use gpui::{AppContext, AsyncAppContext, BackgroundExecutor, Context, EventEmitter, Model, ModelContext,Task,diff --git a/crates/worktree/src/worktree_tests.rs b/crates/worktree/src/worktree_tests.rsindex 5efee216b62..4067d039087 100644--- a/crates/worktree/src/worktree_tests.rs+++ b/crates/worktree/src/worktree_tests.rs@@ -5,8 +5,8 @@ use crate::{use anyhow::Result;use client::Client;use clock::FakeSystemClock;-use fs::{repository::GitFileStatus, FakeFs, Fs, RealFs, RemoveOptions};-use git::GITIGNORE;+use fs::{FakeFs, Fs, RealFs, RemoveOptions};+use git::{repository::GitFileStatus, GITIGNORE};use gpui::{BorrowAppContext, ModelContext, Task, TestAppContext};use parking_lot::Mutex;use postage::stream::Stream;