in focus/internals/src/lib/index/content_hash.rs [382:408]
fn content_hash_tree_path(ctx: &HashContext, path: &Path) -> Result<ContentHash> {
if let Some(hash) = ctx.caches.borrow().tree_path_cache.get(path) {
return Ok(hash.clone());
}
let mut buf = String::new();
write!(
&mut buf,
"PathBufV{VERSION}({tree_id})",
tree_id = get_tree_path_id(ctx.head_tree, path).map_err(Error::ReadTreeEntry)?,
)?;
let hash = git2::Oid::hash_object(git2::ObjectType::Blob, buf.as_bytes())
.map_err(Error::HashObject)?;
let hash = ContentHash(hash);
if let Some(old_value) = ctx
.caches
.borrow_mut()
.tree_path_cache
.insert(path.to_owned(), hash.clone())
{
if old_value != hash {
error!(key = ?path, ?old_value, new_value = ?hash, "Non-deterministic content hashing for path");
}
}
Ok(hash)
}