1480255
use std::sync::Arc;
use export::AppDatabase;
use proto::KenShellClient;
use sea_orm::DatabaseConnection;
use crate::context::facade::GitContext;
use crate::rpcgit::GitBaby;
#[derive(Clone)]
pub struct GitService {
pub(crate) state: GitBackend,
pub(crate) database: Arc<AppDatabase>,
pub(crate) accounts: auth::Accounts,
pub(crate) access: space::Access,
}
impl GitService {
pub fn new(
database: Arc<AppDatabase>,
accounts: auth::Accounts,
access: space::Access,
backend: GitBackend,
) -> Self {
Self {
database,
accounts,
access,
state: backend,
}
}
pub fn ks(&self) -> &KenShellClient {
&self.state.client
}
pub fn baby(&self, ctx: &GitContext) -> GitBaby {
GitBaby::new(Arc::new(ctx.clone()))
}
pub fn db_write(&self) -> &DatabaseConnection {
self.database.write()
}
pub fn db_read(&self) -> &export::DbConn {
self.database.read()
}
}
#[derive(Clone)]
pub struct GitBackend {
pub(crate) config: GitSettings,
cache: cache::Cache,
client: Arc<KenShellClient>,
}
impl GitBackend {
pub fn new(
cache: cache::Cache,
config: config::git::GitConfig,
client: Arc<KenShellClient>,
) -> Self {
Self {
cache,
client,
config: GitSettings { git: config },
}
}
pub(crate) fn context(
&self,
database: Arc<AppDatabase>,
model: models::repo::repos::Model,
space_name: String,
) -> GitContext {
GitContext {
model,
cache: self.cache.clone(),
database,
space_name,
repo_root: std::path::PathBuf::from(&self.config.git.repo_root),
ks: self.client.as_ref().clone(),
}
}
}
#[derive(Clone)]
pub(crate) struct GitSettings {
pub git: config::git::GitConfig,
}