mirror of
https://github.com/martinvonz/jj.git
synced 2025-01-05 02:53:12 +00:00
git: handle lock error that could occur while adding GC-preventing refs
If I spawned ~20 "jj status &" processes, some of them panicked there. Spotted when debugging #924.
This commit is contained in:
parent
b01614bbdd
commit
1675aec388
1 changed files with 12 additions and 11 deletions
|
@ -59,15 +59,16 @@ fn local_branch_name_to_ref_name(branch: &str) -> String {
|
||||||
format!("refs/heads/{branch}")
|
format!("refs/heads/{branch}")
|
||||||
}
|
}
|
||||||
|
|
||||||
fn prevent_gc(git_repo: &git2::Repository, id: &CommitId) {
|
fn prevent_gc(git_repo: &git2::Repository, id: &CommitId) -> Result<(), git2::Error> {
|
||||||
git_repo
|
// If multiple processes do git::import_refs() in parallel, this can fail to
|
||||||
.reference(
|
// acquire a lock file even with force=true.
|
||||||
&format!("{}{}", NO_GC_REF_NAMESPACE, id.hex()),
|
git_repo.reference(
|
||||||
Oid::from_bytes(id.as_bytes()).unwrap(),
|
&format!("{}{}", NO_GC_REF_NAMESPACE, id.hex()),
|
||||||
true,
|
Oid::from_bytes(id.as_bytes()).unwrap(),
|
||||||
"used by jj",
|
true,
|
||||||
)
|
"used by jj",
|
||||||
.unwrap();
|
)?;
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reflect changes made in the underlying Git repo in the Jujutsu repo.
|
/// Reflect changes made in the underlying Git repo in the Jujutsu repo.
|
||||||
|
@ -116,7 +117,7 @@ pub fn import_some_refs(
|
||||||
let head_commit_id = CommitId::from_bytes(head_git_commit.id().as_bytes());
|
let head_commit_id = CommitId::from_bytes(head_git_commit.id().as_bytes());
|
||||||
let head_commit = store.get_commit(&head_commit_id).unwrap();
|
let head_commit = store.get_commit(&head_commit_id).unwrap();
|
||||||
new_git_heads.insert("HEAD".to_string(), vec![head_commit_id.clone()]);
|
new_git_heads.insert("HEAD".to_string(), vec![head_commit_id.clone()]);
|
||||||
prevent_gc(git_repo, &head_commit_id);
|
prevent_gc(git_repo, &head_commit_id)?;
|
||||||
mut_repo.add_head(&head_commit);
|
mut_repo.add_head(&head_commit);
|
||||||
mut_repo.set_git_head(RefTarget::Normal(head_commit_id));
|
mut_repo.set_git_head(RefTarget::Normal(head_commit_id));
|
||||||
} else {
|
} else {
|
||||||
|
@ -157,7 +158,7 @@ pub fn import_some_refs(
|
||||||
let old_target = jj_view_git_refs.remove(&full_name);
|
let old_target = jj_view_git_refs.remove(&full_name);
|
||||||
let new_target = Some(RefTarget::Normal(id.clone()));
|
let new_target = Some(RefTarget::Normal(id.clone()));
|
||||||
if new_target != old_target {
|
if new_target != old_target {
|
||||||
prevent_gc(git_repo, &id);
|
prevent_gc(git_repo, &id)?;
|
||||||
mut_repo.set_git_ref(full_name.clone(), RefTarget::Normal(id.clone()));
|
mut_repo.set_git_ref(full_name.clone(), RefTarget::Normal(id.clone()));
|
||||||
let commit = store.get_commit(&id).unwrap();
|
let commit = store.get_commit(&id).unwrap();
|
||||||
mut_repo.add_head(&commit);
|
mut_repo.add_head(&commit);
|
||||||
|
|
Loading…
Reference in a new issue