From afa72ff4962f4007f6eb472573bed68cdffe1f36 Mon Sep 17 00:00:00 2001 From: Yuya Nishihara Date: Sat, 13 Jan 2024 13:20:42 +0900 Subject: [PATCH] git_backend: inline prevent_gc() to bulk-update refs --- lib/src/git.rs | 2 +- lib/src/git_backend.rs | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/lib/src/git.rs b/lib/src/git.rs index 1ae2d1876..d95b8c8ac 100644 --- a/lib/src/git.rs +++ b/lib/src/git.rs @@ -259,7 +259,7 @@ pub fn import_some_refs( } = diff_refs_to_import(mut_repo.view(), &git_repo, git_ref_filter)?; // Bulk-import all reachable Git commits to the backend to reduce overhead of - // table merging. + // table merging and ref updates. let index = mut_repo.index(); let missing_head_ids = itertools::chain( &changed_git_head, diff --git a/lib/src/git_backend.rs b/lib/src/git_backend.rs index 3a793e6b8..6c4bf3e92 100644 --- a/lib/src/git_backend.rs +++ b/lib/src/git_backend.rs @@ -352,9 +352,9 @@ impl GitBackend { // Create no-gc ref even if known to the extras table. Concurrent GC // process might have deleted the no-gc ref. let locked_repo = self.lock_git_repo(); - for &id in &head_ids { - prevent_gc(&locked_repo, id)?; - } + locked_repo + .edit_references(head_ids.iter().copied().map(to_no_gc_ref_update)) + .map_err(|err| BackendError::Other(Box::new(err)))?; // These commits are imported from Git. Make our change ids persist (otherwise // future write_commit() could reassign new change id.) @@ -584,14 +584,6 @@ fn deserialize_extras(commit: &mut Commit, bytes: &[u8]) { } } -/// Creates a ref in refs/jj/. Used for preventing GC of commits we create. -fn prevent_gc(git_repo: &gix::Repository, id: &CommitId) -> Result<(), BackendError> { - git_repo - .edit_reference(to_no_gc_ref_update(id)) - .map_err(|err| BackendError::Other(Box::new(err)))?; - Ok(()) -} - /// Returns `RefEdit` that will create a ref in `refs/jj/keep` if not exist. /// Used for preventing GC of commits we create. fn to_no_gc_ref_update(id: &CommitId) -> gix::refs::transaction::RefEdit { @@ -1060,7 +1052,9 @@ impl Backend for GitBackend { // Everything up to this point had no permanent effect on the repo except // GC-able objects - prevent_gc(&locked_repo, &id)?; + locked_repo + .edit_reference(to_no_gc_ref_update(&id)) + .map_err(|err| BackendError::Other(Box::new(err)))?; // Update the signature to match the one that was actually written to the object // store