use crate::git::storage::LocalStore;
use anyhow::Result;
use hashtree_config::Config;
use hashtree_core::Store;
use std::collections::HashSet;
use std::path::{Path, PathBuf};
use std::sync::Arc;
pub(super) fn get_hashtree_data_dir() -> PathBuf {
hashtree_config::get_data_dir()
}
pub(super) fn queue_hash_if_new(
queue: &mut Vec<([u8; 32], Option<[u8; 32]>)>,
queued: &mut HashSet<[u8; 32]>,
hash: [u8; 32],
key: Option<[u8; 32]>,
) -> bool {
if queued.insert(hash) {
queue.push((hash, key));
true
} else {
false
}
}
pub(super) fn create_local_store(path: &Path) -> Result<Arc<dyn Store + Send + Sync>> {
let config = Config::load_or_default();
let max_size_bytes = config
.storage
.max_size_gb
.saturating_mul(1024 * 1024 * 1024);
let store = LocalStore::new_for_backend(path, config.storage.backend, max_size_bytes)?;
Ok(Arc::new(store))
}
pub(super) fn build_repo_viewer_url(path: &str, url_secret: Option<&[u8; 32]>) -> String {
match url_secret {
Some(secret) => format!("https://git.iris.to/#/{}?k={}", path, hex::encode(secret)),
None => format!("https://git.iris.to/#/{}", path),
}
}