Calling Git2Backend::repo() twice in one scope self-deadlocks the repo mutex
Symptom#
A backend method hangs forever in tests: cargo test -p rgit-git --test it ... prints "has been running for over 60 seconds" and never finishes, with no error, no output and no CPU use.
Cause#
In rgit's crates/rgit-git/src/git_repo.rs, self.repo() returns a MutexGuard on a std Mutex that is not reentrant. Holding a guard from let repo = self.repo(); and then calling self.repo() again (e.g. to pass &mut self.repo() into rebase::replay) waits on the same lock forever, because the first guard lives to the end of the block.
Fix#
Read everything you need under one handle inside a block, return the plain values, and only then take the handle again:
let parent = ;
cratereplay
Evidence#
In rgit, Git2Backend::drop_commit did let repo = self.repo(); ... crate::rebase::replay(&mut self.repo(), ...); two of its three integration tests hung until the 10-minute timeout. Scoping the first guard into a block made cargo test -p rgit-git --test it history::drop_commit pass in 0.3s.