From 9898e7bf435771856dded74de6271bc23f8e2265 Mon Sep 17 00:00:00 2001 From: Nikita Galaiko Date: Fri, 19 Jan 2024 08:08:59 +0100 Subject: [PATCH] speed up is_remote check by assuming parents are remote --- gitbutler-app/src/virtual_branches/virtual.rs | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/gitbutler-app/src/virtual_branches/virtual.rs b/gitbutler-app/src/virtual_branches/virtual.rs index 24f217fb3..22f034147 100644 --- a/gitbutler-app/src/virtual_branches/virtual.rs +++ b/gitbutler-app/src/virtual_branches/virtual.rs @@ -786,12 +786,20 @@ pub fn list_virtual_branches( } let mut is_integrated = false; + let mut is_remote = false; + // find all commits on head that are not on target.sha let commits = project_repository .log(branch.head, LogUntil::Commit(default_target.sha)) .context(format!("failed to get log for branch {}", branch.name))? .iter() .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 is_integrated = if !is_integrated { is_commit_integrated(project_repository, &default_target, commit)? @@ -803,8 +811,8 @@ pub fn list_virtual_branches( project_repository, branch, commit, - Some(&pushed_commits), is_integrated, + is_remote, ) }) .collect::>>()?; @@ -1063,18 +1071,13 @@ fn commit_to_vbranch_commit( repository: &project_repository::Repository, branch: &branch::Branch, commit: &git::Commit, - upstream_commits: Option<&HashMap>, is_integrated: bool, + is_remote: bool, ) -> Result { let timestamp = u128::try_from(commit.time().seconds())?; let signature = commit.author(); let message = commit.message().unwrap().to_string(); - let is_remote = match upstream_commits { - Some(commits) => commits.contains_key(&commit.id()), - None => true, - }; - let files = list_virtual_commit_files(repository, commit).context("failed to list commit files")?;