Compare commits
7
Commits
534d572154
...
e08a96a106
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e08a96a106 | ||
|
|
db010da4b9 | ||
|
|
1e19fb6b17 | ||
|
|
2414095725 | ||
|
|
22b96c3546 | ||
|
|
7aee19f3aa | ||
|
|
f5cc2ea60f |
Generated
+1
@@ -8006,6 +8006,7 @@ dependencies = [
|
||||
"bitcoin_hashes 1.2.0",
|
||||
"flume 0.11.1",
|
||||
"futures",
|
||||
"gix",
|
||||
"gpui",
|
||||
"log",
|
||||
"nostr",
|
||||
|
||||
@@ -90,9 +90,13 @@ pub fn nostr_dir() -> &'static PathBuf {
|
||||
}
|
||||
|
||||
/// Returns the path to the local git clone cache, the grasp mirrors.
|
||||
///
|
||||
/// The mirrors are disposable and re-cloned from their grasp server on
|
||||
/// demand, so the cache lives in the OS temp directory for the system to
|
||||
/// reclaim.
|
||||
pub fn repos_dir() -> &'static PathBuf {
|
||||
static REPOS_DIR: OnceLock<PathBuf> = OnceLock::new();
|
||||
REPOS_DIR.get_or_init(|| data_dir().join("repos"))
|
||||
REPOS_DIR.get_or_init(|| std::env::temp_dir().join(APP_NAME_LOWERCASE).join("repos"))
|
||||
}
|
||||
|
||||
pub fn settings_file() -> &'static PathBuf {
|
||||
|
||||
@@ -17,6 +17,7 @@ nostr-connect.workspace = true
|
||||
|
||||
bitcoin_hashes = "1"
|
||||
|
||||
gix.workspace = true
|
||||
gpui.workspace = true
|
||||
flume.workspace = true
|
||||
futures.workspace = true
|
||||
|
||||
@@ -5,7 +5,7 @@ use std::time::{Duration, Instant};
|
||||
|
||||
use anyhow::{Error, anyhow, bail};
|
||||
use bitcoin_hashes::sha1::Hash as Sha1Hash;
|
||||
use gpui::{App, AppContext, Context, Entity, EventEmitter, Global, Task};
|
||||
use gpui::{App, AppContext, BackgroundExecutor, Context, Entity, EventEmitter, Global, Task};
|
||||
use nostr::event::IntoEventBuilder;
|
||||
use nostr_connect::prelude::*;
|
||||
use nostr_sdk::client::SyncSummary;
|
||||
@@ -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::GitStore;
|
||||
use crate::git_store::repo_mirror_path;
|
||||
use crate::inbox::Inbox;
|
||||
use crate::repos::RepoListStore;
|
||||
|
||||
@@ -531,6 +531,7 @@ impl Backend {
|
||||
let repo_id = repo_id.clone();
|
||||
let servers = servers.clone();
|
||||
let refs = refs.clone();
|
||||
let executor = cx.background_executor().clone();
|
||||
async move {
|
||||
push_staged_to_grasps(
|
||||
&client,
|
||||
@@ -541,6 +542,7 @@ impl Backend {
|
||||
&destination,
|
||||
&owner,
|
||||
&servers,
|
||||
&executor,
|
||||
signed_git::push_main,
|
||||
)
|
||||
.await
|
||||
@@ -686,6 +688,7 @@ impl Backend {
|
||||
let servers = servers.clone();
|
||||
let refs = refs.clone();
|
||||
let head = head.clone();
|
||||
let executor = cx.background_executor().clone();
|
||||
async move {
|
||||
push_staged_to_grasps(
|
||||
&client,
|
||||
@@ -696,6 +699,7 @@ impl Backend {
|
||||
&path,
|
||||
&owner,
|
||||
&servers,
|
||||
&executor,
|
||||
signed_git::push_all,
|
||||
)
|
||||
.await
|
||||
@@ -752,8 +756,7 @@ impl Backend {
|
||||
announcement: Announcement,
|
||||
cx: &mut Context<Self>,
|
||||
) -> Task<Result<PushOutcome, Error>> {
|
||||
let cache = GitStore::global(cx).cache().clone();
|
||||
let path = cache.repo_path(&announcement.addr());
|
||||
let path = repo_mirror_path(&announcement.addr());
|
||||
self.push_repo_from(announcement, path, None, cx)
|
||||
}
|
||||
|
||||
@@ -854,6 +857,7 @@ impl Backend {
|
||||
let relays = relays.clone();
|
||||
let refs = refs.clone();
|
||||
let head = head.clone();
|
||||
let executor = cx.background_executor().clone();
|
||||
async move {
|
||||
push_staged_to_grasps(
|
||||
&client,
|
||||
@@ -864,6 +868,7 @@ impl Backend {
|
||||
&path,
|
||||
&owner,
|
||||
&relays,
|
||||
&executor,
|
||||
signed_git::push_all,
|
||||
)
|
||||
.await
|
||||
@@ -1700,6 +1705,7 @@ async fn push_staged_to_grasps(
|
||||
path: &Path,
|
||||
owner: &str,
|
||||
servers: &[RelayUrl],
|
||||
executor: &BackgroundExecutor,
|
||||
push: fn(&Path, &str, &str, &str) -> Result<(), Error>,
|
||||
) -> PushOutcome {
|
||||
let mut outcome = PushOutcome::default();
|
||||
@@ -1722,7 +1728,7 @@ async fn push_staged_to_grasps(
|
||||
'server: for attempt in 1..=GRASP_PUSH_ATTEMPTS {
|
||||
if attempt > 1 {
|
||||
// Give the server's ingest a moment before re-staging.
|
||||
std::thread::sleep(GRASP_RETRY_DELAY);
|
||||
executor.timer(GRASP_RETRY_DELAY).await;
|
||||
}
|
||||
|
||||
let (event, created_at) =
|
||||
|
||||
@@ -9,7 +9,7 @@ use settings::{CheckoutRecord, SettingsStore};
|
||||
use signed_core::{Announcement, RepoAddr};
|
||||
|
||||
use crate::backend::{Backend, BackendEvent};
|
||||
use crate::git_store::GitStore;
|
||||
use crate::git_store::repo_mirror_root;
|
||||
use crate::refresh::{RefreshGate, RefreshRequest};
|
||||
use crate::repos::{LocalReposStore, RepoListStore};
|
||||
|
||||
@@ -93,6 +93,8 @@ pub struct CheckoutsStore {
|
||||
/// A recompute defaults the base the same way.
|
||||
requested_head: HashMap<RepoAddr, Option<String>>,
|
||||
refresh: RefreshGate,
|
||||
/// True while the timer between a scheduled refresh and its run is pending.
|
||||
debounce_pending: bool,
|
||||
local_pending: bool,
|
||||
/// When the last full pass (with a remote refresh) completed.
|
||||
///
|
||||
@@ -163,6 +165,7 @@ impl CheckoutsStore {
|
||||
push_statuses: HashMap::new(),
|
||||
requested_head: HashMap::new(),
|
||||
refresh: RefreshGate::default(),
|
||||
debounce_pending: false,
|
||||
local_pending: false,
|
||||
last_full_sync: None,
|
||||
_subscriptions: subscriptions,
|
||||
@@ -279,12 +282,15 @@ impl CheckoutsStore {
|
||||
|
||||
/// Re-resolve the associations and the requested statuses.
|
||||
///
|
||||
/// Requests arriving while a pass runs fold into a follow-up.
|
||||
/// Requests arriving while a pass runs fold into a follow-up, requests
|
||||
/// arriving while the debounce timer is pending are dropped.
|
||||
pub fn refresh(&mut self, cx: &mut Context<Self>) {
|
||||
if self.refresh.request() != RefreshRequest::Schedule {
|
||||
if self.debounce_pending || self.refresh.request() != RefreshRequest::Schedule {
|
||||
return;
|
||||
}
|
||||
|
||||
self.debounce_pending = true;
|
||||
|
||||
cx.spawn(async move |this, cx| {
|
||||
cx.background_executor().timer(REFRESH_DEBOUNCE).await;
|
||||
this.update(cx, |this, cx| this.run_refresh(cx))
|
||||
@@ -300,6 +306,7 @@ impl CheckoutsStore {
|
||||
/// remote reconciliation cadence ([`Self::local_tick`]); they also restart
|
||||
/// the fast local pass.
|
||||
fn run_refresh(&mut self, cx: &mut Context<Self>) {
|
||||
self.debounce_pending = false;
|
||||
self.refresh.begin();
|
||||
|
||||
let records = {
|
||||
@@ -321,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 = GitStore::global(cx).cache().root().canonicalize().ok();
|
||||
let cache_root = repo_mirror_root().canonicalize().ok();
|
||||
|
||||
let requested: Vec<(RepoAddr, Option<String>)> = self
|
||||
.status_requested
|
||||
@@ -453,7 +460,7 @@ impl CheckoutsStore {
|
||||
}
|
||||
|
||||
// A full pass or a fresh request covers this tick, skip it.
|
||||
if self.refresh.running() || self.refresh.debouncing() {
|
||||
if self.refresh.running() || self.debounce_pending {
|
||||
self.schedule_local_pass(cx);
|
||||
return;
|
||||
}
|
||||
@@ -515,7 +522,7 @@ impl CheckoutsStore {
|
||||
this.update(cx, |this, cx| {
|
||||
// A full pass or a fresh request will apply fresher data
|
||||
// (the tracking refs move only when a full pass fetches).
|
||||
if this.refresh.running() || this.refresh.debouncing() {
|
||||
if this.refresh.running() || this.debounce_pending {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,32 +1,41 @@
|
||||
use std::path::PathBuf;
|
||||
use std::sync::OnceLock;
|
||||
|
||||
use gpui::{App, Global};
|
||||
use anyhow::Result;
|
||||
use gix::Repository;
|
||||
use signed_core::RepoAddr;
|
||||
use signed_git::GitCache;
|
||||
|
||||
struct GlobalGitStore(GitCache);
|
||||
static GIT_CACHE: OnceLock<GitCache> = OnceLock::new();
|
||||
|
||||
impl Global for GlobalGitStore {}
|
||||
fn git_cache() -> &'static GitCache {
|
||||
GIT_CACHE
|
||||
.get()
|
||||
.expect("git cache is initialized by signed_state::init")
|
||||
}
|
||||
|
||||
/// Global access to the on-disk git clone cache, the grasp mirrors.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct GitStore(GitCache);
|
||||
/// The root directory of the repository mirrors.
|
||||
pub(crate) fn repo_mirror_root() -> PathBuf {
|
||||
git_cache().root().to_path_buf()
|
||||
}
|
||||
|
||||
impl GitStore {
|
||||
pub fn set_global(root: impl Into<PathBuf>, cx: &mut App) -> Self {
|
||||
let store = Self::new(root);
|
||||
cx.set_global(GlobalGitStore(store.0.clone()));
|
||||
store
|
||||
}
|
||||
/// The on-disk path of the mirror of `addr`.
|
||||
pub fn repo_mirror_path(addr: &RepoAddr) -> PathBuf {
|
||||
git_cache().repo_path(addr)
|
||||
}
|
||||
|
||||
pub fn global(cx: &App) -> Self {
|
||||
Self(cx.global::<GlobalGitStore>().0.clone())
|
||||
}
|
||||
/// Open the mirror of `addr`, if it has been cloned.
|
||||
pub fn open_repo_mirror(addr: &RepoAddr) -> Result<Option<Repository>> {
|
||||
git_cache().open(addr)
|
||||
}
|
||||
|
||||
fn new(root: impl Into<PathBuf>) -> Self {
|
||||
Self(GitCache::new(root.into()))
|
||||
}
|
||||
/// 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 fn cache(&self) -> &GitCache {
|
||||
&self.0
|
||||
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,7 +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::GitStore;
|
||||
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;
|
||||
@@ -31,6 +32,7 @@ pub fn init(
|
||||
// rustls uses the `aws_lc_rs` provider by default.
|
||||
let _ = rustls::crypto::aws_lc_rs::default_provider().install_default();
|
||||
|
||||
// Initialize the nostr client and signer
|
||||
let (client, signer) = cx.foreground_executor().block_on(async move {
|
||||
let path = db_path.as_ref().to_path_buf();
|
||||
new_backend(path)
|
||||
@@ -38,11 +40,22 @@ pub fn init(
|
||||
.expect("failed to initialize nostr backend")
|
||||
});
|
||||
|
||||
// Set Git cache for the repos root
|
||||
set_git_cache(repos_root);
|
||||
|
||||
// Set global stores for the backend
|
||||
Backend::set_global(cx.new(|cx| Backend::new(client, signer, cx)), cx);
|
||||
|
||||
// Set global stores for the profile
|
||||
ProfileStore::set_global(cx.new(ProfileStore::new), cx);
|
||||
|
||||
// Set global stores for the repo list and local repos
|
||||
RepoListStore::set_global(cx.new(RepoListStore::new), cx);
|
||||
GitStore::set_global(repos_root, cx);
|
||||
|
||||
// Set global stores for the local repos
|
||||
LocalReposStore::set_global(cx.new(|cx| LocalReposStore::new(scan_paths, cx)), cx);
|
||||
|
||||
// Set global stores for the checkouts
|
||||
CheckoutsStore::set_global(cx.new(CheckoutsStore::new), cx);
|
||||
}
|
||||
|
||||
@@ -50,10 +63,10 @@ pub fn init(
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn init(cx: &mut App) {
|
||||
let (client, signer) = new_backend().expect("failed to initialize nostr backend");
|
||||
set_git_cache(PathBuf::new());
|
||||
Backend::set_global(cx.new(|cx| Backend::new(client, signer, cx)), cx);
|
||||
ProfileStore::set_global(cx.new(ProfileStore::new), cx);
|
||||
RepoListStore::set_global(cx.new(RepoListStore::new), cx);
|
||||
GitStore::set_global(PathBuf::new(), cx);
|
||||
LocalReposStore::set_global(cx.new(|cx| LocalReposStore::new(Vec::new(), cx)), cx);
|
||||
CheckoutsStore::set_global(cx.new(|cx| CheckoutsStore::new(cx)), cx);
|
||||
}
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
pub struct RefreshGate {
|
||||
running: bool,
|
||||
dirty: bool,
|
||||
debouncing: bool,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum RefreshRequest {
|
||||
/// No run or timer covers the request, start the debounce timer.
|
||||
/// No run covers the request, start one now.
|
||||
Schedule,
|
||||
/// A run or pending timer already covers the request.
|
||||
/// A run is in flight and covers the request, fold it into a follow-up.
|
||||
Fold,
|
||||
}
|
||||
|
||||
@@ -19,28 +18,20 @@ impl RefreshGate {
|
||||
self.running
|
||||
}
|
||||
|
||||
pub fn debouncing(&self) -> bool {
|
||||
self.debouncing
|
||||
}
|
||||
|
||||
/// A new refresh request arrived.
|
||||
///
|
||||
/// Folded into a follow-up run while one is in flight, dropped while the
|
||||
/// debounce timer is pending, otherwise starts the timer.
|
||||
/// Folded into a follow-up run while one is in flight, otherwise the
|
||||
/// caller starts the run itself.
|
||||
pub fn request(&mut self) -> RefreshRequest {
|
||||
if self.running {
|
||||
self.dirty = true;
|
||||
RefreshRequest::Fold
|
||||
} else if self.debouncing {
|
||||
RefreshRequest::Fold
|
||||
} else {
|
||||
self.debouncing = true;
|
||||
RefreshRequest::Schedule
|
||||
}
|
||||
}
|
||||
|
||||
pub fn begin(&mut self) {
|
||||
self.debouncing = false;
|
||||
self.running = true;
|
||||
}
|
||||
|
||||
@@ -55,3 +46,48 @@ impl RefreshGate {
|
||||
self.running = false;
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn a_request_while_running_folds_into_a_follow_up() {
|
||||
let mut gate = RefreshGate::default();
|
||||
gate.begin();
|
||||
|
||||
assert_eq!(gate.request(), RefreshRequest::Fold);
|
||||
assert!(gate.finish());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_request_without_a_run_schedules() {
|
||||
let mut gate = RefreshGate::default();
|
||||
|
||||
assert_eq!(gate.request(), RefreshRequest::Schedule);
|
||||
assert!(!gate.running());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_request_after_a_run_schedules_again() {
|
||||
let mut gate = RefreshGate::default();
|
||||
gate.begin();
|
||||
assert_eq!(gate.request(), RefreshRequest::Fold);
|
||||
assert!(gate.finish());
|
||||
|
||||
assert_eq!(gate.request(), RefreshRequest::Schedule);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn abort_keeps_the_pending_request() {
|
||||
let mut gate = RefreshGate::default();
|
||||
gate.begin();
|
||||
assert_eq!(gate.request(), RefreshRequest::Fold);
|
||||
|
||||
gate.abort();
|
||||
assert!(!gate.running());
|
||||
|
||||
gate.begin();
|
||||
assert!(gate.finish());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ use crate::backend::{
|
||||
user_grasp_list_servers,
|
||||
};
|
||||
use crate::checkouts::CheckoutsStore;
|
||||
use crate::git_store::GitStore;
|
||||
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 = GitStore::global(cx).cache().clone();
|
||||
|
||||
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"))?
|
||||
|
||||
@@ -2,13 +2,48 @@ use nostr::prelude::*;
|
||||
|
||||
/// Shorten a [`PublicKey`] to `npub1abc...wxyz` form.
|
||||
pub fn shorten_pubkey(public_key: PublicKey) -> String {
|
||||
let encoded = public_key
|
||||
.to_bech32()
|
||||
.unwrap_or_else(|_| public_key.to_hex());
|
||||
|
||||
truncate_middle(&encoded)
|
||||
}
|
||||
|
||||
fn truncate_middle(value: &str) -> String {
|
||||
const HEAD_CHARS: usize = 9;
|
||||
const TAIL_CHARS: usize = 4;
|
||||
|
||||
let npub = public_key.to_bech32().unwrap();
|
||||
format!(
|
||||
"{}...{}",
|
||||
&npub[..HEAD_CHARS],
|
||||
&npub[npub.len() - TAIL_CHARS..]
|
||||
)
|
||||
let length = value.chars().count();
|
||||
if length <= HEAD_CHARS + TAIL_CHARS + 3 {
|
||||
return value.to_owned();
|
||||
}
|
||||
|
||||
let head: String = value.chars().take(HEAD_CHARS).collect();
|
||||
let tail: String = value.chars().skip(length - TAIL_CHARS).collect();
|
||||
|
||||
format!("{head}...{tail}")
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
const PUBLIC_KEY_HEX: &str = "68d81165918100b7da43fc28f7d1fc12554466e1115886b9e7bb326f65ec4272";
|
||||
|
||||
#[test]
|
||||
fn shortens_a_valid_pubkey() {
|
||||
let public_key = PublicKey::from_hex(PUBLIC_KEY_HEX).expect("valid pubkey");
|
||||
let npub = public_key.to_bech32().expect("valid pubkey encodes");
|
||||
|
||||
assert_eq!(
|
||||
shorten_pubkey(public_key),
|
||||
format!("{}...{}", &npub[..9], &npub[npub.len() - 4..])
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn leaves_short_values_intact() {
|
||||
assert_eq!(truncate_middle("npub1short"), "npub1short");
|
||||
assert_eq!(truncate_middle("thirteenchars"), "thirteenchars");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -177,7 +177,6 @@ impl InboxView {
|
||||
}
|
||||
|
||||
fn refresh_initial(&mut self, cx: &mut Context<Self>) {
|
||||
debug_assert!(!self.refresh.debouncing());
|
||||
if self.refresh.running() {
|
||||
self.refresh.request();
|
||||
return;
|
||||
|
||||
@@ -26,7 +26,7 @@ use signed_core::{
|
||||
merge_base_of, pull_request_patch,
|
||||
};
|
||||
use signed_git::{FileCommit, patch_commits, patch_diffs};
|
||||
use signed_state::{Backend, GitStore, ProfileStore, RepoStore};
|
||||
use signed_state::{Backend, ProfileStore, RepoStore, ensure_repo_mirror};
|
||||
use signed_ui::{CountBadge, UserAvatar, placeholder, status_badge};
|
||||
use utils::{relative_time, relative_time_secs};
|
||||
|
||||
@@ -217,8 +217,6 @@ impl PullRequestDetailView {
|
||||
self.current_commit = binding.tip.clone().map(SharedString::from);
|
||||
cx.notify();
|
||||
|
||||
let cache = GitStore::global(cx).cache().clone();
|
||||
|
||||
self.load_generation = self.load_generation.wrapping_add(1);
|
||||
let generation = self.load_generation;
|
||||
|
||||
@@ -257,7 +255,6 @@ impl PullRequestDetailView {
|
||||
let git = if use_nostr {
|
||||
None
|
||||
} else {
|
||||
let cache = cache.clone();
|
||||
let addr = addr.clone();
|
||||
let clone_urls = clone_urls.clone();
|
||||
let base = base.clone();
|
||||
@@ -265,7 +262,7 @@ impl PullRequestDetailView {
|
||||
|
||||
Some(
|
||||
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()
|
||||
|
||||
@@ -26,7 +26,9 @@ use signed_git::{
|
||||
delete_refs_with_prefix, fetch_repo_refs, fork_namespace, merge_base, refs_with_prefix,
|
||||
worktree_commit_range_commits, worktree_commit_range_diff,
|
||||
};
|
||||
use signed_state::{Backend, CheckoutsStore, GitStore, RepoListStore, RepoStore};
|
||||
use signed_state::{
|
||||
Backend, CheckoutsStore, RepoListStore, RepoStore, ensure_repo_mirror, repo_mirror_path,
|
||||
};
|
||||
use signed_ui::{CountBadge, placeholder, ref_selector_trigger};
|
||||
|
||||
use crate::views::commit_diff::{COMMIT_ROW_HEIGHT, CommitDiffView, DiffPane, commit_row};
|
||||
@@ -73,7 +75,7 @@ struct ForkCompare {
|
||||
announcement: Announcement,
|
||||
/// Import namespace of the form `<owner-hex>/<sanitized-id>`.
|
||||
namespace: String,
|
||||
/// Path of the target repository's GitCache mirror.
|
||||
/// Path of the target repository's mirror.
|
||||
mirror_path: PathBuf,
|
||||
}
|
||||
|
||||
@@ -533,8 +535,7 @@ impl NewPullRequestView {
|
||||
let Some((base, _euc)) = self.base_repo(cx) else {
|
||||
return;
|
||||
};
|
||||
let cache = GitStore::global(cx).cache().clone();
|
||||
let mirror_path = cache.repo_path(&base);
|
||||
let mirror_path = repo_mirror_path(&base);
|
||||
let namespace = fork_namespace(&announcement);
|
||||
let clone_urls = announcement.clone.clone();
|
||||
|
||||
@@ -561,24 +562,20 @@ impl NewPullRequestView {
|
||||
|
||||
let task: gpui::Task<Result<(), anyhow::Error>> =
|
||||
cx.spawn_in(window, async move |this, cx| {
|
||||
// The fork and base must share history for a merge-base to exist.
|
||||
// The target's mirror is the object store both sides land in.
|
||||
// `ensure_clone` fetches `origin` when the mirror already exists.
|
||||
let result = cx
|
||||
.background_spawn({
|
||||
let cache = cache.clone();
|
||||
let base = base.clone();
|
||||
let base_clone_urls = base_clone_urls.clone();
|
||||
let namespace = namespace.clone();
|
||||
let clone_urls = clone_urls.clone();
|
||||
let mirror_path = mirror_path.clone();
|
||||
async move {
|
||||
cache.ensure_clone(&base, &base_clone_urls)?;
|
||||
ensure_repo_mirror(&base, &base_clone_urls)?;
|
||||
|
||||
// Prune stale imports of any fork.
|
||||
// Then import this fork's heads under its namespace.
|
||||
// Prune stale imports of any fork. Then import this fork's heads under its namespace.
|
||||
delete_refs_with_prefix(&mirror_path, "refs/fork")?;
|
||||
|
||||
// Fetch the fork's refs and import them under the fork's namespace.
|
||||
fetch_repo_refs(
|
||||
&mirror_path,
|
||||
&clone_urls,
|
||||
@@ -658,8 +655,6 @@ impl NewPullRequestView {
|
||||
let (base_branches, compare_branches) = match result {
|
||||
Ok(branches) => branches,
|
||||
Err(error) => {
|
||||
// Keep the previous source, if any.
|
||||
// The error shows inline next to the compare bar.
|
||||
self.error = Some(format!("Could not compare against the fork: {error}").into());
|
||||
cx.notify();
|
||||
return;
|
||||
@@ -673,8 +668,7 @@ impl NewPullRequestView {
|
||||
}
|
||||
|
||||
if base_branches.is_empty() {
|
||||
self.error =
|
||||
Some("Could not list the target repository's branches; try again later".into());
|
||||
self.error = Some("Could not list the target repository's branches.".into());
|
||||
cx.notify();
|
||||
return;
|
||||
}
|
||||
@@ -687,11 +681,8 @@ impl NewPullRequestView {
|
||||
.map(SharedString::from)
|
||||
.collect();
|
||||
|
||||
// Base defaults to the announced HEAD branch when the mirror has it.
|
||||
// Otherwise `main`, then the first branch.
|
||||
// The fork's `main` is the compare default, else the first branch.
|
||||
// A refresh keeps the previous selection when the branch still exists.
|
||||
let announced = self.store.read(cx).head.clone();
|
||||
|
||||
let contains =
|
||||
|name: &str, list: &[SharedString]| list.iter().any(|branch| branch.as_ref() == name);
|
||||
|
||||
@@ -790,16 +781,19 @@ impl NewPullRequestView {
|
||||
"{base_name} and {compare_name} share no common ancestor"
|
||||
)
|
||||
})?;
|
||||
|
||||
let commits = worktree_commit_range_commits(
|
||||
Path::new(&repo_path),
|
||||
&merge_base,
|
||||
&compare,
|
||||
)?;
|
||||
|
||||
let diff = worktree_commit_range_diff(
|
||||
Path::new(&repo_path),
|
||||
&merge_base,
|
||||
&compare,
|
||||
)?;
|
||||
|
||||
Ok::<_, anyhow::Error>((merge_base, commits, diff))
|
||||
}
|
||||
})
|
||||
@@ -923,6 +917,7 @@ impl NewPullRequestView {
|
||||
let Some(repo_path) = self.work_path() else {
|
||||
return;
|
||||
};
|
||||
|
||||
let Some(dock_area) = self.dock_area.upgrade() else {
|
||||
return;
|
||||
};
|
||||
|
||||
@@ -26,8 +26,8 @@ use nostr::prelude::{RelayUrl, ToBech32, Url};
|
||||
use signed_core::{Announcement, RepoAddr, RepoStatus};
|
||||
use signed_git::FileCommit;
|
||||
use signed_state::{
|
||||
Backend, CheckoutStatus, CheckoutsStore, GitStore, LocalReposStore, ProfileStore,
|
||||
RepoListStore, RepoStore, pr_proposes_checkout,
|
||||
Backend, CheckoutStatus, CheckoutsStore, LocalReposStore, ProfileStore, RepoListStore,
|
||||
RepoStore, ensure_repo_mirror, open_repo_mirror, pr_proposes_checkout,
|
||||
};
|
||||
use signed_ui::{
|
||||
CountBadge, DropdownButton, PixelAvatar, UserAvatar, copy_row, menu_copy_row, middle_truncate,
|
||||
@@ -343,15 +343,13 @@ impl RepoDetailView {
|
||||
|
||||
self.repo_started = true;
|
||||
|
||||
let cache = GitStore::global(cx).cache().clone();
|
||||
let addr = announcement.addr();
|
||||
let clone_urls: Vec<Url> = announcement.clone.clone();
|
||||
|
||||
let disk = {
|
||||
let cache = cache.clone();
|
||||
let addr = addr.clone();
|
||||
cx.background_spawn(async move {
|
||||
match cache.open(&addr)? {
|
||||
match open_repo_mirror(&addr)? {
|
||||
Some(repo) => Ok(Some(load_repo_data(&repo)?)),
|
||||
None => Ok(None),
|
||||
}
|
||||
@@ -365,11 +363,10 @@ impl RepoDetailView {
|
||||
let data = match disk {
|
||||
Ok(Some(data)) => Ok(data),
|
||||
Ok(None) => {
|
||||
let cache = cache.clone();
|
||||
let addr = addr.clone();
|
||||
let clone_urls = clone_urls.clone();
|
||||
cx.background_spawn(async move {
|
||||
let repo = cache.ensure_clone(&addr, &clone_urls)?;
|
||||
let repo = ensure_repo_mirror(&addr, &clone_urls)?;
|
||||
load_repo_data(&repo)
|
||||
})
|
||||
.await
|
||||
@@ -393,11 +390,10 @@ impl RepoDetailView {
|
||||
}
|
||||
|
||||
let refresh = {
|
||||
let cache = cache.clone();
|
||||
let addr = addr.clone();
|
||||
|
||||
cx.background_spawn(async move {
|
||||
let Some(repo) = cache.open(&addr)? else {
|
||||
let Some(repo) = open_repo_mirror(&addr)? else {
|
||||
return Ok::<_, Error>(None);
|
||||
};
|
||||
|
||||
|
||||
+4
-3
@@ -4,9 +4,10 @@
|
||||
|
||||
File: `crates/signed_state/src/backend.rs`
|
||||
|
||||
The variant has no subscriber. Remove the variant, the `sync_progress` field and
|
||||
its accessor, and the `progress_task` in `sync_bootstrap`. Keep the terminal
|
||||
`Synced` emission.
|
||||
Kept intentionally. The progress pipeline (the `SyncProgress` variant, the `sync_progress`
|
||||
field and its accessor, and the progress task in `sync_bootstrap`) is retained for a planned
|
||||
sync progress indicator. No subscriber exists yet. Do not remove it without revisiting that
|
||||
plan.
|
||||
|
||||
## `login` / `logout` family
|
||||
|
||||
|
||||
Reference in New Issue
Block a user