Repository: zed-industries/zed
File: crates/git_graph/src/git_graph.rs (Rust)

Code before:

        CommitView::open(
            commit_entry.data.sha.to_string(),
            repository.downgrade(),
            self.workspace.clone(),
            None,
            None,
            window,
            cx,
        );
    }

    fn get_remote(
        &self,
        repository: &Repository,
        _window: &mut Window,
        cx: &mut App,
    ) -> Option<GitRemote> {
        let remote_url = repository.default_remote_url()?;
        let provider_registry = GitHostingProviderRegistry::default_global(cx);
        let (provider, parsed) = parse_git_remote_url(provider_registry, &remote_url)?;
        Some(GitRemote {
            host: provider,
            owner: parsed.owner.into(),
            repo: parsed.repo.into(),
        })
    }

    fn render_loading_spinner(&self, cx: &App) -> AnyElement {
        let rems = TextSize::Large.rems(cx);
        Icon::new(IconName::LoadCircle)
            .size(IconSize::Custom(rems))
            .color(Color::Accent)
            .with_rotate_animation(3)
            .into_any_element()
    }

    fn render_commit_detail_panel(
        &self,
        window: &mut Window,
        cx: &mut Context<Self>,
    ) -> impl IntoElement {
        let Some(selected_idx) = self.selected_entry_idx else {
            return Empty.into_any_element();
        };

        let Some(commit_entry) = self.graph_data.commits.get(selected_idx) else {
            return Empty.into_any_element();
        };

        let Some(repository) = self.get_selected_repository(cx) else {

Review comment (suggestion):
We should probably make a hash map of commit shas to their row in the graph, it will be needed for git search as well. This isn't a blocker, just something to add to our todo list in the future

Code after:
        self._commit_diff_task = Some(cx.spawn(async move |this, cx| {
            if let Ok(Ok(diff)) = diff_receiver.await {
                this.update(cx, |this, cx| {
                    let stats = compute_diff_stats(&diff);
                    this.selected_commit_diff = Some(diff);
                    this.selected_commit_diff_stats = Some(stats);
                    cx.notify();
                })
                .ok();
            }
        }));

        cx.notify();
    }

    pub fn select_commit_by_sha(&mut self, sha: &str, cx: &mut Context<Self>) {
        let Ok(oid) = sha.parse::<Oid>() else {
            return;
        };
        for (idx, commit) in self.graph_data.commits.iter().enumerate() {
            if commit.data.sha == oid {
                self.pending_select_sha = None;
                self.select_entry(idx, cx);
                return;
            }
        }
        self.pending_select_sha = Some((sha.to_string(), PENDING_SELECT_MAX_RETRIES));
    }

    fn retry_pending_select(&mut self, cx: &mut Context<Self>) {
        let Some((sha, retries_remaining)) = self.pending_select_sha.take() else {
            return;
        };
        if let Ok(oid) = sha.parse::<Oid>() {
            for (idx, commit) in self.graph_data.commits.iter().enumerate() {
                if commit.data.sha == oid {
                    self.select_entry(idx, cx);
                    return;
                }
            }
        }
        if retries_remaining > 0 {
            self.pending_select_sha = Some((sha, retries_remaining - 1));
        }
    }

    fn open_selected_commit_view(&mut self, window: &mut Window, cx: &mut Context<Self>) {
        let Some(selected_entry_index) = self.selected_entry_idx else {
            return;
        };