use std::path::Path; use crate::cache::CacheKey; pub const NS_BLOB: u8 = b'B'; pub const NS_BLOB_SIZE: u8 = b'S'; pub const NS_BLOB_EXISTS: u8 = b'E'; pub const NS_COMMIT: u8 = b'C'; pub const NS_REV: u8 = b'r'; pub const NS_TREE_ENTRIES: u8 = b't'; pub const NS_LFS: u8 = b'l'; pub fn encode(ns: u8, suffix: &[u8]) -> CacheKey { let mut key = Vec::with_capacity(1 + suffix.len()); key.push(ns); key.extend_from_slice(suffix); key } pub fn object_key(ns: u8, oid: &gix::ObjectId) -> CacheKey { encode(ns, oid.as_bytes()) } pub fn rev_key(repo_dir: &Path, revision: &str) -> CacheKey { let path = repo_dir.as_os_str().as_encoded_bytes(); let mut key = Vec::with_capacity(1 + 4 + path.len() + 1 + revision.len()); key.push(NS_REV); key.extend_from_slice(&(path.len() as u32).to_le_bytes()); key.extend_from_slice(path); key.push(0); key.extend_from_slice(revision.as_bytes()); key } /// Key for a per-repository blob-existence probe. Blob *existence* is /// repository-scoped (a given oid may be present in one repo's object store but /// absent in another), unlike blob *content* which is content-addressed. The /// canonicalised repo directory is therefore part of the key. pub fn blob_exists_key(repo_dir: &Path, oid: &gix::ObjectId) -> CacheKey { let path = repo_dir.as_os_str().as_encoded_bytes(); let oid_bytes = oid.as_bytes(); let mut key = Vec::with_capacity(1 + 4 + path.len() + 1 + oid_bytes.len()); key.push(NS_BLOB_EXISTS); key.extend_from_slice(&(path.len() as u32).to_le_bytes()); key.extend_from_slice(path); key.push(0); key.extend_from_slice(oid_bytes); key }