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",
"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",

View File

@ -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,

View File

@ -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,

View File

@ -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;

View File

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

View File

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

View File

@ -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");

View File

@ -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
.blames

View File

@ -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,

View File

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

View File

@ -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::{

View File

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

View File

@ -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,

View File

@ -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,

View File

@ -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;