Compare commits

..

No commits in common. "cdad66531eded3a2fd5c51392c613114f79cbc49" and "b07f08b7c1bcb0cfd6f0daa10ea40d1c0e9d236a" have entirely different histories.

9 changed files with 70 additions and 93 deletions

View file

@ -17,6 +17,6 @@ pub use generation::Generation;
pub use git_ref::GitRef; pub use git_ref::GitRef;
pub use git_remote::GitRemote; pub use git_remote::GitRemote;
pub use repo_details::RepoDetails; pub use repo_details::RepoDetails;
pub use repository::OpenRepository; pub use repository::open::OpenRepository;
pub use repository::Repository; pub use repository::Repository;
pub use validate::validate; pub use validate::validate;

View file

@ -1,17 +1,12 @@
use git_next_config::GitDir;
use crate::{
repository::{open::OpenRepository, Error, RepositoryLike},
RepoDetails,
};
use super::*;
pub struct MockRepository; pub struct MockRepository;
impl RepositoryLike for MockRepository { impl RepositoryLike for MockRepository {
fn open(&self, _gitdir: &GitDir) -> Result<OpenRepository, Error> { fn open(&self, _gitdir: &GitDir) -> Result<open::OpenRepository, Error> {
Ok(OpenRepository::Mock) Ok(open::OpenRepository::Mock)
} }
fn git_clone(&self, _repo_details: &RepoDetails) -> Result<OpenRepository, Error> { fn git_clone(&self, _repo_details: &RepoDetails) -> Result<open::OpenRepository, Error> {
Ok(OpenRepository::Mock) Ok(open::OpenRepository::Mock)
} }
} }

View file

@ -2,12 +2,18 @@
#![cfg(not(tarpaulin_include))] #![cfg(not(tarpaulin_include))]
mod mock; mod mock;
mod open; pub mod open;
mod real; mod real;
use git_next_config::GitDir; use std::{
ops::Deref as _,
sync::{atomic::AtomicBool, Arc, Mutex},
};
pub use open::OpenRepository; use git_next_config::{BranchName, GitDir, Hostname, RepoPath};
use tracing::{info, warn};
use crate::{fetch, push, GitRef, GitRemote};
use super::RepoDetails; use super::RepoDetails;
@ -24,8 +30,8 @@ pub const fn mock() -> Repository {
} }
pub trait RepositoryLike { pub trait RepositoryLike {
fn open(&self, gitdir: &GitDir) -> Result<OpenRepository, Error>; fn open(&self, gitdir: &GitDir) -> Result<open::OpenRepository, Error>;
fn git_clone(&self, repo_details: &RepoDetails) -> Result<OpenRepository, Error>; fn git_clone(&self, repo_details: &RepoDetails) -> Result<open::OpenRepository, Error>;
} }
impl std::ops::Deref for Repository { impl std::ops::Deref for Repository {
type Target = dyn RepositoryLike; type Target = dyn RepositoryLike;
@ -61,23 +67,23 @@ pub enum Error {
Wait(std::io::Error), Wait(std::io::Error),
Spawn(std::io::Error), Spawn(std::io::Error),
Validation(String), Validation(String),
Clone(String), GixClone(Box<gix::clone::Error>),
Open(String), GixOpen(Box<gix::open::Error>),
Fetch(String), GixFetch(Box<gix::clone::fetch::Error>),
} }
impl std::error::Error for Error {} impl std::error::Error for Error {}
impl From<gix::clone::Error> for Error { impl From<gix::clone::Error> for Error {
fn from(value: gix::clone::Error) -> Self { fn from(value: gix::clone::Error) -> Self {
Self::Clone(value.to_string()) Self::GixClone(Box::new(value))
} }
} }
impl From<gix::open::Error> for Error { impl From<gix::open::Error> for Error {
fn from(value: gix::open::Error) -> Self { fn from(value: gix::open::Error) -> Self {
Self::Open(value.to_string()) Self::GixOpen(Box::new(value))
} }
} }
impl From<gix::clone::fetch::Error> for Error { impl From<gix::clone::fetch::Error> for Error {
fn from(value: gix::clone::fetch::Error) -> Self { fn from(value: gix::clone::fetch::Error) -> Self {
Self::Fetch(value.to_string()) Self::GixFetch(Box::new(value))
} }
} }

View file

@ -1,14 +1,35 @@
//
use std::sync::{Arc, Mutex};
use git_next_config::{BranchName, Hostname, RepoPath}; use super::*;
use tracing::{info, warn}; #[derive(Clone, Debug)]
pub enum OpenRepository {
Real(RealOpenRepository),
Mock, // TODO: (#38) contain a mock model of a repo
}
pub trait OpenRepositoryLike {
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote>;
fn fetch(&self) -> Result<(), fetch::Error>;
fn push(
&self,
repo_details: &RepoDetails,
branch_name: BranchName,
to_commit: GitRef,
force: push::Force,
) -> Result<(), push::Error>;
}
impl std::ops::Deref for OpenRepository {
type Target = dyn OpenRepositoryLike;
use crate::{fetch, push, repository::Direction, GitRef, GitRemote, RepoDetails}; fn deref(&self) -> &Self::Target {
match self {
Self::Real(real) => real,
Self::Mock => todo!(),
}
}
}
#[derive(Clone, Debug, derive_more::Constructor)] #[derive(Clone, Debug, derive_more::Constructor)]
pub struct RealOpenRepository(Arc<Mutex<gix::Repository>>); pub struct RealOpenRepository(Arc<Mutex<gix::Repository>>);
impl super::OpenRepositoryLike for RealOpenRepository { impl OpenRepositoryLike for RealOpenRepository {
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote> { fn find_default_remote(&self, direction: Direction) -> Option<GitRemote> {
let Ok(repository) = self.0.lock() else { let Ok(repository) = self.0.lock() else {
return None; return None;

View file

@ -1,44 +0,0 @@
//
pub mod oreal;
use std::sync::{Arc, Mutex};
use git_next_config::BranchName;
use crate::{
fetch, push,
repository::{open::oreal::RealOpenRepository, Direction},
GitRef, GitRemote, RepoDetails,
};
#[derive(Clone, Debug)]
pub enum OpenRepository {
Real(oreal::RealOpenRepository),
Mock, // TODO: (#38) contain a mock model of a repo
}
impl OpenRepository {
pub fn new(gix_repo: gix::Repository) -> Self {
Self::Real(RealOpenRepository::new(Arc::new(Mutex::new(gix_repo))))
}
}
pub trait OpenRepositoryLike {
fn find_default_remote(&self, direction: Direction) -> Option<GitRemote>;
fn fetch(&self) -> Result<(), fetch::Error>;
fn push(
&self,
repo_details: &RepoDetails,
branch_name: BranchName,
to_commit: GitRef,
force: push::Force,
) -> Result<(), push::Error>;
}
impl std::ops::Deref for OpenRepository {
type Target = dyn OpenRepositoryLike;
fn deref(&self) -> &Self::Target {
match self {
Self::Real(real) => real,
Self::Mock => todo!(),
}
}
}

View file

@ -1,28 +1,24 @@
use std::sync::atomic::AtomicBool;
use derive_more::Deref as _;
use git_next_config::GitDir;
use crate::{
repository::{open::OpenRepository, Error, RepositoryLike},
RepoDetails,
};
use super::*;
pub struct RealRepository; pub struct RealRepository;
impl RepositoryLike for RealRepository { impl RepositoryLike for RealRepository {
fn open(&self, gitdir: &GitDir) -> Result<OpenRepository, Error> { fn open(&self, gitdir: &GitDir) -> Result<open::OpenRepository, Error> {
let gix_repo = gix::ThreadSafeRepository::open(gitdir.to_path_buf())?.to_thread_local(); Ok(open::OpenRepository::Real(open::RealOpenRepository::new(
Ok(OpenRepository::new(gix_repo)) Arc::new(Mutex::new(
gix::ThreadSafeRepository::open(gitdir.to_path_buf())?.to_thread_local(),
)),
)))
} }
fn git_clone(&self, repo_details: &RepoDetails) -> Result<OpenRepository, Error> { fn git_clone(&self, repo_details: &RepoDetails) -> Result<open::OpenRepository, Error> {
use secrecy::ExposeSecret; use secrecy::ExposeSecret;
let (gix_repo, _outcome) = gix::prepare_clone_bare( let origin = repo_details.origin();
repo_details.origin().expose_secret().as_str(), let (repository, _outcome) =
repo_details.gitdir.deref(), gix::prepare_clone_bare(origin.expose_secret().as_str(), repo_details.gitdir.deref())?
)?
.fetch_only(gix::progress::Discard, &AtomicBool::new(false))?; .fetch_only(gix::progress::Discard, &AtomicBool::new(false))?;
Ok(OpenRepository::new(gix_repo)) Ok(open::OpenRepository::Real(open::RealOpenRepository::new(
Arc::new(Mutex::new(repository)),
)))
} }
} }

View file

@ -1,6 +1,6 @@
use tracing::info; use tracing::info;
use crate::repository::{Direction, OpenRepository}; use crate::repository::{open::OpenRepository, Direction};
use super::{GitRemote, RepoDetails}; use super::{GitRemote, RepoDetails};

View file

@ -21,6 +21,8 @@ tracing-subscriber = { workspace = true }
base64 = { workspace = true } base64 = { workspace = true }
# git # git
# gix = { workspace = true }
gix = { workspace = true }
async-trait = { workspace = true } async-trait = { workspace = true }
# fs/network # fs/network

View file

@ -1,6 +1,7 @@
use actix::prelude::*; use actix::prelude::*;
use git_next_git as git; use git_next_git as git;
use tracing::{info, warn}; use gix::trace::warn;
use tracing::info;
use crate::{actors::repo::ValidateRepo, gitforge, types::MessageToken}; use crate::{actors::repo::ValidateRepo, gitforge, types::MessageToken};