add per-commit publishing from sync status
Rust / build (macos-latest, stable) (push) Waiting to run
Rust / build (ubuntu-latest, stable) (push) Waiting to run
Rust / build (windows-latest, stable) (push) Waiting to run
Rust / build (macos-latest, stable) (pull_request) Waiting to run
Rust / build (ubuntu-latest, stable) (pull_request) Waiting to run
Rust / build (windows-latest, stable) (pull_request) Waiting to run

This commit is contained in:
2026-11-19 05:14:52 +07:00
parent 41f34d0192
commit c7c1d0c741
13 changed files with 518 additions and 244 deletions
+56 -54
View File
@@ -1,5 +1,5 @@
use std::collections::HashSet;
use std::path::PathBuf;
use std::path::{Path, PathBuf};
use anyhow::Error;
use gpui::prelude::FluentBuilder as _;
@@ -13,7 +13,7 @@ use nostr::prelude::{PublicKey, Url};
use signed_core::{Announcement, RepoAddr};
use signed_git::{FileCommit, GitCache, Repo};
use signed_state::{
Backend, CheckoutsStore, LocalReposStore, Mirrors, Nip34Binding, RepoStore, SyncStatusDirectory,
Backend, LocalReposStore, Mirrors, Nip34Binding, RepoStore, SyncStatusDirectory,
};
use ui::alert::{Alert, AlertSeverity};
use ui::avatar::Avatar;
@@ -35,7 +35,6 @@ pub mod history;
pub mod refs;
use files::RepoFilesView;
use header::Banners;
use helpers::{RepoData, load_repo_data};
use history::RepoHistoryView;
use refs::RefSwitcher;
@@ -82,11 +81,10 @@ pub struct RepoDetailView {
error: Option<SharedString>,
head_commit: Option<FileCommit>,
refs: RefSwitcher,
banners: Banners,
tasks: Vec<Task<Result<(), Error>>>,
/// Profiles rendered by the header and maintainers.
pub(super) directory: Entity<ProfileDirectory>,
/// Sync status feeding the sync-to-Nostr banner.
/// Sync status feeding the per-commit sync buttons.
sync_directory: Entity<SyncStatusDirectory>,
pub(super) repo_menu_open: bool,
pub(super) clone_open: bool,
@@ -135,19 +133,24 @@ impl RepoDetailView {
window: &mut Window,
cx: &mut Context<Self>,
) -> Self {
let checkouts = CheckoutsStore::global(cx);
let weak = cx.entity().downgrade();
let sync_directory = SyncStatusDirectory::new(cx);
let files = cx.new(RepoFilesView::new);
let history = cx.new(|_| RepoHistoryView::new(store.clone(), workspace.clone()));
let history = cx.new(|_| {
RepoHistoryView::new(
store.clone(),
workspace.clone(),
weak.clone(),
sync_directory.clone(),
)
});
let issues = cx.new(|cx| IssuesView::new(workspace.clone(), store.clone(), cx));
let pulls = cx.new(|cx| PullRequestsView::new(workspace.clone(), store.clone(), cx));
let weak = cx.entity().downgrade();
let refs = RefSwitcher::new(weak.clone(), window, cx);
let subscriptions = vec![
cx.observe(&checkouts, |this, _checkouts, cx| {
if this.refresh_statuses(cx) {
cx.notify();
}
cx.observe(&sync_directory, |this, _directory, cx| {
this.sync_history_source(cx);
}),
cx.subscribe(&files, |this, _files, _event, cx| {
if this.active_section != RepoSection::Files {
@@ -179,10 +182,9 @@ impl RepoDetailView {
error: None,
head_commit: None,
refs,
banners: Banners::default(),
tasks: Vec::new(),
directory: ProfileDirectory::new(cx),
sync_directory: SyncStatusDirectory::new(cx),
sync_directory,
repo_menu_open: false,
clone_open: false,
_subscriptions: subscriptions,
@@ -203,7 +205,6 @@ impl RepoDetailView {
self.store
.update(cx, |store, cx| store.announce(announcement, cx));
self.refresh_ready_statuses(cx);
cx.notify();
}
@@ -215,7 +216,6 @@ impl RepoDetailView {
) {
self._subscriptions
.push(cx.observe_in(store, window, |this, store, window, cx| {
this.refresh_ready_statuses(cx);
this.track_profiles(cx);
this.track_sync_status(cx);
if !this.repo_started && store.read(cx).announcement.is_some() {
@@ -223,7 +223,6 @@ impl RepoDetailView {
}
cx.notify();
}));
self.refresh_ready_statuses(cx);
}
fn track_profiles(&mut self, cx: &mut Context<Self>) {
@@ -264,45 +263,47 @@ impl RepoDetailView {
});
}
fn refresh_ready_statuses(&mut self, cx: &mut Context<Self>) {
let Some(addr) = self.store.read(cx).addr().cloned() else {
return;
};
/// Commits list a local checkout with unpushed commits, so they can be synced one by one.
fn history_source(&self, displayed: &Path, cx: &App) -> PathBuf {
let store = self.store.read(cx);
let head = self.store.read(cx).head.clone();
let (requested, requested_head) = self.banners.ready_requested_at();
if requested && requested_head == &head {
return;
if store.path.is_some() {
return displayed.to_path_buf();
}
self.banners.mark_ready_requested(head.clone());
let backend = Backend::global(cx);
let checkout = CheckoutsStore::global(cx);
let owned = backend
let Some(addr) = store.addr() else {
return displayed.to_path_buf();
};
let owned = Backend::global(cx)
.read(cx)
.current_user()
.is_some_and(|user| self.store.read(cx).is_author(&user));
.is_some_and(|user| store.is_author(&user));
checkout.update(cx, |store, cx| {
store.request_statuses(&addr, head, cx);
if owned {
store.request_push_statuses(&addr, cx);
}
});
if !owned {
return displayed.to_path_buf();
}
self.sync_directory
.read_with(cx, |directory, cx| directory.statuses_of(addr, cx))
.into_iter()
.find(|checkout| checkout.status.head.is_some() && checkout.status.ahead_total > 0)
.map(|checkout| checkout.path)
.unwrap_or_else(|| displayed.to_path_buf())
}
fn refresh_statuses(&mut self, cx: &mut Context<Self>) -> bool {
let Some(addr) = self.store.read(cx).addr().cloned() else {
return false;
fn sync_history_source(&mut self, cx: &mut Context<Self>) {
let Some(displayed) = self.worktree.clone() else {
return;
};
let checkouts = CheckoutsStore::global(cx).read(cx);
let ready_statuses = checkouts.ready_statuses_of(&addr);
let push_statuses = checkouts.push_statuses_of(&addr);
self.banners.set_statuses(ready_statuses, push_statuses)
let source = self.history_source(&displayed, cx);
self.history.update(cx, |history, cx| {
if history.worktree() == Some(source.as_path()) {
return;
}
history.set_worktree(Some(source));
history.reload(cx);
});
}
fn announcement<'a>(&'a self, cx: &'a App) -> Option<&'a Announcement> {
@@ -493,8 +494,10 @@ impl RepoDetailView {
files.set_readme(readme_path, readme, cx);
});
let history_source = self.history_source(&worktree, cx);
self.history.update(cx, |history, cx| {
history.set_worktree(Some(worktree.clone()));
history.set_worktree(Some(history_source));
history.reload(cx);
});
@@ -731,9 +734,10 @@ impl RepoDetailView {
self.tasks.push(task);
}
fn push_unpushed_checkout(
fn sync_checkout_commit(
&mut self,
path: PathBuf,
commit: String,
window: &mut Window,
cx: &mut Context<Self>,
) {
@@ -748,14 +752,12 @@ impl RepoDetailView {
let task: Task<Result<(), Error>> = cx.spawn_in(window, async move |this, cx| {
let push = this.update_in(cx, |_this, _window, cx| {
store.update(cx, |store, cx| store.push_checkout(path.clone(), cx))
store.update(cx, |store, cx| {
store.push_checkout_commit(path.clone(), commit.clone(), cx)
})
})?;
if let Ok(()) = push.await {
this.update_in(cx, |this, window, cx| {
this.load_repo(window, cx);
})?;
}
push.await?;
Ok(())
});