move config module to a separate gitbutler-config crate

This commit is contained in:
Kiril Videlov 2024-07-08 14:49:45 +02:00
parent 71af86ef1e
commit f7094fcdff
No known key found for this signature in database
GPG Key ID: A4C733025427C471
12 changed files with 53 additions and 25 deletions

12
Cargo.lock generated
View File

@ -2167,6 +2167,16 @@ dependencies = [
"tracing",
]
[[package]]
name = "gitbutler-config"
version = "0.0.0"
dependencies = [
"anyhow",
"git2",
"gitbutler-core",
"serde",
]
[[package]]
name = "gitbutler-core"
version = "0.0.0"
@ -2291,6 +2301,7 @@ dependencies = [
"bstr",
"git2",
"gitbutler-command-context",
"gitbutler-config",
"gitbutler-core",
"gitbutler-git",
"gitbutler-testsupport",
@ -2329,6 +2340,7 @@ dependencies = [
"git2",
"gitbutler-branch",
"gitbutler-command-context",
"gitbutler-config",
"gitbutler-core",
"gitbutler-feedback",
"gitbutler-oplog",

View File

@ -14,6 +14,7 @@ members = [
"crates/gitbutler-repo",
"crates/gitbutler-command-context",
"crates/gitbutler-feedback",
"crates/gitbutler-config",
]
resolver = "2"
@ -39,6 +40,7 @@ gitbutler-branchstate = { path = "crates/gitbutler-branchstate" }
gitbutler-repo = { path = "crates/gitbutler-repo" }
gitbutler-command-context = { path = "crates/gitbutler-command-context" }
gitbutler-feedback = { path = "crates/gitbutler-feedback" }
gitbutler-config = { path = "crates/gitbutler-config" }
[profile.release]
codegen-units = 1 # Compile crates one after another so the compiler can optimize better

View File

@ -0,0 +1,12 @@
[package]
name = "gitbutler-config"
version = "0.0.0"
edition = "2021"
authors = ["GitButler <gitbutler@gitbutler.com>"]
publish = false
[dependencies]
gitbutler-core.workspace = true
git2.workspace = true
anyhow = "1.0.86"
serde = { workspace = true, features = ["std"]}

View File

@ -0,0 +1,20 @@
use anyhow::Result;
use gitbutler_core::projects::Project;
use super::git::{GbConfig, GitConfig};
pub trait ProjectCommands {
fn gb_config(&self) -> Result<GbConfig>;
fn set_gb_config(&self, config: GbConfig) -> Result<()>;
}
impl ProjectCommands for Project {
fn gb_config(&self) -> Result<GbConfig> {
let repo = git2::Repository::open(&self.path)?;
repo.gb_config()
}
fn set_gb_config(&self, config: GbConfig) -> Result<()> {
let repo = git2::Repository::open(&self.path)?;
repo.set_gb_config(config)
}
}

View File

@ -1,15 +0,0 @@
use crate::projects::Project;
use anyhow::Result;
use super::git::{GbConfig, GitConfig};
impl Project {
pub fn gb_config(&self) -> Result<GbConfig> {
let repo = git2::Repository::open(&self.path)?;
repo.gb_config()
}
pub fn set_gb_config(&self, config: GbConfig) -> Result<()> {
let repo = git2::Repository::open(&self.path)?;
repo.set_gb_config(config)
}
}

View File

@ -15,7 +15,6 @@
pub mod askpass;
pub mod assets;
pub mod config;
pub mod dedup;
pub mod error;
pub mod fs;

View File

@ -17,6 +17,7 @@ tempfile = "3.10"
thiserror.workspace = true
resolve-path = "0.1.0"
gitbutler-command-context.workspace = true
gitbutler-config.workspace = true
[[test]]
name="repo"

View File

@ -1,13 +1,11 @@
use anyhow::{anyhow, bail, Context, Result};
use bstr::BString;
use git2::{BlameOptions, Repository, Tree};
use gitbutler_config::git::{GbConfig, GitConfig};
use std::{path::Path, process::Stdio, str};
use tracing::instrument;
use gitbutler_core::{
config::git::{GbConfig, GitConfig},
error::Code,
};
use gitbutler_core::error::Code;
use gitbutler_core::git::{CommitBuffer, CommitHeadersV2, Refname, RemoteRefname};
use std::io::Write;

View File

@ -53,6 +53,7 @@ gitbutler-oplog.workspace = true
gitbutler-repo.workspace = true
gitbutler-command-context.workspace = true
gitbutler-feedback.workspace = true
gitbutler-config.workspace = true
open = "5"
[dependencies.tauri]

View File

@ -1,8 +1,6 @@
use crate::error::Error;
use gitbutler_core::{
config::git::GbConfig,
projects::{self, ProjectId},
};
use gitbutler_config::{api::ProjectCommands, git::GbConfig};
use gitbutler_core::projects::{self, ProjectId};
use tauri::Manager;
use tracing::instrument;