Try to improve performance of repository open

By using `open_ext` with `BARE`, we defer loading of the Git config,
which has been shown to be expensive.
This commit is contained in:
cloudhead 2024-05-13 12:58:38 +02:00
parent 8e541dcf58
commit cce46a3d8b
No known key found for this signature in database
1 changed files with 8 additions and 1 deletions

View File

@ -374,7 +374,14 @@ pub enum Validation {
impl Repository {
/// Open an existing repository.
pub fn open<P: AsRef<Path>>(path: P, id: RepoId) -> Result<Self, RepositoryError> {
let backend = git2::Repository::open_bare(path.as_ref())?;
let backend = git2::Repository::open_ext(
path.as_ref(),
git2::RepositoryOpenFlags::empty()
| git2::RepositoryOpenFlags::BARE
| git2::RepositoryOpenFlags::NO_DOTGIT
| git2::RepositoryOpenFlags::NO_SEARCH,
&[] as &[&std::ffi::OsStr],
)?;
Ok(Self { id, backend })
}