Files
signed/crates/signed_state/src/git_store.rs
T
reya c76e909f7f
Rust / build (macos-latest, stable) (push) Canceled after 0s
Rust / build (ubuntu-latest, stable) (push) Canceled after 0s
Rust / build (windows-latest, stable) (push) Canceled after 0s
chore: refactor backend around domain types (#26)
Reviewed-on: #26
2026-10-03 10:35:48 +00:00

42 lines
1022 B
Rust

use std::path::PathBuf;
use std::sync::OnceLock;
use anyhow::Result;
use nostr::prelude::Url;
use signed_core::RepoAddr;
use signed_git::{GitCache, Repo};
static GIT_CACHE: OnceLock<GitCache> = OnceLock::new();
pub struct Mirrors;
impl Mirrors {
pub fn install(root: impl Into<PathBuf>) {
if GIT_CACHE.set(GitCache::new(root.into())).is_err() {
log::warn!("git cache root is already set, keeping the first one");
}
}
fn cache() -> &'static GitCache {
GIT_CACHE
.get()
.expect("git cache is initialized by signed_state::init")
}
pub(crate) fn root() -> PathBuf {
Self::cache().root().to_path_buf()
}
pub fn path(addr: &RepoAddr) -> PathBuf {
Self::cache().repo_path(addr)
}
pub fn open(addr: &RepoAddr) -> Result<Option<Repo>> {
Self::cache().open(addr)
}
pub fn ensure(addr: &RepoAddr, clone_urls: &[Url]) -> Result<Repo> {
Self::cache().ensure_clone(addr, clone_urls)
}
}