diff --git a/eden/mononoke/git/git_types/src/store.rs b/eden/mononoke/git/git_types/src/store.rs index 501039a0088d1..cf774ab690baa 100644 --- a/eden/mononoke/git/git_types/src/store.rs +++ b/eden/mononoke/git/git_types/src/store.rs @@ -17,6 +17,7 @@ use filestore::fetch_with_size; use filestore::hash_bytes; use filestore::Sha1IncrementalHasher; use futures::TryStreamExt; +use gix_hash::ObjectId; use gix_object::WriteTo; use mononoke_types::hash::GitSha1; use mononoke_types::hash::RichGitSha1; @@ -117,7 +118,7 @@ where { // In git, empty tree is a special object: it's present in every git repo and not persisted in // the storage. - if git_hash == gix_hash::ObjectId::empty_tree(gix_hash::Kind::Sha1) { + if git_hash == ObjectId::empty_tree(gix_hash::Kind::Sha1) { return Ok(gix_object::Object::Tree(gix_object::Tree::empty())); } let raw_bytes = fetch_non_blob_git_object_bytes(ctx, blobstore, git_hash).await?; @@ -163,6 +164,13 @@ impl GitIdentifier { GitIdentifier::Basic(_) => true, // May or may not be a blob, we can't know } } + + pub fn to_object_id(&self) -> Result { + match self { + GitIdentifier::Rich(rich_sha) => Ok(rich_sha.to_object_id()?), + GitIdentifier::Basic(basic_sha) => Ok(basic_sha.to_object_id()?), + } + } } async fn maybe_fetch_blob_bytes( @@ -330,7 +338,6 @@ mod test { use fbinit::FacebookInit; use filestore::FilestoreConfig; use fixtures::TestRepoFixture; - use gix_hash::ObjectId; use gix_object::Object; use gix_object::Tag; use mononoke_macros::mononoke; diff --git a/eden/mononoke/git/protocol/src/store.rs b/eden/mononoke/git/protocol/src/store.rs index 9d5ba948f340e..583405abd6077 100644 --- a/eden/mononoke/git/protocol/src/store.rs +++ b/eden/mononoke/git/protocol/src/store.rs @@ -51,10 +51,7 @@ pub(crate) enum ObjectIdentifierType { impl ObjectIdentifierType { pub(crate) fn to_object_id(&self) -> Result { match self { - Self::AllObjects(ident) => match ident { - GitIdentifier::Basic(sha) => sha.to_object_id(), - GitIdentifier::Rich(rich_sha) => rich_sha.to_object_id(), - }, + Self::AllObjects(ident) => ident.to_object_id(), Self::NonBlobObjects(oid) => Ok(*oid), } }