Merge pull request #2319 from gitbutlerapp/speed-up-is_remote-check

speed up is_remote check
This commit is contained in:
Nikita Galaiko 2024-01-19 08:40:29 +01:00 committed by GitHub
commit 53e30ebee8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -786,12 +786,20 @@ pub fn list_virtual_branches(
} }
let mut is_integrated = false; let mut is_integrated = false;
let mut is_remote = false;
// find all commits on head that are not on target.sha // find all commits on head that are not on target.sha
let commits = project_repository let commits = project_repository
.log(branch.head, LogUntil::Commit(default_target.sha)) .log(branch.head, LogUntil::Commit(default_target.sha))
.context(format!("failed to get log for branch {}", branch.name))? .context(format!("failed to get log for branch {}", branch.name))?
.iter() .iter()
.map(|commit| { .map(|commit| {
is_remote = if !is_remote {
pushed_commits.contains_key(&commit.id())
} else {
is_remote
};
// only check for integration if we haven't already found an integration // only check for integration if we haven't already found an integration
is_integrated = if !is_integrated { is_integrated = if !is_integrated {
is_commit_integrated(project_repository, &default_target, commit)? is_commit_integrated(project_repository, &default_target, commit)?
@ -803,8 +811,8 @@ pub fn list_virtual_branches(
project_repository, project_repository,
branch, branch,
commit, commit,
Some(&pushed_commits),
is_integrated, is_integrated,
is_remote,
) )
}) })
.collect::<Result<Vec<_>>>()?; .collect::<Result<Vec<_>>>()?;
@ -1063,18 +1071,13 @@ fn commit_to_vbranch_commit(
repository: &project_repository::Repository, repository: &project_repository::Repository,
branch: &branch::Branch, branch: &branch::Branch,
commit: &git::Commit, commit: &git::Commit,
upstream_commits: Option<&HashMap<git::Oid, bool>>,
is_integrated: bool, is_integrated: bool,
is_remote: bool,
) -> Result<VirtualBranchCommit> { ) -> Result<VirtualBranchCommit> {
let timestamp = u128::try_from(commit.time().seconds())?; let timestamp = u128::try_from(commit.time().seconds())?;
let signature = commit.author(); let signature = commit.author();
let message = commit.message().unwrap().to_string(); let message = commit.message().unwrap().to_string();
let is_remote = match upstream_commits {
Some(commits) => commits.contains_key(&commit.id()),
None => true,
};
let files = let files =
list_virtual_commit_files(repository, commit).context("failed to list commit files")?; list_virtual_commit_files(repository, commit).context("failed to list commit files")?;