fix: commits list and sync lagging after a sync
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-26 09:40:28 +07:00
parent f57427d30d
commit ae41fac60a
5 changed files with 135 additions and 62 deletions
+2
View File
@@ -38,6 +38,8 @@
- Fix the remove button of a Settings or grasp server row carrying its hover state over to the next row after a removal - Fix the remove button of a Settings or grasp server row carrying its hover state over to the next row after a removal
- Fix the file tree's scrollbar sitting inset from the sidebar's right border, it now rides beside it - Fix the file tree's scrollbar sitting inset from the sidebar's right border, it now rides beside it
- Fix the selected filter in the Explore, Issues and Pull requests views highlighting only after the pointer crossed it, it now highlights as soon as the filter is drawn - Fix the selected filter in the Explore, Issues and Pull requests views highlighting only after the pointer crossed it, it now highlights as soon as the filter is drawn
- Fix the Commits list and its count badge lagging behind the header after a repository opened or after a Sync, they now follow the mirror once it caught up with the servers
- Fix the Sync buttons, the repository menu and the Code button staying disabled or loading after a sync, republish, reset or download finished
## v0.2.0 - 2026/10/21 ## v0.2.0 - 2026/10/21
+10 -10
View File
@@ -12,7 +12,7 @@ use signed_git::{CommitList, FileCommit, Repo};
use signed_state::{Backend, RepoStore, SyncStatusDirectory}; use signed_state::{Backend, RepoStore, SyncStatusDirectory};
use ui::alert::{Alert, AlertSeverity, AlertStyle}; use ui::alert::{Alert, AlertSeverity, AlertStyle};
use ui::avatar::IdentityRow; use ui::avatar::IdentityRow;
use ui::button::{Button, ButtonSide, ButtonVariant}; use ui::button::{Button, ButtonVariant};
use ui::common::{Sizable as _, h_flex, v_flex}; use ui::common::{Sizable as _, h_flex, v_flex};
use ui::empty_state::EmptyState; use ui::empty_state::EmptyState;
use ui::icons::{Icon, IconRole}; use ui::icons::{Icon, IconRole};
@@ -290,7 +290,6 @@ impl Render for RepoHistoryView {
.h_12() .h_12()
.w_full() .w_full()
.gap_2() .gap_2()
.text_sm()
.border_b_1() .border_b_1()
.border_color(cx.theme().colors.border) .border_color(cx.theme().colors.border)
.hover(|this| this.bg(cx.theme().colors.muted)) .hover(|this| this.bg(cx.theme().colors.muted))
@@ -304,15 +303,15 @@ impl Render for RepoHistoryView {
.truncate() .truncate()
.gap_2() .gap_2()
.flex_none() .flex_none()
.w_32() .w_40()
.text_xs()
.text_color(cx.theme().colors.muted_foreground), .text_color(cx.theme().colors.muted_foreground),
) )
.child( .child(
h_flex().w_24().child( h_flex().w_20().child(
Button::new(format!("browse-commit:{}", commit.id)) Button::new(format!("browse-commit:{}", commit.id))
.label(short_id(&commit.id)) .label(short_id(&commit.id))
.variant(ButtonVariant::Ghost) .variant(ButtonVariant::Ghost)
.side(ButtonSide::Left)
.small() .small()
.tooltip(Tooltip::text( .tooltip(Tooltip::text(
"Browse files at commit", "Browse files at commit",
@@ -335,6 +334,7 @@ impl Render for RepoHistoryView {
.flex_1() .flex_1()
.min_w_0() .min_w_0()
.text_ellipsis() .text_ellipsis()
.text_sm()
.whitespace_nowrap() .whitespace_nowrap()
.child(commit.summary.clone()), .child(commit.summary.clone()),
) )
@@ -347,10 +347,11 @@ impl Render for RepoHistoryView {
.child(relative_time_secs(commit.time)), .child(relative_time_secs(commit.time)),
) )
.when_some(ahead, |row, (ahead_id, path)| { .when_some(ahead, |row, (ahead_id, path)| {
let detail = detail.clone();
let path = path.clone(); let path = path.clone();
let target = ahead_id.clone(); let target = ahead_id.clone();
let short = short_id(&commit.id); let detail = detail.clone();
let tooltip =
format!("Sync up to {}", short_id(&commit.id));
row.child( row.child(
Button::new(("sync-commit", ix)) Button::new(("sync-commit", ix))
@@ -358,10 +359,9 @@ impl Render for RepoHistoryView {
.icon(Icon::named(IconRole::ArrowUp)) .icon(Icon::named(IconRole::ArrowUp))
.variant(ButtonVariant::Secondary) .variant(ButtonVariant::Secondary)
.small() .small()
.loading(pushing)
.disabled(pushing) .disabled(pushing)
.tooltip(Tooltip::text(format!( .tooltip(Tooltip::text(tooltip))
"Sync up to {short}"
)))
.on_click(move |_, window, cx| { .on_click(move |_, window, cx| {
cx.stop_propagation(); cx.stop_propagation();
if let Some(detail) = detail.upgrade() { if let Some(detail) = detail.upgrade() {
+74 -31
View File
@@ -15,7 +15,7 @@ use signed_core::{Announcement, RepoAddr};
use signed_git::{FileCommit, GitCache, Repo}; use signed_git::{FileCommit, GitCache, Repo};
use signed_state::{ use signed_state::{
Backend, BackendEvent, LocalReposStore, Mirrors, Nip34Binding, Nip34Kind, PushStepStatus, Backend, BackendEvent, LocalReposStore, Mirrors, Nip34Binding, Nip34Kind, PushStepStatus,
RepoStore, SyncStatusDirectory, RefreshGate, RefreshRequest, RepoStore, SyncStatusDirectory,
}; };
use ui::alert::{Alert, AlertSeverity}; use ui::alert::{Alert, AlertSeverity};
use ui::avatar::Avatar; use ui::avatar::Avatar;
@@ -127,6 +127,8 @@ pub struct RepoDetailView {
sync_directory: Entity<SyncStatusDirectory>, sync_directory: Entity<SyncStatusDirectory>,
/// Only a commit sync reports push steps; republish stays silent. /// Only a commit sync reports push steps; republish stays silent.
sync_progress: bool, sync_progress: bool,
/// Folds mirror refreshes requested while one is running.
mirror_refresh: RefreshGate,
pub(super) repo_menu_open: bool, pub(super) repo_menu_open: bool,
pub(super) clone_open: bool, pub(super) clone_open: bool,
_subscriptions: Vec<Subscription>, _subscriptions: Vec<Subscription>,
@@ -193,11 +195,15 @@ impl RepoDetailView {
) )
}); });
let subscriptions = vec![ let mut subscriptions = vec![];
cx.observe(&sync_directory, |this, _directory, cx| {
this.sync_history_source(cx); subscriptions.push(
cx.observe_in(&sync_directory, window, |this, _, window, cx| {
this.sync_history_source(window, cx);
}), }),
cx.subscribe(&backend, |this, _backend, event, cx| { );
subscriptions.push(cx.subscribe(&backend, |this, _, event, cx| {
let BackendEvent::PushProgress { addr, status } = event else { let BackendEvent::PushProgress { addr, status } = event else {
return; return;
}; };
@@ -207,29 +213,28 @@ impl RepoDetailView {
} }
let current = this.store.read(cx).addr().cloned(); let current = this.store.read(cx).addr().cloned();
if current.as_ref() != Some(addr) { if current.as_ref() != Some(addr) {
return; return;
} }
cx.show_system_notification(Self::sync_progress_notification(addr, status)); cx.show_system_notification(Self::sync_progress_notification(addr, status));
}), }));
cx.subscribe(&files, |this, _files, _event, cx| {
subscriptions.push(cx.subscribe(&files, |this, _, _, cx| {
if this.active_section != RepoSection::Files { if this.active_section != RepoSection::Files {
this.active_section = RepoSection::Files; this.active_section = RepoSection::Files;
cx.notify(); cx.notify();
} }
}), }));
];
let store_for_attach = store.clone();
let mut header = None; let mut header = None;
AboutModel::sync(&mut header, &store, cx); AboutModel::sync(&mut header, &store, cx);
let store_for_attach = store.clone(); cx.defer_in(window, move |this, window, cx| {
window.defer(cx, move |window, cx| {
log_dropped(weak.update(cx, |this, cx| {
this.attach_store(&store_for_attach, window, cx); this.attach_store(&store_for_attach, window, cx);
this.load_repo(window, cx); this.load_repo(window, cx);
}));
}); });
Self { Self {
@@ -252,6 +257,7 @@ impl RepoDetailView {
directory: ProfileDirectory::new(cx), directory: ProfileDirectory::new(cx),
sync_directory, sync_directory,
sync_progress: false, sync_progress: false,
mirror_refresh: RefreshGate::default(),
repo_menu_open: false, repo_menu_open: false,
clone_open: false, clone_open: false,
_subscriptions: subscriptions, _subscriptions: subscriptions,
@@ -367,18 +373,36 @@ impl RepoDetailView {
.unwrap_or_else(|| displayed.to_path_buf()) .unwrap_or_else(|| displayed.to_path_buf())
} }
fn sync_history_source(&mut self, cx: &mut Context<Self>) { fn sync_history_source(&mut self, window: &mut Window, cx: &mut Context<Self>) {
let Some(displayed) = self.worktree.clone() else {
return;
};
let reads_mirror = self.history.read(cx).worktree() == Some(displayed.as_path());
let lists_mirror = self.history_source(&displayed, cx) == displayed;
// A checkout that just caught up hands the list to a mirror lagging behind the sync.
if lists_mirror && !reads_mirror {
self.refresh_mirror(window, cx);
} else {
self.reload_history_source(false, cx);
}
}
/// Points the commit list at its source again, reloading a mirror whose HEAD moved.
fn reload_history_source(&mut self, mirror_head_moved: bool, cx: &mut Context<Self>) {
let Some(displayed) = self.worktree.clone() else { let Some(displayed) = self.worktree.clone() else {
return; return;
}; };
let source = self.history_source(&displayed, cx); let source = self.history_source(&displayed, cx);
self.history.update(cx, |history, cx| { self.history.update(cx, |history, cx| {
if history.worktree() == Some(source.as_path()) { if history.worktree() != Some(source.as_path()) {
return;
}
history.set_worktree(Some(source)); history.set_worktree(Some(source));
history.reload(cx); history.reload(cx);
} else if mirror_head_moved && source == displayed {
history.reload(cx);
}
}); });
} }
@@ -432,7 +456,6 @@ impl RepoDetailView {
self.repo_started = true; self.repo_started = true;
let store = self.store.downgrade();
let addr = announcement.addr(); let addr = announcement.addr();
let clone_urls: Vec<Url> = announcement.clone.clone(); let clone_urls: Vec<Url> = announcement.clone.clone();
@@ -469,24 +492,37 @@ impl RepoDetailView {
Ok(data) => this.apply_repo_data(data, window, cx), Ok(data) => this.apply_repo_data(data, window, cx),
Err(error) => this.error = Some(error.to_string().into()), Err(error) => this.error = Some(error.to_string().into()),
} }
this.loading = false; this.loading = false;
cx.notify(); cx.notify();
// A cached mirror may lag behind the grasp servers since the last visit.
if had_clone && !this.store.read(cx).pushing {
this.refresh_mirror(window, cx);
}
})?; })?;
if !had_clone { Ok(())
return Ok(()); });
self.push_task(task);
} }
let pushing = store.read_with(cx, |this, _| this.pushing)?; /// Fetches the mirror and fast-forwards its branches, showing the caught-up state.
fn refresh_mirror(&mut self, window: &mut Window, cx: &mut Context<Self>) {
if pushing { if self.mirror_refresh.request() != RefreshRequest::Schedule {
return Ok(()); return;
} }
let refresh = { let Some(addr) = self.store.read(cx).addr().cloned() else {
let addr = addr.clone(); return;
};
cx.background_spawn(async move { self.mirror_refresh.begin();
let task: Task<Result<(), Error>> = cx.spawn_in(window, async move |this, cx| {
let refresh = cx
.background_spawn(async move {
let Some(repo) = Mirrors::open(&addr)? else { let Some(repo) = Mirrors::open(&addr)? else {
return Ok::<_, Error>(None); return Ok::<_, Error>(None);
}; };
@@ -503,14 +539,15 @@ impl RepoDetailView {
}; };
Ok::<_, Error>(Some((moved, repo.snapshot()?))) Ok::<_, Error>(Some((moved, repo.snapshot()?)))
}) })
.await .await;
};
this.update_in(cx, |this, window, cx| { this.update_in(cx, |this, window, cx| {
let again = this.mirror_refresh.finish();
let mut head_changed = false;
if let Ok(Some((moved, snapshot))) = refresh { if let Ok(Some((moved, snapshot))) = refresh {
let branches: Vec<SharedString> = let branches: Vec<SharedString> =
snapshot.branches.iter().map(Into::into).collect(); snapshot.branches.iter().map(Into::into).collect();
let tags: Vec<SharedString> = snapshot.tags.iter().map(Into::into).collect(); let tags: Vec<SharedString> = snapshot.tags.iter().map(Into::into).collect();
let current_branch = snapshot.current_branch.clone(); let current_branch = snapshot.current_branch.clone();
let head_commit = snapshot.head_commit.clone(); let head_commit = snapshot.head_commit.clone();
@@ -525,7 +562,7 @@ impl RepoDetailView {
let new_head_commit = head_commit.as_ref().map(|c| &c.id); let new_head_commit = head_commit.as_ref().map(|c| &c.id);
let current_head_commit = this.head_commit.as_ref().map(|c| &c.id); let current_head_commit = this.head_commit.as_ref().map(|c| &c.id);
let head_changed = new_head_commit != current_head_commit; head_changed = new_head_commit != current_head_commit;
this.head_commit = head_commit; this.head_commit = head_commit;
if moved { if moved {
@@ -536,6 +573,12 @@ impl RepoDetailView {
cx.notify(); cx.notify();
} }
} }
this.reload_history_source(head_changed, cx);
if again {
this.refresh_mirror(window, cx);
}
})?; })?;
Ok(()) Ok(())
+1
View File
@@ -29,6 +29,7 @@ serde_json.workspace = true
rustls = "0.23" rustls = "0.23"
[dev-dependencies] [dev-dependencies]
gpui = { workspace = true, features = ["test-support"] }
tempfile = "3" tempfile = "3"
[lints] [lints]
+29 -2
View File
@@ -1275,6 +1275,9 @@ impl RepoStore {
let result = push.await; let result = push.await;
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
this.pushing = false;
this.push_steps.clear();
match &result { match &result {
Ok(outcome) => { Ok(outcome) => {
this.last_error = None; this.last_error = None;
@@ -1287,12 +1290,12 @@ impl RepoStore {
}); });
} }
// Re-probe so sync badges reflect the pushed state.
let sync_status = SyncStatusStore::global(cx); let sync_status = SyncStatusStore::global(cx);
let addr = pushed_checkout let addr = pushed_checkout
.as_ref() .as_ref()
.map(|(addr, _)| addr.clone()) .map(|(addr, _)| addr.clone())
.or_else(|| this.addr.clone()); .or_else(|| this.addr.clone());
sync_status.read(cx).probe(addr); sync_status.read(cx).probe(addr);
} }
Err(e) => { Err(e) => {
@@ -1371,6 +1374,8 @@ impl RepoStore {
let result = clone.await; let result = clone.await;
this.update(cx, |this, cx| { this.update(cx, |this, cx| {
this.cloning = false;
match &result { match &result {
Ok(()) => { Ok(()) => {
let checkouts = CheckoutsStore::global(cx); let checkouts = CheckoutsStore::global(cx);
@@ -1387,7 +1392,6 @@ impl RepoStore {
})?; })?;
guard.abort(); guard.abort();
result result
}) })
} }
@@ -1604,3 +1608,26 @@ fn comment_builder(
.into_event_builder() .into_event_builder()
.tags([Tag::coordinate(addr.clone().into(), None)]) .tags([Tag::coordinate(addr.clone().into(), None)])
} }
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use anyhow::anyhow;
use gpui::{AppContext as _, Task, TestAppContext};
use super::RepoStore;
#[gpui::test]
fn a_finished_push_releases_the_busy_flag(cx: &mut TestAppContext) {
let store = cx.new(|_| RepoStore::new_local(PathBuf::from("repo"), None));
let push = store.update(cx, |store, cx| {
store.run_push(Task::ready(Err(anyhow!("push refused"))), None, cx)
});
cx.run_until_parked();
assert!(push.is_ready());
assert!(!cx.update(|app| store.read(app).pushing));
}
}