forked from mirrors/jj
git: on import_refs(), don't clobber view's heads with known HEAD@git
In colocated mid-size "linux" repo, this saves ~450ms needed to do enforce_view_invariants(). We could instead make add_head() to return early, but the condition would be a bit weird since HEAD@git is typically a parent of known heads, not a head itself.
This commit is contained in:
parent
5e3913bf56
commit
cf2c14296b
2 changed files with 10 additions and 4 deletions
|
@ -130,11 +130,13 @@ pub fn import_some_refs(
|
|||
// to `old_git_heads` because HEAD move doesn't automatically mean the old
|
||||
// HEAD branch has been rewritten.
|
||||
let head_commit_id = CommitId::from_bytes(head_git_commit.id().as_bytes());
|
||||
let head_commit = store.get_commit(&head_commit_id).unwrap();
|
||||
new_git_heads.insert("HEAD".to_string(), vec![head_commit_id.clone()]);
|
||||
prevent_gc(git_repo, &head_commit_id)?;
|
||||
mut_repo.add_head(&head_commit);
|
||||
mut_repo.set_git_head(RefTarget::Normal(head_commit_id));
|
||||
if !matches!(mut_repo.git_head(), Some(RefTarget::Normal(id)) if id == head_commit_id) {
|
||||
let head_commit = store.get_commit(&head_commit_id).unwrap();
|
||||
prevent_gc(git_repo, &head_commit_id)?;
|
||||
mut_repo.add_head(&head_commit);
|
||||
mut_repo.set_git_head(RefTarget::Normal(head_commit_id));
|
||||
}
|
||||
} else {
|
||||
mut_repo.clear_git_head();
|
||||
}
|
||||
|
|
|
@ -947,6 +947,10 @@ impl MutableRepo {
|
|||
self.view_mut().remove_git_ref(name);
|
||||
}
|
||||
|
||||
pub fn git_head(&self) -> Option<RefTarget> {
|
||||
self.view.with_ref(|v| v.git_head().cloned())
|
||||
}
|
||||
|
||||
pub fn set_git_head(&mut self, target: RefTarget) {
|
||||
self.view_mut().set_git_head(target);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue