use std::path::PathBuf; use std::sync::Arc; use ::cache::Cache; use db::AppDatabase; use models::repo::repos; use proto::kenshell::common::v1::{GitActor, RepositoryRef, WriteOptions}; #[derive(Clone)] pub struct GitContext { pub model: repos::Model, pub cache: Cache, pub database: Arc, pub space_name: String, pub repo_root: PathBuf, pub ks: proto::KenShellClient, } impl GitContext { pub fn repository_ref(&self) -> RepositoryRef { RepositoryRef { org_name: self.space_name.clone(), repo_name: self.model.name.clone(), } } pub fn actor(&self) -> GitActor { GitActor { user_id: 0, username: String::new(), } } pub fn write_options(&self) -> WriteOptions { WriteOptions { holder: format!("kenapi-{}", self.model.id), lock_ttl: Some(prost_types::Duration { seconds: 30, nanos: 0, }), lock_wait: Some(prost_types::Duration { seconds: 5, nanos: 0, }), require_all_replicas: false, } } /// 本地不再保存提交计数,空仓库的判定交给托管面返回空结果。 pub fn repo_uninitialized(&self) -> bool { false } }