Show "Restore Checkpoint" only when there were changes (#27243)
Release Notes: - N/A --------- Co-authored-by: Agus Zubiaga <hi@aguz.me> Co-authored-by: Bennet Bo Fenner <bennetbo@gmx.de> Co-authored-by: Danilo Leal <daniloleal09@gmail.com>
This commit is contained in:
parent
9d965bc98a
commit
e14ebcf267
9 changed files with 350 additions and 112 deletions
|
@ -580,6 +580,44 @@ impl GitStore {
|
|||
})
|
||||
}
|
||||
|
||||
/// Compares two checkpoints, returning true if they are equal.
|
||||
pub fn compare_checkpoints(
|
||||
&self,
|
||||
left: GitStoreCheckpoint,
|
||||
mut right: GitStoreCheckpoint,
|
||||
cx: &App,
|
||||
) -> Task<Result<bool>> {
|
||||
let repositories_by_dot_git_abs_path = self
|
||||
.repositories
|
||||
.values()
|
||||
.map(|repo| (repo.read(cx).dot_git_abs_path.clone(), repo))
|
||||
.collect::<HashMap<_, _>>();
|
||||
|
||||
let mut tasks = Vec::new();
|
||||
for (dot_git_abs_path, left_checkpoint) in left.checkpoints_by_dot_git_abs_path {
|
||||
if let Some(right_checkpoint) = right
|
||||
.checkpoints_by_dot_git_abs_path
|
||||
.remove(&dot_git_abs_path)
|
||||
{
|
||||
if let Some(repository) = repositories_by_dot_git_abs_path.get(&dot_git_abs_path) {
|
||||
let compare = repository
|
||||
.read(cx)
|
||||
.compare_checkpoints(left_checkpoint, right_checkpoint);
|
||||
tasks.push(async move { compare.await? });
|
||||
}
|
||||
} else {
|
||||
return Task::ready(Ok(false));
|
||||
}
|
||||
}
|
||||
cx.background_spawn(async move {
|
||||
Ok(future::try_join_all(tasks)
|
||||
.await?
|
||||
.into_iter()
|
||||
.all(|result| result))
|
||||
})
|
||||
}
|
||||
|
||||
/// Blames a buffer.
|
||||
pub fn blame_buffer(
|
||||
&self,
|
||||
buffer: &Entity<Buffer>,
|
||||
|
@ -3266,6 +3304,21 @@ impl Repository {
|
|||
}
|
||||
})
|
||||
}
|
||||
|
||||
pub fn compare_checkpoints(
|
||||
&self,
|
||||
left: GitRepositoryCheckpoint,
|
||||
right: GitRepositoryCheckpoint,
|
||||
) -> oneshot::Receiver<Result<bool>> {
|
||||
self.send_job(move |repo, cx| async move {
|
||||
match repo {
|
||||
RepositoryState::Local(git_repository) => {
|
||||
git_repository.compare_checkpoints(left, right, cx).await
|
||||
}
|
||||
RepositoryState::Remote { .. } => Err(anyhow!("not implemented yet")),
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
fn get_permalink_in_rust_registry_src(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue