git: Don't call git2::Repository::find_remote for every blamed buffer (#44107)

We already store the remote URLs for `origin` and `upstream` in the
`RepositorySnapshot`, so just use that data. Follow-up to #44092.

Release Notes:

- N/A
This commit is contained in:
Cole Miller
2025-12-04 13:25:30 -05:00
committed by GitHub
parent 74a1b5d14d
commit d5ed9d3e3a
11 changed files with 51 additions and 52 deletions
+1 -7
View File
@@ -19,7 +19,6 @@ pub use git2 as libgit;
pub struct Blame {
pub entries: Vec<BlameEntry>,
pub messages: HashMap<Oid, String>,
pub remote_url: Option<String>,
}
#[derive(Clone, Debug, Default)]
@@ -36,7 +35,6 @@ impl Blame {
working_directory: &Path,
path: &RepoPath,
content: &Rope,
remote_url: Option<String>,
) -> Result<Self> {
let output = run_git_blame(git_binary, working_directory, path, content).await?;
let mut entries = parse_git_blame(&output)?;
@@ -53,11 +51,7 @@ impl Blame {
.await
.context("failed to get commit messages")?;
Ok(Self {
entries,
messages,
remote_url,
})
Ok(Self { entries, messages })
}
}
+10 -21
View File
@@ -1494,28 +1494,17 @@ impl GitRepository for RealGitRepository {
let git_binary_path = self.any_git_binary_path.clone();
let executor = self.executor.clone();
async move {
let remote_url = if let Some(remote_url) = self.remote_url("upstream").await {
Some(remote_url)
} else if let Some(remote_url) = self.remote_url("origin").await {
Some(remote_url)
} else {
None
};
executor
.spawn(async move {
crate::blame::Blame::for_path(
&git_binary_path,
&working_directory?,
&path,
&content,
remote_url,
)
.await
})
executor
.spawn(async move {
crate::blame::Blame::for_path(
&git_binary_path,
&working_directory?,
&path,
&content,
)
.await
}
.boxed()
})
.boxed()
}
fn file_history(&self, path: RepoPath) -> BoxFuture<'_, Result<FileHistory>> {