Skip to content

Commit

Permalink
fix: speedup HEAD detection in is_git()
Browse files Browse the repository at this point in the history
Previously it would always check with a `store` which has a fuzzy search
right now. Instead, we check once ourselves before trying to read HEAD
for validation.
  • Loading branch information
Byron committed Apr 26, 2023
1 parent 7543fab commit 7613249
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gix-discover/src/is.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ pub fn git(git_dir: impl AsRef<Path>) -> Result<crate::repository::Kind, crate::
};

{
// Fast-path: avoid doing the complete search if HEAD is already not there.
// TODO(reftable): use a ref-store to lookup HEAD if ref-tables should be supported, or detect ref-tables beforehand.
if !dot_git.join("HEAD").exists() {
return Err(crate::is_git::Error::MissingHead);
}
// We expect to be able to parse any ref-hash, so we shouldn't have to know the repos hash here.
// With ref-table, the has is probably stored as part of the ref-db itself, so we can handle it from there.
// In other words, it's important not to fail on detached heads here because we guessed the hash kind wrongly.
Expand Down
2 changes: 2 additions & 0 deletions gix-discover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ pub mod is_git {
pub enum Error {
#[error("Could not find a valid HEAD reference")]
FindHeadRef(#[from] gix_ref::file::find::existing::Error),
#[error("Missing HEAD at '.git/HEAD'")]
MissingHead,
#[error("Expected HEAD at '.git/HEAD', got '.git/{}'", .name)]
MisplacedHead { name: bstr::BString },
#[error("Expected an objects directory at '{}'", .missing.display())]
Expand Down

0 comments on commit 7613249

Please sign in to comment.