mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-09-11 12:25:42 +03:00
remove dependence of projects controller towards repo actions
This commit is contained in:
parent
50577f3865
commit
569d282700
@ -16,6 +16,8 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use crate::{error::Code, git::CommitHeadersV2};
|
use crate::{error::Code, git::CommitHeadersV2};
|
||||||
|
|
||||||
|
use super::Config;
|
||||||
|
|
||||||
pub struct ProjectRepo {
|
pub struct ProjectRepo {
|
||||||
git_repository: git2::Repository,
|
git_repository: git2::Repository,
|
||||||
project: projects::Project,
|
project: projects::Project,
|
||||||
@ -137,14 +139,9 @@ pub trait RepoActions {
|
|||||||
P: AsRef<std::path::Path>;
|
P: AsRef<std::path::Path>;
|
||||||
fn get_head(&self) -> Result<git2::Reference>;
|
fn get_head(&self) -> Result<git2::Reference>;
|
||||||
fn git_index_size(&self) -> Result<usize>;
|
fn git_index_size(&self) -> Result<usize>;
|
||||||
fn config(&self) -> super::Config;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl RepoActions for ProjectRepo {
|
impl RepoActions for ProjectRepo {
|
||||||
fn config(&self) -> super::Config {
|
|
||||||
super::Config::from(&self.git_repository)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn git_index_size(&self) -> Result<usize> {
|
fn git_index_size(&self) -> Result<usize> {
|
||||||
let head = self.git_repository.index()?.len();
|
let head = self.git_repository.index()?.len();
|
||||||
Ok(head)
|
Ok(head)
|
||||||
@ -657,7 +654,7 @@ impl RepoActions for ProjectRepo {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn signatures(project_repo: &ProjectRepo) -> Result<(git2::Signature, git2::Signature)> {
|
fn signatures(project_repo: &ProjectRepo) -> Result<(git2::Signature, git2::Signature)> {
|
||||||
let config = project_repo.config();
|
let config: Config = project_repo.repo().into();
|
||||||
|
|
||||||
let author = match (config.user_name()?, config.user_email()?) {
|
let author = match (config.user_name()?, config.user_email()?) {
|
||||||
(None, Some(email)) => git2::Signature::now(&email, &email)?,
|
(None, Some(email)) => git2::Signature::now(&email, &email)?,
|
||||||
|
@ -10,7 +10,7 @@ use bstr::BString;
|
|||||||
use super::{storage, storage::UpdateRequest, Project, ProjectId};
|
use super::{storage, storage::UpdateRequest, Project, ProjectId};
|
||||||
use crate::projects::AuthKey;
|
use crate::projects::AuthKey;
|
||||||
use crate::{error, project_repository};
|
use crate::{error, project_repository};
|
||||||
use crate::{git::RepositoryExt, project_repository::RepoActions};
|
use crate::{git::RepositoryExt, project_repository::Config};
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait Watchers {
|
pub trait Watchers {
|
||||||
@ -217,15 +217,17 @@ impl Controller {
|
|||||||
pub fn get_local_config(&self, id: ProjectId, key: &str) -> Result<Option<String>> {
|
pub fn get_local_config(&self, id: ProjectId, key: &str) -> Result<Option<String>> {
|
||||||
let project = self.projects_storage.get(id)?;
|
let project = self.projects_storage.get(id)?;
|
||||||
|
|
||||||
let repo = project_repository::ProjectRepo::open(&project)?;
|
let project_repo = project_repository::ProjectRepo::open(&project)?;
|
||||||
repo.config().get_local(key)
|
let config: Config = project_repo.repo().into();
|
||||||
|
config.get_local(key)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_local_config(&self, id: ProjectId, key: &str, value: &str) -> Result<()> {
|
pub fn set_local_config(&self, id: ProjectId, key: &str, value: &str) -> Result<()> {
|
||||||
let project = self.projects_storage.get(id)?;
|
let project = self.projects_storage.get(id)?;
|
||||||
|
|
||||||
let repo = project_repository::ProjectRepo::open(&project)?;
|
let project_repo = project_repository::ProjectRepo::open(&project)?;
|
||||||
repo.config().set_local(key, value)
|
let config: Config = project_repo.repo().into();
|
||||||
|
config.set_local(key, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_signing_settings(&self, id: ProjectId) -> Result<bool> {
|
pub fn check_signing_settings(&self, id: ProjectId) -> Result<bool> {
|
||||||
|
Loading…
Reference in New Issue
Block a user