From 6495268f002e1eeb27d13c58eec34ac4fa9b4ee6 Mon Sep 17 00:00:00 2001 From: Mica White Date: Mon, 30 Mar 2026 21:06:31 -0400 Subject: Refactor out config type --- src/lib.rs | 41 ++++------------------------------------- 1 file changed, 4 insertions(+), 37 deletions(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 9535bf7..dd8ee86 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -27,45 +27,20 @@ * git repair-autosave */ -use std::collections::{HashMap, HashSet}; -use std::path::{Path, PathBuf}; +use std::path::Path; -use confy::ConfyError; use git2::{ Commit, FetchOptions, MergeOptions, Oid, PushOptions, Reference, RemoteCallbacks, Repository, Signature, Time, Tree, }; use is_executable::is_executable; -use serde::{Deserialize, Serialize}; use thiserror::Error; use uuid::Uuid; pub mod authenticate; +pub mod config; -#[derive(Default, Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] -pub struct Config { - repositories: HashSet, - passwords: HashMap, String)>, - passphrases: HashMap, -} - -impl Config { - pub fn repositories(&self) -> &HashSet { - &self.repositories - } - - pub fn username_for_url(&self, url: &str) -> Option<&String> { - self.passwords.get(url)?.0.as_ref() - } - - pub fn password_for_url(&self, url: &str) -> Option<&String> { - Some(&self.passwords.get(url)?.1) - } - - pub fn passphrase_for_key(&self, key: &Path) -> Option<&String> { - self.passphrases.get(key) - } -} +pub use config::Config; #[derive(Debug, Error)] pub enum TreeError { @@ -75,14 +50,6 @@ pub enum TreeError { Git(#[from] git2::Error), } -pub fn load_config() -> Result { - confy::load("git-autosave", "git-autosaved") -} - -pub fn save_config(config: &Config) -> Result<(), ConfyError> { - confy::store("git-autosave", "git-autosaved", config) -} - pub fn repository_id(repository: &Repository) -> Result { repository .config()? @@ -106,7 +73,7 @@ pub fn init(repository: &Repository, config: Option<&mut Config>) -> Result