fs: Move Repository trait into git crate (#10768)

/cc @mrnugget 
Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2024-04-19 11:57:17 +02:00 committed by GitHub
parent 8513a24dd8
commit 3273f5e404
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 38 additions and 35 deletions

6
Cargo.lock generated
View file

@ -4318,7 +4318,9 @@ dependencies = [
"git2", "git2",
"lazy_static", "lazy_static",
"log", "log",
"parking_lot",
"pretty_assertions", "pretty_assertions",
"rope",
"serde", "serde",
"serde_json", "serde_json",
"smol", "smol",
@ -4327,6 +4329,7 @@ dependencies = [
"time", "time",
"unindent", "unindent",
"url", "url",
"util",
"windows 0.53.0", "windows 0.53.0",
] ]
@ -7375,6 +7378,7 @@ dependencies = [
"db", "db",
"editor", "editor",
"file_icons", "file_icons",
"git",
"gpui", "gpui",
"language", "language",
"menu", "menu",
@ -10988,8 +10992,8 @@ name = "vcs_menu"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"fs",
"fuzzy", "fuzzy",
"git",
"gpui", "gpui",
"picker", "picker",
"ui", "ui",

View file

@ -9,8 +9,9 @@ use anyhow::{anyhow, Result};
use call::{room, ActiveCall, ParticipantLocation, Room}; use call::{room, ActiveCall, ParticipantLocation, Room};
use client::{User, RECEIVE_TIMEOUT}; use client::{User, RECEIVE_TIMEOUT};
use collections::{HashMap, HashSet}; 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 futures::{channel::mpsc, StreamExt as _};
use git::repository::GitFileStatus;
use gpui::{ use gpui::{
px, size, AppContext, BackgroundExecutor, BorrowAppContext, Model, Modifiers, MouseButton, px, size, AppContext, BackgroundExecutor, BorrowAppContext, Model, Modifiers, MouseButton,
MouseDownEvent, TestAppContext, MouseDownEvent, TestAppContext,

View file

@ -5,8 +5,9 @@ use async_trait::async_trait;
use call::ActiveCall; use call::ActiveCall;
use collections::{BTreeMap, HashMap}; use collections::{BTreeMap, HashMap};
use editor::Bias; use editor::Bias;
use fs::{repository::GitFileStatus, FakeFs, Fs as _}; use fs::{FakeFs, Fs as _};
use futures::StreamExt; use futures::StreamExt;
use git::repository::GitFileStatus;
use gpui::{BackgroundExecutor, Model, TestAppContext}; use gpui::{BackgroundExecutor, Model, TestAppContext};
use language::{ use language::{
range_to_lsp, FakeLspAdapter, Language, LanguageConfig, LanguageMatcher, PointUtf16, range_to_lsp, FakeLspAdapter, Language, LanguageConfig, LanguageMatcher, PointUtf16,

View file

@ -6,6 +6,7 @@ use crate::{
use anyhow::{anyhow, Context as _, Result}; use anyhow::{anyhow, Context as _, Result};
use collections::HashSet; use collections::HashSet;
use futures::future::try_join_all; use futures::future::try_join_all;
use git::repository::GitFileStatus;
use gpui::{ use gpui::{
point, AnyElement, AppContext, AsyncWindowContext, Context, Entity, EntityId, EventEmitter, point, AnyElement, AppContext, AsyncWindowContext, Context, Entity, EntityId, EventEmitter,
IntoElement, Model, ParentElement, Pixels, SharedString, Styled, Task, View, ViewContext, 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, proto::serialize_anchor as serialize_text_anchor, Bias, Buffer, CharKind, OffsetRangeExt,
Point, SelectionGoal, Point, SelectionGoal,
}; };
use project::repository::GitFileStatus;
use project::{search::SearchQuery, FormatTrigger, Item as _, Project, ProjectPath}; use project::{search::SearchQuery, FormatTrigger, Item as _, Project, ProjectPath};
use rpc::proto::{self, update_view, PeerId}; use rpc::proto::{self, update_view, PeerId};
use settings::Settings; use settings::Settings;

View file

@ -16,7 +16,6 @@ collections.workspace = true
rope.workspace = true rope.workspace = true
text.workspace = true text.workspace = true
util.workspace = true util.workspace = true
sum_tree.workspace = true
anyhow.workspace = true anyhow.workspace = true
async-tar.workspace = true async-tar.workspace = true
@ -29,9 +28,7 @@ smol.workspace = true
git.workspace = true git.workspace = true
git2.workspace = true git2.workspace = true
serde.workspace = true serde.workspace = true
serde_derive.workspace = true
serde_json.workspace = true serde_json.workspace = true
log.workspace = true
libc = "0.2" libc = "0.2"
time.workspace = true time.workspace = true
@ -50,4 +47,4 @@ windows.workspace = true
gpui = { workspace = true, features = ["test-support"] } gpui = { workspace = true, features = ["test-support"] }
[features] [features]
test-support = ["gpui/test-support"] test-support = ["gpui/test-support", "git/test-support"]

View file

@ -1,5 +1,3 @@
pub mod repository;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
#[cfg(unix)] #[cfg(unix)]
@ -7,9 +5,9 @@ use std::os::unix::fs::MetadataExt;
use async_tar::Archive; use async_tar::Archive;
use futures::{future::BoxFuture, AsyncRead, Stream, StreamExt}; use futures::{future::BoxFuture, AsyncRead, Stream, StreamExt};
use git::repository::{GitRepository, RealGitRepository};
use git2::Repository as LibGitRepository; use git2::Repository as LibGitRepository;
use parking_lot::Mutex; use parking_lot::Mutex;
use repository::{GitRepository, RealGitRepository};
use rope::Rope; use rope::Rope;
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
use smol::io::AsyncReadExt; use smol::io::AsyncReadExt;
@ -29,7 +27,7 @@ use util::{paths, ResultExt};
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
use collections::{btree_map, BTreeMap}; use collections::{btree_map, BTreeMap};
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
use repository::{FakeGitRepositoryState, GitFileStatus}; use git::repository::{FakeGitRepositoryState, GitFileStatus};
#[cfg(any(test, feature = "test-support"))] #[cfg(any(test, feature = "test-support"))]
use std::ffi::OsStr; use std::ffi::OsStr;
@ -525,7 +523,7 @@ enum FakeFsEntry {
inode: u64, inode: u64,
mtime: SystemTime, mtime: SystemTime,
entries: BTreeMap<String, Arc<Mutex<FakeFsEntry>>>, entries: BTreeMap<String, Arc<Mutex<FakeFsEntry>>>,
git_repo_state: Option<Arc<Mutex<repository::FakeGitRepositoryState>>>, git_repo_state: Option<Arc<Mutex<git::repository::FakeGitRepositoryState>>>,
}, },
Symlink { Symlink {
target: PathBuf, target: PathBuf,
@ -1417,7 +1415,7 @@ impl Fs for FakeFs {
let state = git_repo_state let state = git_repo_state
.get_or_insert_with(|| Arc::new(Mutex::new(FakeGitRepositoryState::default()))) .get_or_insert_with(|| Arc::new(Mutex::new(FakeGitRepositoryState::default())))
.clone(); .clone();
Some(repository::FakeGitRepository::open(state)) Some(git::repository::FakeGitRepository::open(state))
} else { } else {
None None
} }

View file

@ -24,6 +24,9 @@ text.workspace = true
time.workspace = true time.workspace = true
url.workspace = true url.workspace = true
serde.workspace = true serde.workspace = true
rope.workspace = true
util.workspace = true
parking_lot.workspace = true
windows.workspace = true windows.workspace = true
[dev-dependencies] [dev-dependencies]

View file

@ -11,6 +11,7 @@ pub mod blame;
pub mod commit; pub mod commit;
pub mod diff; pub mod diff;
pub mod permalink; pub mod permalink;
pub mod repository;
lazy_static! { lazy_static! {
pub static ref DOT_GIT: &'static OsStr = OsStr::new(".git"); pub static ref DOT_GIT: &'static OsStr = OsStr::new(".git");

View file

@ -1,10 +1,10 @@
use crate::blame::Blame;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use collections::HashMap; use collections::HashMap;
use git::blame::Blame;
use git2::{BranchType, StatusShow}; use git2::{BranchType, StatusShow};
use parking_lot::Mutex; use parking_lot::Mutex;
use rope::Rope; use rope::Rope;
use serde_derive::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{
cmp::Ordering, cmp::Ordering,
path::{Component, Path, PathBuf}, path::{Component, Path, PathBuf},
@ -59,7 +59,7 @@ pub trait GitRepository: Send {
fn change_branch(&self, _: &str) -> Result<()>; fn change_branch(&self, _: &str) -> Result<()>;
fn create_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 { impl std::fmt::Debug for dyn GitRepository {
@ -231,7 +231,7 @@ impl GitRepository for RealGitRepository {
Ok(()) 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 let working_directory = self
.repository .repository
.workdir() .workdir()
@ -240,7 +240,7 @@ impl GitRepository for RealGitRepository {
const REMOTE_NAME: &str = "origin"; const REMOTE_NAME: &str = "origin";
let remote_url = self.remote_url(REMOTE_NAME); let remote_url = self.remote_url(REMOTE_NAME);
git::blame::Blame::for_path( crate::blame::Blame::for_path(
&self.git_binary_path, &self.git_binary_path,
working_directory, working_directory,
path, path,
@ -358,7 +358,7 @@ impl GitRepository for FakeGitRepository {
Ok(()) 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(); let state = self.state.lock();
state state
.blames .blames

View file

@ -21,7 +21,6 @@ use clock::ReplicaId;
use collections::{hash_map, BTreeMap, HashMap, HashSet, VecDeque}; use collections::{hash_map, BTreeMap, HashMap, HashSet, VecDeque};
use copilot::Copilot; use copilot::Copilot;
use debounced_delay::DebouncedDelay; use debounced_delay::DebouncedDelay;
use fs::repository::GitRepository;
use futures::{ use futures::{
channel::{ channel::{
mpsc::{self, UnboundedReceiver}, mpsc::{self, UnboundedReceiver},
@ -32,7 +31,7 @@ use futures::{
stream::FuturesUnordered, stream::FuturesUnordered,
AsyncWriteExt, Future, FutureExt, StreamExt, TryFutureExt, AsyncWriteExt, Future, FutureExt, StreamExt, TryFutureExt,
}; };
use git::blame::Blame; use git::{blame::Blame, repository::GitRepository};
use globset::{Glob, GlobSet, GlobSetBuilder}; use globset::{Glob, GlobSet, GlobSetBuilder};
use gpui::{ use gpui::{
AnyModel, AppContext, AsyncAppContext, BackgroundExecutor, BorrowAppContext, Context, Entity, AnyModel, AppContext, AsyncAppContext, BackgroundExecutor, BorrowAppContext, Context, Entity,

View file

@ -18,6 +18,7 @@ collections.workspace = true
db.workspace = true db.workspace = true
editor.workspace = true editor.workspace = true
file_icons.workspace = true file_icons.workspace = true
git.workspace = true
gpui.workspace = true gpui.workspace = true
menu.workspace = true menu.workspace = true
pretty_assertions.workspace = true pretty_assertions.workspace = true

View file

@ -8,6 +8,7 @@ use file_icons::FileIcons;
use anyhow::{anyhow, Result}; use anyhow::{anyhow, Result};
use collections::{hash_map, HashMap}; use collections::{hash_map, HashMap};
use git::repository::GitFileStatus;
use gpui::{ use gpui::{
actions, anchored, deferred, div, impl_actions, px, uniform_list, Action, AppContext, actions, anchored, deferred, div, impl_actions, px, uniform_list, Action, AppContext,
AssetSource, AsyncWindowContext, ClipboardItem, DismissEvent, Div, EventEmitter, FocusHandle, AssetSource, AsyncWindowContext, ClipboardItem, DismissEvent, Div, EventEmitter, FocusHandle,
@ -16,10 +17,7 @@ use gpui::{
UniformListScrollHandle, View, ViewContext, VisualContext as _, WeakView, WindowContext, UniformListScrollHandle, View, ViewContext, VisualContext as _, WeakView, WindowContext,
}; };
use menu::{Confirm, SelectNext, SelectPrev}; use menu::{Confirm, SelectNext, SelectPrev};
use project::{ use project::{Entry, EntryKind, Fs, Project, ProjectEntryId, ProjectPath, Worktree, WorktreeId};
repository::GitFileStatus, Entry, EntryKind, Fs, Project, ProjectEntryId, ProjectPath,
Worktree, WorktreeId,
};
use project_panel_settings::{ProjectPanelDockPosition, ProjectPanelSettings}; use project_panel_settings::{ProjectPanelDockPosition, ProjectPanelSettings};
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::{ use std::{

View file

@ -10,8 +10,8 @@ workspace = true
[dependencies] [dependencies]
anyhow.workspace = true anyhow.workspace = true
fs.workspace = true
fuzzy.workspace = true fuzzy.workspace = true
git.workspace = true
gpui.workspace = true gpui.workspace = true
picker.workspace = true picker.workspace = true
ui.workspace = true ui.workspace = true

View file

@ -1,6 +1,6 @@
use anyhow::{anyhow, bail, Result}; use anyhow::{anyhow, bail, Result};
use fs::repository::Branch;
use fuzzy::{StringMatch, StringMatchCandidate}; use fuzzy::{StringMatch, StringMatchCandidate};
use git::repository::Branch;
use gpui::{ use gpui::{
actions, rems, AnyElement, AppContext, DismissEvent, Element, EventEmitter, FocusHandle, actions, rems, AnyElement, AppContext, DismissEvent, Element, EventEmitter, FocusHandle,
FocusableView, InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled, FocusableView, InteractiveElement, IntoElement, ParentElement, Render, SharedString, Styled,

View file

@ -8,11 +8,8 @@ use anyhow::{anyhow, Context as _, Result};
use client::{proto, Client}; use client::{proto, Client};
use clock::ReplicaId; use clock::ReplicaId;
use collections::{HashMap, HashSet, VecDeque}; use collections::{HashMap, HashSet, VecDeque};
use fs::Fs;
use fs::{copy_recursive, RemoveOptions}; use fs::{copy_recursive, RemoveOptions};
use fs::{
repository::{GitFileStatus, GitRepository, RepoPath},
Fs,
};
use futures::{ use futures::{
channel::{ channel::{
mpsc::{self, UnboundedSender}, mpsc::{self, UnboundedSender},
@ -23,7 +20,10 @@ use futures::{
FutureExt as _, Stream, StreamExt, FutureExt as _, Stream, StreamExt,
}; };
use fuzzy::CharBag; use fuzzy::CharBag;
use git::{DOT_GIT, GITIGNORE}; use git::{
repository::{GitFileStatus, GitRepository, RepoPath},
DOT_GIT, GITIGNORE,
};
use gpui::{ use gpui::{
AppContext, AsyncAppContext, BackgroundExecutor, Context, EventEmitter, Model, ModelContext, AppContext, AsyncAppContext, BackgroundExecutor, Context, EventEmitter, Model, ModelContext,
Task, Task,

View file

@ -5,8 +5,8 @@ use crate::{
use anyhow::Result; use anyhow::Result;
use client::Client; use client::Client;
use clock::FakeSystemClock; use clock::FakeSystemClock;
use fs::{repository::GitFileStatus, FakeFs, Fs, RealFs, RemoveOptions}; use fs::{FakeFs, Fs, RealFs, RemoveOptions};
use git::GITIGNORE; use git::{repository::GitFileStatus, GITIGNORE};
use gpui::{BorrowAppContext, ModelContext, Task, TestAppContext}; use gpui::{BorrowAppContext, ModelContext, Task, TestAppContext};
use parking_lot::Mutex; use parking_lot::Mutex;
use postage::stream::Stream; use postage::stream::Stream;