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)
| 220 | /// directory, is never projected into Git, and a missing file reads as an |
| 221 | /// empty map; malformed or future-versioned maps fail closed. |
| 222 | pub 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)] |
no test coverage detected