(
repo: &git2::Repository,
object: &GitObjectId,
)
| 4734 | } |
| 4735 | |
| 4736 | pub(super) fn git_oid_from_object( |
| 4737 | repo: &git2::Repository, |
| 4738 | object: &GitObjectId, |
| 4739 | ) -> Result<git2::Oid, RepositoryError> { |
| 4740 | let hex = git_object_hex(object)?; |
| 4741 | let oid = git2::Oid::from_str(&hex).map_err(|error| RepositoryError::InvalidRepository { |
| 4742 | reason: format!("cannot parse Git object id '{hex}': {error}"), |
| 4743 | })?; |
| 4744 | let expected_width = match object.algorithm() { |
| 4745 | GitHashAlgorithm::Sha1 => 20, |
| 4746 | GitHashAlgorithm::Sha256 => 32, |
| 4747 | }; |
| 4748 | if oid.as_bytes().len() != expected_width { |
| 4749 | return Err(RepositoryError::InvalidRepository { |
| 4750 | reason: format!( |
| 4751 | "Git object id '{hex}' width {} disagrees with the repository format", |
| 4752 | oid.as_bytes().len() |
| 4753 | ), |
| 4754 | }); |
| 4755 | } |
| 4756 | let _ = repo; |
| 4757 | Ok(oid) |
| 4758 | } |
| 4759 | |
| 4760 | fn unsupported_effect_error(target: &EffectTarget) -> RepositoryError { |
| 4761 | RepositoryError::InvalidOperation { |
no test coverage detected