From 3a1720459d0858d8226756d297c976d9c496b0ae Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Fri, 8 Sep 2023 11:05:54 +0900 Subject: [PATCH] git: import new head commits all at once --- lib/src/git.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/src/git.rs b/lib/src/git.rs index d6066f8648..45505efd5b 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -219,10 +219,19 @@ pub fn import_some_refs( // TODO: It might be better to obtain both git_repo and git_backend from // mut_repo, and return error if the repo isn't backed by Git. let git_backend = store.backend_impl().downcast_ref::().unwrap(); + // Bulk-import all reachable commits to reduce overhead of table merging. + let head_ids = itertools::chain( + &changed_git_head, + changed_git_refs.values().map(|(_, new_target)| new_target), + ) + .flat_map(|target| target.added_ids()); + let heads_imported = git_backend.import_head_commits(head_ids).is_ok(); let mut head_commits = Vec::new(); - // TODO: Import commits in bulk (but we'll need to adjust error handling.) let get_commit = |id| { - git_backend.import_head_commits([id])?; + // If bulk-import failed, try again to find bad head or ref. + if !heads_imported { + git_backend.import_head_commits([id])?; + } store.get_commit(id) }; if let Some(new_head_target) = &changed_git_head {