gitdataai/lib/git/cmd/blob/blob_helper.rs
2026-05-30 01:38:40 +08:00

28 lines
771 B
Rust

use crate::{
bare::GitBare,
cmd::oid::ObjectId,
errors::{GitError, GitResult},
};
impl GitBare {
pub fn blob_is_binary(&self, id: ObjectId) -> GitResult<bool> {
let repo = self.gix_repo()?;
let gix_id: gix::hash::ObjectId = (&id).try_into()?;
let blob = repo
.find_blob(gix_id)
.map_err(|_| GitError::ObjectNotFound(id.as_str().to_string()))?;
let check_len = std::cmp::min(8000, blob.data.len());
let is_binary = blob.data[..check_len].contains(&0);
Ok(is_binary)
}
pub fn blob_exists(&self, id: ObjectId) -> GitResult<bool> {
let repo = self.gix_repo()?;
let gix_id: gix::hash::ObjectId = (&id).try_into()?;
Ok(repo.has_object(gix_id))
}
}