ok/jj
1
0
Fork 0
forked from mirrors/jj

git_backend: inline prevent_gc() to bulk-update refs

This commit is contained in:
Yuya Nishihara 2024-01-13 13:20:42 +09:00
parent 96ee9bdb9f
commit afa72ff496
2 changed files with 7 additions and 13 deletions

View file

@ -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,

View file

@ -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