chore: restructure backend
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

This commit is contained in:
2026-11-28 09:06:13 +07:00
parent 44c2dc6345
commit 71bbcfaf51
35 changed files with 1781 additions and 2214 deletions
+18 -26
View File
@@ -1,3 +1,4 @@
use std::collections::HashMap;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::Arc;
@@ -10,7 +11,7 @@ use gpui::{
UniformListScrollHandle, WeakEntity, Window, div, uniform_list,
};
use signed_git::{CommitList, FileCommit, Repo};
use signed_state::{Backend, RepoStore, SyncStatusDirectory};
use signed_state::RepoStore;
use ui::alert::{Alert, AlertSeverity, AlertStyle};
use ui::avatar::Avatar;
use ui::button::{Button, ButtonVariant};
@@ -47,13 +48,14 @@ pub struct RepoHistoryView {
store: Entity<RepoStore>,
workspace: WeakEntity<AppRoot>,
detail: WeakEntity<RepoDetailView>,
sync_directory: Entity<SyncStatusDirectory>,
worktree: Option<PathBuf>,
all_commits: Option<Arc<CommitList>>,
loading_all_commits: bool,
/// The loaded commit list, shared with the render without a per-frame copy.
commits: Arc<Vec<FileCommit>>,
rows: Arc<Vec<HistoryRow>>,
/// Commit ids that exist in a local checkout but not on Nostr.
ahead: Arc<HashMap<String, PathBuf>>,
/// The last load failure, shown instead of the empty list.
error: Option<SharedString>,
scroll_handle: UniformListScrollHandle,
@@ -66,18 +68,17 @@ impl RepoHistoryView {
store: Entity<RepoStore>,
workspace: WeakEntity<AppRoot>,
detail: WeakEntity<RepoDetailView>,
sync_directory: Entity<SyncStatusDirectory>,
) -> Self {
Self {
store,
workspace,
detail,
sync_directory,
worktree: None,
all_commits: None,
loading_all_commits: false,
commits: Arc::new(Vec::new()),
rows: Arc::new(Vec::new()),
ahead: Arc::new(HashMap::new()),
error: None,
scroll_handle: UniformListScrollHandle::new(),
load_task: None,
@@ -88,6 +89,14 @@ impl RepoHistoryView {
self.worktree = path;
}
pub fn set_ahead(&mut self, ahead: HashMap<String, PathBuf>, cx: &mut Context<Self>) {
let next = Arc::new(ahead);
if *self.ahead != *next {
self.ahead = next;
cx.notify();
}
}
pub fn worktree(&self) -> Option<&Path> {
self.worktree.as_deref()
}
@@ -224,6 +233,8 @@ impl RepoHistoryView {
impl Render for RepoHistoryView {
fn render(&mut self, _window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let scroll_handle = self.scroll_handle.clone();
let Some(list) = self.all_commits.as_ref() else {
return if self.loading_all_commits {
Spinner::centered("commits-loading").into_any_element()
@@ -272,27 +283,8 @@ impl Render for RepoHistoryView {
}));
let detail = self.detail.clone();
let backend = Backend::global(cx);
let user = backend.read(cx).current_user();
let author = user.is_some_and(|user| self.store.read(cx).is_author(&user));
let checkout = self.worktree.clone();
let pushing = self.store.read(cx).pushing;
let scroll_handle = self.scroll_handle.clone();
let ahead = self
.store
.read(cx)
.addr()
.cloned()
.filter(|_| author)
.map(|addr| {
self.sync_directory.read_with(cx, |directory, cx| {
directory.ahead_commits_of(&addr, checkout.as_deref(), cx)
})
})
.unwrap_or_default();
let ahead = Arc::clone(&self.ahead);
v_flex()
.relative()
@@ -318,8 +310,8 @@ impl Render for RepoHistoryView {
let browse_commit = browse_commit.clone();
let ahead = ahead
.iter()
.find(|(id, _)| id.starts_with(commit.id.as_str()));
.get(commit.id.as_str())
.map(|path| (commit.id.to_string(), path.clone()));
h_flex()
.id(row_id.clone())
+35 -14
View File
@@ -78,6 +78,8 @@ struct AboutModel {
nip05: Option<SharedString>,
ngit_command: SharedString,
nak_command: SharedString,
description: SharedString,
clone_commands: Arc<Vec<String>>,
avatar_seed: SharedString,
}
@@ -109,6 +111,8 @@ impl AboutModel {
nip05: nip05.map(SharedString::from),
ngit_command,
nak_command,
description: SharedString::from(announcement.description()),
clone_commands: Arc::new(announcement.clone_urls()),
avatar_seed,
}
});
@@ -206,14 +210,8 @@ impl RepoDetailView {
let tabs = AppRoot::repo_tabs(&store, &workspace, cx);
let refs = RefSwitcher::new(weak.clone(), window, cx);
let history = cx.new(|_| {
RepoHistoryView::new(
store.clone(),
workspace.clone(),
weak.clone(),
sync_directory.clone(),
)
});
let history =
cx.new(|_| RepoHistoryView::new(store.clone(), workspace.clone(), weak.clone()));
let mut subscriptions = vec![];
@@ -392,11 +390,11 @@ impl RepoDetailView {
return displayed.to_path_buf();
}
self.sync_directory
.read_with(cx, |directory, cx| directory.statuses_of(addr, cx))
.into_iter()
let statuses = self.sync_directory.read(cx).statuses_of(addr);
statuses
.iter()
.find(|checkout| checkout.status.head.is_some() && checkout.status.ahead_total > 0)
.map(|checkout| checkout.path)
.map(|checkout| checkout.path.clone())
.unwrap_or_else(|| displayed.to_path_buf())
}
@@ -414,6 +412,29 @@ impl RepoDetailView {
} else {
self.reload_history_source(false, cx);
}
let backend = Backend::global(cx);
let checkout = self.history.read(cx).worktree().map(Path::to_path_buf);
let ahead = self
.store
.read(cx)
.addr()
.cloned()
.filter(|_| {
let user = backend.read(cx).current_user();
user.is_some_and(|user| self.store.read(cx).is_author(&user))
})
.map(|addr| {
self.sync_directory
.read(cx)
.ahead_commits_of(&addr, checkout.as_deref())
})
.unwrap_or_default();
self.history.update(cx, |history, cx| {
history.set_ahead(ahead, cx);
});
}
/// Points the commit list at its source again, reloading a mirror whose HEAD moved.
@@ -1379,7 +1400,7 @@ impl RepoDetailView {
let nak_command = header.nak_command.clone();
let name = self.store.read(cx).display_name();
let description = announcement.description();
let description = header.description.clone();
let announcement_for_menu = Arc::clone(&header.announcement);
let weak_menu_open = cx.weak_entity();
@@ -1388,7 +1409,7 @@ impl RepoDetailView {
let weak_download = cx.weak_entity();
let ngit_for_popover = ngit_command.clone();
let nak_for_popover = nak_command.clone();
let git_for_popover = Arc::new(announcement.clone_urls());
let git_for_popover = Arc::clone(&header.clone_commands);
h_flex()
.p_6()