refactor git cache
This commit is contained in:
@@ -17,6 +17,7 @@ nostr-connect.workspace = true
|
||||
|
||||
bitcoin_hashes = "1"
|
||||
|
||||
gix.workspace = true
|
||||
gpui.workspace = true
|
||||
flume.workspace = true
|
||||
futures.workspace = true
|
||||
|
||||
@@ -13,7 +13,7 @@ use nostr_sdk::prelude::*;
|
||||
use signed_core::{Announcement, RepoAddr, build_state, filters, identifier_from_name};
|
||||
use signed_nostr::{SignedAuthUrlHandler, UniversalSigner, Update};
|
||||
|
||||
use crate::git_store::git_cache;
|
||||
use crate::git_store::repo_mirror_path;
|
||||
use crate::inbox::Inbox;
|
||||
use crate::repos::RepoListStore;
|
||||
|
||||
@@ -756,8 +756,7 @@ impl Backend {
|
||||
announcement: Announcement,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<Result<PushOutcome, Error>> {
|
||||
let cache = git_cache();
|
||||
let path = cache.repo_path(&announcement.addr());
|
||||
let path = repo_mirror_path(&announcement.addr());
|
||||
self.push_repo_from(announcement, path, None, cx)
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ use settings::{CheckoutRecord, SettingsStore};
|
||||
use signed_core::{Announcement, RepoAddr};
|
||||
|
||||
use crate::backend::{Backend, BackendEvent};
|
||||
use crate::git_store::git_cache;
|
||||
use crate::git_store::repo_mirror_root;
|
||||
use crate::refresh::{RefreshGate, RefreshRequest};
|
||||
use crate::repos::{LocalReposStore, RepoListStore};
|
||||
|
||||
@@ -328,7 +328,7 @@ impl CheckoutsStore {
|
||||
|
||||
let announcements = RepoListStore::global(cx).read(cx).announcements.clone();
|
||||
let scanned = LocalReposStore::global(cx).read(cx).repos.clone();
|
||||
let cache_root = git_cache().root().canonicalize().ok();
|
||||
let cache_root = repo_mirror_root().canonicalize().ok();
|
||||
|
||||
let requested: Vec<(RepoAddr, Option<String>)> = self
|
||||
.status_requested
|
||||
|
||||
@@ -1,17 +1,39 @@
|
||||
use std::path::PathBuf;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use anyhow::Result;
|
||||
use gix::Repository;
|
||||
use signed_core::RepoAddr;
|
||||
use signed_git::GitCache;
|
||||
|
||||
static GIT_CACHE: OnceLock<GitCache> = OnceLock::new();
|
||||
|
||||
/// Global access to the on-disk git clone cache, the grasp mirrors.
|
||||
pub fn git_cache() -> &'static GitCache {
|
||||
fn git_cache() -> &'static GitCache {
|
||||
GIT_CACHE
|
||||
.get()
|
||||
.expect("git cache is initialized by signed_state::init")
|
||||
}
|
||||
|
||||
/// The root directory of the repository mirrors.
|
||||
pub(crate) fn repo_mirror_root() -> PathBuf {
|
||||
git_cache().root().to_path_buf()
|
||||
}
|
||||
|
||||
/// The on-disk path of the mirror of `addr`.
|
||||
pub fn repo_mirror_path(addr: &RepoAddr) -> PathBuf {
|
||||
git_cache().repo_path(addr)
|
||||
}
|
||||
|
||||
/// Open the mirror of `addr`, if it has been cloned.
|
||||
pub fn open_repo_mirror(addr: &RepoAddr) -> Result<Option<Repository>> {
|
||||
git_cache().open(addr)
|
||||
}
|
||||
|
||||
/// Open the mirror of `addr`, cloning it first when it does not exist yet.
|
||||
pub fn ensure_repo_mirror<U: AsRef<str>>(addr: &RepoAddr, clone_urls: &[U]) -> Result<Repository> {
|
||||
git_cache().ensure_clone(addr, clone_urls)
|
||||
}
|
||||
|
||||
pub(crate) fn set_git_cache(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");
|
||||
|
||||
@@ -11,8 +11,8 @@ use std::path::{Path, PathBuf};
|
||||
|
||||
pub use backend::{Backend, BackendEvent, user_grasp_list_servers};
|
||||
pub use checkouts::{CheckoutStatus, CheckoutsStore, pr_proposes_checkout};
|
||||
pub use git_store::git_cache;
|
||||
use git_store::set_git_cache;
|
||||
pub use git_store::{ensure_repo_mirror, open_repo_mirror, repo_mirror_path};
|
||||
use gpui::{App, AppContext};
|
||||
pub use inbox::{Inbox, query_inbox};
|
||||
pub use nostr_sdk::prelude::Timestamp;
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::backend::{
|
||||
user_grasp_list_servers,
|
||||
};
|
||||
use crate::checkouts::CheckoutsStore;
|
||||
use crate::git_store::git_cache;
|
||||
use crate::git_store::ensure_repo_mirror;
|
||||
use crate::refresh::{RefreshGate, RefreshRequest};
|
||||
use crate::repos::RepoListStore;
|
||||
|
||||
@@ -1196,8 +1196,6 @@ impl RepoStore {
|
||||
return;
|
||||
}
|
||||
|
||||
let cache = git_cache();
|
||||
|
||||
let clone_urls: Vec<Url> = self
|
||||
.announcement
|
||||
.as_ref()
|
||||
@@ -1223,7 +1221,7 @@ impl RepoStore {
|
||||
let root = root.clone();
|
||||
|
||||
let apply = cx.background_spawn(async move {
|
||||
let repo = cache.ensure_clone(&addr, &clone_urls)?;
|
||||
let repo = ensure_repo_mirror(&addr, &clone_urls)?;
|
||||
let workdir = repo
|
||||
.workdir()
|
||||
.ok_or_else(|| anyhow::anyhow!("repository has no worktree"))?
|
||||
|
||||
Reference in New Issue
Block a user