Skip to content
This repository was archived by the owner on Jan 2, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions server/bleep/src/background.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ pub fn rayon_pool() -> &'static ThreadPool {
pub struct Progress {
#[serde(rename = "ref")]
reporef: RepoRef,
#[serde(rename = "rsync")]
resync: bool,
#[serde(rename = "b")]
branch_filter: Option<BranchFilterConfig>,
#[serde(rename = "ev")]
Expand Down
15 changes: 15 additions & 0 deletions server/bleep/src/background/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ pub struct SyncPipes {
/// Together with `filter_updates`, it uniquely identifies the sync process
reporef: RepoRef,

/// Is this a re-sync?
resync: bool,

/// Together with `reporef`, it uniquely identifies the sync process
filter_updates: FilterUpdate,

Expand All @@ -42,11 +45,13 @@ pub struct SyncPipes {
impl SyncPipes {
pub(super) fn new(
reporef: RepoRef,
resync: bool,
filter_updates: FilterUpdate,
progress: super::ProgressStream,
) -> Self {
Self {
reporef,
resync,
progress,
filter_updates,
git_interrupt: Default::default(),
Expand All @@ -58,6 +63,7 @@ impl SyncPipes {
// clear any state stored on the frontend
_ = self.progress.send(Progress {
reporef: self.reporef.clone(),
resync: self.resync,
branch_filter: self.filter_updates.branch_filter.clone(),
event: ProgressEvent::IndexPercent(None),
});
Expand All @@ -70,13 +76,15 @@ impl SyncPipes {
name: Default::default(),
progress: self.progress.clone(),
reporef: self.reporef.clone(),
resync: self.resync,
filter_updates: self.filter_updates.clone(),
}
}

pub(crate) fn index_percent(&self, current: u8) {
_ = self.progress.send(Progress {
reporef: self.reporef.clone(),
resync: self.resync,
branch_filter: self.filter_updates.branch_filter.clone(),
event: ProgressEvent::IndexPercent(Some(current)),
});
Expand All @@ -85,6 +93,7 @@ impl SyncPipes {
pub(crate) fn status(&self, new: SyncStatus) {
_ = self.progress.send(Progress {
reporef: self.reporef.clone(),
resync: self.resync,
branch_filter: self.filter_updates.branch_filter.clone(),
event: ProgressEvent::StatusChange(new),
});
Expand Down Expand Up @@ -132,6 +141,9 @@ pub(crate) struct GitSync {
/// Copy from `SyncPipes`, because we can't make this a referential type
reporef: RepoRef,

/// Copy from `SyncPipes`, because we can't make this a referential type
resync: bool,

/// Copy from `SyncPipes`, because we can't make this a referential type
filter_updates: FilterUpdate,

Expand Down Expand Up @@ -181,6 +193,7 @@ impl gix::progress::Count for GitSync {
let current = ((step as f32 / self.max.load(Ordering::SeqCst) as f32) * 100f32) as u8;
_ = self.progress.send(Progress {
reporef: self.reporef.clone(),
resync: self.resync,
branch_filter: self.filter_updates.branch_filter.clone(),
event: ProgressEvent::IndexPercent(Some(current.min(100))),
});
Expand Down Expand Up @@ -218,6 +231,7 @@ impl gix::progress::Count for GitSync {

_ = self.progress.send(Progress {
reporef: self.reporef.clone(),
resync: self.resync,
branch_filter: self.filter_updates.branch_filter.clone(),
event: ProgressEvent::IndexPercent(Some(current.min(100))),
});
Expand Down Expand Up @@ -258,6 +272,7 @@ impl gix::progress::NestedProgress for GitSync {
cnt: self.cnt.clone(),
filter_updates: self.filter_updates.clone(),
reporef: self.reporef.clone(),
resync: self.resync,
progress,
name,
id,
Expand Down
50 changes: 27 additions & 23 deletions server/bleep/src/background/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,6 @@ impl SyncHandle {
};

let (exited, exit_signal) = flume::bounded(1);
let pipes = SyncPipes::new(reporef.clone(), filter_updates.clone(), status);
let current = app
.repo_pool
.entry_async(reporef.clone())
Expand Down Expand Up @@ -196,6 +195,13 @@ impl SyncHandle {
}
});

let pipes = SyncPipes::new(
reporef.clone(),
current.get().last_index_unix_secs != 0,
filter_updates.clone(),
status,
);

// if we're not upgrading from shallow to full checkout
// this seems to be a speed optimization for git operations
if !shallow && !current.get().shallow {
Expand Down Expand Up @@ -289,9 +295,7 @@ impl SyncHandle {
error!(?err, "failed to generate tutorial questions");
}
}

// technically `sync_done_with` does this, but we want to send notifications
self.set_status(|repo| repo.sync_status.clone())
self.set_status(|_| SyncStatus::Done)
}
Err(SyncError::Cancelled) => self.set_status(|_| SyncStatus::Cancelled),
Err(err) => self.set_status(|_| SyncStatus::Error {
Expand Down Expand Up @@ -514,33 +518,34 @@ impl SyncHandle {
&self,
updater: impl FnOnce(&Repository) -> SyncStatus,
) -> Option<SyncStatus> {
let new_status = self.app.repo_pool.update(&self.reporef, move |_k, repo| {
let new_status = (updater)(repo);
let old_status = std::mem::replace(&mut repo.sync_status, new_status);

if !matches!(repo.sync_status, SyncStatus::Queued)
|| matches!(old_status, SyncStatus::Syncing)
{
repo.pub_sync_status = repo.sync_status.clone();
}
let (new_status, old_status) =
self.app.repo_pool.update(&self.reporef, move |_k, repo| {
let new_status = (updater)(repo);
let old_status = std::mem::replace(&mut repo.sync_status, new_status);

if !matches!(repo.sync_status, SyncStatus::Queued)
|| matches!(old_status, SyncStatus::Syncing)
{
repo.pub_sync_status = repo.sync_status.clone();
}

if matches!(
repo.sync_status,
SyncStatus::Error { .. } | SyncStatus::Done
) {
repo.locked = false;
}
if matches!(
repo.sync_status,
SyncStatus::Error { .. } | SyncStatus::Done
) {
repo.locked = false;
}

repo.sync_status.clone()
})?;
(repo.sync_status.clone(), old_status)
})?;

if let SyncStatus::Error { ref message } = new_status {
error!(?self.reporef, err=?message, "indexing failed");
} else {
debug!(?self.reporef, ?new_status, "new status");
}

if !matches!(new_status, SyncStatus::Queued) {
if !matches!(new_status, SyncStatus::Queued) && new_status != old_status {
self.pipes.status(new_status.clone());
}
Some(new_status)
Expand All @@ -563,7 +568,6 @@ impl SyncHandle {
Some(Ok(repo)) => {
let new_status = repo.sync_status.clone();
debug!(?self.reporef, ?new_status, "new status");
self.pipes.status(new_status);
Ok(repo)
}
Some(err) => err,
Expand Down
8 changes: 2 additions & 6 deletions server/bleep/src/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,12 +354,8 @@ impl Repository {

if shallow {
self.sync_status = SyncStatus::Shallow
} else {
if let Some(ref ff) = filter_update.file_filter {
self.file_filter = ff.patch_into(&self.file_filter);
}

self.sync_status = SyncStatus::Done
} else if let Some(ref ff) = filter_update.file_filter {
self.file_filter = ff.patch_into(&self.file_filter);
};
}
}
Expand Down