Skip to content

armgit / zed

Public Imported from GitHub
0

Code at the speed of thought – Zed is a high-performance, multiplayer code editor from the creators of Atom and Tree-sitter.

git_ui: Fix stale loading message in git history pane (#58133)

Lukas Wirth0711d9e42bcb
diff --git a/crates/git_ui/src/git_panel.rs b/crates/git_ui/src/git_panel.rs
index feb843d4b4a..84c1cc63f61 100644
--- a/crates/git_ui/src/git_panel.rs
+++ b/crates/git_ui/src/git_panel.rs
@@ -695,7 +695,7 @@ pub struct GitPanel {
stash_entries: GitStash,
active_tab: GitPanelTab,
commit_history_scroll_handle: UniformListScrollHandle,
- commit_history_shas: Vec<Oid>,
+ commit_history_shas: Option<Vec<Oid>>,
focused_history_entry: Option<usize>,
history_keyboard_nav: bool,
_repo_subscriptions: Vec<Subscription>,
@@ -892,7 +892,7 @@ impl GitPanel {
stash_entries: Default::default(),
active_tab: GitPanelTab::Changes,
commit_history_scroll_handle: UniformListScrollHandle::new(),
- commit_history_shas: Vec::new(),
+ commit_history_shas: None,
focused_history_entry: None,
history_keyboard_nav: false,
_repo_subscriptions: Vec::new(),
@@ -5088,7 +5088,7 @@ impl GitPanel {
}
fn select_next_history_entry(&mut self, cx: &mut Context<Self>) {
- let count = self.commit_history_shas.len();
+ let count = self.commit_history_shas.as_ref().map_or(0, Vec::len);
if count == 0 {
return;
}
@@ -5104,7 +5104,7 @@ impl GitPanel {
}
fn select_previous_history_entry(&mut self, cx: &mut Context<Self>) {
- let count = self.commit_history_shas.len();
+ let count = self.commit_history_shas.as_ref().map_or(0, Vec::len);
if count == 0 {
return;
}
@@ -5123,7 +5123,7 @@ impl GitPanel {
let Some(index) = self.focused_history_entry else {
return;
};
- let Some(sha) = self.commit_history_shas.get(index) else {
+ let Some(sha) = self.commit_history_shas.as_ref().and_then(|s| s.get(index)) else {
return;
};
let Some(active_repository) = self.active_repository.as_ref() else {
@@ -5171,7 +5171,7 @@ impl GitPanel {
}
GitPanelTab::Changes => {
self.focus_handle.focus(window, cx);
- self.commit_history_shas.clear();
+ self.commit_history_shas.take();
self.focused_history_entry = None;
self._repo_subscriptions.clear();
}
@@ -5237,10 +5237,10 @@ impl GitPanel {
let log_source = LogSource::Branch(branch_name.into());
let log_order = LogOrder::DateOrder;
- self.commit_history_shas = active_repository.update(cx, |repository, cx| {
+ self.commit_history_shas = Some(active_repository.update(cx, |repository, cx| {
let response = repository.graph_data(log_source, log_order, 0..usize::MAX, cx);
response.commits.iter().map(|commit| commit.sha).collect()
- });
+ }));
}
fn git_remote(&self, cx: &mut App) -> Option<GitRemote> {
@@ -5260,14 +5260,10 @@ impl GitPanel {
window: &mut Window,
cx: &mut Context<Self>,
) -> Option<impl IntoElement> {
- if self.commit_history_shas.is_empty() {
- return None;
- }
-
+ let shas = self.commit_history_shas.clone()?;
let active_repository = self.active_repository.as_ref()?;
let workspace = self.workspace.clone();
let repo_weak = active_repository.downgrade();
- let shas = self.commit_history_shas.clone();
let item_count = shas.len();
let commit_history_scroll_handle = self.commit_history_scroll_handle.clone();
let remote = self.git_remote(cx);