MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / read_head_map

Function read_head_map

atomic-repository/src/repository/anchor.rs:222–243  ·  view source on GitHub ↗

Read the workspace-local head map. It lives under the shim-private directory, is never projected into Git, and a missing file reads as an empty map; malformed or future-versioned maps fail closed.

(root: &Path)

Source from the content-addressed store, hash-verified

220/// directory, is never projected into Git, and a missing file reads as an
221/// empty map; malformed or future-versioned maps fail closed.
222pub fn read_head_map(root: &Path) -> Result<BTreeMap<String, HeadMapEntry>, RepositoryError> {
223 let path = root.join(HEAD_MAP_RELATIVE);
224 let bytes = match fs::read(&path) {
225 Ok(bytes) => bytes,
226 Err(error) if error.kind() == std::io::ErrorKind::NotFound => return Ok(BTreeMap::new()),
227 Err(error) => {
228 return Err(RepositoryError::InvalidRepository {
229 reason: format!("cannot read shim head map '{}': {error}", path.display()),
230 })
231 }
232 };
233 let wire: HeadMapWire =
234 serde_json::from_slice(&bytes).map_err(|error| RepositoryError::InvalidRepository {
235 reason: format!("shim head map '{}' is malformed: {error}", path.display()),
236 })?;
237 if wire.version != 1 {
238 return Err(RepositoryError::InvalidRepository {
239 reason: format!("unsupported shim head map version {}", wire.version),
240 });
241 }
242 Ok(wire.mappings)
243}
244
245/// The §7.5 view a detached commit imports into (CB-7B reconcile routing).
246#[derive(Debug, Clone, PartialEq, Eq)]

Calls 2

readFunction · 0.50
kindMethod · 0.45

Tested by

no test coverage detected