summaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs41
1 files changed, 4 insertions, 37 deletions
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<PathBuf>,
- passwords: HashMap<String, (Option<String>, String)>,
- passphrases: HashMap<PathBuf, String>,
-}
-
-impl Config {
- pub fn repositories(&self) -> &HashSet<PathBuf> {
- &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<Config, ConfyError> {
- 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<String, git2::Error> {
repository
.config()?
@@ -106,7 +73,7 @@ pub fn init(repository: &Repository, config: Option<&mut Config>) -> Result<Uuid
if let Some(config) = config
&& let Some(workdir) = workdir
{
- config.repositories.insert(workdir.into());
+ config.repositories_mut().insert(workdir.into());
}
Ok(id)