Skip to content

Commit

Permalink
git_backend: inline prevent_gc() to bulk-update refs
Browse files Browse the repository at this point in the history
  • Loading branch information
yuja committed Jan 17, 2024
1 parent 96ee9bd commit afa72ff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 6 additions & 12 deletions lib/src/git_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.)
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit afa72ff

Please sign in to comment.